Support Forum       G3D Web Page     
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD > Class Template Reference

Implemented with an open-addressing hash table that does not support remove. More...

Classes

class  ConstIterator
 
class  Iterator
 
class  IteratorBase
 
C++ STL style iterator variable. More...
 

Public Member Functions

 FastPODTable (int expectedSize=16)
 
virtual ~FastPODTable ()
 
ConstIterator begin () const
 
Iterator begin ()
 
void clear (int newExpectedSize=-1)
 Removes all elements and shrinks table to its initial size. More...
 
void clearAndSetMemoryManager (shared_ptr< MemoryManager > memoryManager)
 
bool containsKey (const Key &key) const
 
void debugCheckStatus () const
 Asserts that the table is well-conditioned for performance. More...
 
void debugPrintStatus () const
 
void fastClear ()
 Leaves slot memory allocated but removes the contents. More...
 
Value & getCreate (const Key &key)
 Synonym for operator[]. More...
 
Value * getPointer (const Key &key)
 Returns a pointer to the value for the specified key, or nullptr if that key is empty. More...
 
const Value * getPointer (const Key &key) const
 
int numSlots () const
 Exposes the total number of slots used for debugging, profiling, and porting purposes. More...
 
Value & operator[] (const Key &key)
 Returns a reference to the value at key, creating the value if it did not previously exist. More...
 
int size () const
 Returns the number of key-value pairs stored. More...
 
size_t sizeInMemory (size_t(*valueSizeFunction)(const Value &)=nullptr) const
 Returns the size of everything in this table (not counting objects reference from Values by pointers). More...
 

Protected Types

enum  { NOT_FOUND = -1 }
 Constant used as a return value for findSlot. More...
 
typedef _internal::FastPODTable_Entry< Key, Value, valueIsSimplePOD > Entry
 The type of the individual slots in the hash table. More...
 
typedef FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD > MyType
 The type of this class. More...
 

Protected Member Functions

 FastPODTable (const MyType &other)
 
int findSlot (const Key &key, bool createIfNotFound, const typename Entry::StoredValueType &valueToUse, bool useValue)
 Returns the index of the slot for key. More...
 
void getStats (int &longestProbe, float &averageProbe) const
 
void grow ()
 Double the size of the table (must be a power of two size) More...
 
int hashCode (const Key &key) const
 
MyTypeoperator= (const MyType &other)
 
void probe (int &i, int &probeDistance) const
 Step to the next index while probing for a slot. More...
 

Protected Attributes

Entry::StoredValueType m_empty
 A default "empty" value; nullptr if Entry stores pointers. More...
 
int m_initialSlots
 
shared_ptr< MemoryManagerm_memoryManager
 
int m_numSlots
 Number of elements in m_slot. More...
 
Entrym_slot
 Hash table slots. More...
 
int m_usedSlots
 Number of elements in m_slot currently storing valid Value pointers. More...
 

Static Protected Attributes

static const int SLOTS_PER_ENTRY = 3
 Number of slots to allocate for every entry used. More...
 

Detailed Description

template<typename Key, typename Value, class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
class G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >

Implemented with an open-addressing hash table that does not support remove.

This is substantially faster than Table<Point3int16, Value>. Implemented with quadratic probing.

Parameters
KeyMust be plain-old-data (POD), i.e., not have a destructor, since it will be memset rather than constructed.
valueAssignmentIsFastSet to true only if Value is relatively small (e.g., 128 bytes or less), the assignment operator is efficient when applied to it (e.g., G3D::Array assignment is slow), and that is a POD type.
Default is true.

Member Typedef Documentation

◆ Entry

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
typedef _internal::FastPODTable_Entry<Key, Value, valueIsSimplePOD> G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::Entry
protected

The type of the individual slots in the hash table.

◆ MyType

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
typedef FastPODTable<Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD> G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::MyType
protected

The type of this class.

Member Enumeration Documentation

◆ anonymous enum

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
anonymous enum
protected

Constant used as a return value for findSlot.

Enumerator
NOT_FOUND 

Constructor & Destructor Documentation

◆ FastPODTable() [1/2]

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::FastPODTable ( const MyType other)
protected

◆ FastPODTable() [2/2]

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::FastPODTable ( int  expectedSize = 16)
inline
Parameters
expectedSizeNumber of key-value pairs that are expected to be stored in this table.

◆ ~FastPODTable()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
virtual G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::~FastPODTable ( )
inlinevirtual

Member Function Documentation

◆ begin() [1/2]

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
ConstIterator G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::begin ( ) const
inline

◆ begin() [2/2]

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
Iterator G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::begin ( )
inline

◆ clear()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
void G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::clear ( int  newExpectedSize = -1)
inline

◆ clearAndSetMemoryManager()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
void G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::clearAndSetMemoryManager ( shared_ptr< MemoryManager memoryManager)
inline

◆ containsKey()

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

◆ debugCheckStatus()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
void G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::debugCheckStatus ( ) const
inline

Asserts that the table is well-conditioned for performance.

◆ debugPrintStatus()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
void G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::debugPrintStatus ( ) const
inline

◆ fastClear()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
void G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::fastClear ( )
inline

Leaves slot memory allocated but removes the contents.

◆ findSlot()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
int G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::findSlot ( const Key &  key,
bool  createIfNotFound,
const typename Entry::StoredValueType &  valueToUse,
bool  useValue 
)
inlineprotected

Returns the index of the slot for key.

If key is not in the table and createIfNotFound is true, then this creates the slot. If key is not in the table and createIfNotFound is false, then this returns NOT_FOUND;

Parameters
valueToUseif a spot is created and useValue true, this is used as the value (allows the implementation of grow to re-insert existing values).

Referenced by G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getPointer(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::grow(), and G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::operator[]().

◆ getCreate()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
Value& G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getCreate ( const Key &  key)
inline

Synonym for operator[].

◆ getPointer() [1/2]

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
Value* G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getPointer ( const Key &  key)
inline

◆ getPointer() [2/2]

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
const Value* G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getPointer ( const Key &  key) const
inline

◆ getStats()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
void G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getStats ( int &  longestProbe,
float &  averageProbe 
) const
inlineprotected

◆ grow()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
void G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::grow ( )
inlineprotected

Double the size of the table (must be a power of two size)

Referenced by G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::findSlot().

◆ hashCode()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
int G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::hashCode ( const Key &  key) const
inlineprotected

◆ numSlots()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
int G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::numSlots ( ) const
inline

Exposes the total number of slots used for debugging, profiling, and porting purposes.

◆ operator=()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
MyType& G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::operator= ( const MyType other)
protected

◆ operator[]()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
Value& G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::operator[] ( const Key &  key)
inline

Returns a reference to the value at key, creating the value if it did not previously exist.

◆ probe()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
void G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::probe ( int &  i,
int &  probeDistance 
) const
inlineprotected

Step to the next index while probing for a slot.

Parameters
probeDistanceNumber of times probed. 0 on the first call.

Referenced by G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::findSlot(), and G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getStats().

◆ size()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
int G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::size ( ) const
inline

◆ sizeInMemory()

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
size_t G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::sizeInMemory ( size_t(*)(const Value &)  valueSizeFunction = nullptr) const
inline

Returns the size of everything in this table (not counting objects reference from Values by pointers).

Parameters
valueSizeFunctionA function that computes the size of a Value. If nullptr, sizeof(Value) is used.

Example for a table of Arrays, where it is desirable to recurse into the arrays:

size_t arraySize(const Array<X>& y) {
return y.sizeInMemory();
}
FastPODTable<int, Array<X> > table;
...
size_t s = table.sizeInMemory(&arraySize);

Member Data Documentation

◆ m_empty

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
Entry::StoredValueType G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::m_empty
protected

◆ m_initialSlots

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
int G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::m_initialSlots
protected

◆ m_memoryManager

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
shared_ptr<MemoryManager> G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::m_memoryManager
protected

◆ m_numSlots

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
int G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::m_numSlots
protected

◆ m_slot

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
Entry* G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::m_slot
protected

◆ m_usedSlots

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
int G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::m_usedSlots
protected

◆ SLOTS_PER_ENTRY

template<typename Key , typename Value , class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>, bool valueIsSimplePOD = false>
const int G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::SLOTS_PER_ENTRY = 3
staticprotected

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