RingBuffer - an array with a Front and Back pointer and with implicit wraparound to the beginning of the array when reaching the end of the array when iterating from Front to Back Useful for providing O(1) push/pop at the end of the array (for Queue or Stack) while still having high cache coherency during iteration. 更多...
#include <RingBuffer.h>
Public 类型 | |
| typedef T | ElementType |
| Type of the Elements in the container. | |
| typedef TMakeSigned< typenameAllocator::SizeType >::Type | IndexType |
| Type used to request values at a given index in the container. | |
| typedef TMakeUnsigned< typenameAllocator::SizeType >::Type | SizeType |
| Type used to communicate size and capacity and counts | |
| typedef TIndexedContainerIterator< TRingBuffer, ElementType, typename Allocator::SizeType > | TIterator |
| Iterator type used for ranged-for traversal. | |
Public 成员函数 | |
| IndexType | Add (const ElementType &Element) |
| Add a new element after the back pointer of the RingBuffer, resizing if necessary. 更多... | |
| IndexType | Add (ElementType &&Element) |
| Add a new element after the back pointer of the RingBuffer, resizing if necessary. 更多... | |
| ElementType & | Add_GetRef (const ElementType &Element) |
| Add a new element after the back pointer of the RingBuffer, resizing if necessary. 更多... | |
| ElementType & | Add_GetRef (ElementType &&Element) |
| Add a new element after the back pointer of the RingBuffer, resizing if necessary. 更多... | |
| IndexType | AddFront (const ElementType &Element) |
| Add a new element before the front pointer of the RingBuffer, resizing if necessary. 更多... | |
| IndexType | AddFront (ElementType &&Element) |
| Add a new element before the front pointer of the RingBuffer, resizing if necessary. 更多... | |
| ElementType & | AddFront_GetRef (const ElementType &Element) |
| Add a new element before the front pointer of the RingBuffer, resizing if necessary. 更多... | |
| ElementType & | AddFront_GetRef (ElementType &&Element) |
| Add a new element before the front pointer of the RingBuffer, resizing if necessary. 更多... | |
| IndexType | AddFrontUninitialized () |
| Add a new element before the front pointer of the RingBuffer, resizing if necessary. 更多... | |
| ElementType & | AddFrontUninitialized_GetRef () |
| Add a new element before the front pointer of the RingBuffer, resizing if necessary. 更多... | |
| IndexType | AddUninitialized () |
| Add a new element after the back pointer of the RingBuffer, resizing if necessary. 更多... | |
| ElementType & | AddUninitialized_GetRef () |
| Add a new element after the back pointer of the RingBuffer, resizing if necessary. 更多... | |
| TIterator | begin () |
| begin iterator for ranged-for | |
| TConstIterator | begin () const |
| begin iterator for const ranged-for | |
| TArrayView< T > | Compact () |
| Shift all elements so that the front pointer's location in memory is less than the back pointer's. 更多... | |
| IndexType | ConvertPointerToIndex (const ElementType *Ptr) const |
| Given a pointer to an Element anywhere in memory, return the index of the element in the RingBuffer, or INDEX_NONE if it is not present. | |
| template<typename... ArgsType> | |
| IndexType | Emplace (ArgsType &&... Args) |
| Add a new element after the back pointer of the RingBuffer, resizing if necessary. 更多... | |
| template<typename... ArgsType> | |
| ElementType & | Emplace_GetRef (ArgsType &&... Args) |
| Add a new element after the back pointer of the RingBuffer, resizing if necessary. 更多... | |
| template<typename... ArgsType> | |
| IndexType | EmplaceFront (ArgsType &&... Args) |
| Add a new element before the front pointer of the RingBuffer, resizing if necessary. 更多... | |
| template<typename... ArgsType> | |
| ElementType & | EmplaceFront_GetRef (ArgsType &&... Args) |
| Add a new element before the front pointer of the RingBuffer, resizing if necessary. 更多... | |
| void | Empty (SizeType Capacity=0) |
| Empty the RingBuffer, destructing any elements and releasing the RingBuffer's storage. 更多... | |
| TIterator | end () |
| end iterator for ranged-for | |
| TConstIterator | end () const |
| end iterator for const ranged-for | |
| ElementType & | First () |
| Return a reference to the element at the front pointer of the RingBuffer. 更多... | |
| const ElementType & | First () const |
| Return a const reference to the element at the front pointer of the RingBuffer. 更多... | |
| ElementType & | GetAtIndexNoCheck (IndexType Index) |
| Unsafely return a writable reference to the value at the given Index. 更多... | |
| const ElementType & | GetAtIndexNoCheck (IndexType Index) const |
| Unsafely return a const reference to the value at the given Index. 更多... | |
| bool | IsEmpty () const |
| Returns true if the RingBuffer is empty. | |
| bool | IsValidIndex (IndexType Index) const |
| Tests if index is valid, i.e. 更多... | |
| ElementType & | Last () |
| Return a reference to the element at the back pointer of the RingBuffer. 更多... | |
| const ElementType & | Last () const |
| Return a const reference to the element at the back pointer of the RingBuffer. 更多... | |
| IndexType | Max () const |
| Current allocated Capacity, note this will always be a power of two, or the special case 0. | |
| IndexType | Num () const |
| Gets the number of elements in the RingBuffer. | |
| ElementType & | operator[] (IndexType Index) |
| Return a writable reference to the value at the given Index. 更多... | |
| const ElementType & | operator[] (IndexType Index) const |
| Return a const reference to the value at the given Index. 更多... | |
| void | Pop (SizeType PopCount=1) |
| Pop the given number of arguments (default: 1) from the back pointer of the RingBuffer. 更多... | |
| void | PopFront (SizeType PopCount=1) |
| Pop the given number of elements (default: 1) from the front pointer of the RingBuffer. 更多... | |
| void | PopFrontNoCheck (SizeType PopCount=1) |
| Unsafely pop the given number of arguments (default: 1) from the front pointer of the RingBuffer. 更多... | |
| void | PopNoCheck (SizeType PopCount=1) |
| Pop the given number of elements (default: 1) from the back pointer of the RingBuffer. 更多... | |
| SizeType | Remove (const ElementType &Item) |
| Removes as many instances of Item as there are in the array, maintaining order but not indices. 更多... | |
| template<typename PredicateType > | |
| SizeType | RemoveAll (PredicateType Predicate) |
| Removes as many instances of Item as there are in the array, maintaining order but not indices. 更多... | |
| void | RemoveAt (IndexType Index) |
| Remove the value at the given index from the RingBuffer, and shift values ahead or behind it into its location to fill the hole. 更多... | |
| void | Reserve (SizeType RequiredCapacity) |
| Set the capacity to the maximum of the current capacity and the (next power of two greater than or equal to) the given capacity. | |
| void | Reset () |
| Empty the RingBuffer, destructing any elements in the RingBuffer but not releasing the RingBuffer's storage. | |
| void | ShiftIndexToBack (IndexType Index) |
| Move the value at the given index into the back pointer of the RingBuffer, and shift all elements behind of it up by one to make room for it. 更多... | |
| void | ShiftIndexToFront (IndexType Index) |
| Move the value at the given index into the front pointer of the RingBuffer, and shift all elements ahead of it down by one to make room for it. 更多... | |
| void | Trim () |
| Set the capacity to the minimum power of two (or 0) greater than or equal to the current number of elements in the RingBuffer. | |
| TRingBuffer () | |
| Construct Empty Queue with capacity 0. | |
| TRingBuffer (SizeType InitialCapacity) | |
| Construct Empty Queue with the given initial requested capacity. | |
| TRingBuffer (std::initializer_list< ElementType > InitList) | |
| Construct a Queue with initial state (from front to back) equal to the given list. | |
RingBuffer - an array with a Front and Back pointer and with implicit wraparound to the beginning of the array when reaching the end of the array when iterating from Front to Back Useful for providing O(1) push/pop at the end of the array (for Queue or Stack) while still having high cache coherency during iteration.
Not threadsafe; caller must ensure there is no simultaneous access from multiple threads.
Implementation Details: Relies on unsigned arithmetics and ever increasing Front and Back indices to avoid having to store an extra element or maintain explicit empty state. Capacity will always be rounded up to the next power of two, to provide rapid masking of the index.
|
inline |
Add a new element after the back pointer of the RingBuffer, resizing if necessary.
The new element is copy constructed from the argument. Returns the index to the added element.
|
inline |
Add a new element after the back pointer of the RingBuffer, resizing if necessary.
The new element is move constructed from the argument. Returns the index of the added element.
|
inline |
Add a new element after the back pointer of the RingBuffer, resizing if necessary.
The new element is copy constructed from the argument. Returns a reference to the added element.
|
inline |
Add a new element after the back pointer of the RingBuffer, resizing if necessary.
The new element is move constructed from the argument. Returns a reference to the added element.
|
inline |
Add a new element before the front pointer of the RingBuffer, resizing if necessary.
The new element is copy constructed from the argument. Returns the index to the added element.
|
inline |
Add a new element before the front pointer of the RingBuffer, resizing if necessary.
The new element is move constructed from the argument. Returns the index of the added element.
|
inline |
Add a new element before the front pointer of the RingBuffer, resizing if necessary.
The new element is copy constructed from the argument. Returns a reference to the added element.
|
inline |
Add a new element before the front pointer of the RingBuffer, resizing if necessary.
The new element is move constructed from the argument. Returns a reference to the added element.
|
inline |
Add a new element before the front pointer of the RingBuffer, resizing if necessary.
The constructor is not called on the new element and its values in memory are arbitrary. Returns the index to the added element.
|
inline |
Add a new element before the front pointer of the RingBuffer, resizing if necessary.
The constructor is not called on the new element and its values in memory are arbitrary. Returns a reference to the added element.
|
inline |
Add a new element after the back pointer of the RingBuffer, resizing if necessary.
The constructor is not called on the new element and its values in memory are arbitrary. Returns the index to the added element.
|
inline |
Add a new element after the back pointer of the RingBuffer, resizing if necessary.
The constructor is not called on the new element and its values in memory are arbitrary. Returns a reference to the added element.
|
inline |
Shift all elements so that the front pointer's location in memory is less than the back pointer's.
Returns a temporary ArrayView for the RingBuffer's elements; the returned ArrayView will be invalid after the next write operation on the RingBuffer.
|
inline |
Add a new element after the back pointer of the RingBuffer, resizing if necessary.
The new element is constructed from the given arguments. Returns the index to the added element.
|
inline |
Add a new element after the back pointer of the RingBuffer, resizing if necessary.
The new element is constructed from the given arguments. Returns a reference to the added element.
|
inline |
Add a new element before the front pointer of the RingBuffer, resizing if necessary.
The new element is constructed from the given arguments. Returns the index to the added element.
|
inline |
Add a new element before the front pointer of the RingBuffer, resizing if necessary.
The new element is constructed from the given arguments. Returns a reference to the added element.
|
inline |
Empty the RingBuffer, destructing any elements and releasing the RingBuffer's storage.
Sets the new capacity after release to the given capacity.
|
inline |
Return a reference to the element at the front pointer of the RingBuffer.
Invalid to call on an empty RingBuffer.
|
inline |
Return a const reference to the element at the front pointer of the RingBuffer.
Invalid to call on an empty RingBuffer.
|
inline |
Unsafely return a writable reference to the value at the given Index.
Invalid to call (and does not warn) with an index less than 0 or greater than or equal to the number of elements in the RingBuffer.
|
inline |
Unsafely return a const reference to the value at the given Index.
Invalid to call (and does not warn) with an index less than 0 or greater than or equal to the number of elements in the RingBuffer.
|
inline |
Tests if index is valid, i.e.
greater than or equal to zero, and less than the number of elements in the array.
|
inline |
Return a reference to the element at the back pointer of the RingBuffer.
Invalid to call on an empty RingBuffer.
|
inline |
Return a const reference to the element at the back pointer of the RingBuffer.
Invalid to call on an empty RingBuffer.
|
inline |
Return a writable reference to the value at the given Index.
Invalid to call with an index less than 0 or greater than or equal to the number of elements in the RingBuffer.
|
inline |
Return a const reference to the value at the given Index.
Invalid to call with an index less than 0 or greater than or equal to the number of elements in the RingBuffer.
|
inline |
Pop the given number of arguments (default: 1) from the back pointer of the RingBuffer.
Invalid to call with a number of elements greater than the current number of elements in the RingBuffer.
|
inline |
Pop the given number of elements (default: 1) from the front pointer of the RingBuffer.
Invalid to call with a number of elements greater than the current number of elements in the RingBuffer.
|
inline |
Unsafely pop the given number of arguments (default: 1) from the front pointer of the RingBuffer.
Invalid to call (and does not warn) with a number of elements greater than the current number of elements in the RingBuffer.
|
inline |
Pop the given number of elements (default: 1) from the back pointer of the RingBuffer.
Invalid to call (and does not warn) with a number of elements greater than the current number of elements in the RingBuffer.
|
inline |
Removes as many instances of Item as there are in the array, maintaining order but not indices.
| Item | Item to remove from array. |
|
inline |
Removes as many instances of Item as there are in the array, maintaining order but not indices.
| Item | Item to remove from array. |
|
inline |
Remove the value at the given index from the RingBuffer, and shift values ahead or behind it into its location to fill the hole.
It is valid to call with Index outside of the range of the array; does nothing in that case.
|
inline |
Move the value at the given index into the back pointer of the RingBuffer, and shift all elements behind of it up by one to make room for it.
Invalid to call with an index less than 0 or greater than or equal to the number of elements in the RingBuffer.
|
inline |
Move the value at the given index into the front pointer of the RingBuffer, and shift all elements ahead of it down by one to make room for it.
Invalid to call with a negative index or index greater than the number of elements in the RingBuffer.