File tree 2 files changed +21
-27
lines changed
2 files changed +21
-27
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package bloom_test
3
3
import (
4
4
"fmt"
5
5
"github.com/yourbasic/bloom"
6
- "math/rand"
7
6
"strconv"
8
7
)
9
8
@@ -26,30 +25,6 @@ func Example_basics() {
26
25
// Output: https://rascal.com seems to be shady.
27
26
}
28
27
29
- // Estimate the number of false positives.
30
- func Example_falsePositives () {
31
- // Create a Bloom filter with room for n elements
32
- // at a false-positives rate less than 1/p.
33
- n , p := 10000 , 100
34
- filter := bloom .New (n , p )
35
-
36
- // Add n random strings.
37
- for i := 0 ; i < n ; i ++ {
38
- filter .Add (strconv .Itoa (rand .Int ()))
39
- }
40
-
41
- // Do n random lookups and count the (mostly accidental) hits.
42
- // It shouldn't be much more than n/p, and hopefully less.
43
- count := 0
44
- for i := 0 ; i < n ; i ++ {
45
- if filter .Test (strconv .Itoa (rand .Int ())) {
46
- count ++
47
- }
48
- }
49
- fmt .Println (count , "mistakes were made." )
50
- // Output: 26 mistakes were made.
51
- }
52
-
53
28
// Compute the union of two filters.
54
29
func ExampleFilter_Union () {
55
30
// Create two Bloom filters, each with room for 1000 elements
Original file line number Diff line number Diff line change 9
9
// a member”. Only false positives can occur: an element that has been added
10
10
// to the filter will always be identified as ”likely member”.
11
11
//
12
+ // The probabilities of different outcomes of a membership test at
13
+ // a false-positives rate of 1/100 are:
14
+ //
15
+ // Test(s) true false
16
+ // --------------------------------------
17
+ // s has been added 1 0
18
+ // s has not been added 0.01 0.99
19
+ //
12
20
// Elements can be added, but not removed. With more elements in the filter,
13
21
// the probability of false positives increases.
14
22
//
15
- // Implementation
23
+ // Performance
16
24
//
17
25
// A full filter with a false-positives rate of 1/p uses roughly
18
26
// 0.26ln(p) bytes per element and performs ⌈1.4ln(p)⌉ bit array lookups
30
38
// 512 1.6 9
31
39
// 1024 1.8 10
32
40
//
33
- // This implementation is not intended for cryptographic use.
34
41
// Each membership test makes a single call to a 128-bit hash function.
35
42
// This improves speed without increasing the false-positives rate
36
43
// as shown by Kirsch and Mitzenmacher.
37
44
//
45
+ // Limitations
46
+ //
47
+ // This implementation is not intended for cryptographic use.
48
+ //
49
+ // The internal data representation is different for big-endian
50
+ // and little-endian machines.
51
+ //
52
+ // Typical use case
53
+ //
54
+ // The Basics example contains a typcial use case:
55
+ // a blacklist of shady websites.
56
+ //
38
57
package bloom
39
58
40
59
import (
You can’t perform that action at this time.
0 commit comments