ESE_DynamicQueue Class - NarcoMarshDev/Enforce-Script-Extensions GitHub Wiki

Category: Data Structure
Path: scripts/Game/Collections/ESE_DynamicQueue.c

Template class for dynamically sized first-in, first-out collection of objects.

Overview

FIFO data structure with no maximum size or auto dequeuing, oldest element can only be manually dequeued. The raw data behind the scenes is stored in reverse order for optimisation so if wanting to access it directly with ESE_DynamicQueue.Raw make sure to account for this.

Code example of creating, enqueueing entries up the max size and automatically dequeuing to make space for new entries:

auto m_Queue = new ESE_DynamicQueue<int>(); // no starting size parameter
for (int i = 0; i < 5; i++)
{
    m_Queue.Enqueue(i);
}
m_Queue.PrintRaw(); // >>> {4,3,2,1,0}

// add new entry to show lack of auto dequeuing, queue size increases dynamically
m_Queue.Enqueue(5);
m_Queue.PrintRaw(); // >>> {5,4,3,2,1,0}

// manual dequeue
int val = m_Queue.Dequeue();
m_Queue.PrintRaw(); // >>> {5,4,3,2,1}
Print(val); // >>> 0

Constructor

Name⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Description
ESE_Queue<Class T>() Template constructor, no other parameters

Methods

Name⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Return⠀⠀⠀⠀⠀ Description
Enqueue (T value) void Enqueues entry to the end of the queue, increases queue size by 1.
Dequeue () T Returns oldest entry from the queue and removes it. Returned value will be null if queue is empty.
Peek () T Returns oldest entry from the queue without removing it. Returned value will be null if queue is empty.
TryDequeue (out T output) bool (out T) Attempts to dequeue from the queue, returning true if successful or false if the queue is empty. The value dequeued is outputted as an out parameter and will be null if empty.
TryPeek (out T output) Same as TryDequeue() but does not remove entry from queue if found.
Contains (T value) bool Returns true if given value is found in the queue, false otherwise.
Clear () void Clears the contents of the queue.
Count () int Returns number of elements currently in the queue.
TrimTo (int size) void Trims queue to given size. If new size is smaller than old size, all oldest elements beyond new size are removed.
Compact () void Compacts underlying array to reduce memory usage, this has a decent performance impact so don't use in tight loops.
GetDataType () typename Returns current data type of queue contents.
CopyToArray (notnull inout array<T> newArray) void (inout) Copies raw array data of the queue to another array, NOTE the queue data is in reverse order.
CopyFromArray (notnull array<T> inArray) void Copies contents from given array to current queue, and resizes queue to accommodate the new array data.
CopyToStaticQueue (notnull inout ESE_Queue<T> newQueue) void (inout) Copies queue contents to static queue and resizes new queue setting its max size to the count of current dynamic queue.
PrintRaw () void Prints raw array data, Print(ESE_DynamicQueue.Raw) also works for this use.

Properties

Name⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Type⠀⠀⠀⠀⠀ Description
Raw ref array<T> Raw data array of the queue. Data is stored in reverse order.
nullValue T Null value used in returns. This is needed because null is sometimes invalid for certain types.
⚠️ **GitHub.com Fallback** ⚠️