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


An unordered data structure mapping keys to values; maintained behind the scenes in a linear array More...

Classes

class  Entry
 
The pairs returned by iterator. More...
 
class  Iterator
 
C++ STL style iterator variable. More...
 

Public Member Functions

 SmallTable ()
 
Creates an empty hash table using the default MemoryManager. More...
 
 SmallTable (const ThisType &h)
 Uses the default memory manager. More...
 
Iterator begin () const
 
C++ STL style iterator method. More...
 
void clear ()
 
Removes all elements. More...
 
bool containsKey (const Key &key) const
 
Returns true if key is in the table. More...
 
bool containsValue (const Value &value) const
 
Returns true if any key maps to value using operator==. More...
 
void deleteKeys ()
 
Calls delete on all of the keys and then clears the table. More...
 
void deleteValues ()
 
Calls delete on all of the values. More...
 
const Iterator end () const
 
C++ STL style iterator method. More...
 
void fastClear ()
 
Value & get (const Key &key) const
 
Returns the value associated with key. More...
 
bool get (const Key &key, Value &val) const
 
If the key is present in the table, val is set to the associated value and returns true. More...
 
Value & getCreate (const Key &key)
 Returns the current value that key maps to, creating it if necessary. More...
 
Value & getCreate (const Key &key, bool &created)
 
EntrygetCreateEntry (const Key &key, bool &created)
 Called by getCreate() and set() More...
 
EntrygetCreateEntry (const Key &key)
 
const Key * getKeyPointer (const Key &key) const
 If a value that is EqualsFunc to member is present, returns a pointer to the version stored in the data structure, otherwise returns nullptr. More...
 
Array< Key > getKeys () const
 
Returns an array of all of the keys in the table. More...
 
void getKeys (Array< Key > &keyArray) const
 
Value * getPointer (const Key &key) const
 Returns a pointer to the element if it exists, or nullptr if it does not. More...
 
bool getRemove (const Key &key, Key &removedKey, Value &removedValue)
 If member is present, sets removed to the element being removed and returns true. More...
 
void getValues (Array< Value > &valueArray) const
 Will contain duplicate values if they exist in the table. More...
 
template<class H , class E >
bool operator!= (const Table< Key, Value, H, E > &other) const
 
SmallTableoperator= (const ThisType &h)
 
template<class H , class E >
bool operator== (const Table< Key, Value, H, E > &other) const
 
Value & operator[] (const Key &key) const
 
Short syntax for get. More...
 
bool remove (const Key &key)
 
Removes an element from the table if it is present. More...
 
void set (const Key &key, const Value &value)
 
If you insert a pointer into the key or value of a table, you are responsible for deallocating the object eventually. More...
 
void setSizeHint (size_t n)
 
Recommends that the table resize to anticipate at least this number of elements. More...
 
size_t size () const
 
Returns the number of keys. More...
 

Detailed Description

template<class Key, class Value, class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
class G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >


An unordered data structure mapping keys to values; maintained behind the scenes in a linear array

See also
G3D::Table

Constructor & Destructor Documentation

◆ SmallTable() [1/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::SmallTable ( )
inline


Creates an empty hash table using the default MemoryManager.

◆ SmallTable() [2/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::SmallTable ( const ThisType h)
inline

Uses the default memory manager.

Member Function Documentation

◆ begin()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Iterator G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::begin ( ) const
inline


C++ STL style iterator method.

Returns the first Entry, which contains a key and value. Use preincrement (++entry) to get to the next element. Do not modify the table while iterating.

Referenced by G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::containsValue(), and G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::operator==().

◆ clear()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
void G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::clear ( )
inline


Removes all elements.

Guaranteed to free all memory associated with the table.

Referenced by G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::deleteKeys().

◆ containsKey()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
bool G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::containsKey ( const Key &  key) const
inline


Returns true if key is in the table.

◆ containsValue()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
bool G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::containsValue ( const Value &  value) const
inline


Returns true if any key maps to value using operator==.

◆ deleteKeys()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
void G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::deleteKeys ( )
inline


Calls delete on all of the keys and then clears the table.

◆ deleteValues()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
void G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::deleteValues ( )
inline


Calls delete on all of the values.

This is unsafe– do not call unless you know that each value appears at most once.

Does not clear the table, so you are left with a table of nullptr pointers.

◆ end()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
const Iterator G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::end ( ) const
inline


C++ STL style iterator method.

Returns one after the last iterator element.

◆ fastClear()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
void G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::fastClear ( )
inline

◆ get() [1/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Value& G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::get ( const Key &  key) const
inline


Returns the value associated with key.

Deprecated:
Use get(key, val) or getPointer(key)

◆ get() [2/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
bool G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::get ( const Key &  key,
Value &  val 
) const
inline


If the key is present in the table, val is set to the associated value and returns true.

If the key is not present, returns false.

◆ getCreate() [1/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Value& G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getCreate ( const Key &  key)
inline

Returns the current value that key maps to, creating it if necessary.

◆ getCreate() [2/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Value& G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getCreate ( const Key &  key,
bool &  created 
)
inline
Parameters
createdTrue if the element was created.

◆ getCreateEntry() [1/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Entry& G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getCreateEntry ( const Key &  key,
bool &  created 
)
inline

◆ getCreateEntry() [2/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Entry& G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getCreateEntry ( const Key &  key)
inline

◆ getKeyPointer()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
const Key* G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getKeyPointer ( const Key &  key) const
inline

If a value that is EqualsFunc to member is present, returns a pointer to the version stored in the data structure, otherwise returns nullptr.

◆ getKeys() [1/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Array<Key> G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getKeys ( ) const
inline


Returns an array of all of the keys in the table.

You can iterate over the keys to get the values.

Deprecated:

◆ getKeys() [2/2]

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
void G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getKeys ( Array< Key > &  keyArray) const
inline

◆ getPointer()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Value* G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getPointer ( const Key &  key) const
inline

Returns a pointer to the element if it exists, or nullptr if it does not.

Note that if your value type is a pointer, the return value is a pointer to a pointer. Do not remove the element while holding this pointer.

It is easy to accidentally mis-use this method. Consider making a Table<Value*> and using get(key, val) instead, which makes you manage the memory for the values yourself and is less likely to result in pointer errors.

Referenced by G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::get().

◆ getRemove()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
bool G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getRemove ( const Key &  key,
Key &  removedKey,
Value &  removedValue 
)
inline

If member is present, sets removed to the element being removed and returns true.

Otherwise returns false and does not write to removed.

◆ getValues()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
void G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getValues ( Array< Value > &  valueArray) const
inline

Will contain duplicate values if they exist in the table.

This array is parallel to the one returned by getKeys() if the table has not been modified.

◆ operator!=()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
template<class H , class E >
bool G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::operator!= ( const Table< Key, Value, H, E > &  other) const
inline

◆ operator=()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
SmallTable& G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::operator= ( const ThisType h)
inline

◆ operator==()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
template<class H , class E >
bool G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::operator== ( const Table< Key, Value, H, E > &  other) const
inline

◆ operator[]()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
Value& G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::operator[] ( const Key &  key) const
inline


Short syntax for get.

◆ remove()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
bool G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::remove ( const Key &  key)
inline


Removes an element from the table if it is present.

Returns
true if the element was found and removed, otherwise false

◆ set()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
void G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::set ( const Key &  key,
const Value &  value 
)
inline


If you insert a pointer into the key or value of a table, you are responsible for deallocating the object eventually.

Inserting key into a table is O(1), but may cause a potentially slow rehashing.

◆ setSizeHint()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
void G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::setSizeHint ( size_t  n)
inline


Recommends that the table resize to anticipate at least this number of elements.

◆ size()

template<class Key , class Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
size_t G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::size ( ) const
inline


Returns the number of keys.

Referenced by G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::operator==().


documentation generated on Wed Nov 24 2021 08:02:00 using doxygen 1.8.15