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 <stdint.h> | |
9 | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/basictypes.h" | |
14 #include "components/rappor/byte_vector_utils.h" | |
15 | |
16 namespace rappor { | |
17 | |
18 // BloomFilter is a simple Bloom filter for keeping track of a set of strings. | |
19 class BloomFilter { | |
20 public: | |
21 // Constructs a BloomFilter using |bytes_size| bytes of Bloom filter bits, | |
22 // and |hash_function_count| hash functions to set bits in the filter. | |
23 // Currently, |hash_function_count| must be at most 4. | |
24 BloomFilter(uint32_t bytes_size, uint32_t hash_function_count, | |
Alexei Svitkine (slow)
2014/02/05 18:07:01
Nit: 1 param per line; align.
Steven Holte
2014/02/05 22:44:37
Done.
| |
25 uint32_t hash_seed_offset); | |
Alexei Svitkine (slow)
2014/02/05 18:07:01
Document hash_seed_offset.
Steven Holte
2014/02/05 22:44:37
Done.
| |
26 ~BloomFilter(); | |
27 | |
28 // Add a single string to the Bloom filter. | |
29 void AddString(const std::string& str); | |
30 | |
31 // Returns the current value of the Bloom filter's bit array. | |
32 const ByteVector& bytes() const { return bytes_; }; | |
33 | |
34 // Returns the number of bits set for each string added to the filter. | |
35 uint32_t hash_function_count() const { return hash_function_count_; }; | |
36 | |
37 private: | |
38 // Stores the byte array of the Bloom filter. | |
39 ByteVector bytes_; | |
40 // The number of bits to set for each string added. | |
41 uint32_t hash_function_count_; | |
42 uint32_t hash_seed_offset_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(BloomFilter); | |
45 }; | |
46 | |
47 } // namespace rappor | |
48 | |
49 #endif // COMPONENTS_RAPPOR_BLOOM_FILTER_H_ | |
OLD | NEW |