summaryrefslogtreecommitdiff
path: root/unittests
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
commitc7384cfc7addb5d2818ac0bb4492778f28183c49 (patch)
tree472493649952159b2c3fca4a62fabe516ccf0149 /unittests
parent74bab7f597b24d847175f8550002d8a014f63c8c (diff)
downloadllvm-c7384cfc7addb5d2818ac0bb4492778f28183c49.tar.gz
llvm-c7384cfc7addb5d2818ac0bb4492778f28183c49.tar.bz2
llvm-c7384cfc7addb5d2818ac0bb4492778f28183c49.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151882 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/HashingTest.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/unittests/ADT/HashingTest.cpp b/unittests/ADT/HashingTest.cpp
index a6a0034129..a9458bb5a5 100644
--- a/unittests/ADT/HashingTest.cpp
+++ b/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; }