Util::Dictionary< KEYTYPE, VALUETYPE > Class Template Reference
#include <dictionary.h>
Detailed Description
template<class KEYTYPE, class VALUETYPE>
class Util::Dictionary< KEYTYPE, VALUETYPE >
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).Internally the dictionary is implemented as a sorted array.
On insertion performance: Key/value pairs are inserted with the Add() method, which normally calls the Util::Array::InsertSorted() method internally. If many insertions are performed at once, it may be beneficial to call BeginBulkAdd() before, and EndBulkAdd() after adding the key/value pairs. Between BeginBulkAdd() and EndBulkAdd(), the Add() method will just append the new elements to the internal array, and only call Util::Array::Sort() inside EndBulkAdd().
Any methods which require the internal array to be sorted will throw an assertion between BeginBulkAdd() and EndBulkAdd().
(C) 2006 Radon Labs GmbH
Public Member Functions | |
Dictionary () | |
default constructor | |
Dictionary (const Dictionary< KEYTYPE, VALUETYPE > &rhs) | |
copy constructor | |
void | operator= (const Dictionary< KEYTYPE, VALUETYPE > &rhs) |
assignment operator | |
VALUETYPE & | operator[] (const KEYTYPE &key) |
read/write [] operator | |
const VALUETYPE & | operator[] (const KEYTYPE &key) const |
read-only [] operator | |
SizeT | Size () const |
return number of key/value pairs in the dictionary | |
void | Clear () |
clear the dictionary | |
bool | IsEmpty () const |
return true if empty | |
void | Reserve (SizeT numElements) |
reserve space (useful if number of elements is known beforehand) | |
void | BeginBulkAdd () |
begin a bulk insert (array will be sorted at End) | |
void | Add (const KeyValuePair< KEYTYPE, VALUETYPE > &kvp) |
add a key/value pair | |
void | Add (const KEYTYPE &key, const VALUETYPE &value) |
add a key and associated value | |
void | EndBulkAdd () |
end a bulk insert (this will sort the internal array) | |
void | Erase (const KEYTYPE &key) |
erase a key and its associated value | |
void | EraseAtIndex (IndexT index) |
erase a key at index | |
IndexT | FindIndex (const KEYTYPE &key) const |
find index of key/value pair (InvalidIndex if doesn't exist) | |
bool | Contains (const KEYTYPE &key) const |
return true if key exists in the array | |
const KEYTYPE & | KeyAtIndex (IndexT index) const |
get a key at given index | |
VALUETYPE & | ValueAtIndex (IndexT index) |
access to value at given index | |
const VALUETYPE & | ValueAtIndex (IndexT index) const |
get a value at given index | |
KeyValuePair< KEYTYPE, VALUETYPE > & | KeyValuePairAtIndex (IndexT index) const |
get key/value pair at index | |
Array< KEYTYPE > | KeysAsArray () const |
get all keys as an Util::Array | |
Array< VALUETYPE > | ValuesAsArray () const |
get all keys as an Util::Array | |
template<class RETURNTYPE> | |
RETURNTYPE | KeysAs () const |
get all keys as (typically) an array | |
template<class RETURNTYPE> | |
RETURNTYPE | ValuesAs () const |
get all keys as (typically) an array | |
Protected Member Functions | |
void | SortIfDirty () const |
make sure the key value pair array is sorted |