Skip to content

Commit 53e0653

Browse files
committed
Moving kickout bucket selection to fastrandn
For faster initialization through avoiding mutex on global random. Benchmark: goos: linux goarch: amd64 pkg: github.com/panmari/cuckoofilter cpu: 12th Gen Intel(R) Core(TM) i7-1265U │ master.bench │ fastrandn.bench │ │ sec/op │ sec/op vs base │ Filter_Insert-12 36.74n ± 3% 33.76n ± 1% -8.11% (p=0.000 n=100)
1 parent d389eb2 commit 53e0653

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

cuckoofilter.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"encoding/binary"
66
"fmt"
7-
"math/rand"
87
)
98

109
// maxCuckooKickouts is the maximum number of times reinsert
@@ -85,7 +84,7 @@ func (cf *Filter) insert(fp fingerprint, i uint) bool {
8584

8685
func (cf *Filter) reinsert(fp fingerprint, i uint) bool {
8786
for k := 0; k < maxCuckooKickouts; k++ {
88-
j := rand.Intn(bucketSize)
87+
j := fastrandn(bucketSize)
8988
// Swap fingerprint with bucket entry.
9089
cf.buckets[i][j], fp = fp, cf.buckets[i][j]
9190

0 commit comments

Comments
 (0)