Queue¶
| Spice | |
|---|---|
Queue<T> struct¶
A queue in Spice is a commonly used data structure, which uses the FiFo (first in, first out) principle.
Time complexity:
Insert: O(1)
Delete: O(1)
Search: O(n)
Queues pre-allocate space using an initial size and a resize factor to not have to re-allocate with every item pushed.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a queue pre-filled with a number of copies of a default value
Parameters
| Name | Type | Description |
|---|---|---|
initAllocItems |
unsigned long |
Number of items to insert |
defaultValue |
const T& |
Value to fill the queue with |
ctor¶
| Spice | |
|---|---|
Construct a queue, pre-allocating space for the given number of items
Parameters
| Name | Type | Description |
|---|---|---|
initAllocItems |
unsigned int |
Number of items to pre-allocate space for |
ctor¶
| Spice | |
|---|---|
Construct a queue, pre-allocating space for the given number of items
Parameters
| Name | Type | Description |
|---|---|---|
initAllocItems |
unsigned long |
Number of items to pre-allocate space for (default: INITIAL_CAPACITY) |
ctor¶
| Spice | |
|---|---|
Construct a queue as a deep copy of another queue
Parameters
| Name | Type | Description |
|---|---|---|
original |
const Queue<T>& |
Queue to copy |
Methods¶
push¶
| Spice | |
|---|---|
Add an item at the end of the queue
Parameters
| Name | Type | Description |
|---|---|---|
item |
const T& |
pop¶
| Spice | |
|---|---|
Retrieve the first item and remove it
Returns: T& — First item
front¶
| Spice | |
|---|---|
Retrieve the first item without removing it from the queue
Returns: T& — First item
back¶
| Spice | |
|---|---|
Retrieve the last item without removing it from the queue
Returns: T& — Last item
getSize¶
| Spice | |
|---|---|
Retrieve the current size of the queue
Returns: long — Current size of the queue
getCapacity¶
| Spice | |
|---|---|
Retrieve the current capacity of the queue
Returns: long — Current capacity of the queue
isEmpty¶
| Spice | |
|---|---|
Checks if the queue contains any items at the moment
Returns: bool — Empty or not empty
isFull¶
| Spice | |
|---|---|
Checks if the queue exhausts its capacity and needs to resize at the next call of push
Returns: bool — Full or not full
reserve¶
| Spice | |
|---|---|
Reserves itemCount items
Parameters
| Name | Type | Description |
|---|---|---|
itemCount |
unsigned long |
pack¶
| Spice | |
|---|---|
Frees allocated memory that is not used by the queue
Operators¶
operator=¶
| Spice | |
|---|---|
Copy-assign the contents of another queue into this one
Parameters
| Name | Type | Description |
|---|---|---|
newValue |
const Queue<T>& |
Queue to copy from |
operator==¶
| Spice | |
|---|---|
Check if two queues are equal, i.e. they have the same size and equal contents in order
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const Queue<T>& |
|
rhs |
const Queue<T>& |
Returns: bool — Equal or not equal
operator!=¶
| Spice | |
|---|---|
Check if two queues are not equal
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const Queue<T>& |
|
rhs |
const Queue<T>& |
Returns: bool — Not equal or equal