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

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

Issue 1090683003: Alternative Multi-dimensional Rappor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sampler test 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
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 #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
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);
Alexei Svitkine (slow) 2015/04/23 21:42:34 Add a comment above this check (i.e. in order for
Steven Holte 2015/04/24 16:59:05 Done.
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);
Alexei Svitkine (slow) 2015/04/23 21:42:34 Nit: Make a helper in the anon namespace that wrap
Steven Holte 2015/04/24 16:59:05 Done.
59 output |= 1 << (index % (bytes_size * 8));
Alexei Svitkine (slow) 2015/04/23 21:42:34 Nit: Move bytes_size * 8 to a variable outside the
Steven Holte 2015/04/24 16:59:05 Done.
60 }
61 return output;
62 }
63
64 } // namespace internal
65
46 } // namespace rappor 66 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698