1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:47:43 +00:00

AK: Add hash traits for floating-point primitives

This allows us to use float and double as hash keys.
This commit is contained in:
Andreas Kling 2022-04-10 12:27:08 +02:00
parent 69ca27d3d7
commit ae6b09f4dc
2 changed files with 38 additions and 0 deletions

View file

@ -256,6 +256,30 @@ TEST_CASE(non_trivial_type_table)
EXPECT_EQ(table.remove_all_matching([&](auto&) { return true; }), false);
}
TEST_CASE(floats)
{
HashTable<float> table;
table.set(0);
table.set(1.0f);
table.set(2.0f);
EXPECT_EQ(table.size(), 3u);
EXPECT(table.contains(0));
EXPECT(table.contains(1.0f));
EXPECT(table.contains(2.0f));
}
TEST_CASE(doubles)
{
HashTable<double> table;
table.set(0);
table.set(1.0);
table.set(2.0);
EXPECT_EQ(table.size(), 3u);
EXPECT(table.contains(0));
EXPECT(table.contains(1.0));
EXPECT(table.contains(2.0));
}
// Inserting and removing a bunch of elements will "thrash" the table, leading to a lot of "deleted" markers.
BENCHMARK_CASE(benchmark_thrashing)
{