Queue

Array structure that allows addition/deletion at both ends.

Intended to be used as a FIFO-queue or as a stack by combining pushFront/pushBack and popFront/popBack appropriately. Implemented as a circular buffer inside a continuous block of memory that is automatically expanded as necessary, similar to jive.Array.

Constructors

this
this(Stuff stuff)

constructor that gets content from arbitrary range

Destructor

~this
~this()

destructor

Postblit

this(this)
this(this)

post-blit that does a full copy

Members

Functions

back
inout(V) back()

last element, same as this[$-1]

capacity
size_t capacity()

number of elements this structure can hold without further allocations

clear
void clear()

remove all content but keep allocated memory

empty
bool empty()

check for emptiness

front
inout(V) front()

first element, same as this[0]

length
size_t length()

number of elements

memUsage
size_t memUsage()

Allocated heap memory in bytes. This is recursive if V has a .memUsage property. Otherwise it is equal to V.sizeof * capacity

opDollar
size_t opDollar()

number of elements

opIndex
inout(V) opIndex(size_t i)

indexing

opSlice
auto opSlice()

default range

popBack
V popBack()

removes last element of the queue and returns it

popFront
V popFront()

removes first element of the queue and returns it

pushBack
void pushBack(V val)

add an element to the back of the queue

pushBack
void pushBack(Stuff stuff)

add multiple elements to the back of the queue

pushFront
void pushFront(V val)

add an element to the front of the queue

pushFront
void pushFront(Stuff stuff)

add multiple elements to the front of the queue

reserve
void reserve(size_t newCap, bool overEstimate)

make sure this structure can contain given number of elements without further allocs

Examples

Queue!int a;
a.pushBack([1,2,3]);
a.pushFront([4,5,6]);

assert(equal(a[], [6,5,4,1,2,3]));

assert(a.popFront == 6);
assert(a.popBack == 3);

assert(a.length == 4);

Meta