diff options
author | Abseil Team <absl-team@google.com> | 2023-02-06 15:23:40 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-02-06 15:24:24 -0800 |
commit | 92fc445f7c0d8158c5f26abab9049fcfbcd0ccff (patch) | |
tree | 950b231ee5b9c973269a9de775ca45b8e0183e9a /absl/hash/hash_test.cc | |
parent | cdad8cd96ee9bfe11056997dc960eb2e52c6b00e (diff) |
Fix a discrepancy between absl::Hash and absl::HashOf for some negative signed integral types and improve the performance of absl::Hash.
PiperOrigin-RevId: 507598042
Change-Id: I96a7bd6b9c360f435f216b2671ae84d9768a46e8
Diffstat (limited to 'absl/hash/hash_test.cc')
-rw-r--r-- | absl/hash/hash_test.cc | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/absl/hash/hash_test.cc b/absl/hash/hash_test.cc index 5b556180..4ed6e50a 100644 --- a/absl/hash/hash_test.cc +++ b/absl/hash/hash_test.cc @@ -17,6 +17,7 @@ #include <algorithm> #include <array> #include <bitset> +#include <cstdint> #include <cstring> #include <deque> #include <forward_list> @@ -1241,14 +1242,24 @@ TEST(HashTest, DoesNotUseImplicitConversionsToBool) { TEST(HashOf, MatchesHashForSingleArgument) { std::string s = "forty two"; - int i = 42; double d = 42.0; std::tuple<int, int> t{4, 2}; + int i = 42; + int neg_i = -42; + int16_t i16 = 42; + int16_t neg_i16 = -42; + int8_t i8 = 42; + int8_t neg_i8 = -42; EXPECT_EQ(absl::HashOf(s), absl::Hash<std::string>{}(s)); - EXPECT_EQ(absl::HashOf(i), absl::Hash<int>{}(i)); EXPECT_EQ(absl::HashOf(d), absl::Hash<double>{}(d)); EXPECT_EQ(absl::HashOf(t), (absl::Hash<std::tuple<int, int>>{}(t))); + EXPECT_EQ(absl::HashOf(i), absl::Hash<int>{}(i)); + EXPECT_EQ(absl::HashOf(neg_i), absl::Hash<int>{}(neg_i)); + EXPECT_EQ(absl::HashOf(i16), absl::Hash<int16_t>{}(i16)); + EXPECT_EQ(absl::HashOf(neg_i16), absl::Hash<int16_t>{}(neg_i16)); + EXPECT_EQ(absl::HashOf(i8), absl::Hash<int8_t>{}(i8)); + EXPECT_EQ(absl::HashOf(neg_i8), absl::Hash<int8_t>{}(neg_i8)); } TEST(HashOf, MatchesHashOfTupleForMultipleArguments) { |