mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
AK: Implement take_all_matching(predicate) API in HashTable
This commit is contained in:
parent
70efa8c1c5
commit
5097e72174
Notes:
github-actions[bot]
2025-08-08 17:11:26 +00:00
Author: https://github.com/IdanHo
Commit: 5097e72174
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5766
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 51 additions and 0 deletions
|
|
@ -131,6 +131,38 @@ TEST_CASE(remove_all_matching)
|
|||
EXPECT_EQ(ints.remove_all_matching([&](int) { return true; }), false);
|
||||
}
|
||||
|
||||
TEST_CASE(take_all_matching)
|
||||
{
|
||||
HashTable<int> ints;
|
||||
|
||||
ints.set(1);
|
||||
ints.set(2);
|
||||
ints.set(3);
|
||||
ints.set(4);
|
||||
|
||||
EXPECT_EQ(ints.size(), 4u);
|
||||
|
||||
auto first_values = ints.take_all_matching([&](int value) { return value > 2; });
|
||||
EXPECT_EQ(first_values.size(), 2u);
|
||||
EXPECT(first_values.contains_slow(3));
|
||||
EXPECT(first_values.contains_slow(4));
|
||||
EXPECT(ints.take_all_matching([&](int) { return false; }).is_empty());
|
||||
|
||||
EXPECT_EQ(ints.size(), 2u);
|
||||
|
||||
EXPECT(ints.contains(1));
|
||||
EXPECT(ints.contains(2));
|
||||
|
||||
auto second_values = ints.take_all_matching([&](int) { return true; });
|
||||
EXPECT_EQ(second_values.size(), 2u);
|
||||
EXPECT(second_values.contains_slow(1));
|
||||
EXPECT(second_values.contains_slow(2));
|
||||
|
||||
EXPECT(ints.is_empty());
|
||||
|
||||
EXPECT(ints.take_all_matching([&](int) { return true; }).is_empty());
|
||||
}
|
||||
|
||||
TEST_CASE(case_insensitive)
|
||||
{
|
||||
HashTable<ByteString, CaseInsensitiveStringTraits> casetable;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue