Support Forum       G3D Web Page     
Public Member Functions | List of all members
G3D::OrderedTable< Key, Value > Class Template Reference


A Table that can be iterated through by index, preserves ordering, and implicitly supports removal during iteration. More...

Public Member Functions

void clear ()
 
bool containsKey (const Key &key) const
 
bool containsValue (const Value &v) const
 
void fastRemoveKey (const Key &k)
 Removes the element with this key by swapping it with the last element. More...
 
int findIndexOfKey (const Key &key) const
 Returns -1 if not found. More...
 
int findIndexOfValue (const Value &value) const
 Returns -1 if not found. More...
 
int index (const Key &key) const
 Returns the index for this key (same as findIndexOfKey) More...
 
const Key & key (int i) const
 Return the key for this index. More...
 
void removeKey (const Key &k)
 Removes the element with this key and slides other elements down to fill the hole. More...
 
void set (const Key &key, const Value &value)
 
int size () const
 
Value & valueFromIndex (int i)
 
const Value & valueFromIndex (int i) const
 
Value & valueFromKey (const Key &k)
 
const Value & valueFromKey (const Key &k) const
 

Detailed Description

template<class Key, class Value>
class G3D::OrderedTable< Key, Value >


A Table that can be iterated through by index, preserves ordering, and implicitly supports removal during iteration.

Useful for creating arrays of Entitys or other objects that need efficient fetch by name or ID but also efficient, order-preserving iteration.

Does not overload operator[] to avoid ambiguity when the Key is an integer type.

Member Function Documentation

◆ clear()

template<class Key , class Value >
void G3D::OrderedTable< Key, Value >::clear ( )
inline

◆ containsKey()

template<class Key , class Value >
bool G3D::OrderedTable< Key, Value >::containsKey ( const Key &  key) const
inline

◆ containsValue()

template<class Key , class Value >
bool G3D::OrderedTable< Key, Value >::containsValue ( const Value &  v) const
inline

◆ fastRemoveKey()

template<class Key , class Value >
void G3D::OrderedTable< Key, Value >::fastRemoveKey ( const Key &  k)
inline

Removes the element with this key by swapping it with the last element.

Amortized expected O(1) time.

◆ findIndexOfKey()

template<class Key , class Value >
int G3D::OrderedTable< Key, Value >::findIndexOfKey ( const Key &  key) const
inline

Returns -1 if not found.

O(1) amortized expected time.

Referenced by G3D::OrderedTable< Key, Value >::index().

◆ findIndexOfValue()

template<class Key , class Value >
int G3D::OrderedTable< Key, Value >::findIndexOfValue ( const Value &  value) const
inline

Returns -1 if not found.

O(n) expected time.

Referenced by G3D::OrderedTable< Key, Value >::containsValue().

◆ index()

template<class Key , class Value >
int G3D::OrderedTable< Key, Value >::index ( const Key &  key) const
inline

Returns the index for this key (same as findIndexOfKey)

See also
key

Referenced by G3D::OrderedTable< Key, Value >::set().

◆ key()

template<class Key , class Value >
const Key& G3D::OrderedTable< Key, Value >::key ( int  i) const
inline

◆ removeKey()

template<class Key , class Value >
void G3D::OrderedTable< Key, Value >::removeKey ( const Key &  k)
inline

Removes the element with this key and slides other elements down to fill the hole.

O(n) time in the size of the table.

◆ set()

template<class Key , class Value >
void G3D::OrderedTable< Key, Value >::set ( const Key &  key,
const Value &  value 
)
inline

◆ size()

template<class Key , class Value >
int G3D::OrderedTable< Key, Value >::size ( ) const
inline

◆ valueFromIndex() [1/2]

template<class Key , class Value >
Value& G3D::OrderedTable< Key, Value >::valueFromIndex ( int  i)
inline

◆ valueFromIndex() [2/2]

template<class Key , class Value >
const Value& G3D::OrderedTable< Key, Value >::valueFromIndex ( int  i) const
inline

◆ valueFromKey() [1/2]

template<class Key , class Value >
Value& G3D::OrderedTable< Key, Value >::valueFromKey ( const Key &  k)
inline

◆ valueFromKey() [2/2]

template<class Key , class Value >
const Value& G3D::OrderedTable< Key, Value >::valueFromKey ( const Key &  k) const
inline

documentation generated on Wed Nov 24 2021 08:01:58 using doxygen 1.8.15