summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/HashingTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-03-02 08:32:29 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-03-02 08:32:29 +0000
commit4718430a5a4300bc4d8441ff6112ffb8280229a8 (patch)
treed37bf647a2574b6e2890c8b372f6ab7dd26cd12b /llvm/unittests/ADT/HashingTest.cpp
parent35ecb36fcd71f113a1c574bd4f7cd2d32d033213 (diff)
downloadbcm5719-llvm-4718430a5a4300bc4d8441ff6112ffb8280229a8.tar.gz
bcm5719-llvm-4718430a5a4300bc4d8441ff6112ffb8280229a8.zip
Add support for hashing pairs by delegating to each sub-object. There is
an open question of whether we can do better than this by treating pairs as boring data containers and directly hashing the two subobjects. This at least makes the API reasonable. In order to make this change, I reorganized the header a bit. I lifted the declarations of the hash_value functions up to the top of the header with their doxygen comments as these are intended for users to interact with. They shouldn't have to wade through implementation details. I then defined them at the very end so that they could be defined in terms of hash_combine or any other hashing infrastructure. Added various pair-hashing unittests. llvm-svn: 151882
Diffstat (limited to 'llvm/unittests/ADT/HashingTest.cpp')
-rw-r--r--llvm/unittests/ADT/HashingTest.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/HashingTest.cpp b/llvm/unittests/ADT/HashingTest.cpp
index a6a0034129f..a9458bb5a5a 100644
--- a/llvm/unittests/ADT/HashingTest.cpp
+++ b/llvm/unittests/ADT/HashingTest.cpp
@@ -60,6 +60,17 @@ TEST(HashingTest, HashValueBasicTest) {
EXPECT_EQ(hash_value(c), hash_value('x'));
EXPECT_EQ(hash_value('4'), hash_value('0' + 4));
EXPECT_EQ(hash_value(addr), hash_value(&y));
+
+ EXPECT_EQ(hash_combine(42, 43), hash_value(std::make_pair(42, 43)));
+ EXPECT_NE(hash_combine(43, 42), hash_value(std::make_pair(42, 43)));
+ EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43ull)));
+ EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42, 43ull)));
+ EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43)));
+ EXPECT_EQ(hash_combine(42, hash_combine(43, hash_combine(44, 45))),
+ hash_value(
+ std::make_pair(42, std::make_pair(43, std::make_pair(44, 45)))));
+ EXPECT_EQ(hash_combine(42, 43), hash_value(std::make_pair(42, 43)));
+ EXPECT_EQ(hash_combine(42, 43), hash_value(std::make_pair(42, 43)));
}
template <typename T, size_t N> T *begin(T (&arr)[N]) { return arr; }
OpenPOWER on IntegriCloud