-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
44 lines (37 loc) · 929 Bytes
/
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
package memtable
type memtableOptions struct {
numBuckets uint32
entryListSize uint32
leaseTimeout uint32
}
// Option ...
type Option func(opts *memtableOptions)
func computeOptions(options ...Option) memtableOptions {
result := memtableOptions{
numBuckets: 1024,
entryListSize: 16,
leaseTimeout: 30,
}
for _, o := range options {
o(&result)
}
return result
}
// WithNumBuckets configures number of lease buckets
func WithNumBuckets(n uint32) Option {
return func(opts *memtableOptions) {
opts.numBuckets = ceilPowerOfTwo(n)
}
}
// WithLeaseListSize configures the number of entries in a lease list
func WithLeaseListSize(n uint32) Option {
return func(opts *memtableOptions) {
opts.entryListSize = ceilPowerOfTwo(n)
}
}
// WithLeaseTimeout for duration of lease timeout, in second
func WithLeaseTimeout(d uint32) Option {
return func(opts *memtableOptions) {
opts.leaseTimeout = d
}
}