-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
69 lines (58 loc) · 1.46 KB
/
Copy pathconfig.go
File metadata and controls
69 lines (58 loc) · 1.46 KB
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
65
66
67
68
69
package oddsketch
import (
"github.com/koykov/byteseq"
"github.com/koykov/pbtk/lsh"
)
const defaultFPP = .01
type Config[T byteseq.Q] struct {
// Number of desired items to store in the filter
// Mandatory param.
ItemsNumber uint64
// False positive probability value.
// If this param omit, defaultFPP (0.01) will use instead.
FPP float64
// Hasher to calculate hash sum of the items.
// Mandatory param.
LSH lsh.Hasher[T]
// Setting up this section enables concurrent read/write operations.
Concurrent *ConcurrentConfig
}
// ConcurrentConfig configures concurrent section of config.
type ConcurrentConfig struct {
// How many write attempts may perform.
WriteAttemptsLimit uint64
}
func NewConfig[T byteseq.Q](items uint64, fpp float64, lsh lsh.Hasher[T]) *Config[T] {
return &Config[T]{
ItemsNumber: items,
FPP: fpp,
LSH: lsh,
}
}
func (c *Config[T]) WithConcurrency() *Config[T] {
c.Concurrent = &ConcurrentConfig{}
return c
}
func (c *Config[T]) WithItemsNumber(items uint64) *Config[T] {
c.ItemsNumber = items
return c
}
func (c *Config[T]) WithFPP(fpp float64) *Config[T] {
c.FPP = fpp
return c
}
func (c *Config[T]) WithLSH(lsh lsh.Hasher[T]) *Config[T] {
c.LSH = lsh
return c
}
func (c *Config[T]) WithWriteAttemptsLimit(limit uint64) *Config[T] {
if c.Concurrent == nil {
c.Concurrent = &ConcurrentConfig{}
}
c.Concurrent.WriteAttemptsLimit = limit
return c
}
func (c *Config[T]) copy() *Config[T] {
cpy := *c
return &cpy
}