|
| Table () |
|
void | clearAndSetMemoryManager (const MemoryManager::Ref &m) |
|
void | setSizeHint (size_t n) |
|
virtual | ~Table () |
|
| Table (const ThisType &h) |
|
Table & | operator= (const ThisType &h) |
|
size_t | debugGetDeepestBucketSize () const |
|
float | debugGetAverageBucketSize () const |
|
double | debugGetLoad () const |
|
size_t | debugGetNumBuckets () const |
|
Iterator | begin () const |
|
const Iterator | end () const |
|
void | clear () |
|
size_t | size () const |
|
void | set (const Key &key, const Value &value) |
|
bool | getRemove (const Key &key, Key &removedKey, Value &removedValue) |
|
bool | remove (const Key &key) |
|
const Key * | getKeyPointer (const Key &key) const |
|
Value & | get (const Key &key) const |
|
Value * | getPointer (const Key &key) const |
|
bool | get (const Key &key, Value &val) const |
|
Entry & | getCreateEntry (const Key &key, bool &created) |
|
Entry & | getCreateEntry (const Key &key) |
|
Value & | getCreate (const Key &key) |
|
Value & | getCreate (const Key &key, bool &created) |
|
bool | containsKey (const Key &key) const |
|
Value & | operator[] (const Key &key) const |
|
Array< Key > | getKeys () const |
|
void | getKeys (Array< Key > &keyArray) const |
|
void | getValues (Array< Value > &valueArray) const |
|
void | deleteKeys () |
|
void | deleteValues () |
|
template<class H , class E > |
bool | operator== (const Table< Key, Value, H, E > &other) const |
|
template<class H , class E > |
bool | operator!= (const Table< Key, Value, H, E > &other) const |
|
void | debugPrintStatus () |
|
template<class Key, class Value, class HashFunc = HashTrait<Key>, class EqualsFunc = EqualsTrait<Key>>
class G3D::Table< Key, Value, HashFunc, EqualsFunc >
An unordered data structure mapping keys to values.
There are two ways of definining custom hash functions (G3D provides built-in ones for most classes):
class Foo {
public:
std::string name;
int index;
static size_t hashCode(const Foo& key) {
return HashTrait<std::string>::hashCode(key.name) + key.index;
}
};
template<> struct HashTrait<class Foo> {
static size_t hashCode(const Foo& key) { return HashTrait<std::string>::hashCode(key.name) + key.index; }
};
// Use Foo::hashCode
Table<Foo, std::string, Foo> fooTable1;
// Use HashTrait<Foo>
Table<Foo, std::string> fooTable2;
Key must be a pointer, an int, a std::string or provide overloads for:
template<> struct HashTrait<class Key> {
static size_t hashCode(const Key& key) { return reinterpret_cast<size_t>( ... ); }
};
and one of
template<> struct EqualsTrait<class Key>{
static bool equals(const Key& a, const Key& b) { return ... ; }
};
bool operator==(const Key&, const Key&);
G3D pre-defines HashTrait specializations for common types (like int
and std::string
). If you use a Table with a different type you must write those functions yourself. For example, an enum would use:
template<> struct HashTrait<MyEnum> {
static size_t hashCode(const MyEnum& key) const { return reinterpret_cast<size_t>( key ); }
};
And rely on the default enum operator==.
Periodically check that debugGetLoad() is low (> 0.1). When it gets near 1.0 your hash function is badly designed and maps too many inputs to the same output.