43#include <gtest/gtest.h>
55 template <
class Stats>
56 size_t num_chains(
const Stats & st)
59 for (
size_t i = 0; i < st.lens.size(); ++i)
65 template <
class Stats>
66 size_t num_entries(
const Stats & st)
69 for (
size_t i = 0; i < st.lens.size(); ++i)
70 count += i * st.lens(i);
75 size_t constant_hash(
const int &)
noexcept {
return 0; }
77 template <
class Table>
78 class HashChainStats :
public ::testing::Test
88 const TypeParam table;
89 const auto st = table.stats();
90 EXPECT_EQ(num_chains(st), table.capacity());
91 EXPECT_EQ(num_entries(st), 0u);
92 EXPECT_EQ(st.avg, 0.0f);
95TYPED_TEST(HashChainStats, HistogramAccountsForEveryChainAndEntry)
98 for (
int i = 0; i < 1000; ++i)
99 ASSERT_NE(table.insert(i * 7919),
nullptr);
101 const auto st = table.stats();
102 EXPECT_EQ(num_chains(st), table.capacity());
103 EXPECT_EQ(num_entries(st), table.size());
104 EXPECT_NEAR(st.avg,
static_cast<float>(table.size()) / table.capacity(), 1e-4);
107TEST(HashChainStats, ChainLongerThanSeveralHistogramBlocks)
112 constexpr int n = 9000;
113 for (
int i = 0; i < n; ++i)
114 ASSERT_NE(table.
insert(i),
nullptr);
116 const auto st = table.stats();
117 ASSERT_EQ(st.lens.size(),
static_cast<size_t>(n) + 1);
118 EXPECT_EQ(st.lens(n), 1u);
119 EXPECT_EQ(st.lens(n / 2), 0u);
120 EXPECT_EQ(num_chains(st), table.capacity());
121 EXPECT_EQ(num_entries(st),
static_cast<size_t>(n));
127TEST(HashChainStats, ATableWithoutListsHasNoChains)
130 for (
int i = 0; i < 100; ++i)
131 ASSERT_NE(source.insert(i),
nullptr);
133 ASSERT_EQ(target.size(), 100u);
134 ASSERT_EQ(source.capacity(), 0u);
136 const auto st = source.stats();
137 EXPECT_EQ(st.lens.size(), 0u);
138 EXPECT_EQ(st.avg, 0.0f);
139 EXPECT_EQ(st.var, 0.0f);
140 EXPECT_EQ(source.current_alpha(), 0.0f);
TYPED_TEST_SUITE(ArcHeapLifecycle, ArcHeapKinds)
Self-adjusting dynamic hash table.
Key * insert(const Key &key)
Inserts key into the hash set.
TYPED_TEST(HashChainStats, EmptyTableHasOnlyEmptyChains)
Main namespace for Aleph-w library functions.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Hash-based dynamic set (defined in tpl_dynSetHash.H).
Container for comprehensive statistical results.
Dynamic set implementations based on hash tables.