Import upstream version 0.2.3+git20201124.1.9240e18
Debian Janitor
2 years ago
0 | 0 |
language: go
|
1 | 1 |
sudo: false
|
|
2 |
arch:
|
|
3 |
- AMD64
|
|
4 |
- ppc64le
|
2 | 5 |
before_script:
|
3 | |
- go get -t ./...
|
4 | |
- go vet ./...
|
|
6 |
- go get -t ./...
|
|
7 |
- go vet ./...
|
5 | 8 |
script: make release test
|
6 | 9 |
deploy:
|
7 | 10 |
provider: releases
|
20 | 20 |
type BloomFilter struct {
|
21 | 21 |
//bit array
|
22 | 22 |
v []uint64
|
|
23 |
|
23 | 24 |
//desired maximum number of elements
|
24 | 25 |
n uint64
|
|
26 |
|
25 | 27 |
//desired false positive probability
|
26 | 28 |
p float64
|
|
29 |
|
27 | 30 |
//number of hash functions
|
28 | 31 |
k uint64
|
|
32 |
|
29 | 33 |
//number of bits
|
30 | 34 |
m uint64
|
|
35 |
|
31 | 36 |
//number of elements in the filter
|
32 | 37 |
N uint64
|
|
38 |
|
33 | 39 |
//number of 64-bit integers (generated automatically)
|
34 | 40 |
M uint64
|
|
41 |
|
35 | 42 |
//arbitrary data that we can attach to the filter
|
36 | 43 |
Data []byte
|
37 | 44 |
}
|
|
290 | 297 |
// Initialize returns a new, empty Bloom filter with the given capacity (n)
|
291 | 298 |
// and FP probability (p).
|
292 | 299 |
func Initialize(n uint64, p float64) BloomFilter {
|
|
300 |
m := math.Abs(math.Ceil(float64(n) * math.Log(p) / math.Pow(math.Log(2.0), 2.0)))
|
293 | 301 |
var bf BloomFilter
|
294 | 302 |
bf.n = n
|
295 | 303 |
bf.p = p
|
296 | |
bf.m = uint64(math.Abs(math.Ceil(float64(n) * math.Log(float64(p)) / (math.Pow(math.Log(2.0), 2.0)))))
|
297 | |
bf.M = uint64(math.Ceil(float64(bf.m) / 64.0))
|
298 | |
bf.k = uint64(math.Ceil(math.Log(2) * float64(bf.m) / float64(n)))
|
|
304 |
bf.m = uint64(m)
|
|
305 |
bf.M = uint64(math.Ceil(m / 64.0))
|
|
306 |
bf.k = uint64(math.Ceil(math.Log(2) * m / float64(n)))
|
299 | 307 |
bf.v = make([]uint64, bf.M)
|
300 | 308 |
return bf
|
301 | 309 |
}
|