-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
42 lines (34 loc) · 856 Bytes
/
options.go
File metadata and controls
42 lines (34 loc) · 856 Bytes
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
package counting_bloom_filter
import "time"
const (
NO_EXPIRATION = 0
LAZY_EXPIRATION = 1
RESET_EVERY_PERIOD = 2
EXPIRY_DURATION = 3
)
// Option represents the optional function.
type Option func(opts *Options)
type ExpiryStrategy int
type Options struct {
ExpiryStrategy ExpiryStrategy
Duration time.Duration
}
func loadOptions(options ...Option) *Options {
opts := new(Options)
for _, option := range options {
option(opts)
}
return opts
}
func WithOptions(options Options) Option {
return func(opts *Options) {
*opts = options
}
}
// WithExpiryDuration sets up the interval time of cleaning up the bloom filter
func WithExpiryDuration(expiryStrategy ExpiryStrategy, expiryDuration time.Duration) Option {
return func(opts *Options) {
opts.ExpiryStrategy = expiryStrategy
opts.Duration = expiryDuration
}
}