#include <LDK/CStringHash.h>
Inheritance diagram for LDK::Hash< Key, Data, Alloc >:
Public Types | |
typedef Iterator | iterator |
typedef ConstIterator | const_iterator |
Public Member Functions | |
Hash (size_t initialSize=100) | |
Hash (const Hash &rhs) | |
~Hash () throw () | |
Destructor. | |
Hash & | operator= (const Hash &rhs) |
ConstIterator | find (const Key &key) const |
Iterator | find (const Key &key) |
Pair * | element (size_t idx) |
const Pair * | element (size_t idx) const |
void | set (const Key &k, const Data &d) |
bool | insert (const Key &key, const Data &data) |
bool | insert (const Pair &p) |
Iterator | erase (const Key &key) |
Iterator | erase (Iterator it) |
size_t | size () const |
size_t | allocated () const |
Iterator | begin () |
ConstIterator | begin () const |
Iterator | end () |
ConstIterator | end () const |
void | clear () |
Clears all elements. Does not resize the table. | |
DataProxy | operator[] (const Key &k) |
const Data & | operator[] (const Key &k) const |
Protected Types | |
typedef Alloc< Pair > | PairAlloc |
typedef Alloc< Pair * > | PairPtrAlloc |
Protected Member Functions | |
size_t | hash (const Key &k, size_t allocated) const |
void | rehash (size_t newAlloc) |
void | assign (const Hash &rhs) |
Static Protected Member Functions | |
static size_t | primeGreaterThan (size_t size) |
static size_t | newSize (size_t currentSize, size_t freeSlots) |
Protected Attributes | |
PairAlloc | mPairAlloc |
PairPtrAlloc | mPairPtrAlloc |
Pair ** | mArray |
size_t | mAllocated |
size_t | mFreeSlots |
size_t | mSize |
Static Protected Attributes | |
static const int | cIncBy = 7 |
Data Structures | |
class | ConstIterator |
Allows iteration over a const Hash. More... | |
class | DataProxy |
Returned by an "[]" operator to allow transparent getting and setting of keys/value pairs. More... | |
class | Iterator |
Allows iteration over a non-const Hash. More... | |
class | Pair |
A sensible, less generic substitute for std::pair<>. More... |
A partial specialisation Hash<const char*, Data> is provided for using c-style strings as keys - it copies and holds the strings internally. This is probably the fastest string key Hash.
Note that many methods can pass through Runtime and BadAlloc exceptions from methods and functions they call. Influenced by hash table code by Per Nilson available at http://www.codeguru.com/Cpp/Cpp/algorithms/hash/
Warning: Uses LDK::Allocator by default, so DON'T use this class across threads without changing it to an LDK::MallocAllocator.
Definition at line 173 of file Hash.h.
ConstIterator LDK::Hash< Key, Data, Alloc >::find | ( | const Key & | key | ) | const [inline] |
Find an ConstIterator assocated with a key.
key | The key to search for in the table |
Definition at line 610 of file Hash.h.
References LDK::Hash< Key, Data, Alloc >::Pair::mData, LDK::Hash< Key, Data, Alloc >::Pair::mKey, and NULL.
Iterator LDK::Hash< Key, Data, Alloc >::find | ( | const Key & | key | ) | [inline] |
Find an Iterator assocated with a key.
key | The key to search for in the table |
Definition at line 643 of file Hash.h.
References LDK::Hash< Key, Data, Alloc >::Pair::mData, and LDK::Hash< Key, Data, Alloc >::Pair::mKey.
Pair* LDK::Hash< Key, Data, Alloc >::element | ( | size_t | idx | ) | [inline] |
Get a pointer to the Pair at an index in the table
idx | The index to look at |
Definition at line 674 of file Hash.h.
References LDK_INDEX_ERROR.
Referenced by LDK::Hash< Key, Data, Alloc >::rehash().
const Pair* LDK::Hash< Key, Data, Alloc >::element | ( | size_t | idx | ) | const [inline] |
Get a const pointer to the Pair at an index in the table
idx | The index to look at |
Definition at line 684 of file Hash.h.
References LDK_INDEX_ERROR.
void LDK::Hash< Key, Data, Alloc >::set | ( | const Key & | k, | |
const Data & | d | |||
) | [inline] |
Associate some data with a key. Can associate a new piece of data with a key already in the table.
k | The key to associate the data with | |
d | The data to associate with key |
IndexError | if there is a problem inserting a new key/data pair |
Definition at line 696 of file Hash.h.
References LDK_INDEX_ERROR.
bool LDK::Hash< Key, Data, Alloc >::insert | ( | const Key & | key, | |
const Data & | data | |||
) | [inline] |
bool LDK::Hash< Key, Data, Alloc >::insert | ( | const Pair & | p | ) | [inline] |
Insert a Pair into the table.
p | The key/data pair to insert. |
Definition at line 749 of file Hash.h.
References LDK::Hash< Key, Data, Alloc >::Pair::mData, and LDK::Hash< Key, Data, Alloc >::Pair::mKey.
Iterator LDK::Hash< Key, Data, Alloc >::erase | ( | const Key & | key | ) | [inline] |
Erase an element associated with a key.
key | The key associated with the element to erase. |
Definition at line 755 of file Hash.h.
References LDK::Hash< Key, Data, Alloc >::Iterator::index(), and NULL.
Here is the call graph for this function:
Iterator LDK::Hash< Key, Data, Alloc >::erase | ( | Iterator | it | ) | [inline] |
Erase an element referenced by an Iterator.
it | The Iterator referencing the element to erase. |
LogicError | if the Iterator references a different Hash instance. |
Definition at line 776 of file Hash.h.
References LDK::Hash< Key, Data, Alloc >::Iterator::index(), LDK::Hash< Key, Data, Alloc >::Iterator::mHash, and NULL.
Here is the call graph for this function:
size_t LDK::Hash< Key, Data, Alloc >::size | ( | ) | const [inline] |
size_t LDK::Hash< Key, Data, Alloc >::allocated | ( | ) | const [inline] |
ConstIterator LDK::Hash< Key, Data, Alloc >::begin | ( | ) | const [inline] |
Get an iterator that references the first element in the table.
ConstIterator LDK::Hash< Key, Data, Alloc >::end | ( | ) | const [inline] |
Get an iterator that is one past the end of the table.
DataProxy LDK::Hash< Key, Data, Alloc >::operator[] | ( | const Key & | k | ) | [inline] |
Makes the Hash resemble a simple array.
IndexError | if the key is not present in the table. |
const Data& LDK::Hash< Key, Data, Alloc >::operator[] | ( | const Key & | k | ) | const [inline] |
Makes the Hash resemble a simple array. Does not require a DataProxy because this method does not allow setting of the data associated with key.
IndexError | if the key is not present in the table. |
Definition at line 843 of file Hash.h.
References LDK_INDEX_ERROR.