![]() |
Murl Engine API
Version 2018.3
|
A generic map template base class. More...
#include <murl_map_base.h>
A generic map template base class.
A map stores a number of key/value pairs, where the keys do not have to be unique.
This is the base class of the Map and ObjectMap class.
This class is based on the NTL AMap container, see http://www.ultimatepp.org
KeyType | The key's data type of the map. |
DataType | The value's data type of the map. |
ArrayType | The array type of the values. |
HashFunc | The hash function of the key. |
Public Types | |
typedef KeyType | KeyValueType |
The template key parameter value type. More... | |
typedef DataType | ValueType |
The template data parameter value type. More... | |
typedef Index< KeyType, HashFunc > | KeyIndexType |
Definition of the key index type. | |
typedef KeyIndexType::ConstIterator | KeyConstIterator |
Definition of the const key iterator. | |
typedef ArrayType::ConstIterator | ConstIterator |
Definition of the const iterator. | |
typedef ArrayType::Iterator | Iterator |
Definition of the iterator. | |
Public Member Functions | |
void | Clear () |
Clear the map and remove the underlying storage. | |
void | Empty () |
Empty the map, but keep the underlying storage. | |
void | Shrink () |
Shrink the map so that the underlying key and value storage is only as large as necessary. | |
void | Trim (SInt32 n) |
Reduce the map to a given number of items. More... | |
void | Drop (SInt32 n=1) |
Reduce the map by removing a given number of items from the end. More... | |
void | Reserve (SInt32 n) |
Reserve storage space. More... | |
void | Sweep () |
Remove any unlinked pairs from the map. | |
void | SetKey (SInt32 index, const KeyType &key) |
Set the key of a given index. More... | |
void | Swap (MapBase &other) |
Exchange the content of the map with a given second one. More... | |
DataType & | Add (const KeyType &key) |
Add a new key/value pair to the map. More... | |
DataType & | Add (const KeyType &key, const DataType &value) |
Add a key/value pair to the map. More... | |
DataType & | Put (const KeyType &key) |
Add a new key/value pair to the map, replacing an unlinked element if present. More... | |
SInt32 | Put (const KeyType &key, const DataType &value) |
Add a key/value pair to the map, replacing an unlinked element if present. More... | |
DataType & | Insert (SInt32 index, const KeyType &key) |
Insert a new key/value pair into the map at a given position. More... | |
DataType & | Insert (SInt32 index, const KeyType &key, const DataType &value) |
Insert a key/value pair into the map at a given position. More... | |
void | Unlink (SInt32 index) |
Unlink the pair at a given index. More... | |
SInt32 | UnlinkKey (const KeyType &key) |
Unlink all pairs matching a given key. More... | |
SInt32 | UnlinkKey (const KeyType &key, UInt32 hash) |
Unlink all pairs matching a given key, using a precomputed hash value. More... | |
Bool | IsUnlinked (SInt32 index) const |
Check if the pair at a given index is unlinked. More... | |
void | Remove (SInt32 index) |
Remove the key/value pair at a given position from the map. More... | |
void | Remove (SInt32 index, SInt32 count) |
Remove a number of key/value pairs from the map at a given starting position. More... | |
void | Remove (const SInt32 *sortedIndices, SInt32 count) |
Remove a number of key/value pairs from the map at given positions. More... | |
void | Remove (const SInt32Array &sortedIndices) |
Remove a number of key/value pairs from the map at given positions. More... | |
SInt32 | RemoveKey (const KeyType &key) |
Remove all pairs from the map that match a given key. More... | |
SInt32 | Find (const KeyType &key) const |
Find the first occurrence of a given key in the map. More... | |
SInt32 | Find (const KeyType &key, UInt32 hash) const |
Find the first occurrence of a given key in the map, using a precomputed hash value. More... | |
SInt32 | FindLast (const KeyType &key) const |
Find the last occurrence of a given key in the map. More... | |
SInt32 | FindLast (const KeyType &key, UInt32 hash) const |
Find the last occurrence of a given key in the map, using a precomputed hash value. More... | |
SInt32 | FindNext (SInt32 index) const |
Find the next occurrence of a key that is specified by a given index. More... | |
SInt32 | FindPrev (SInt32 index) const |
Find the previous occurrence of a key that is specified by a given index. More... | |
SInt32 | FindAdd (const KeyType &key) |
Find the first occurrence of a given key in the map, or add a new pair if the key was not found. More... | |
SInt32 | FindAdd (const KeyType &key, const DataType &value) |
Find the first occurrence of a given key in the map, or add a new pair if the key was not found. More... | |
SInt32 | FindPut (const KeyType &key) |
Find the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible. More... | |
SInt32 | FindPut (const KeyType &key, const DataType &value) |
Find the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible. More... | |
DataType & | Get (const KeyType &key) |
Get a reference to the first occurrence of a given key in the map. More... | |
const DataType & | Get (const KeyType &key) const |
Get a const reference to the first occurrence of a given key in the map. More... | |
const DataType & | Get (const KeyType &key, const DataType &defaultValue) const |
Get a const reference to the first occurrence of a given key in the map. More... | |
DataType * | GetPtr (const KeyType &key) |
Get a pointer to the first occurrence of a given key in the map. More... | |
const DataType * | GetPtr (const KeyType &key) const |
Get a const pointer to the first occurrence of a given key in the map. More... | |
DataType & | GetAdd (const KeyType &key) |
Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found. More... | |
DataType & | GetAdd (const KeyType &key, const DataType &value) |
Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found. More... | |
DataType & | GetPut (const KeyType &key) |
Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible. More... | |
DataType & | GetPut (const KeyType &key, const DataType &value) |
Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible. More... | |
const KeyType & | GetKey (SInt32 index) const |
Get a const reference to the key at a given index. More... | |
const KeyIndexType & | GetIndex () const |
Get a const reference to the key storage. More... | |
const Array< KeyType > & | GetKeys () const |
Get a const reference to the array of keys. More... | |
ArrayType & | GetValues () |
Get a reference to the array of values. More... | |
const ArrayType & | GetValues () const |
Get a const reference to the array of values. More... | |
Bool | IsIndexValid (SInt32 index) const |
Check if a given index is a valid index. More... | |
const DataType & | operator[] (SInt32 index) const |
Get a const reference to the value at a given index. More... | |
DataType & | operator[] (SInt32 index) |
Get a reference to the value at a given index. More... | |
DataType & | Bottom () |
Get a reference to the first value in the storage. More... | |
const DataType & | Bottom () const |
Get a const reference to the first value in the storage. More... | |
const KeyType & | BottomKey () const |
Get a const reference to the first key in the storage. More... | |
DataType & | Top () |
Get a reference to the last value in the storage. More... | |
const DataType & | Top () const |
Get a const reference to the last value in the storage. More... | |
const KeyType & | TopKey () const |
Get a const reference to the last key in the storage. More... | |
KeyType | PopKey () |
Remove the last key/value pair from the map and return its key. More... | |
SInt32 | GetAlloc () const |
Get the number of actually allocated pairs. More... | |
SInt32 | GetCount () const |
Get the number of items in the map. More... | |
Bool | IsEmpty () const |
Check if the map is empty. More... | |
KeyConstIterator | KeyBegin () const |
Get the const key iterator to the first element. More... | |
KeyConstIterator | KeyEnd () const |
Get the const key iterator next to the last element. More... | |
KeyConstIterator | KeyGetIter (SInt32 index) const |
Get the const key iterator of a specified index. More... | |
ConstIterator | Begin () const |
Get the const iterator to the first element. More... | |
ConstIterator | End () const |
Get the const iterator next to the last element. More... | |
ConstIterator | GetIter (SInt32 index) const |
Get the const iterator of a specified index. More... | |
Iterator | Begin () |
Get the iterator to the first element. More... | |
Iterator | End () |
Get the iterator next to the last element. More... | |
Iterator | GetIter (SInt32 index) |
Get the iterator of a specified index. More... | |
Bool | IsEqual (const MapBase &other) const |
Compare the map to another one. More... | |
bool | operator== (const MapBase &rhs) const |
The "equal to" comparison operator, calls IsEqual(). More... | |
bool | operator!= (const MapBase &rhs) const |
The "not equal to" comparison operator, calls IsEqual(). More... | |
typedef KeyType Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::KeyValueType |
The template key parameter value type.
typedef DataType Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::ValueType |
The template data parameter value type.
|
inline |
Reduce the map to a given number of items.
n | The new number of items in the map, must be smaller than the current item count. |
|
inline |
Reduce the map by removing a given number of items from the end.
n | The number of items to remove from the end. |
|
inline |
Reserve storage space.
If the given size is less than the actual size, nothing is done.
n | The number of items the underlying storage should hold. |
|
inline |
Set the key of a given index.
index | The index to replace. |
key | The new key. |
|
inline |
Exchange the content of the map with a given second one.
other | The second map. |
|
inline |
Add a new key/value pair to the map.
The newly added value is initialized using the value type's default constructor.
key | The key under which the value can be retrieved. |
|
inline |
Add a key/value pair to the map.
The newly added value is initialized using the given reference value's copy constructor.
key | The key under which the value can be retrieved. |
value | The reference value to add. |
|
inline |
Add a new key/value pair to the map, replacing an unlinked element if present.
The newly added value is initialized using the value type's default constructor.
key | The key under which the value can be retrieved. |
|
inline |
Add a key/value pair to the map, replacing an unlinked element if present.
The newly added value is initialized using the given reference value's copy constructor.
key | The key under which the value can be retrieved. |
value | The reference value to add. |
|
inline |
Insert a new key/value pair into the map at a given position.
The newly added value is initialized using the value type's default constructor.
index | The index where to insert the new pair. |
key | The key under which the value can be retrieved. |
|
inline |
Insert a key/value pair into the map at a given position.
The newly added value is initialized using the given reference value's copy constructor.
index | The index where to insert the new pair. |
key | The key under which the value can be retrieved. |
value | The reference value to insert. |
|
inline |
Unlink the pair at a given index.
Unlinked elements remain in the map, but are ignored by any search operations.
index | The index of the pair to unlink. |
|
inline |
Unlink all pairs matching a given key.
Unlinked elements remain in the map, but are ignored by any search operations.
key | The key for which to unlink all elements. |
|
inline |
Unlink all pairs matching a given key, using a precomputed hash value.
Unlinked elements remain in the map, but are ignored by any search operations.
key | The key for which to unlink all elements. |
hash | The precomputed hash value. |
|
inline |
Check if the pair at a given index is unlinked.
index | The index of the pair to check. |
|
inline |
Remove the key/value pair at a given position from the map.
index | The zero-based index from where to remove the pair. |
|
inline |
Remove a number of key/value pairs from the map at a given starting position.
index | The zero-based index from where to remove the first pair. |
count | The number of subsequent pairs to remove. |
|
inline |
Remove a number of key/value pairs from the map at given positions.
sortedIndices | A pointer to sorted indices where to remove the pairs. |
count | The number of pairs to remove, i.e. the number of indices. |
|
inline |
Remove a number of key/value pairs from the map at given positions.
sortedIndices | A sorted array of indices where to remove the items. |
|
inline |
Remove all pairs from the map that match a given key.
key | The key for which to remove the pairs. |
|
inline |
Find the first occurrence of a given key in the map.
key | The key to search for. |
|
inline |
Find the first occurrence of a given key in the map, using a precomputed hash value.
key | The key to search for. |
hash | The precomputed hash value. |
|
inline |
Find the last occurrence of a given key in the map.
key | The key to search for. |
|
inline |
Find the last occurrence of a given key in the map, using a precomputed hash value.
key | The key to search for. |
hash | The precomputed hash value. |
|
inline |
Find the next occurrence of a key that is specified by a given index.
index | The index of the pair containing the key to search for. |
|
inline |
Find the previous occurrence of a key that is specified by a given index.
index | The index of the pair containing the key to search for. |
|
inline |
Find the first occurrence of a given key in the map, or add a new pair if the key was not found.
If a pair needs to be added, the newly created value is initialized using the value type's default constructor.
key | The key to search for. |
|
inline |
Find the first occurrence of a given key in the map, or add a new pair if the key was not found.
If a pair needs to be added, the newly created value is initialized using the given value's copy constructor.
key | The key to search for. |
value | The reference value to add. |
|
inline |
Find the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible.
If a pair needs to be added, the newly created value is initialized using the value type's default constructor.
key | The key to search for. |
|
inline |
Find the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible.
If a pair needs to be added, the newly created value is initialized using the given value's copy constructor.
key | The key to search for. |
value | The reference value to add. |
|
inline |
Get a reference to the first occurrence of a given key in the map.
If the key was not found, the behaviour is undefined.
key | The key to search for. |
|
inline |
Get a const reference to the first occurrence of a given key in the map.
If the key was not found, the behaviour is undefined.
key | The key to search for. |
|
inline |
Get a const reference to the first occurrence of a given key in the map.
If the key was not found, the given default value is returned
key | The key to search for. |
defaultValue | The default value to return if the key was not found. |
|
inline |
Get a pointer to the first occurrence of a given key in the map.
If the key was not found, a null pointer is returned.
key | The key to search for. |
|
inline |
Get a const pointer to the first occurrence of a given key in the map.
If the key was not found, a null pointer is returned.
key | The key to search for. |
|
inline |
Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found.
If a pair needs to be added, the newly created value is initialized using the value type's default constructor.
key | The key to search for. |
|
inline |
Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found.
If a pair needs to be added, the newly created value is initialized using the given value's copy constructor.
key | The key to search for. |
value | The reference value to add. |
|
inline |
Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible.
If a pair needs to be added, the newly created value is initialized using the value type's default constructor.
key | The key to search for. |
|
inline |
Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible.
If a pair needs to be added, the newly created value is initialized using the given value's copy constructor.
key | The key to search for. |
value | The reference value to add. |
|
inline |
Get a const reference to the key at a given index.
If the index is out of range, the behaviour is undefined.
index | The index of the key to retrieve. |
|
inline |
Get a const reference to the key storage.
|
inline |
Get a const reference to the array of keys.
|
inline |
Get a reference to the array of values.
|
inline |
Get a const reference to the array of values.
|
inline |
Check if a given index is a valid index.
index | The index to check. |
|
inline |
Get a const reference to the value at a given index.
If the index is out of range, the behaviour is undefined.
index | The index of the value to retrieve. |
|
inline |
Get a reference to the value at a given index.
If the index is out of range, the behaviour is undefined.
index | The index of the value to retrieve. |
|
inline |
Get a reference to the first value in the storage.
|
inline |
Get a const reference to the first value in the storage.
|
inline |
Get a const reference to the first key in the storage.
|
inline |
Get a reference to the last value in the storage.
|
inline |
Get a const reference to the last value in the storage.
|
inline |
Get a const reference to the last key in the storage.
|
inline |
Remove the last key/value pair from the map and return its key.
|
inline |
Get the number of actually allocated pairs.
|
inline |
Get the number of items in the map.
|
inline |
Check if the map is empty.
|
inline |
Get the const key iterator to the first element.
|
inline |
Get the const key iterator next to the last element.
|
inline |
Get the const key iterator of a specified index.
index | The index for the key iterator. |
|
inline |
Get the const iterator to the first element.
|
inline |
Get the const iterator next to the last element.
|
inline |
Get the const iterator of a specified index.
index | The index for the iterator. |
|
inline |
Get the iterator to the first element.
|
inline |
Get the iterator next to the last element.
|
inline |
Get the iterator of a specified index.
index | The index for the iterator. |
|
inline |
Compare the map to another one.
other | The map to compare. |
|
inline |
The "equal to" comparison operator, calls IsEqual().
rhs | The right hand side map to compare. |
|
inline |
The "not equal to" comparison operator, calls IsEqual().
rhs | The right hand side map to compare. |