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

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

Issue 1551433002: Switch to standard integer types in components/, part 3 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 4 years, 12 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 | « components/rappor/bloom_filter.h ('k') | components/rappor/bloom_filter_unittest.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 #include "components/rappor/bloom_filter.h" 5 #include "components/rappor/bloom_filter.h"
6 6
7 #include <stddef.h>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "third_party/smhasher/src/City.h" 10 #include "third_party/smhasher/src/City.h"
9 11
10 namespace rappor { 12 namespace rappor {
11 13
12 namespace { 14 namespace {
13 15
14 uint32_t ComputeHash(const std::string& str, uint32_t seed) { 16 uint32_t ComputeHash(const std::string& str, uint32_t seed) {
15 // Using CityHash here because we have support for it in Dremel. Many hash 17 // Using CityHash here because we have support for it in Dremel. Many hash
16 // functions, such as MD5, SHA1, or Murmur, would probably also work. 18 // functions, such as MD5, SHA1, or Murmur, would probably also work.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 bytes_[i] = bytes[i]; 51 bytes_[i] = bytes[i];
50 } 52 }
51 } 53 }
52 54
53 namespace internal { 55 namespace internal {
54 56
55 uint64_t GetBloomBits(uint32_t bytes_size, 57 uint64_t GetBloomBits(uint32_t bytes_size,
56 uint32_t hash_function_count, 58 uint32_t hash_function_count,
57 uint32_t hash_seed_offset, 59 uint32_t hash_seed_offset,
58 const std::string& str) { 60 const std::string& str) {
59 // Make sure result fits in uint64. 61 // Make sure result fits in uint64_t.
60 DCHECK_LE(bytes_size, 8u); 62 DCHECK_LE(bytes_size, 8u);
61 uint64_t output = 0; 63 uint64_t output = 0;
62 const uint32_t bits_size = bytes_size * 8; 64 const uint32_t bits_size = bytes_size * 8;
63 for (size_t i = 0; i < hash_function_count; ++i) { 65 for (size_t i = 0; i < hash_function_count; ++i) {
64 uint32_t index = ComputeHash(str, hash_seed_offset + i); 66 uint32_t index = ComputeHash(str, hash_seed_offset + i);
65 output |= 1ULL << uint64_t(index % bits_size); 67 output |= 1ULL << uint64_t(index % bits_size);
66 } 68 }
67 return output; 69 return output;
68 } 70 }
69 71
70 } // namespace internal 72 } // namespace internal
71 73
72 } // namespace rappor 74 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/bloom_filter.h ('k') | components/rappor/bloom_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698