mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
AK: Add a simple Queue<T> class.
The underlying data structure is a singly-linked list of Vector<T>. We never shift any of the vector contents around, but we batch the memory allocations into 1000-element segments.
This commit is contained in:
parent
9443957c14
commit
c699d9d79d
4 changed files with 87 additions and 4 deletions
|
@ -1,9 +1,12 @@
|
|||
all: TestString
|
||||
all: TestString TestQueue
|
||||
|
||||
CXXFLAGS = -std=c++17 -Wall -Wextra
|
||||
|
||||
TestString: TestString.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp TestHelpers.h
|
||||
$(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestString.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
|
||||
|
||||
TestQueue: TestQueue.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp TestHelpers.h
|
||||
$(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestQueue.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
|
||||
|
||||
clean:
|
||||
rm -f TestString
|
||||
rm -f TestString TestQueue
|
||||
|
|
31
AK/Tests/TestQueue.cpp
Normal file
31
AK/Tests/TestQueue.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "TestHelpers.h"
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/Queue.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
EXPECT(Queue<int>().is_empty());
|
||||
EXPECT(Queue<int>().size() == 0);
|
||||
|
||||
Queue<int> ints;
|
||||
ints.enqueue(1);
|
||||
ints.enqueue(2);
|
||||
ints.enqueue(3);
|
||||
EXPECT(ints.size() == 3);
|
||||
EXPECT(ints.dequeue() == 1);
|
||||
EXPECT(ints.size() == 2);
|
||||
EXPECT(ints.dequeue() == 2);
|
||||
EXPECT(ints.size() == 1);
|
||||
EXPECT(ints.dequeue() == 3);
|
||||
EXPECT(ints.size() == 0);
|
||||
|
||||
Queue<String> strings;
|
||||
strings.enqueue("ABC");
|
||||
strings.enqueue("DEF");
|
||||
EXPECT(strings.size() == 2);
|
||||
EXPECT(strings.dequeue() == "ABC");
|
||||
EXPECT(strings.dequeue() == "DEF");
|
||||
EXPECT(strings.is_empty());
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue