GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bloom_filter.hpp
1 /*
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #ifndef BLOOM_FILTER_HPP
25 #define BLOOM_FILTER_HPP
26 #include <graphlab/util/dense_bitset.hpp>
27 
28 template <size_t len, size_t probes>
29 class fixed_bloom_filter {
30  private:
31  fixed_dense_bitset<len> bits;
32  public:
33  inline fixed_bloom_filter() { }
34 
35  inline void clear() {
36  bits.clear();
37  }
38 
39  inline void insert(uint64_t i) {
40  for (size_t i = 0;i < probes; ++i) {
41  bits.set_bit_unsync(i % len);
42  i = i * 0x9e3779b97f4a7c13LL;
43  }
44  }
45 
46  inline bool may_contain(size_t i) {
47  for (size_t i = 0;i < probes; ++i) {
48  if (bits.get_bit_unsync(i % len) == false) return false;
49  i = i * 0x9e3779b97f4a7c13LL;
50  }
51  return true;
52  }
53 
54 };
55 
56 #endif