ezEngine  Milestone 7
ezIdTableBase< IdType, ValueType > Class Template Reference

Implementation of an id mapping table which stores id/value pairs. More...

#include <IdTable.h>

Inheritance diagram for ezIdTableBase< IdType, ValueType >:

Classes

class  ConstIterator
 Const iterator. More...
 
struct  Entry
 
struct  Iterator
 Iterator with write access. More...
 

Public Types

typedef IdType::StorageType IndexType
 
typedef IdType TypeOfId
 

Public Member Functions

void Reserve (IndexType uiCapacity)
 Expands the table so it can at least store the given capacity.
 
IndexType GetCount () const
 Returns the number of active entries in the table.
 
bool IsEmpty () const
 Returns true, if the table does not contain any elements.
 
void Clear ()
 Clears the table.
 
IdType Insert (const ValueType &value)
 Inserts the value into the table and returns the corresponding id.
 
bool Remove (const IdType id, ValueType *out_oldValue=nullptr)
 Removes the entry with the given id. Returns if an entry was removed and optionally writes out the old value to out_oldValue.
 
bool TryGetValue (const IdType id, ValueType &out_value) const
 Returns if an entry with the given id was found and if found writes out the corresponding value to out_value.
 
bool TryGetValue (const IdType id, ValueType *&out_pValue) const
 Returns if an entry with the given id was found and if found writes out the pointer to the corresponding value to out_pValue.
 
const ValueType & operator[] (const IdType id) const
 Returns the value to the given id. Does bounds checks in debug builds.
 
ValueType & operator[] (const IdType id)
 Returns the value to the given id. Does bounds checks in debug builds.
 
const ValueType & GetValueUnchecked (const IndexType index) const
 Returns the value at the given index. Does bounds checks in debug builds but does not check for stale access.
 
ValueType & GetValueUnchecked (const IndexType index)
 Returns the value at the given index. Does bounds checks in debug builds but does not check for stale access.
 
bool Contains (const IdType id) const
 Returns if the table contains an entry corresponding to the given id.
 
Iterator GetIterator ()
 Returns an Iterator to the very first element.
 
ConstIterator GetIterator () const
 Returns a constant Iterator to the very first element.
 
ezAllocatorBaseGetAllocator () const
 Returns the allocator that is used by this instance.
 
bool IsFreelistValid () const
 Returns whether the internal free-list is valid. For testing purpose only.
 

Protected Member Functions

 ezIdTableBase (ezAllocatorBase *pAllocator)
 Creates an empty id-table. Does not allocate any data yet.
 
 ezIdTableBase (const ezIdTableBase< IdType, ValueType > &rhs, ezAllocatorBase *pAllocator)
 Creates a copy of the given id-table.
 
 ~ezIdTableBase ()
 Destructor.
 
void operator= (const ezIdTableBase< IdType, ValueType > &rhs)
 Copies the data from another table into this one.
 

Private Types

enum  { CAPACITY_ALIGNMENT = 16 }
 

Private Member Functions

void SetCapacity (IndexType uiCapacity)
 
void InitializeFreelist (IndexType uiStart, IndexType uiEnd)
 

Private Attributes

Entrym_pEntries
 
IndexType m_uiCount
 
IndexType m_uiCapacity
 
IndexType m_uiFreelistEnqueue
 
IndexType m_uiFreelistDequeue
 
ezAllocatorBasem_pAllocator
 

Detailed Description

template<typename IdType, typename ValueType>
class ezIdTableBase< IdType, ValueType >

Implementation of an id mapping table which stores id/value pairs.

An id contains an index into the table and a generation counter to detect if a table entry was re-used. All insertion/erasure/lookup functions take O(1) time if the table does not need to be expanded. Lookup is nearly as fast as a simple array lookup. The table stores a free-list in its free elements to ensure fast insertion/erasure.

See Also
ezGenericId

Class Documentation

struct ezIdTableBase::Entry

template<typename IdType, typename ValueType>
struct ezIdTableBase< IdType, ValueType >::Entry

Class Members
IdType id
ValueType value

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