@@ -26,7 +26,7 @@ func TestHashing(t *testing.T) {
2626
2727 // Override the hash function to return easier to reason about values. Assumes
2828 // the keys can be converted to an integer.
29- hash := New (3 , func (key []byte ) uint32 {
29+ hash := New (3 , 6 , func (key []byte ) uint32 {
3030 i , err := strconv .Atoi (string (key ))
3131 if err != nil {
3232 panic (err )
@@ -66,8 +66,8 @@ func TestHashing(t *testing.T) {
6666}
6767
6868func TestConsistency (t * testing.T ) {
69- hash1 := New (1 , nil )
70- hash2 := New (1 , nil )
69+ hash1 := New (1 , 6 , nil )
70+ hash2 := New (1 , 6 , nil )
7171
7272 hash1 .Add ("Bill" , "Bob" , "Bonny" )
7373 hash2 .Add ("Bob" , "Bonny" , "Bill" )
@@ -86,25 +86,31 @@ func TestConsistency(t *testing.T) {
8686
8787}
8888
89- func BenchmarkGet8 (b * testing.B ) { benchmarkGet (b , 8 ) }
90- func BenchmarkGet32 (b * testing.B ) { benchmarkGet (b , 32 ) }
91- func BenchmarkGet128 (b * testing.B ) { benchmarkGet (b , 128 ) }
92- func BenchmarkGet512 (b * testing.B ) { benchmarkGet (b , 512 ) }
89+ func BenchmarkGet8 (b * testing.B ) { benchmarkGet (b , 8 , 6 ) }
90+ func BenchmarkGet32 (b * testing.B ) { benchmarkGet (b , 32 , 6 ) }
91+ func BenchmarkGet128 (b * testing.B ) { benchmarkGet (b , 128 , 6 ) }
92+ func BenchmarkGet512 (b * testing.B ) { benchmarkGet (b , 512 , 6 ) }
9393
94- func benchmarkGet (b * testing.B , shards int ) {
94+ func benchmarkGet (b * testing.B , shards int , expansion int ) {
9595
96- hash := New (50 , nil )
96+ hash := New (50 , expansion , nil )
9797
9898 var buckets []string
9999 for i := 0 ; i < shards ; i ++ {
100100 buckets = append (buckets , fmt .Sprintf ("shard-%d" , i ))
101101 }
102102
103+ testStringCount := shards
104+ var testStrings []string
105+ for i := 0 ; i < testStringCount ; i ++ {
106+ testStrings = append (testStrings , fmt .Sprintf ("%d" , i ))
107+ }
108+
103109 hash .Add (buckets ... )
104110
105111 b .ResetTimer ()
106112
107113 for i := 0 ; i < b .N ; i ++ {
108- hash .Get (buckets [i & (shards - 1 )])
114+ hash .Get (testStrings [i & (testStringCount - 1 )])
109115 }
110116}
0 commit comments