Add SetCookieAndChannelIdStores method to URLRequestContextBuilder
[chromium-blink-merge.git] / components / rappor / bloom_filter.h
blob482f1c3668eeadff185ba9ead35aa4b90cf70e2a
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.
5 #ifndef COMPONENTS_RAPPOR_BLOOM_FILTER_H_
6 #define COMPONENTS_RAPPOR_BLOOM_FILTER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/macros.h"
12 #include "components/rappor/byte_vector_utils.h"
14 namespace rappor {
16 // BloomFilter is a simple Bloom filter for keeping track of a set of strings.
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();
28 // Sets the Bloom filter bits to contain a single string.
29 void SetString(const std::string& str);
31 // Returns the current value of the Bloom filter's bit array.
32 const ByteVector& bytes() const { return bytes_; };
34 // Sets bytes for testing purposes.
35 void SetBytesForTesting(const ByteVector& bytes);
37 private:
38 // Stores the byte array of the Bloom filter.
39 ByteVector bytes_;
41 // The number of bits to set for each string added.
42 uint32_t hash_function_count_;
44 // A number add to a hash function index to get a seed for that hash function.
45 uint32_t hash_seed_offset_;
47 DISALLOW_COPY_AND_ASSIGN(BloomFilter);
50 } // namespace rappor
52 #endif // COMPONENTS_RAPPOR_BLOOM_FILTER_H_