1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:57:44 +00:00

AK: Consolidate iterators for HashTable and DoublyLinkedList respectively.

Get rid of the ConstIterator classes for these containers and use templated
FooIterator<T, ...> and FooIterator<const T, ...> helpers.

This makes the HashTable class a lot easier to read.
This commit is contained in:
Andreas Kling 2019-06-27 15:57:49 +02:00
parent 50700c107f
commit 516d736afe
5 changed files with 150 additions and 240 deletions

1
AK/Tests/.gitignore vendored
View file

@ -1,5 +1,6 @@
TestString
TestQueue
TestVector
TestHashMap
*.d
*.o

View file

@ -1,4 +1,6 @@
all: TestString TestQueue TestVector
PROGRAMS = TestString TestQueue TestVector TestHashMap
all: $(PROGRAMS)
CXXFLAGS = -std=c++17 -Wall -Wextra
@ -11,5 +13,8 @@ TestQueue: TestQueue.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ..
TestVector: TestVector.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp TestHelpers.h
$(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestVector.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
TestHashMap: TestHashMap.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp TestHelpers.h
$(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestHashMap.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
clean:
rm -f TestString TestQueue
rm -f $(PROGRAMS)

28
AK/Tests/TestHashMap.cpp Normal file
View file

@ -0,0 +1,28 @@
#include "TestHelpers.h"
#include <AK/AKString.h>
#include <AK/HashMap.h>
typedef HashMap<int, int> IntIntMap;
int main()
{
EXPECT(IntIntMap().is_empty());
EXPECT(IntIntMap().size() == 0);
HashMap<int, String> number_to_string;
number_to_string.set(1, "One");
number_to_string.set(2, "Two");
number_to_string.set(3, "Three");
EXPECT_EQ(number_to_string.is_empty(), false);
EXPECT_EQ(number_to_string.size(), 3);
int loop_counter = 0;
for (auto& it : number_to_string) {
EXPECT(!it.value.is_null());
++loop_counter;
}
EXPECT_EQ(loop_counter, 3);
return 0;
}