-
Notifications
You must be signed in to change notification settings - Fork 37
/
options.go
64 lines (56 loc) · 1.19 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cfilter
import (
"hash"
"hash/fnv"
)
type option func(*CFilter)
// Size sets the number of buckets in the filter.
// Defaults to ((1 << 18) / BucketSize).
func Size(s uint) option {
return func(cf *CFilter) {
cf.size = s
}
}
// BucketSize sets the size of each bucket in the filter. Defaults to 4.
func BucketSize(s uint8) option {
return func(cf *CFilter) {
cf.bSize = s
}
}
// FingerprintSize sets the size of the fingerprint. Defaults to 2.
func FingerprintSize(s uint8) option {
return func(cf *CFilter) {
cf.fpSize = s
}
}
// MaximumKicks sets the maximum number of times we kick down items/displace
// from their buckets. Defaults to 500.
func MaximumKicks(k uint) option {
return func(cf *CFilter) {
cf.kicks = k
}
}
// HashFn sets the hashing function to be used for fingerprinting. Defaults to
// a 64-bit FNV-1 hash.Hash.
func HashFn(hashfn hash.Hash) option {
return func(cf *CFilter) {
cf.hashfn = hashfn
}
}
func configure(cf *CFilter) {
if cf.hashfn == nil {
cf.hashfn = fnv.New64()
}
if cf.bSize == 0 {
cf.bSize = 4
}
if cf.fpSize == 0 {
cf.fpSize = 3
}
if cf.kicks == 0 {
cf.kicks = 500
}
if cf.size == 0 {
cf.size = (1 << 18) / uint(cf.bSize)
}
}