diff --git a/gradle.properties b/gradle.properties index b784920..926924e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official specifyKotlinAsDependency=false projectGroup=ru.dbotthepony.kommons -projectVersion=2.13.0 +projectVersion=2.13.1 guavaDepVersion=33.0.0 gsonDepVersion=2.8.9 diff --git a/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2d.kt b/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2d.kt index 8c56853..9a0e8a8 100644 --- a/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2d.kt +++ b/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2d.kt @@ -116,7 +116,14 @@ data class Vector2d( } override fun hashCode(): Int { - return x.hashCode().rotateLeft(16) xor y.hashCode() + var x = x.hashCode().rotateLeft(16) xor y.hashCode() + // avalanche bits using murmur3 hash + x = x xor (x ushr 16) + x *= -0x7a143595 + x = x xor (x ushr 13) + x *= -0x3d4d51cb + x = x xor (x ushr 16) + return x } override fun toString(): String { diff --git a/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2f.kt b/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2f.kt index 36d3a32..57dccbc 100644 --- a/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2f.kt +++ b/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2f.kt @@ -116,7 +116,14 @@ data class Vector2f( } override fun hashCode(): Int { - return x.hashCode().rotateLeft(16) xor y.hashCode() + var x = x.hashCode().rotateLeft(16) xor y.hashCode() + // avalanche bits using murmur3 hash + x = x xor (x ushr 16) + x *= -0x7a143595 + x = x xor (x ushr 13) + x *= -0x3d4d51cb + x = x xor (x ushr 16) + return x } override fun toString(): String { diff --git a/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2i.kt b/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2i.kt index faa0559..ae00bb6 100644 --- a/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2i.kt +++ b/linear-algebra/src/main/kotlin/ru/dbotthepony/kommons/vector/Vector2i.kt @@ -93,7 +93,14 @@ data class Vector2i( } override fun hashCode(): Int { - return x.rotateLeft(16) xor y + var x = x.rotateLeft(16) xor y + // avalanche bits using murmur3 hash + x = x xor (x ushr 16) + x *= -0x7a143595 + x = x xor (x ushr 13) + x *= -0x3d4d51cb + x = x xor (x ushr 16) + return x } override fun toString(): String {