summaryrefslogtreecommitdiff
path: root/Tests/AK/TestHashTable.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-05 16:45:42 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-05 18:57:14 +0100
commit54cf42fac1cf3d89c91c5a241b6c98fc3cbf413f (patch)
treea14bd9441b90cddca59846bbd255203206e1b62b /Tests/AK/TestHashTable.cpp
parent365bd8a0c356facc9b781a085778e10e70efe900 (diff)
downloadserenity-54cf42fac1cf3d89c91c5a241b6c98fc3cbf413f.zip
AK: Add HashTable::remove_all_matching(predicate)
This removes all matching entries from a table in a single pass.
Diffstat (limited to 'Tests/AK/TestHashTable.cpp')
-rw-r--r--Tests/AK/TestHashTable.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/Tests/AK/TestHashTable.cpp b/Tests/AK/TestHashTable.cpp
index 9729eac9a3..a5eb34d97c 100644
--- a/Tests/AK/TestHashTable.cpp
+++ b/Tests/AK/TestHashTable.cpp
@@ -84,6 +84,26 @@ TEST_CASE(table_remove)
EXPECT(strings.find("Two") != strings.end());
}
+TEST_CASE(table_remove_all_matching)
+{
+ HashTable<int> ints;
+
+ ints.set(1);
+ ints.set(2);
+ ints.set(3);
+ ints.set(4);
+
+ EXPECT_EQ(ints.size(), 4u);
+
+ ints.remove_all_matching([&](int value) { return value > 2; });
+
+ EXPECT_EQ(ints.size(), 2u);
+
+ ints.remove_all_matching([&](int) { return true; });
+
+ EXPECT(ints.is_empty());
+}
+
TEST_CASE(case_insensitive)
{
HashTable<String, CaseInsensitiveStringTraits> casetable;