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 can be added at any time with the Add() methods. Internally, lazy evaluation is used to keep the array sorted only when it needs to be sorted. Thus adding many keys is very fast, but the first search may be slow because that's when the sorting happens.
(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 | 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 | 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 array (slow) | |
Array< VALUETYPE > | ValuesAsArray () const |
get all values as array (slow) | |
Protected Member Functions | |
void | SortIfDirty () const |
make sure the key value pair array is sorted |