OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_RAPPOR_BLOOM_FILTER_H_ |
| 6 #define COMPONENTS_RAPPOR_BLOOM_FILTER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "components/rappor/byte_vector_utils.h" |
| 12 |
| 13 namespace rappor { |
| 14 |
| 15 // BloomFilter is a simple Bloom filter for keeping track of a set of strings. |
| 16 class BloomFilter { |
| 17 public: |
| 18 // Constructs a BloomFilter using |bytes_size| bytes of Bloom filter bits, |
| 19 // and |hash_function_count| hash functions to set bits in the filter. The |
| 20 // hash functions will be generated by using seeds in the range |
| 21 // |hash_seed_offset| to (|hash_seed_offset| + |hash_function_count|). |
| 22 BloomFilter(uint32_t bytes_size, |
| 23 uint32_t hash_function_count, |
| 24 uint32_t hash_seed_offset); |
| 25 ~BloomFilter(); |
| 26 |
| 27 // Add a single string to the Bloom filter. |
| 28 void AddString(const std::string& str); |
| 29 |
| 30 // Returns the current value of the Bloom filter's bit array. |
| 31 const ByteVector& bytes() const { return bytes_; }; |
| 32 |
| 33 private: |
| 34 // Stores the byte array of the Bloom filter. |
| 35 ByteVector bytes_; |
| 36 |
| 37 // The number of bits to set for each string added. |
| 38 uint32_t hash_function_count_; |
| 39 |
| 40 // A number add to a hash function index to get a seed for that hash function. |
| 41 uint32_t hash_seed_offset_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(BloomFilter); |
| 44 }; |
| 45 |
| 46 } // namespace rappor |
| 47 |
| 48 #endif // COMPONENTS_RAPPOR_BLOOM_FILTER_H_ |
OLD | NEW |