/
options.go
56 lines (48 loc) · 1.42 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
package consistenthash
type options struct {
hashFunc HashFunc
hashFunc64 HashFunc64
initialRingSize int
defaultReplicas uint
blockPartitioning int
metrics bool
readLockFree bool
}
type Option func(*options)
// WithDefaultReplicas default number of replicas to add for each key
func WithDefaultReplicas(replicas uint) Option {
return func(o *options) {
o.defaultReplicas = replicas
}
}
// WithHashFunc hash function for 32bit CH
func WithHashFunc(hashFunc HashFunc) Option {
return func(o *options) {
o.hashFunc = hashFunc
}
}
// WithHashFunc64 hash function for 64bit CH
func WithHashFunc64(hashFunc HashFunc64) Option {
return func(o *options) {
o.hashFunc64 = hashFunc
}
}
// WithReadLockFree setting to false, will disable creating a copy of hash records, and will use read lock for lookup process
func WithReadLockFree(readLockFree bool) Option {
return func(o *options) {
o.readLockFree = readLockFree
}
}
// WithBlockPartitioning uses block partitioning, divides total number of keys to the given number to get number of blocks
func WithBlockPartitioning(divisionBy int) Option {
return func(o *options) {
o.blockPartitioning = divisionBy
}
}
// WithMetrics enables collecting metrics for block partitioning
// using metrics is not thread safe, and needs to be used only for test and debugging
func WithMetrics() Option {
return func(o *options) {
o.metrics = true
}
}