Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "components/rappor/bloom_filter.h" | 5 #include "components/rappor/bloom_filter.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/smhasher/src/City.h" | 8 #include "third_party/smhasher/src/City.h" |
| 9 | 9 |
| 10 namespace rappor { | 10 namespace rappor { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 void BloomFilter::SetBytesForTesting(const ByteVector& bytes) { | 39 void BloomFilter::SetBytesForTesting(const ByteVector& bytes) { |
| 40 DCHECK_EQ(bytes_.size(), bytes.size()); | 40 DCHECK_EQ(bytes_.size(), bytes.size()); |
| 41 for (size_t i = 0; i < bytes_.size(); ++i) { | 41 for (size_t i = 0; i < bytes_.size(); ++i) { |
| 42 bytes_[i] = bytes[i]; | 42 bytes_[i] = bytes[i]; |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 namespace internal { | |
| 47 | |
| 48 uint64_t GetBloomBits(uint32_t bytes_size, | |
| 49 uint32_t hash_function_count, | |
| 50 uint32_t hash_seed_offset, | |
| 51 const std::string& str) { | |
| 52 DCHECK_LE(bytes_size, 8u); | |
| 53 uint64_t output = 0; | |
| 54 for (size_t i = 0; i < hash_function_count; ++i) { | |
| 55 // Using CityHash here because we have support for it in Dremel. Many hash | |
| 56 // functions, such as MD5, SHA1, or Murmur, would probably also work. | |
| 57 uint32_t index = | |
| 58 CityHash64WithSeed(str.data(), str.size(), hash_seed_offset + i); | |
| 59 output |= 1 << (index % (bytes_size * 8)); | |
| 60 } | |
| 61 return output; | |
| 62 } | |
| 63 | |
| 64 } | |
|
Alexei Svitkine (slow)
2015/04/16 15:09:43
// namespace internal
Steven Holte
2015/04/22 19:24:28
Done.
| |
| 65 | |
| 46 } // namespace rappor | 66 } // namespace rappor |
| OLD | NEW |