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

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

Issue 419683014: Randomly select a single rappor sample when more than one is collected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 15 matching lines...) Expand all
26 // functions, such as MD5, SHA1, or Murmur, would probably also work. 26 // functions, such as MD5, SHA1, or Murmur, would probably also work.
27 uint32_t index = 27 uint32_t index =
28 CityHash64WithSeed(str.data(), str.size(), hash_seed_offset_ + i); 28 CityHash64WithSeed(str.data(), str.size(), hash_seed_offset_ + i);
29 // Note that the "bytes" are uint8_t, so they are always 8-bits. 29 // Note that the "bytes" are uint8_t, so they are always 8-bits.
30 uint32_t byte_index = (index / 8) % bytes_.size(); 30 uint32_t byte_index = (index / 8) % bytes_.size();
31 uint32_t bit_index = index % 8; 31 uint32_t bit_index = index % 8;
32 bytes_[byte_index] |= 1 << bit_index; 32 bytes_[byte_index] |= 1 << bit_index;
33 } 33 }
34 } 34 }
35 35
36 void BloomFilter::Clear() {
37 for (size_t i = 0; i < bytes_.size(); ++i) {
38 bytes_[i] = 0;
39 }
40 }
41
42 void BloomFilter::SetBytesForTesting(const ByteVector& bytes) {
43 DCHECK_EQ(bytes.size(), bytes_.size());
Alexei Svitkine (slow) 2014/07/30 17:12:47 Nit: Swap params (expected size should be on the l
Steven Holte 2014/08/04 23:30:26 Done.
44 for (size_t i = 0; i < bytes_.size(); ++i) {
45 bytes_[i] = bytes[i];
46 }
47 }
48
36 } // namespace rappor 49 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698