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

Unified Diff: base/containers/hash_tables.h

Issue 1538743002: Switch to standard integer types in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DEPS roll too Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/compiler_specific.h ('k') | base/containers/hash_tables_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/containers/hash_tables.h
diff --git a/base/containers/hash_tables.h b/base/containers/hash_tables.h
index a1244f7b287e751cf9763047bae6ad0e5fbcffb4..c421dddf3e7c707beb1c57d72865a32376f6d9db 100644
--- a/base/containers/hash_tables.h
+++ b/base/containers/hash_tables.h
@@ -21,9 +21,11 @@
#ifndef BASE_CONTAINERS_HASH_TABLES_H_
#define BASE_CONTAINERS_HASH_TABLES_H_
+#include <stddef.h>
+#include <stdint.h>
+
#include <utility>
-#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
@@ -196,19 +198,19 @@ using hash_set = BASE_HASH_IMPL_NAMESPACE::hash_set<Key, Hash, Pred, Alloc>;
// h32(x32, y32) = (h64(x32, y32) * rand_odd64 + rand16 * 2^16) % 2^64 / 2^32
//
// Contact danakj@chromium.org for any questions.
-inline std::size_t HashInts32(uint32 value1, uint32 value2) {
- uint64 value1_64 = value1;
- uint64 hash64 = (value1_64 << 32) | value2;
+inline std::size_t HashInts32(uint32_t value1, uint32_t value2) {
+ uint64_t value1_64 = value1;
+ uint64_t hash64 = (value1_64 << 32) | value2;
- if (sizeof(std::size_t) >= sizeof(uint64))
+ if (sizeof(std::size_t) >= sizeof(uint64_t))
return static_cast<std::size_t>(hash64);
- uint64 odd_random = 481046412LL << 32 | 1025306955LL;
- uint32 shift_random = 10121U << 16;
+ uint64_t odd_random = 481046412LL << 32 | 1025306955LL;
+ uint32_t shift_random = 10121U << 16;
hash64 = hash64 * odd_random + shift_random;
std::size_t high_bits = static_cast<std::size_t>(
- hash64 >> (8 * (sizeof(uint64) - sizeof(std::size_t))));
+ hash64 >> (8 * (sizeof(uint64_t) - sizeof(std::size_t))));
return high_bits;
}
@@ -217,33 +219,33 @@ inline std::size_t HashInts32(uint32 value1, uint32 value2) {
// breaking the two 64-bit inputs into 4 32-bit values:
// http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECTION00832000000000000000
// Then we reduce our result to 32 bits if required, similar to above.
-inline std::size_t HashInts64(uint64 value1, uint64 value2) {
- uint32 short_random1 = 842304669U;
- uint32 short_random2 = 619063811U;
- uint32 short_random3 = 937041849U;
- uint32 short_random4 = 3309708029U;
+inline std::size_t HashInts64(uint64_t value1, uint64_t value2) {
+ uint32_t short_random1 = 842304669U;
+ uint32_t short_random2 = 619063811U;
+ uint32_t short_random3 = 937041849U;
+ uint32_t short_random4 = 3309708029U;
- uint32 value1a = static_cast<uint32>(value1 & 0xffffffff);
- uint32 value1b = static_cast<uint32>((value1 >> 32) & 0xffffffff);
- uint32 value2a = static_cast<uint32>(value2 & 0xffffffff);
- uint32 value2b = static_cast<uint32>((value2 >> 32) & 0xffffffff);
+ uint32_t value1a = static_cast<uint32_t>(value1 & 0xffffffff);
+ uint32_t value1b = static_cast<uint32_t>((value1 >> 32) & 0xffffffff);
+ uint32_t value2a = static_cast<uint32_t>(value2 & 0xffffffff);
+ uint32_t value2b = static_cast<uint32_t>((value2 >> 32) & 0xffffffff);
- uint64 product1 = static_cast<uint64>(value1a) * short_random1;
- uint64 product2 = static_cast<uint64>(value1b) * short_random2;
- uint64 product3 = static_cast<uint64>(value2a) * short_random3;
- uint64 product4 = static_cast<uint64>(value2b) * short_random4;
+ uint64_t product1 = static_cast<uint64_t>(value1a) * short_random1;
+ uint64_t product2 = static_cast<uint64_t>(value1b) * short_random2;
+ uint64_t product3 = static_cast<uint64_t>(value2a) * short_random3;
+ uint64_t product4 = static_cast<uint64_t>(value2b) * short_random4;
- uint64 hash64 = product1 + product2 + product3 + product4;
+ uint64_t hash64 = product1 + product2 + product3 + product4;
- if (sizeof(std::size_t) >= sizeof(uint64))
+ if (sizeof(std::size_t) >= sizeof(uint64_t))
return static_cast<std::size_t>(hash64);
- uint64 odd_random = 1578233944LL << 32 | 194370989LL;
- uint32 shift_random = 20591U << 16;
+ uint64_t odd_random = 1578233944LL << 32 | 194370989LL;
+ uint32_t shift_random = 20591U << 16;
hash64 = hash64 * odd_random + shift_random;
std::size_t high_bits = static_cast<std::size_t>(
- hash64 >> (8 * (sizeof(uint64) - sizeof(std::size_t))));
+ hash64 >> (8 * (sizeof(uint64_t) - sizeof(std::size_t))));
return high_bits;
}
« no previous file with comments | « base/compiler_specific.h ('k') | base/containers/hash_tables_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698