-
Notifications
You must be signed in to change notification settings - Fork 0
/
bloomfilter_test.go
57 lines (44 loc) · 975 Bytes
/
bloomfilter_test.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
57
// Copyright 2019 Alberto Bregliano. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package bloomfilter_test
import (
"fmt"
"sync"
randomdata "github.com/Pallinder/go-randomdata"
"github.com/axamon/bloomfilter"
)
func ExampleBloomFilter_Add() {
f := bloomfilter.New()
fmt.Println(f.Exists("pluto"))
f.Add("pluto")
fmt.Println(f.Exists("pluto"))
// Output:
// false
// true
}
func ExampleBloomFilter_Exists() {
f := bloomfilter.New()
n := 10000
var wg sync.WaitGroup
wg.Add(n)
for i := 0; i < n; i++ {
go func() {
defer wg.Done()
f.Add(randomdata.FirstName(randomdata.Male))
f.Add(randomdata.FirstName(randomdata.Female))
}()
}
wg.Wait()
f.Add("pluto")
f.Add("pippo")
fmt.Println(f.Exists("pippo"))
fmt.Println(f.Exists("pluto"))
fmt.Println(f.Exists("minnie"))
fmt.Println(f.Exists("paperino"))
// Output:
// true
// true
// false
// false
}