6 #include <gtest/gtest.h>
24 } hash_chain{
nullptr,
nullptr };
38 return item->hash_chain.
prev;
44 return item->hash_chain.
next;
50 item->hash_chain.prev = prev;
56 item->hash_chain.next = next;
83 TEST(IntrusiveHashTests, test_int_hash)
91 EXPECT_EQ(&*m.
find(42), &i1);
99 EXPECT_EQ(&*m.
find(42), &i1);
101 int seen_i1 = 0, seen_i2 = 0;
102 for (
const MyItem & i : m)
104 EXPECT_TRUE((&i == &i1) || (&i == &i2));
114 EXPECT_EQ(seen_i1, 1);
115 EXPECT_EQ(seen_i2, 1);
118 TEST(IntrusiveHashTests, test_str_hash)
122 EXPECT_EQ(m.
find(
"42"), m.
end());
126 EXPECT_EQ(&*m.
find(
"42"), &i1);
132 EXPECT_EQ(m.
find(
"42"), m.
end());
134 EXPECT_EQ(&*m.
find(
"42"), &i1);
136 int seen_i1 = 0, seen_i2 = 0;
139 EXPECT_TRUE((&i == &i1) || (&i == &i2));
149 EXPECT_EQ(seen_i1, 1);
150 EXPECT_EQ(seen_i2, 1);
jlm::util::IntrusiveHash< int, MyItem, MyAccessor > my_hash
TEST(IntrusiveHashTests, test_int_hash)
jlm::util::IntrusiveHash< std::string, MyStringItem, MyStringItem::hash_accessor > my_strhash
Iterator insert(ElementType *element)
void erase(ElementType *element) noexcept
Iterator find(const KeyType &key) noexcept
int get_key(const MyItem *item) const noexcept
void set_prev(MyItem *item, MyItem *prev) const noexcept
MyItem * get_next(const MyItem *item) const noexcept
void set_next(MyItem *item, MyItem *next) const noexcept
MyItem * get_prev(const MyItem *item) const noexcept
MyStringItem(const std::string &k, const std::string &v)
jlm::util::IntrusiveHashAccessor< std::string, MyStringItem, &MyStringItem::key, &MyStringItem::hash_chain > hash_accessor
jlm::util::IntrusiveHashAnchor< MyStringItem > hash_chain