|
| 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 |
|
MyType & | operator= (const MyType &other) |
|
void | probe (int &i, int &probeDistance) const |
| Step to the next index while probing for a slot. More...
|
|
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
-
Key | Must be plain-old-data (POD), i.e., not have a destructor, since it will be memset rather than constructed. |
valueAssignmentIsFast | Set 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. |
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
-
valueToUse | if 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[]().
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 |
Returns a pointer to the value for the specified key, or nullptr if that key is empty.
Referenced by G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::containsKey(), and G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getPointer().
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 |
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.
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.
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 |
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
-
valueSizeFunction | A 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);
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 |
A default "empty" value; nullptr if Entry stores pointers.
Referenced by G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::FastPODTable(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getPointer(), and G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::operator[]().
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 |
Number of elements in m_slot currently storing valid Value pointers.
Referenced by G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::clear(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::debugPrintStatus(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::fastClear(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::findSlot(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::getStats(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::grow(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::operator[](), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::size(), and G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::sizeInMemory().
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 |
Number of slots to allocate for every entry used.
Load factor is 1 / SLOTS_PER_ENTRY. This was tuned for performance.
Referenced by G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::clear(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::debugPrintStatus(), G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::FastPODTable(), and G3D::FastPODTable< Key, Value, HashFunc, EqualsFunc, valueIsSimplePOD >::findSlot().