libbf  0.1
 All Classes Functions Typedefs Friends Pages
counting.h
1 #ifndef BF_BLOOM_FILTER_COUNTING_H
2 #define BF_BLOOM_FILTER_COUNTING_H
3 
4 #include <bf/counter_vector.h>
5 #include <bf/bloom_filter.h>
6 #include <bf/hash.h>
7 
8 namespace bf {
9 
10 class spectral_mi_bloom_filter;
11 class spectral_rm_bloom_filter;
12 
15 {
18 
19 public:
24  counting_bloom_filter(hasher h, size_t cells, size_t width);
25 
28 
29  using bloom_filter::add;
31 
32  virtual void add(object const& o) override;
33  virtual size_t lookup(object const& o) const override;
34  virtual void clear() override;
35 
38  void remove(object const& o);
39 
40  template <typename T>
41  void remove(T const& x)
42  {
43  remove(wrap(x));
44  }
45 
46 protected:
57  std::vector<size_t> find_indices(object const& o, bool part = false) const;
58 
62  size_t find_minimum(std::vector<size_t> const& indices) const;
63 
67  std::vector<size_t> find_minima(std::vector<size_t> const& indices) const;
68 
72  bool increment(std::vector<size_t> const& indices, size_t value = 1);
73 
77  bool decrement(std::vector<size_t> const& indices, size_t value = 1);
78 
82  size_t count(size_t index) const;
83 
84  hasher hasher_;
85  counter_vector cells_;
86 };
87 
90 {
91 public:
96  spectral_mi_bloom_filter(hasher h, size_t cells, size_t width);
97 
98  using bloom_filter::add;
101  virtual void add(object const& o) override;
102 };
103 
106 {
107 public:
115  spectral_rm_bloom_filter(hasher h1, size_t cells1, size_t width1,
116  hasher h2, size_t cells2, size_t width2);
117 
118  using bloom_filter::add;
119  using bloom_filter::lookup;
120  virtual void add(object const& o) override;
121  virtual size_t lookup(object const& o) const override;
122  virtual void clear() override;
123 
126  void remove(object const& o);
127 
128 private:
129  counting_bloom_filter first_;
130  counting_bloom_filter second_;
131 };
132 
133 } // namespace bf
134 
135 #endif