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 package org.archive.util;
28
29 /***
30 * Common interface for different Bloom filter
31 * implementations
32 *
33 * @author Gordon Mohr
34 */
35 public interface BloomFilter {
36 /*** The number of character sequences in the filter.
37 *
38 * @return the number of character sequences in the filter (but see {@link #contains(CharSequence)}).
39 */
40 public abstract int size();
41
42 /*** Checks whether the given character sequence is in this filter.
43 *
44 * <P>Note that this method may return true on a character sequence that is has
45 * not been added to the filter. This will happen with probability 2<sub>-<var>d</var></sub>,
46 * where <var>d</var> is the number of hash functions specified at creation time, if
47 * the number of the elements in the filter is less than <var>n</var>, the number
48 * of expected elements specified at creation time.
49 *
50 * @param s a character sequence.
51 * @return true if the sequence is in the filter (or if a sequence with the
52 * same hash sequence is in the filter).
53 */
54 public abstract boolean contains(final CharSequence s);
55
56 /*** Adds a character sequence to the filter.
57 *
58 * @param s a character sequence.
59 * @return true if the character sequence was not in the filter (but see {@link #contains(CharSequence)}).
60 */
61 public abstract boolean add(final CharSequence s);
62
63 /***
64 * The amount of memory in bytes consumed by the bloom
65 * bitfield.
66 *
67 * @return memory used by bloom bitfield, in bytes
68 */
69 public abstract long getSizeBytes();
70 }