2021-04-02 01:38:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, thislooksfun <tlf@thislooks.fun>
|
2024-11-01 11:14:53 +00:00
|
|
|
* Copyright (c) 2023, Jelle Raaijmakers <jelle@ladybird.org>
|
2021-04-02 01:38:56 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-02 01:38:56 +00:00
|
|
|
*/
|
|
|
|
|
2021-04-25 05:53:23 +00:00
|
|
|
#include <LibTest/TestCase.h>
|
2021-04-02 01:38:56 +00:00
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
#include <AK/ByteString.h>
|
2021-04-02 01:38:56 +00:00
|
|
|
#include <AK/HashTable.h>
|
2022-03-07 23:43:21 +00:00
|
|
|
#include <AK/NonnullOwnPtr.h>
|
2023-04-28 12:02:38 +00:00
|
|
|
#include <AK/Vector.h>
|
2021-04-02 01:38:56 +00:00
|
|
|
|
|
|
|
TEST_CASE(construct)
|
|
|
|
{
|
|
|
|
using IntTable = HashTable<int>;
|
|
|
|
EXPECT(IntTable().is_empty());
|
|
|
|
EXPECT_EQ(IntTable().size(), 0u);
|
|
|
|
}
|
|
|
|
|
2021-05-30 12:23:23 +00:00
|
|
|
TEST_CASE(basic_move)
|
|
|
|
{
|
|
|
|
HashTable<int> foo;
|
|
|
|
foo.set(1);
|
|
|
|
EXPECT_EQ(foo.size(), 1u);
|
|
|
|
auto bar = move(foo);
|
|
|
|
EXPECT_EQ(bar.size(), 1u);
|
|
|
|
EXPECT_EQ(foo.size(), 0u);
|
|
|
|
foo = move(bar);
|
|
|
|
EXPECT_EQ(bar.size(), 0u);
|
|
|
|
EXPECT_EQ(foo.size(), 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(move_is_not_swap)
|
|
|
|
{
|
|
|
|
HashTable<int> foo;
|
|
|
|
foo.set(1);
|
|
|
|
HashTable<int> bar;
|
|
|
|
bar.set(2);
|
|
|
|
foo = move(bar);
|
|
|
|
EXPECT(foo.contains(2));
|
|
|
|
EXPECT(!bar.contains(1));
|
|
|
|
EXPECT_EQ(bar.size(), 0u);
|
|
|
|
}
|
|
|
|
|
2021-04-02 01:38:56 +00:00
|
|
|
TEST_CASE(populate)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
HashTable<ByteString> strings;
|
2021-04-02 01:38:56 +00:00
|
|
|
strings.set("One");
|
|
|
|
strings.set("Two");
|
|
|
|
strings.set("Three");
|
|
|
|
|
|
|
|
EXPECT_EQ(strings.is_empty(), false);
|
|
|
|
EXPECT_EQ(strings.size(), 3u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(range_loop)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
HashTable<ByteString> strings;
|
2021-04-02 01:38:56 +00:00
|
|
|
EXPECT_EQ(strings.set("One"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(strings.set("Two"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(strings.set("Three"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
|
|
|
|
int loop_counter = 0;
|
|
|
|
for (auto& it : strings) {
|
2023-10-10 11:30:58 +00:00
|
|
|
EXPECT_EQ(it.is_empty(), false);
|
2021-04-02 01:38:56 +00:00
|
|
|
++loop_counter;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(loop_counter, 3);
|
|
|
|
}
|
|
|
|
|
2023-09-24 18:34:55 +00:00
|
|
|
TEST_CASE(range_loop_reverse)
|
|
|
|
{
|
|
|
|
Array strings = { "One"sv, "Two"sv, "Three"sv };
|
2023-12-16 14:19:34 +00:00
|
|
|
OrderedHashTable<ByteString> table;
|
2023-09-24 18:34:55 +00:00
|
|
|
EXPECT_EQ(table.set(strings[0]), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(table.set(strings[1]), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(table.set(strings[2]), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
|
|
|
|
int loop_counter = 0;
|
|
|
|
int index = strings.size() - 1;
|
|
|
|
for (auto& it : table.in_reverse()) {
|
|
|
|
EXPECT_EQ(it, strings[index]);
|
|
|
|
++loop_counter;
|
|
|
|
--index;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(loop_counter, 3);
|
|
|
|
}
|
|
|
|
|
2021-04-02 01:38:56 +00:00
|
|
|
TEST_CASE(table_remove)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
HashTable<ByteString> strings;
|
2021-04-02 01:38:56 +00:00
|
|
|
EXPECT_EQ(strings.set("One"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(strings.set("Two"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(strings.set("Three"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
|
|
|
|
EXPECT_EQ(strings.remove("One"), true);
|
|
|
|
EXPECT_EQ(strings.size(), 2u);
|
|
|
|
EXPECT(strings.find("One") == strings.end());
|
|
|
|
|
|
|
|
EXPECT_EQ(strings.remove("Three"), true);
|
|
|
|
EXPECT_EQ(strings.size(), 1u);
|
|
|
|
EXPECT(strings.find("Three") == strings.end());
|
|
|
|
EXPECT(strings.find("Two") != strings.end());
|
|
|
|
}
|
|
|
|
|
2022-01-05 16:13:56 +00:00
|
|
|
TEST_CASE(remove_all_matching)
|
2022-01-05 15:45:42 +00:00
|
|
|
{
|
|
|
|
HashTable<int> ints;
|
|
|
|
|
|
|
|
ints.set(1);
|
|
|
|
ints.set(2);
|
|
|
|
ints.set(3);
|
|
|
|
ints.set(4);
|
|
|
|
|
|
|
|
EXPECT_EQ(ints.size(), 4u);
|
|
|
|
|
2022-01-05 15:57:45 +00:00
|
|
|
EXPECT_EQ(ints.remove_all_matching([&](int value) { return value > 2; }), true);
|
|
|
|
EXPECT_EQ(ints.remove_all_matching([&](int) { return false; }), false);
|
2022-01-05 15:45:42 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(ints.size(), 2u);
|
|
|
|
|
2022-01-05 16:13:56 +00:00
|
|
|
EXPECT(ints.contains(1));
|
|
|
|
EXPECT(ints.contains(2));
|
|
|
|
|
2022-01-05 15:57:45 +00:00
|
|
|
EXPECT_EQ(ints.remove_all_matching([&](int) { return true; }), true);
|
2022-01-05 15:45:42 +00:00
|
|
|
|
|
|
|
EXPECT(ints.is_empty());
|
2022-01-05 15:57:45 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(ints.remove_all_matching([&](int) { return true; }), false);
|
2022-01-05 15:45:42 +00:00
|
|
|
}
|
|
|
|
|
2021-04-02 01:38:56 +00:00
|
|
|
TEST_CASE(case_insensitive)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
HashTable<ByteString, CaseInsensitiveStringTraits> casetable;
|
|
|
|
EXPECT_EQ(ByteString("nickserv").to_lowercase(), ByteString("NickServ").to_lowercase());
|
2021-04-02 01:38:56 +00:00
|
|
|
EXPECT_EQ(casetable.set("nickserv"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(casetable.set("NickServ"), AK::HashSetResult::ReplacedExistingEntry);
|
|
|
|
EXPECT_EQ(casetable.size(), 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(many_strings)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
HashTable<ByteString> strings;
|
2021-04-02 01:38:56 +00:00
|
|
|
for (int i = 0; i < 999; ++i) {
|
2023-12-16 14:19:34 +00:00
|
|
|
EXPECT_EQ(strings.set(ByteString::number(i)), AK::HashSetResult::InsertedNewEntry);
|
2021-04-02 01:38:56 +00:00
|
|
|
}
|
|
|
|
EXPECT_EQ(strings.size(), 999u);
|
|
|
|
for (int i = 0; i < 999; ++i) {
|
2023-12-16 14:19:34 +00:00
|
|
|
EXPECT_EQ(strings.remove(ByteString::number(i)), true);
|
2021-04-02 01:38:56 +00:00
|
|
|
}
|
|
|
|
EXPECT_EQ(strings.is_empty(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(many_collisions)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
struct StringCollisionTraits : public DefaultTraits<ByteString> {
|
|
|
|
static unsigned hash(ByteString const&) { return 0; }
|
2021-04-02 01:38:56 +00:00
|
|
|
};
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
HashTable<ByteString, StringCollisionTraits> strings;
|
2021-04-02 01:38:56 +00:00
|
|
|
for (int i = 0; i < 999; ++i) {
|
2023-12-16 14:19:34 +00:00
|
|
|
EXPECT_EQ(strings.set(ByteString::number(i)), AK::HashSetResult::InsertedNewEntry);
|
2021-04-02 01:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(strings.set("foo"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(strings.size(), 1000u);
|
|
|
|
|
|
|
|
for (int i = 0; i < 999; ++i) {
|
2023-12-16 14:19:34 +00:00
|
|
|
EXPECT_EQ(strings.remove(ByteString::number(i)), true);
|
2021-04-02 01:38:56 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 00:27:19 +00:00
|
|
|
EXPECT(strings.find("foo") != strings.end());
|
2021-04-02 01:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(space_reuse)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
struct StringCollisionTraits : public DefaultTraits<ByteString> {
|
|
|
|
static unsigned hash(ByteString const&) { return 0; }
|
2021-04-02 01:38:56 +00:00
|
|
|
};
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
HashTable<ByteString, StringCollisionTraits> strings;
|
2021-04-02 01:38:56 +00:00
|
|
|
|
|
|
|
// Add a few items to allow it to do initial resizing.
|
|
|
|
EXPECT_EQ(strings.set("0"), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
for (int i = 1; i < 5; ++i) {
|
2023-12-16 14:19:34 +00:00
|
|
|
EXPECT_EQ(strings.set(ByteString::number(i)), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(strings.remove(ByteString::number(i - 1)), true);
|
2021-04-02 01:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto capacity = strings.capacity();
|
|
|
|
|
|
|
|
for (int i = 5; i < 999; ++i) {
|
2023-12-16 14:19:34 +00:00
|
|
|
EXPECT_EQ(strings.set(ByteString::number(i)), AK::HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(strings.remove(ByteString::number(i - 1)), true);
|
2021-04-02 01:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(strings.capacity(), capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(basic_remove)
|
|
|
|
{
|
|
|
|
HashTable<int> table;
|
|
|
|
table.set(1);
|
|
|
|
table.set(2);
|
|
|
|
table.set(3);
|
|
|
|
|
|
|
|
EXPECT_EQ(table.remove(3), true);
|
|
|
|
EXPECT_EQ(table.remove(3), false);
|
|
|
|
EXPECT_EQ(table.size(), 2u);
|
|
|
|
|
|
|
|
EXPECT_EQ(table.remove(1), true);
|
|
|
|
EXPECT_EQ(table.remove(1), false);
|
|
|
|
EXPECT_EQ(table.size(), 1u);
|
|
|
|
|
|
|
|
EXPECT_EQ(table.remove(2), true);
|
|
|
|
EXPECT_EQ(table.remove(2), false);
|
|
|
|
EXPECT_EQ(table.size(), 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(basic_contains)
|
|
|
|
{
|
|
|
|
HashTable<int> table;
|
|
|
|
table.set(1);
|
|
|
|
table.set(2);
|
|
|
|
table.set(3);
|
|
|
|
|
|
|
|
EXPECT_EQ(table.contains(1), true);
|
|
|
|
EXPECT_EQ(table.contains(2), true);
|
|
|
|
EXPECT_EQ(table.contains(3), true);
|
|
|
|
EXPECT_EQ(table.contains(4), false);
|
|
|
|
|
|
|
|
EXPECT_EQ(table.remove(3), true);
|
|
|
|
EXPECT_EQ(table.contains(3), false);
|
|
|
|
EXPECT_EQ(table.contains(1), true);
|
|
|
|
EXPECT_EQ(table.contains(2), true);
|
|
|
|
|
|
|
|
EXPECT_EQ(table.remove(2), true);
|
|
|
|
EXPECT_EQ(table.contains(2), false);
|
|
|
|
EXPECT_EQ(table.contains(3), false);
|
|
|
|
EXPECT_EQ(table.contains(1), true);
|
|
|
|
|
|
|
|
EXPECT_EQ(table.remove(1), true);
|
|
|
|
EXPECT_EQ(table.contains(1), false);
|
|
|
|
}
|
2022-03-06 18:37:26 +00:00
|
|
|
|
|
|
|
TEST_CASE(capacity_leak)
|
|
|
|
{
|
|
|
|
HashTable<int> table;
|
|
|
|
for (size_t i = 0; i < 10000; ++i) {
|
|
|
|
table.set(i);
|
|
|
|
table.remove(i);
|
|
|
|
}
|
|
|
|
EXPECT(table.capacity() < 100u);
|
|
|
|
}
|
2022-03-07 21:24:15 +00:00
|
|
|
|
2022-03-07 23:43:21 +00:00
|
|
|
TEST_CASE(non_trivial_type_table)
|
|
|
|
{
|
|
|
|
HashTable<NonnullOwnPtr<int>> table;
|
|
|
|
|
|
|
|
table.set(make<int>(3));
|
|
|
|
table.set(make<int>(11));
|
|
|
|
|
|
|
|
for (int i = 0; i < 1'000; ++i) {
|
|
|
|
table.set(make<int>(-i));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 10'000; ++i) {
|
|
|
|
table.set(make<int>(i));
|
|
|
|
table.remove(make<int>(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(table.remove_all_matching([&](auto&) { return true; }), true);
|
|
|
|
EXPECT(table.is_empty());
|
|
|
|
EXPECT_EQ(table.remove_all_matching([&](auto&) { return true; }), false);
|
|
|
|
}
|
|
|
|
|
2022-04-10 10:27:08 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2022-06-23 15:00:41 +00:00
|
|
|
TEST_CASE(reinsertion)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
OrderedHashTable<ByteString> map;
|
2022-06-23 15:00:41 +00:00
|
|
|
map.set("ytidb::LAST_RESULT_ENTRY_KEY");
|
|
|
|
map.set("__sak");
|
|
|
|
map.remove("__sak");
|
|
|
|
map.set("__sak");
|
|
|
|
}
|
2022-11-11 01:54:43 +00:00
|
|
|
|
|
|
|
TEST_CASE(clear_with_capacity_when_empty)
|
|
|
|
{
|
|
|
|
HashTable<int> map;
|
|
|
|
map.clear_with_capacity();
|
|
|
|
map.set(0);
|
|
|
|
map.set(1);
|
|
|
|
VERIFY(map.size() == 2);
|
|
|
|
}
|
2023-02-14 00:27:19 +00:00
|
|
|
|
|
|
|
TEST_CASE(iterator_removal)
|
|
|
|
{
|
|
|
|
HashTable<int> map;
|
|
|
|
map.set(0);
|
|
|
|
map.set(1);
|
|
|
|
|
|
|
|
auto it = map.begin();
|
|
|
|
map.remove(it);
|
|
|
|
EXPECT_EQ(it, map.end());
|
|
|
|
EXPECT_EQ(map.size(), 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(ordered_insertion_and_deletion)
|
|
|
|
{
|
|
|
|
OrderedHashTable<int> table;
|
|
|
|
EXPECT_EQ(table.set(0), HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(table.set(1), HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(table.set(2), HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(table.set(3), HashSetResult::InsertedNewEntry);
|
|
|
|
EXPECT_EQ(table.size(), 4u);
|
|
|
|
|
|
|
|
auto expect_table = [](OrderedHashTable<int>& table, Span<int> values) {
|
|
|
|
auto index = 0u;
|
|
|
|
for (auto it = table.begin(); it != table.end(); ++it, ++index) {
|
|
|
|
EXPECT_EQ(*it, values[index]);
|
|
|
|
EXPECT(table.contains(values[index]));
|
|
|
|
}
|
2023-09-24 18:34:55 +00:00
|
|
|
|
|
|
|
index = table.size() - 1;
|
|
|
|
for (auto it = table.rbegin(); it != table.rend(); ++it, --index) {
|
|
|
|
EXPECT_EQ(*it, values[index]);
|
|
|
|
EXPECT(table.contains(values[index]));
|
|
|
|
}
|
2023-02-14 00:27:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
expect_table(table, Array<int, 4> { 0, 1, 2, 3 });
|
|
|
|
|
|
|
|
EXPECT(table.remove(0));
|
|
|
|
EXPECT(table.remove(2));
|
|
|
|
EXPECT(!table.remove(4));
|
|
|
|
EXPECT_EQ(table.size(), 2u);
|
|
|
|
|
|
|
|
expect_table(table, Array<int, 2> { 1, 3 });
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(ordered_deletion_and_reinsertion)
|
|
|
|
{
|
|
|
|
OrderedHashTable<int> table;
|
|
|
|
table.set(1);
|
|
|
|
table.set(3);
|
|
|
|
table.remove(1);
|
|
|
|
EXPECT_EQ(table.size(), 1u);
|
|
|
|
|
|
|
|
// By adding 1 again but this time in a different position, we
|
2023-05-06 14:28:34 +00:00
|
|
|
// test whether the bucket's neighbors are reset properly.
|
2023-02-14 00:27:19 +00:00
|
|
|
table.set(1);
|
|
|
|
EXPECT_EQ(table.size(), 2u);
|
|
|
|
|
|
|
|
auto it = table.begin();
|
|
|
|
EXPECT_EQ(*it, 3);
|
|
|
|
++it;
|
|
|
|
EXPECT_EQ(*it, 1);
|
|
|
|
++it;
|
|
|
|
EXPECT_EQ(it, table.end());
|
2023-09-24 18:34:55 +00:00
|
|
|
|
|
|
|
auto rit = table.rbegin();
|
|
|
|
EXPECT_EQ(*rit, 1);
|
|
|
|
++rit;
|
|
|
|
EXPECT_EQ(*rit, 3);
|
|
|
|
++rit;
|
|
|
|
EXPECT_EQ(rit, table.rend());
|
2023-02-14 00:27:19 +00:00
|
|
|
}
|
|
|
|
|
2023-02-21 10:30:52 +00:00
|
|
|
TEST_CASE(ordered_take_last)
|
2023-02-14 00:27:19 +00:00
|
|
|
{
|
|
|
|
OrderedHashTable<int> table;
|
|
|
|
table.set(1);
|
|
|
|
table.set(2);
|
|
|
|
table.set(3);
|
|
|
|
|
2023-02-21 10:30:52 +00:00
|
|
|
EXPECT_EQ(table.take_last(), 3);
|
|
|
|
EXPECT_EQ(table.take_last(), 2);
|
|
|
|
EXPECT_EQ(table.take_last(), 1);
|
2023-02-14 00:27:19 +00:00
|
|
|
EXPECT(table.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(ordered_iterator_removal)
|
|
|
|
{
|
|
|
|
OrderedHashTable<int> map;
|
|
|
|
map.set(0);
|
|
|
|
map.set(1);
|
|
|
|
|
|
|
|
auto it = map.begin();
|
|
|
|
map.remove(it);
|
|
|
|
EXPECT_EQ(it, map.end());
|
|
|
|
EXPECT_EQ(map.size(), 1u);
|
|
|
|
}
|
2023-02-21 10:30:52 +00:00
|
|
|
|
|
|
|
TEST_CASE(ordered_remove_from_head)
|
|
|
|
{
|
|
|
|
OrderedHashTable<int> map;
|
|
|
|
map.set(1);
|
|
|
|
map.set(2);
|
|
|
|
map.set(3);
|
|
|
|
map.set(4);
|
|
|
|
map.set(5);
|
|
|
|
map.set(6);
|
|
|
|
|
|
|
|
EXPECT_EQ(map.size(), 6u);
|
|
|
|
|
|
|
|
auto it = map.begin();
|
|
|
|
map.remove(it);
|
|
|
|
it = map.begin();
|
|
|
|
map.remove(it);
|
|
|
|
it = map.begin();
|
|
|
|
map.remove(it);
|
|
|
|
it = map.begin();
|
|
|
|
map.remove(it);
|
|
|
|
it = map.begin();
|
|
|
|
map.remove(it);
|
|
|
|
it = map.begin();
|
|
|
|
map.remove(it);
|
|
|
|
|
|
|
|
EXPECT_EQ(map.size(), 0u);
|
|
|
|
}
|
2023-03-15 17:37:55 +00:00
|
|
|
|
|
|
|
TEST_CASE(ordered_infinite_loop_clang_regression)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
OrderedHashTable<ByteString> map;
|
2023-03-15 17:37:55 +00:00
|
|
|
map.set("");
|
|
|
|
map.set("1");
|
|
|
|
map.set("_cb");
|
|
|
|
map.set("2");
|
|
|
|
map.set("3");
|
|
|
|
map.set("_cb_svref");
|
|
|
|
map.set("_cb_svref_expires");
|
|
|
|
map.remove("_cb_svref");
|
|
|
|
map.remove("_cb_svref_expires");
|
|
|
|
map.set("_cb_svref");
|
|
|
|
|
|
|
|
size_t iterations = 0;
|
|
|
|
auto size = map.size();
|
|
|
|
for (auto it = map.begin(); it != map.end(); ++it) {
|
|
|
|
if (++iterations > size) {
|
|
|
|
VERIFY(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-28 12:02:38 +00:00
|
|
|
|
|
|
|
TEST_CASE(values)
|
|
|
|
{
|
|
|
|
OrderedHashTable<int> table;
|
|
|
|
table.set(10);
|
|
|
|
table.set(30);
|
|
|
|
table.set(20);
|
|
|
|
|
|
|
|
Vector<int> values = table.values();
|
|
|
|
|
|
|
|
EXPECT_EQ(values.size(), table.size());
|
|
|
|
EXPECT_EQ(values[0], 10);
|
|
|
|
EXPECT_EQ(values[1], 30);
|
|
|
|
EXPECT_EQ(values[2], 20);
|
|
|
|
}
|