1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +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:
Andreas Kling 2019-06-15 10:34:03 +02:00
parent 9443957c14
commit c699d9d79d
4 changed files with 87 additions and 4 deletions

31
AK/Tests/TestQueue.cpp Normal file
View 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;
}