Queue
An ordered, first-in-first-out (FIFO) collection
The Queue is implemented using a circular buffer, which allows for efficient enqueue and dequeue operations with a constant time complexity. To optimize performance, it utilizes an UnsafeMutablePointer instead of a standard Swift Array. The buffer automatically resizes to ensure optimal use of memory, by increasing the capacity when the number of elements in the queue reaches the current capacity, and reducing it when it drops below a quarter of the current capacity.
-
Maximum capacity of buffer
-
The front element of the queue
-
A boolean indicating whether the queue is empty
-
Initializes a new queue with a given capacity
-
Enqueues an element to the back of the queue
Complexity
O(1)
-
Dequeues the front element from the queue
Complexity
O(1)
View on GitHub
Install in Dash
Queue Class Reference