Even better spread out hashCode for 2d vectors
This commit is contained in:
parent
44de54d9f9
commit
5ace88e01e
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=2.13.0
|
projectVersion=2.13.1
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -116,7 +116,14 @@ data class Vector2d(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
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 {
|
override fun toString(): String {
|
||||||
|
@ -116,7 +116,14 @@ data class Vector2f(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
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 {
|
override fun toString(): String {
|
||||||
|
@ -93,7 +93,14 @@ data class Vector2i(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
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 {
|
override fun toString(): String {
|
||||||
|
Loading…
Reference in New Issue
Block a user