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().
- Copyright
- (C) 2006 Radon Labs GmbH (C) 2013-2020 Individual contributors, see AUTHORS file
|
| | Dictionary () |
| | default constructor
|
| |
| | Dictionary (const Dictionary< KEYTYPE, VALUETYPE > &rhs) |
| | copy constructor
|
| |
| | Dictionary (Dictionary< KEYTYPE, VALUETYPE > &&rhs) noexcept |
| | move constructor
|
| |
| void | operator= (const Dictionary< KEYTYPE, VALUETYPE > &rhs) |
| | assignment operator
|
| |
| void | operator= (Dictionary< KEYTYPE, VALUETYPE > &&rhs) noexcept |
| | move 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)
|
| |
| IndexT | Add (const KeyValuePair< KEYTYPE, VALUETYPE > &kvp) |
| | add a key/value pair
|
| |
| IndexT | Add (const KEYTYPE &key, const VALUETYPE &value) |
| | add a key and associated value
|
| |
| VALUETYPE & | Emplace (const KEYTYPE &key) |
| | creates a new entry of VALUETYPE if key does not exist, or returns the existing element
|
| |
| void | EndBulkAdd () |
| | end a bulk insert (this will sort the internal array)
|
| |
| void | Merge (const Dictionary< KEYTYPE, VALUETYPE > &rhs) |
| | merge two dictionaries
|
| |
| 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
|
| |
| bool | Contains (const KEYTYPE &key, IndexT &index) const |
| | return true if key exists in the array, and saves index
|
| |
| 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
|
| |
| KeyValuePair< KEYTYPE, VALUETYPE > * | begin () const |
| | functions for stl like behaviour
|
| |
| KeyValuePair< KEYTYPE, VALUETYPE > * | end () const |
| |
| void | clear () |
| |
| void | emplace (KEYTYPE &&key, VALUETYPE &&value) |
| |