Base Framework
Classes | Public Types | Public Member Functions | Related Functions | List of all members
Map< KEY, VALUE > Class Template Reference

Map collection. More...

#include <base/collection/Map.h>

Inherits Collection.

Classes

class  Element
 
class  NodePredicate
 
class  ReadEnumerator
 Non-modifying enumerator of map. More...
 
class  ValueEnumerator
 Modifying enumerator of values of map. More...
 

Public Types

typedef KEY Key
 
typedef VALUE Value
 
typedef Association< Key, ValueNode
 
typedef OrderedBinaryTree< Node, KeyTree
 
typedef Tree::Iterator Iterator
 
typedef Tree::ReadIterator ReadIterator
 

Public Member Functions

 Map () noexcept
 
 Map (std::initializer_list< Node > values)
 
 Map (const Map &copy) noexcept
 
 Map (Map &&move) noexcept
 
Mapoperator= (const Map &copy)
 
Mapoperator= (Map &&move)
 
MemorySize getSize () const noexcept
 
bool isEmpty () const noexcept
 
 operator bool () const noexcept
 
ValueEnumerator getValueEnumerator () noexcept
 
ReadEnumerator getReadEnumerator () const noexcept
 
bool hasKey (const Key &key) const noexcept
 
Valuefind (const Key &key)
 
const Valuefind (const Key &key) const
 
ValuegetValue (const Key &key)
 
const ValuegetValue (const Key &key) const
 
void rebalance ()
 
bool add (const Key &key, const Value &value)
 
bool add (const Key &key, Value &&value)
 
bool add (const Node &value)
 
void remove (const Key &key)
 
void remove (const Iterator &it)
 
template<class PREDICATE >
void removeByPredicate (PREDICATE predicate)
 
void removeAll ()
 
Valueoperator[] (const Key &key)
 
const Valueoperator[] (const Key &key) const
 
const TreegetTree () const noexcept
 
Iterator begin () noexcept
 
Iterator end () noexcept
 
ReadIterator begin () const noexcept
 
ReadIterator end () const noexcept
 
Mapoperator<< (const Node &value)
 
Mapoperator<< (Node &&value)
 

Related Functions

(Note that these are not member functions.)

template<class KEY , class VALUE >
FormatOutputStreamoperator<< (FormatOutputStream &stream, const Map< KEY, VALUE > &value)
 

Detailed Description

template<class KEY, class VALUE>
class Map< KEY, VALUE >

Map collection.

Map collection implemented using an ordered binary tree.

Version
1.1
Examples
testsuite/Map.cpp.

Member Typedef Documentation

◆ Key

template<class KEY , class VALUE >
typedef KEY Map< KEY, VALUE >::Key

The type of a key in the map.

◆ Node

template<class KEY , class VALUE >
typedef Association<Key, Value> Map< KEY, VALUE >::Node

The type of an association in the map.

◆ Value

template<class KEY , class VALUE >
typedef VALUE Map< KEY, VALUE >::Value

The type of a value in the map.

Constructor & Destructor Documentation

◆ Map() [1/4]

template<class KEY , class VALUE >
Map< KEY, VALUE >::Map ( )
inlinenoexcept

Initializes an empty map.

◆ Map() [2/4]

template<class KEY , class VALUE >
Map< KEY, VALUE >::Map ( std::initializer_list< Node values)
inline

Initializes map with given values.

◆ Map() [3/4]

template<class KEY , class VALUE >
Map< KEY, VALUE >::Map ( const Map< KEY, VALUE > &  copy)
inlinenoexcept

Initializes map from other map.

◆ Map() [4/4]

template<class KEY , class VALUE >
Map< KEY, VALUE >::Map ( Map< KEY, VALUE > &&  move)
inlinenoexcept

Initializes map from other map.

Member Function Documentation

◆ add() [1/2]

template<class KEY , class VALUE >
bool Map< KEY, VALUE >::add ( const Key key,
const Value value 
)
inline

Associates the specified key with the specified value in this map. If the key already is associated with a value, the value is overridden.

Parameters
keyThe key.
valueThe value.
Returns
Returns true if new key was added.

◆ add() [2/2]

template<class KEY , class VALUE >
bool Map< KEY, VALUE >::add ( const Key key,
Value &&  value 
)
inline

Associates the specified key with the specified value in this map. If the key already is associated with a value, the value is overridden.

Parameters
keyThe key.
valueThe value.
Returns
Returns true if new key was added.

◆ find() [1/2]

template<class KEY , class VALUE >
Value* Map< KEY, VALUE >::find ( const Key key)
inline

Returns the value associated with the specified key.

Parameters
keyThe key of the value.
Returns
nullptr is key doesn't exist.

◆ find() [2/2]

template<class KEY , class VALUE >
const Value* Map< KEY, VALUE >::find ( const Key key) const
inline

Returns the value associated with the specified key.

Parameters
keyThe key of the value.
Returns
nullptr is key doesn't exist.

◆ getReadEnumerator()

template<class KEY , class VALUE >
ReadEnumerator Map< KEY, VALUE >::getReadEnumerator ( ) const
inlinenoexcept

Returns a non-modifying enumerator of the ordered binary tree.

◆ getSize()

template<class KEY , class VALUE >
MemorySize Map< KEY, VALUE >::getSize ( ) const
inlinenoexcept

Returns the number of associations in the map.

◆ getValue() [1/2]

template<class KEY , class VALUE >
Value& Map< KEY, VALUE >::getValue ( const Key key)
inline

Returns the value associated with the specified key. Raises InvalidKey if the specified key doesn't exist in this map.

Parameters
keyThe key of the value.

◆ getValue() [2/2]

template<class KEY , class VALUE >
const Value& Map< KEY, VALUE >::getValue ( const Key key) const
inline

Returns the value associated with the specified key. Raises InvalidKey if the specified key doesn't exist in this map.

Parameters
keyThe key of the value.

◆ getValueEnumerator()

template<class KEY , class VALUE >
ValueEnumerator Map< KEY, VALUE >::getValueEnumerator ( )
inlinenoexcept

Returns a modifying enumerator of the ordered binary tree.

◆ hasKey()

template<class KEY , class VALUE >
bool Map< KEY, VALUE >::hasKey ( const Key key) const
inlinenoexcept

Returns true if the specified key is associated with a value in this map.

Parameters
keyThe value to search for.

◆ isEmpty()

template<class KEY , class VALUE >
bool Map< KEY, VALUE >::isEmpty ( ) const
inlinenoexcept

Returns true if the map is empty.

◆ operator bool()

template<class KEY , class VALUE >
Map< KEY, VALUE >::operator bool ( ) const
inlinenoexcept

Returns true if the map is not empty.

◆ operator<<() [1/2]

template<class KEY , class VALUE >
Map& Map< KEY, VALUE >::operator<< ( const Node value)
inline

Adds value.

◆ operator<<() [2/2]

template<class KEY , class VALUE >
Map& Map< KEY, VALUE >::operator<< ( Node &&  value)
inline

Adds value.

◆ operator=() [1/2]

template<class KEY , class VALUE >
Map& Map< KEY, VALUE >::operator= ( const Map< KEY, VALUE > &  copy)
inline

Assignment of map to map.

◆ operator=() [2/2]

template<class KEY , class VALUE >
Map& Map< KEY, VALUE >::operator= ( Map< KEY, VALUE > &&  move)
inline

Assignment of map to map.

◆ operator[]() [1/2]

template<class KEY , class VALUE >
Value& Map< KEY, VALUE >::operator[] ( const Key key)
inline

Returns the value associated with the specified key.

◆ operator[]() [2/2]

template<class KEY , class VALUE >
const Value& Map< KEY, VALUE >::operator[] ( const Key key) const
inline

Returns the value associated with the specified key.

◆ remove()

template<class KEY , class VALUE >
void Map< KEY, VALUE >::remove ( const Key key)
inline

Removes the specified key and its associated value from this map. Raises InvalidKey if the key doesn't exist in this map.

◆ removeAll()

template<class KEY , class VALUE >
void Map< KEY, VALUE >::removeAll ( )
inline

Removes all the keys from this map.

Friends And Related Function Documentation

◆ operator<<()

template<class KEY , class VALUE >
FormatOutputStream & operator<< ( FormatOutputStream stream,
const Map< KEY, VALUE > &  value 
)
related

Writes a string representation of a map to a format stream.