Nebula
Loading...
Searching...
No Matches
Util::Queue< TYPE > Class Template Reference

#include <queue.h>

Detailed Description

template<class TYPE>
class Util::Queue< TYPE >

Nebula's queue class (a FIFO container).

Faster queue class that apart from Enqueue has constant time operations.

Todo
This is extremely slow and should probably use a list instead.

Assumes that items can be trivially moved by using memmove.

Public Member Functions

 Queue ()
 constructor
 
 ~Queue ()
 destructor
 
 Queue (const Queue< TYPE > &rhs)
 copy constructor
 
 Queue (Queue< TYPE > &&rhs)
 move constructor
 
void operator= (const Queue< TYPE > &rhs)
 assignment operator
 
void operator= (Queue< TYPE > &&rhs)
 move assignment operator
 
TYPE & operator[] (IndexT index) const
 access element by index, 0 is the frontmost element (next to be dequeued)
 
bool operator== (const Queue< TYPE > &rhs) const
 equality operator
 
bool operator!= (const Queue< TYPE > &rhs) const
 inequality operator
 
void Reserve (SizeT num)
 increase capacity to fit N more elements into the Dequeue (slow)
 
void Grow ()
 grow Dequeue by internal growing rules (slow)
 
SizeT Size () const
 returns number of elements in the Dequeue
 
SizeT Capacity () const
 returns allocation of elements in the Dequeue
 
bool IsEmpty () const
 return true if Dequeue is empty
 
void Clear ()
 remove all elements from the Dequeue
 
bool Contains (const TYPE &e) const
 return true if Dequeue contains element
 
void EraseIndex (const IndexT i)
 erase element at index (slow!!)
 
void Enqueue (const TYPE &e)
 add element to the back of the Dequeue, can trigger grow
 
void Enqueue (TYPE &&e)
 
TYPE Dequeue ()
 remove the element from the front of the Dequeue
 
TYPE & Peek () const
 access to element at front of Dequeue without removing it
 

Protected Member Functions

template<typename X >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==false >::type DestroyElement (IndexT idx)
 
template<typename X >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==true >::type DestroyElement (IndexT idx)
 
template<typename X >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==false >::type ClearAll ()
 
template<typename X >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==true >::type ClearAll ()
 
IndexT MapIndex (IndexT index) const
 maps index to actual item position using wrapping
 

Protected Attributes

TYPE * data
 
SizeT grow
 
SizeT start
 
SizeT size
 
SizeT capacity
 

Static Protected Attributes

static const SizeT MinGrowSize = 16
 
static const SizeT MaxGrowSize = 65536
 

Constructor & Destructor Documentation

◆ Queue() [1/3]

template<class TYPE >
Util::Queue< TYPE >::Queue ( )

constructor

◆ ~Queue()

template<class TYPE >
Util::Queue< TYPE >::~Queue ( )

destructor

◆ Queue() [2/3]

template<class TYPE >
Util::Queue< TYPE >::Queue ( const Queue< TYPE > & rhs)

copy constructor

◆ Queue() [3/3]

template<class TYPE >
Util::Queue< TYPE >::Queue ( Queue< TYPE > && rhs)

move constructor

Member Function Documentation

◆ Capacity()

template<class TYPE >
__forceinline SizeT Util::Queue< TYPE >::Capacity ( ) const

returns allocation of elements in the Dequeue

◆ Clear()

template<class TYPE >
void Util::Queue< TYPE >::Clear ( )

remove all elements from the Dequeue

◆ ClearAll() [1/2]

template<class TYPE >
template<typename X >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==false >::type Util::Queue< TYPE >::ClearAll ( )
inlineprotected

◆ ClearAll() [2/2]

template<class TYPE >
template<typename X >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==true >::type Util::Queue< TYPE >::ClearAll ( )
inlineprotected

◆ Contains()

template<class TYPE >
bool Util::Queue< TYPE >::Contains ( const TYPE & e) const

return true if Dequeue contains element

◆ Dequeue()

template<class TYPE >
__forceinline TYPE Util::Queue< TYPE >::Dequeue ( )

remove the element from the front of the Dequeue

◆ DestroyElement() [1/2]

template<class TYPE >
template<typename X >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==false >::type Util::Queue< TYPE >::DestroyElement ( IndexT idx)
inlineprotected

◆ DestroyElement() [2/2]

template<class TYPE >
template<typename X >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==true >::type Util::Queue< TYPE >::DestroyElement ( IndexT idx)
inlineprotected

◆ Enqueue() [1/2]

template<class TYPE >
__forceinline void Util::Queue< TYPE >::Enqueue ( const TYPE & e)

add element to the back of the Dequeue, can trigger grow

◆ Enqueue() [2/2]

template<class TYPE >
__forceinline void Util::Queue< TYPE >::Enqueue ( TYPE && e)

◆ EraseIndex()

template<class TYPE >
void Util::Queue< TYPE >::EraseIndex ( const IndexT i)

erase element at index (slow!!)

◆ Grow()

template<class TYPE >
void Util::Queue< TYPE >::Grow ( )

grow Dequeue by internal growing rules (slow)

◆ IsEmpty()

template<class TYPE >
__forceinline bool Util::Queue< TYPE >::IsEmpty ( ) const

return true if Dequeue is empty

◆ MapIndex()

template<class TYPE >
__forceinline IndexT Util::Queue< TYPE >::MapIndex ( IndexT idx) const
protected

maps index to actual item position using wrapping

Maps an index onto the actual array index by wrapping around.

can deal with negative indices as well

◆ operator!=()

template<class TYPE >
bool Util::Queue< TYPE >::operator!= ( const Queue< TYPE > & rhs) const

inequality operator

◆ operator=() [1/2]

template<class TYPE >
void Util::Queue< TYPE >::operator= ( const Queue< TYPE > & rhs)

assignment operator

◆ operator=() [2/2]

template<class TYPE >
void Util::Queue< TYPE >::operator= ( Queue< TYPE > && rhs)

move assignment operator

◆ operator==()

template<class TYPE >
bool Util::Queue< TYPE >::operator== ( const Queue< TYPE > & rhs) const

equality operator

◆ operator[]()

template<class TYPE >
__forceinline TYPE & Util::Queue< TYPE >::operator[] ( IndexT index) const

access element by index, 0 is the frontmost element (next to be dequeued)

◆ Peek()

template<class TYPE >
__forceinline TYPE & Util::Queue< TYPE >::Peek ( ) const

access to element at front of Dequeue without removing it

◆ Reserve()

template<class TYPE >
void Util::Queue< TYPE >::Reserve ( SizeT num)

increase capacity to fit N more elements into the Dequeue (slow)

◆ Size()

template<class TYPE >
__forceinline SizeT Util::Queue< TYPE >::Size ( ) const

returns number of elements in the Dequeue

Member Data Documentation

◆ capacity

template<class TYPE >
SizeT Util::Queue< TYPE >::capacity
protected

◆ data

template<class TYPE >
TYPE* Util::Queue< TYPE >::data
protected

◆ grow

template<class TYPE >
SizeT Util::Queue< TYPE >::grow
protected

◆ MaxGrowSize

template<class TYPE >
const SizeT Util::Queue< TYPE >::MaxGrowSize = 65536
staticprotected

◆ MinGrowSize

template<class TYPE >
const SizeT Util::Queue< TYPE >::MinGrowSize = 16
staticprotected

◆ size

template<class TYPE >
SizeT Util::Queue< TYPE >::size
protected

◆ start

template<class TYPE >
SizeT Util::Queue< TYPE >::start
protected

The documentation for this class was generated from the following file: