The default hash does not like using pointers as keys. #4

This commit is contained in:
greg
2019-04-02 07:25:46 -04:00
parent e15f2bb959
commit 2234bd037b
2 changed files with 10 additions and 2 deletions
+2 -2
View File
@@ -99,7 +99,7 @@ struct Hash<T *>
{
inline size_t operator()(const T *val) const noexcept
{
return phmap_mix_64(static_cast<const uintptr_t>(val));
return phmap_mix_64((const uintptr_t)val);
}
};
@@ -2547,7 +2547,7 @@ protected:
bool operator==(const Inner& o) const
{
MutexLock_ m1(const_cast<Inner *>(this));
MutexLock_ m2(const_cast<Inner *>(&o));
MutexLock_ m2(const_cast<Inner *>(&o)); // deadlock - use std::lock
return set_ == o.set_;
}
+8
View File
@@ -143,6 +143,14 @@ struct Eq {
}
};
TEST(THIS_TEST_NAME, PtrKet) {
using H = THIS_HASH_MAP<void *, bool>;
H hash;
int a, b;
hash.insert(H::value_type(&a, true));
hash.insert(H::value_type(&b, false));
};
TEST(THIS_TEST_NAME, LazyKeyPattern) {
// hashes are only guaranteed in opt mode, we use assertions to track internal
// state that can cause extra calls to hash.