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

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

Issue 1058333002: Multi-dimension rappor metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add xml support Created 5 years, 8 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
« no previous file with comments | « no previous file | components/rappor/bloom_filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_RAPPOR_BLOOM_FILTER_H_ 5 #ifndef COMPONENTS_RAPPOR_BLOOM_FILTER_H_
6 #define COMPONENTS_RAPPOR_BLOOM_FILTER_H_ 6 #define COMPONENTS_RAPPOR_BLOOM_FILTER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "components/rappor/byte_vector_utils.h" 12 #include "components/rappor/byte_vector_utils.h"
13 13
14 namespace rappor { 14 namespace rappor {
15 15
16 // BloomFilter is a simple Bloom filter for keeping track of a set of strings. 16 namespace internal {
17 class BloomFilter {
18 public:
19 // Constructs a BloomFilter using |bytes_size| bytes of Bloom filter bits,
20 // and |hash_function_count| hash functions to set bits in the filter. The
21 // hash functions will be generated by using seeds in the range
22 // |hash_seed_offset| to (|hash_seed_offset| + |hash_function_count|).
23 BloomFilter(uint32_t bytes_size,
24 uint32_t hash_function_count,
25 uint32_t hash_seed_offset);
26 ~BloomFilter();
27 17
28 // Sets the Bloom filter bits to contain a single string. 18 // Converts a string to a bloom filter.
29 void SetString(const std::string& str); 19 // The first |bytes_size| bytes of |output| will be cleared, and have
20 // |hash_function_count| bits set in it. Which bits will be determined by
21 // hashing |str| with a hash function using seeds in the range
22 // |hash_seed_offset| to (|hash_seed_offset| + |hash_function_count|).
23 void SetBloomBits(uint32_t bytes_size,
24 uint32_t hash_function_count,
25 uint32_t hash_seed_offset,
26 const std::string& str,
27 ByteVector* output);
30 28
31 // Returns the current value of the Bloom filter's bit array. 29 } // namespace internal
32 const ByteVector& bytes() const { return bytes_; };
33
34 // Sets bytes for testing purposes.
35 void SetBytesForTesting(const ByteVector& bytes);
36
37 private:
38 // Stores the byte array of the Bloom filter.
39 ByteVector bytes_;
40
41 // The number of bits to set for each string added.
42 uint32_t hash_function_count_;
43
44 // A number add to a hash function index to get a seed for that hash function.
45 uint32_t hash_seed_offset_;
46
47 DISALLOW_COPY_AND_ASSIGN(BloomFilter);
48 };
49 30
50 } // namespace rappor 31 } // namespace rappor
51 32
52 #endif // COMPONENTS_RAPPOR_BLOOM_FILTER_H_ 33 #endif // COMPONENTS_RAPPOR_BLOOM_FILTER_H_
OLDNEW
« no previous file with comments | « no previous file | components/rappor/bloom_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698