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.
Этот коммит содержится в:
родитель
4a2faeb2c5
коммит
a360c82b40
1 изменённых файлов: 2 добавлений и 2 удалений
|
@ -391,13 +391,13 @@ func hashmapInterfaceHash(itf interface{}) uint32 {
|
|||
case reflect.Array:
|
||||
var hash uint32
|
||||
for i := 0; i < x.Len(); i++ {
|
||||
hash |= hashmapInterfaceHash(valueInterfaceUnsafe(x.Index(i)))
|
||||
hash ^= hashmapInterfaceHash(valueInterfaceUnsafe(x.Index(i)))
|
||||
}
|
||||
return hash
|
||||
case reflect.Struct:
|
||||
var hash uint32
|
||||
for i := 0; i < x.NumField(); i++ {
|
||||
hash |= hashmapInterfaceHash(valueInterfaceUnsafe(x.Field(i)))
|
||||
hash ^= hashmapInterfaceHash(valueInterfaceUnsafe(x.Field(i)))
|
||||
}
|
||||
return hash
|
||||
default:
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче