2#include "../Memory/MemoryBuffer.h"
3#include "../BitTwiddling/PowerOfTwo.h"
16 template<
typename Element,
typename IndexBaseType>
23 typedef typename std::make_unsigned<IndexBaseType>::type
IndexType;
36 return frontOffsetWrap == backOffsetWrap;
44 return backOffsetWrap - frontOffsetWrap + (backOffsetWrap < frontOffsetWrap ? capacity() : static_cast<IndexType>(0));
67 if (sizeL2New ==
sizeL2)
return;
94 assert(
false &&
"queue is empty");
103 assert(
empty() ==
false);
113 assert(
empty() ==
false);
141 if (
empty())
return false;
177 for (uint32_t i = 0; i <
N; i++) {
Indexable queue where an element index is fixed through arbitrary enqueues and dequeues.
Definition: FixedIndexQueue.h:18
void pushFront(Element e)
Adds a new element to the front of the queue.
Definition: FixedIndexQueue.h:82
IndexType count() const
Returns number of elements currently in the queue.
Definition: FixedIndexQueue.h:40
bool validIndex(uint32_t fixedIndex) const
Check if a fixed index is valid, that is, refers to an element in the queue.
Definition: FixedIndexQueue.h:139
Element & operator[](IndexType fixedIndex)
Look up an element in the queue by a fixed index.
Definition: FixedIndexQueue.h:101
void clear()
Removes all entries from the queue, but will continue with new unused indices.
Definition: FixedIndexQueue.h:48
Element & front()
Returns front element.
Definition: FixedIndexQueue.h:121
const Element & front() const
Returns front element.
Definition: FixedIndexQueue.h:124
IndexType frontOffset
Definition: FixedIndexQueue.h:151
void shrink()
Reduce capacity to the minimum needed to preserve the contents.
Definition: FixedIndexQueue.h:64
bool noCapacity() const
True if there is no free capacity left.
Definition: FixedIndexQueue.h:157
void resize(IndexType sizeL2New)
Definition: FixedIndexQueue.h:168
void pushBack(Element e)
Adds a new element to the back of the queue.
Definition: FixedIndexQueue.h:73
IndexType frontIndex() const
Returns fixed index of front.
Definition: FixedIndexQueue.h:133
void reset()
Removes all entries from the queue, recycles indices and starts from zero.
Definition: FixedIndexQueue.h:56
IndexType empty() const
Returns true if there are currently no elements in the queue.
Definition: FixedIndexQueue.h:32
const IndexType capacity() const
Returns the current capacity of the queue.
Definition: FixedIndexQueue.h:29
IndexType sizeL2
Definition: FixedIndexQueue.h:149
IndexType backOffset
Definition: FixedIndexQueue.h:152
const Element & operator[](IndexType fixedIndex) const
Look up an element in the queue by a fixed index.
Definition: FixedIndexQueue.h:111
Element & back()
Returns back element.
Definition: FixedIndexQueue.h:127
std::make_signed< IndexBaseType >::type SignedIndexType
Signed helper type.
Definition: FixedIndexQueue.h:20
IndexType offsetToFixedIndexShift
Definition: FixedIndexQueue.h:153
void grow()
Double the capacity of the queue.
Definition: FixedIndexQueue.h:160
Cogs::Memory::TypedBuffer< Element > storage
Definition: FixedIndexQueue.h:154
const Element & back() const
Returns back element.
Definition: FixedIndexQueue.h:130
IndexType sizeMask
Definition: FixedIndexQueue.h:150
void popFront()
Removes the front from the queue.
Definition: FixedIndexQueue.h:91
IndexType backIndex() const
Returns fixed index of current back element.
Definition: FixedIndexQueue.h:136
std::make_unsigned< IndexBaseType >::type IndexType
Unsigned type used for indices, typically uint32_t or uin64_t.
Definition: FixedIndexQueue.h:23
FixedIndexQueue()
Constructor.
Definition: FixedIndexQueue.h:26
Definition: MemoryBuffer.h:197
void swap(TypedBuffer &other)
Definition: MemoryBuffer.h:235
bool resize(size_t size, bool keep=true, bool forceRealloc=false)
Definition: MemoryBuffer.h:213
Main Cogs namespace.
Definition: MortonCode.h:5
bool isPowerOfTwo(T x)
Definition: PowerOfTwo.h:15
uint8_t roundUpToPowerOfTwoShift(uint8_t x)
Definition: PowerOfTwo.h:170