Unbounded queue with automatic capacity growth. More...
#include <queue.hpp>
Public Member Functions | |
| TUnboundedVectorQueue (size_t capacity=16) | |
| Construct queue with initial capacity. | |
| void | Push (T &&item) |
| Add element to the back of the queue. | |
| T & | Front () |
| Get reference to the front element. | |
| void | Pop () |
| Remove the front element from the queue. | |
| bool | TryPop (T &item) |
| size_t | Size () const |
| Get current number of elements in the queue. | |
| bool | Empty () const |
| Check if the queue is empty. | |
Unbounded queue with automatic capacity growth.
| T | Element type stored in the queue |
TUnboundedVectorQueue uses a single vector as circular buffer to avoid the frequent chunk allocations/deallocations that std::queue (std::deque) performs. Power-of-two sizing enables fast bitwise indexing operations. The queue grows by doubling capacity when full, maintaining amortized O(1) push operations while keeping memory usage predictable.
|
inline |
Construct queue with initial capacity.
| capacity | Initial capacity (will be rounded up to power of two) |
|
inline |
Check if the queue is empty.
|
inline |
Get reference to the front element.
|
inline |
Remove the front element from the queue.
|
inline |
Add element to the back of the queue.
| item | Element to add (moved into the queue) |
|
inline |
Get current number of elements in the queue.