Murl::Map< KeyType, DataType, HashFunc > Class Template Reference

A generic map template class for moveable objects eg. structs or fundamental data types like UInt32, Real, etc. More...

#include "murl_map.h"

Inheritance diagram for Murl::Map< KeyType, DataType, HashFunc >:

Public Types

using KeyValueType = KeyType
 The template key parameter value type.
 
using ValueType = DataType
 The template data parameter value type.
 
- Public Types inherited from Murl::MapBase< KeyType, DataType, Array< DataType >, HashFunc >
using KeyValueType = KeyType
 The template key parameter value type.
 
using ValueType = DataType
 The template data parameter value type.
 
using KeyIndexType = Index< KeyType, HashFunc >
 Definition of the key index type.
 
using KeyConstIterator = typename KeyIndexType::ConstIterator
 Definition of the const key iterator.
 
using ConstIterator = typename ArrayType::ConstIterator
 Definition of the const iterator.
 
using Iterator = typename ArrayType::Iterator
 Definition of the iterator.
 

Public Member Functions

 Map ()
 The default constructor. More...
 
 Map (const Map &map)
 The copy constructor. More...
 
DataType Pop ()
 Remove the last key/value pair from the map and return its value. More...
 
- Public Member Functions inherited from Murl::MapBase< KeyType, DataType, Array< DataType >, HashFunc >
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...
 
Bool HasUnlinked () const
 Check if the map has unlinked items. More...
 
SInt32Array GetUnlinked () const
 Get an array of indices of all unlinked items. 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 KeyIndexTypeGetIndex () 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...
 
Array< DataType > & GetValues ()
 Get a reference to the array of values. More...
 
const Array< DataType > & 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 & Front ()
 Get a reference to the first value in the storage. More...
 
const DataType & Front () const
 Get a const reference to the first value in the storage. More...
 
const KeyType & FrontKey () const
 Get a const reference to the first key in the storage. More...
 
DataType & Back ()
 Get a reference to the last value in the storage. More...
 
const DataType & Back () const
 Get a const reference to the last value in the storage. More...
 
const KeyType & BackKey () const
 Get a const reference to the last key in the storage. 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...
 
UInt32 GetCountUInt32 () 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...
 
Iterator Begin ()
 Get the iterator to the first element. More...
 
ConstIterator End () const
 Get the const iterator next to the last element. More...
 
Iterator End ()
 Get the iterator next to the last element. More...
 
ConstIterator GetIter (SInt32 index) const
 Get the const iterator of a specified index. 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...
 

Detailed Description

template<class KeyType, class DataType, class HashFunc>
class Murl::Map< KeyType, DataType, HashFunc >

A generic map template class for moveable objects eg. structs or fundamental data types like UInt32, Real, etc.

See MapBase class for all map methods.
A map stores a number of key/value pairs, where the keys do not have to be unique.
The map class works for moveable objects only, use ObjectMap class for storing non-moveable objects.
This class is based on the NTL VectorMap container, see http://www.ultimatepp.org

Template Parameters
KeyTypeThe key's data type of the map.
DataTypeThe value's data type of the map.
HashFuncThe hash function of the key.

Constructor & Destructor Documentation

◆ Map() [1/2]

template<class KeyType , class DataType , class HashFunc >
Murl::Map< KeyType, DataType, HashFunc >::Map ( )
inline

The default constructor.

Create an empty map.

◆ Map() [2/2]

template<class KeyType , class DataType , class HashFunc >
Murl::Map< KeyType, DataType, HashFunc >::Map ( const Map< KeyType, DataType, HashFunc > &  map)
inline

The copy constructor.

Parameters
mapThe map object to copy.

Member Function Documentation

◆ Pop()

template<class KeyType , class DataType , class HashFunc >
DataType Murl::Map< KeyType, DataType, HashFunc >::Pop ( )
inline

Remove the last key/value pair from the map and return its value.

Returns
The value of the removed pair.

References Murl::MapBase< KeyType, DataType, Array< DataType >, HashFunc >::Drop(), and Murl::MapBase< KeyType, DataType, Array< DataType >, HashFunc >::Top().


The documentation for this class was generated from the following file:
  • murl_map.h


Copyright © 2011-2024 Spraylight GmbH.