diff options
| author | Russ Cox <rsc@golang.org> | 2014-08-06 16:47:54 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2014-08-06 16:47:54 -0400 |
| commit | 5fbcdb26613a819ba693ee3933f6e283e139630b (patch) | |
| tree | 991b2a39fa54562ca25a1ce03744e1ffb7f03172 /src/pkg/runtime | |
| parent | 1338f327b2deb81ba81107b5033d1b10e97e3abe (diff) | |
| download | go-5fbcdb26613a819ba693ee3933f6e283e139630b.tar.xz | |
runtime: use better hash for floating point inputs
Hashing on the bytes instead of the words does
a (much) better job of using all the bits, so that
maps of floats have linear performance.
LGTM=khr
R=golang-codereviews, khr
CC=adonovan, golang-codereviews
https://golang.org/cl/126720044
Diffstat (limited to 'src/pkg/runtime')
| -rw-r--r-- | src/pkg/runtime/alg.go | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/pkg/runtime/alg.go b/src/pkg/runtime/alg.go index 251374a946..f2bb202c68 100644 --- a/src/pkg/runtime/alg.go +++ b/src/pkg/runtime/alg.go @@ -75,7 +75,7 @@ func f32hash(a *float32, s, h uintptr) uintptr { case f != f: return c1 * (c0 ^ h ^ uintptr(fastrand2())) // any kind of NaN default: - return c1 * (c0 ^ h ^ uintptr(*(*uint32)(unsafe.Pointer(a)))) + return memhash(unsafe.Pointer(a), 4, h) } } @@ -86,11 +86,8 @@ func f64hash(a *float64, s, h uintptr) uintptr { return c1 * (c0 ^ h) // +0, -0 case f != f: return c1 * (c0 ^ h ^ uintptr(fastrand2())) // any kind of NaN - case ptrSize == 4: - x := (*[2]uintptr)(unsafe.Pointer(a)) - return c1 * (c0 ^ h ^ (x[1] * c1) ^ x[0]) default: - return c1 * (c0 ^ h ^ *(*uintptr)(unsafe.Pointer(a))) + return memhash(unsafe.Pointer(a), 8, h) } } |
