1
1
#Bloom Filter
2
2
3
- A bloom filter is a data structure designed to
4
- test whether an element is present in a set. It
5
- is designed to be blazingly fast and use minimal
6
- memory at the cost of potential false positives.
3
+ A bloom filter is a space-efficient probabilistic
4
+ data structure designed to test whether an element
5
+ is present in a set. It is designed to be blazingly
6
+ fast and use minimal memory at the cost of potential
7
+ false positives. False positive matches are possible,
8
+ but false negatives are not – in other words, a query
9
+ returns either "possibly in set" or "definitely not in set".
10
+
11
+ Bloom proposed the technique for applications where the
12
+ amount of source data would require an impractically large
13
+ amount of memory if "conventional" error-free hashing
14
+ techniques were applied.
15
+
16
+ ##Algorithm description
17
+
18
+ An empty Bloom filter is a bit array of` m ` bits, all
19
+ set to` 0 ` . There must also be` k ` different hash functions
20
+ defined, each of which maps or hashes some set element to
21
+ one of the` m ` array positions, generating a uniform random
22
+ distribution. Typically,` k ` is a constant, much smaller
23
+ than` m ` , which is proportional to the number of elements
24
+ to be added; the precise choice of` k ` and the constant of
25
+ proportionality of` m ` are determined by the intended
26
+ false positive rate of the filter.
27
+
28
+ Here is an example of a Bloom filter, representing the
29
+ set` {x, y, z} ` . The colored arrows show the positions
30
+ in the bit array that each set element is mapped to. The
31
+ element` w ` is not in the set` {x, y, z} ` , because it
32
+ hashes to one bit-array position containing` 0 ` . For
33
+ this figure,` m = 18 ` and` k = 3 ` .
7
34
8
35
![ Bloom Filter] ( https://upload.wikimedia.org/wikipedia/commons/a/ac/Bloom_filter.svg )
9
36
10
37
##Operations
11
38
12
39
There are two main operations a bloom filter can
13
- perform:insertion andsearch . Search may result in
40
+ perform:_ insertion _ and_ search _ . Search may result in
14
41
false positives. Deletion is not possible.
15
42
16
43
In other words, the filter can take in items. When
17
44
we go to check if an item has previously been
18
45
inserted, it can tell us either "no" or "maybe".
19
46
20
- Both insertion and search are O(1) operations.
47
+ Both insertion and search are` O(1) ` operations.
21
48
22
49
##Making the filter
23
50
24
51
A bloom filter is created by allotting a certain size.
25
- In our example, we use 100 as a default length. All
52
+ In our example, we use` 100 ` as a default length. All
26
53
locations are initialized to` false ` .
27
54
28
55
###Insertion
29
56
30
57
During insertion, a number of hash functions,
31
- in our case3 hash functions, are used to create
58
+ in our case` 3 ` hash functions, are used to create
32
59
hashes of the input. These hash functions output
33
60
indexes. At every index received, we simply change
34
61
the value in our bloom filter to` true ` .
@@ -65,13 +92,13 @@ The formula to calculate probablity of a false positive is:
65
92
66
93
( 1 - e <sup >-kn/m</sup > ) <sup >k</sup >
67
94
68
- k =# hash functions
95
+ ` k ` =number of hash functions
69
96
70
- m = size
97
+ ` m ` = filter size
71
98
72
- n =# items inserted
99
+ ` n ` =number of items inserted
73
100
74
- These variables,k, m , andn , should be picked based
101
+ These variables,` k ` , ` m ` , and` n ` , should be picked based
75
102
on how acceptable false positives are. If the values
76
103
are picked and the resulting probability is too high,
77
104
the values should be tweaked and the probability
@@ -92,9 +119,6 @@ but the cost is acceptable. It's ok if a user never sees
92
119
a few articles as long as they have other, brand new ones
93
120
to see every time they visit the site.
94
121
95
- The popular blog site Medium does a version of this.
96
- Feel free to read[ their article] ( https://blog.medium.com/what-are-bloom-filters-1ec2a50c68ff ) .
97
-
98
122
##References
99
123
100
124
- [ Wikipedia] ( https://en.wikipedia.org/wiki/Bloom_filter )