This repository was archived by the owner on Feb 1, 2019. It is now read-only.
File tree 2 files changed +9
-8
lines changed
2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -22,14 +22,14 @@ type (
22
22
}
23
23
)
24
24
25
- const m64 = 18446744073709551615 // modulus (2**64-1)
26
-
27
25
func weight (x uint64 , y uint64 ) uint64 {
28
26
acc := x ^ y
27
+ // here used mmh3 64 bit finalizer
28
+ // https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash3.cpp#L81
29
29
acc ^= acc >> 33
30
- acc = ( acc * 0xff51afd7ed558ccd ) % m64
30
+ acc = acc * 0xff51afd7ed558ccd
31
31
acc ^= acc >> 33
32
- acc = ( acc * 0xc4ceb9fe1a85ec53 ) % m64
32
+ acc = acc * 0xc4ceb9fe1a85ec53
33
33
acc ^= acc >> 33
34
34
return acc
35
35
}
Original file line number Diff line number Diff line change 4
4
"encoding/binary"
5
5
"fmt"
6
6
"hash/fnv"
7
+ "math"
7
8
"reflect"
8
9
"strconv"
9
10
"testing"
@@ -54,14 +55,14 @@ func (h hashString) Hash() uint64 {
54
55
hs := fnv .New64 ()
55
56
// error always nil
56
57
_ , _ = hs .Write ([]byte (h ))
57
- return ( hs .Sum64 () >> 1 ) % m64
58
+ return hs .Sum64 () >> 1
58
59
}
59
60
60
61
func hash (key []byte ) uint64 {
61
62
h := fnv .New64 ()
62
63
// error always nil
63
64
_ , _ = h .Write (key )
64
- return (h .Sum64 () >> 1 ) ^ m64
65
+ return (h .Sum64 () >> 1 ) ^ math . MaxUint64
65
66
}
66
67
67
68
func mur3hash (key []byte ) uint64 {
@@ -184,7 +185,7 @@ func TestSortByWeight(t *testing.T) {
184
185
func TestUniformDistribution (t * testing.T ) {
185
186
var (
186
187
i uint64
187
- size = uint64 (4 )
188
+ size = uint64 (10 )
188
189
nodes = make ([]uint64 , 0 , size )
189
190
counts = make (map [uint64 ]uint64 )
190
191
key = make ([]byte , 16 )
@@ -202,7 +203,7 @@ func TestUniformDistribution(t *testing.T) {
202
203
}
203
204
204
205
mean := float64 (keys ) / float64 (len (nodes ))
205
- delta := mean * 0.002 // 0.2 %
206
+ delta := mean * 0.01 // 1 %
206
207
for node , count := range counts {
207
208
d := mean - float64 (count )
208
209
if d > delta || (0 - d ) > delta {
You can’t perform that action at this time.
0 commit comments