mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-25 06:49:04 +00:00
src/runtime: strengthen hash function for structs and arrays
Using `|` to combine hash values will slowly turn every bit on. Hashes combined with `^` with keep more entropy.
This commit is contained in:
@@ -391,13 +391,13 @@ func hashmapInterfaceHash(itf interface{}) uint32 {
|
|||||||
case reflect.Array:
|
case reflect.Array:
|
||||||
var hash uint32
|
var hash uint32
|
||||||
for i := 0; i < x.Len(); i++ {
|
for i := 0; i < x.Len(); i++ {
|
||||||
hash |= hashmapInterfaceHash(valueInterfaceUnsafe(x.Index(i)))
|
hash ^= hashmapInterfaceHash(valueInterfaceUnsafe(x.Index(i)))
|
||||||
}
|
}
|
||||||
return hash
|
return hash
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
var hash uint32
|
var hash uint32
|
||||||
for i := 0; i < x.NumField(); i++ {
|
for i := 0; i < x.NumField(); i++ {
|
||||||
hash |= hashmapInterfaceHash(valueInterfaceUnsafe(x.Field(i)))
|
hash ^= hashmapInterfaceHash(valueInterfaceUnsafe(x.Field(i)))
|
||||||
}
|
}
|
||||||
return hash
|
return hash
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user