Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: components/rappor/bloom_filter.h

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RapporMetrics StatsTest Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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);
25 ~BloomFilter();
26
27 // Add a single string to the Bloom filter.
28 void AddString(const std::string& str);
29
30 // Adds multiple strings to the Bloom filter.
31 void AddStrings(const std::vector<std::string>& strings);
32
33 // Returns the current value of the Bloom filter's bit array.
34 const ByteVector& bytes() const { return bytes_; };
35
36 // Returns the number of bits set for each string added to the filter.
37 uint32_t hash_function_count() const { return hash_function_count_; };
38
39 private:
40 // Stores the byte array of the Bloom filter.
41 ByteVector bytes_;
42 // The number of bits to set for each string added.
43 uint32_t hash_function_count_;
44
45 DISALLOW_COPY_AND_ASSIGN(BloomFilter);
46 };
47
48 } // namespace rappor
49
50 #endif // COMPONENTS_RAPPOR_BLOOM_FILTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698