ROSE
0.11.96.11
|
Container associating values with keys.
This container is similar to the std::map
container in the standard template library, but with these differences in addition to those described in the documentation for the Sawyer::Container name space:
insertMaybe
methods.See also, HashMap.
Definition at line 66 of file Sawyer/Map.h.
#include <Map.h>
Classes | |
class | ConstKeyIterator |
Bidirectional iterator over keys. More... | |
class | ConstNodeIterator |
Bidirectional iterator over key/value nodes. More... | |
class | ConstValueIterator |
Bidirectional iterator over values. More... | |
class | Node |
Type for stored nodes. More... | |
class | NodeIterator |
Bidirectional iterator over key/value nodes. More... | |
class | ValueIterator |
Bidirectional iterator over values. More... | |
Public Types | |
typedef K | Key |
Type for keys. | |
typedef T | Value |
Type for values associated with each key. | |
typedef Cmp | Comparator |
Type of comparator, third template argument. | |
typedef Alloc | Allocator |
Type of allocator, fourth template argument. | |
Public Member Functions | |
Map () | |
Default constructor. More... | |
Map (const Comparator &comparator, const Allocator &allocator=Allocator()) | |
Constructs an empty map. More... | |
Map (const Map &other) | |
Copy constructor. | |
template<class Key2 , class T2 , class Cmp2 , class Alloc2 > | |
Map (const Map< Key2, T2, Cmp2, Alloc2 > &other) | |
Copy constructor. More... | |
template<class Key2 , class T2 , class Cmp2 , class Alloc2 > | |
Map & | operator= (const Map< Key2, T2, Cmp2, Alloc2 > &other) |
Make this map be a copy of another map. More... | |
bool | isEmpty () const |
Determines whether this container is empty. More... | |
size_t | size () const |
Number of nodes, keys, or values in this container. More... | |
Key | least () const |
Returns the minimum key. More... | |
Key | greatest () const |
Returns the maximum key. More... | |
Interval< Key > | hull () const |
Returns the range of keys in this map. More... | |
bool | exists (const Key &key) const |
Determine if a key exists. More... | |
Optional< Value > | getOptional (const Key &key) const |
Lookup and return a value or nothing. More... | |
const Value & | getOrDefault (const Key &key) const |
Lookup and return a value or a default. More... | |
Map & | insert (const Key &key, const Value &value) |
Insert or update a key/value pair. More... | |
Map & | insertDefault (const Key &key) |
Insert or update a key with a default value. More... | |
Value & | insertMaybe (const Key &key, const Value &value) |
Conditionally insert a new key/value pair. More... | |
Value & | insertMaybeDefault (const Key &key) |
Conditionally insert a new key with default value. More... | |
template<class OtherNodeIterator > | |
Map & | insertMaybeMultiple (const boost::iterator_range< OtherNodeIterator > &range) |
Conditionally insert multiple key/value pairs. More... | |
Map & | clear () |
Remove all nodes. More... | |
Map & | erase (const Key &key) |
Remove a node with specified key. More... | |
template<class OtherKeyIterator > | |
Map & | eraseMultiple (const boost::iterator_range< OtherKeyIterator > &range) |
Remove keys stored in another Map. More... | |
boost::iterator_range< NodeIterator > | nodes () |
Iterators for container nodes. More... | |
boost::iterator_range< ConstNodeIterator > | nodes () const |
Iterators for container nodes. More... | |
boost::iterator_range< ConstKeyIterator > | keys () |
Iterators for container keys. More... | |
boost::iterator_range< ConstKeyIterator > | keys () const |
Iterators for container keys. More... | |
boost::iterator_range< ValueIterator > | values () |
Iterators for container values. More... | |
boost::iterator_range< ConstValueIterator > | values () const |
Iterators for container values. More... | |
NodeIterator | find (const Key &key) |
Find a node by key. More... | |
ConstNodeIterator | find (const Key &key) const |
Find a node by key. More... | |
NodeIterator | lowerBound (const Key &key) |
Find a node close to a key. More... | |
ConstNodeIterator | lowerBound (const Key &key) const |
Find a node close to a key. More... | |
NodeIterator | upperBound (const Key &key) |
Find a node close to a key. More... | |
ConstNodeIterator | upperBound (const Key &key) const |
Find a node close to a key. More... | |
Value & | operator[] (const Key &key) |
Return a reference to an existing value. More... | |
const Value & | operator[] (const Key &key) const |
Return a reference to an existing value. More... | |
Value & | get (const Key &key) |
Lookup and return an existing value. More... | |
const Value & | get (const Key &key) const |
Lookup and return an existing value. More... | |
Value & | getOrElse (const Key &key, Value &dflt) |
Lookup and return a value or something else. More... | |
const Value & | getOrElse (const Key &key, const Value &dflt) const |
Lookup and return a value or something else. More... | |
template<class OtherNodeIterator > | |
Map & | insertMultiple (const OtherNodeIterator &begin, const OtherNodeIterator &end) |
Insert multiple values. More... | |
template<class OtherNodeIterator > | |
Map & | insertMultiple (const boost::iterator_range< OtherNodeIterator > &range) |
Insert multiple values. More... | |
Map & | eraseAt (const NodeIterator &iter) |
Remove a node by iterator. More... | |
Map & | eraseAt (const ConstKeyIterator &iter) |
Remove a node by iterator. More... | |
Map & | eraseAt (const ValueIterator &iter) |
Remove a node by iterator. More... | |
template<class Iter > | |
Map & | eraseAtMultiple (const Iter &begin, const Iter &end) |
Remove multiple nodes by iterator range. More... | |
template<class Iter > | |
Map & | eraseAtMultiple (const boost::iterator_range< Iter > &range) |
Remove multiple nodes by iterator range. More... | |
|
inline |
|
inlineexplicit |
Constructs an empty map.
This is like the default constructor, but a comparer and allocator can be specified.
Definition at line 301 of file Sawyer/Map.h.
|
inline |
Copy constructor.
Initializes the new map with copies of the nodes of the other
map. The keys and values must be convertible from the other map to this map.
Definition at line 314 of file Sawyer/Map.h.
|
inline |
Make this map be a copy of another map.
The keys and values of the other
map must be convertible to the types used for this map.
Definition at line 325 of file Sawyer/Map.h.
|
inline |
Iterators for container nodes.
This returns a range of node-iterators that will traverse all nodes (key/value pairs) of this container.
Definition at line 344 of file Sawyer/Map.h.
Referenced by Sawyer::Attribute::Storage< SyncTag >::attributeOrDefault(), Sawyer::Container::BiMap< S, T >::BiMap(), Sawyer::Container::DistinctList< T, Cmp >::erase(), Sawyer::Container::IntervalMap< Interval, int >::erase(), Sawyer::Attribute::Storage< SyncTag >::getAttribute(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::Map(), Sawyer::Container::IntervalMap< Interval, int >::nodes(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::operator=(), Sawyer::Attribute::Storage< SyncTag >::optionalAttribute(), Sawyer::Container::DistinctList< T, Cmp >::pushBack(), Sawyer::Container::DistinctList< T, Cmp >::pushFront(), and Sawyer::Container::IntervalMap< Interval, int >::upperBound().
|
inline |
Iterators for container nodes.
This returns a range of node-iterators that will traverse all nodes (key/value pairs) of this container.
Definition at line 347 of file Sawyer/Map.h.
|
inline |
Iterators for container keys.
Returns a range of key-iterators that will traverse the keys of this container.
Definition at line 357 of file Sawyer/Map.h.
Referenced by Sawyer::Attribute::Storage< SyncTag >::attributeIds(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::eraseAt(), Sawyer::Container::IntervalMap< Interval, int >::greatest(), Sawyer::Container::IntervalMap< Interval, int >::intervals(), and Sawyer::Container::IntervalMap< Interval, int >::least().
|
inline |
Iterators for container keys.
Returns a range of key-iterators that will traverse the keys of this container.
Definition at line 360 of file Sawyer/Map.h.
|
inline |
Iterators for container values.
Returns a range of iterators that will traverse the user-defined values of this container. The values are iterated in key order, although the keys are not directly available via these iterators.
Definition at line 371 of file Sawyer/Map.h.
Referenced by Sawyer::Container::Algorithm::graphBreakCycles(), and Sawyer::Container::IntervalMap< Interval, int >::values().
|
inline |
Iterators for container values.
Returns a range of iterators that will traverse the user-defined values of this container. The values are iterated in key order, although the keys are not directly available via these iterators.
Definition at line 374 of file Sawyer/Map.h.
|
inline |
Determines whether this container is empty.
Returns true if the container is empty, and false if it has at least one node. This method executes in constant time.
Definition at line 388 of file Sawyer/Map.h.
Referenced by Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::greatest(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::hull(), Sawyer::Container::DistinctList< T, Cmp >::isEmpty(), Sawyer::Container::IntervalMap< Interval, int >::isEmpty(), and Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::least().
|
inline |
Number of nodes, keys, or values in this container.
Returns the number of nodes (elements) in this container. This method executes in constant time.
Definition at line 395 of file Sawyer/Map.h.
Referenced by Sawyer::Attribute::Storage< SyncTag >::attributeIds(), Sawyer::Container::IntervalMap< Interval, int >::erase(), Sawyer::Container::Algorithm::graphBreakCycles(), Sawyer::Container::IntervalMap< Interval, int >::insert(), Sawyer::Attribute::Storage< SyncTag >::nAttributes(), Sawyer::Container::IntervalMap< Interval, int >::nIntervals(), and Sawyer::Container::DistinctList< T, Cmp >::size().
|
inline |
Returns the minimum key.
The map must not be empty.
Definition at line 400 of file Sawyer/Map.h.
Referenced by Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::hull().
|
inline |
Returns the maximum key.
The map must not be empty.
Definition at line 406 of file Sawyer/Map.h.
Referenced by Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::hull().
|
inline |
Returns the range of keys in this map.
The return value is an interval containing the least and greatest keys, inclusive. If the map is empty then an empty interval is returned.
This method is only defined when the map key type is appropriate for the Interval class template (such as when the keys are an integer type).
Definition at line 420 of file Sawyer/Map.h.
|
inline |
Find a node by key.
Looks for a node whose key is equal to the specified key
and returns an iterator to that node, or the end iterator if no such node exists. Two keys are considered equal if this container's Comparator object returns false reflexively. The method executes logorithmic time based on the number of nodes in the container.
Definition at line 437 of file Sawyer/Map.h.
Referenced by Sawyer::Attribute::Storage< SyncTag >::attributeOrDefault(), Sawyer::Container::DistinctList< T, Cmp >::erase(), Sawyer::Attribute::Storage< SyncTag >::getAttribute(), Sawyer::Attribute::Storage< SyncTag >::optionalAttribute(), Sawyer::Container::DistinctList< T, Cmp >::pushBack(), and Sawyer::Container::DistinctList< T, Cmp >::pushFront().
|
inline |
Find a node by key.
Looks for a node whose key is equal to the specified key
and returns an iterator to that node, or the end iterator if no such node exists. Two keys are considered equal if this container's Comparator object returns false reflexively. The method executes logorithmic time based on the number of nodes in the container.
Definition at line 440 of file Sawyer/Map.h.
|
inline |
Determine if a key exists.
Looks for a node whose key is equal to the specified key
and returns true if found, or false if no such node exists. Two keys are considered equal if this container's Comparator object returns false reflexively. The method executes in logorithmic time based on the number of nodes in the container.
Definition at line 450 of file Sawyer/Map.h.
Referenced by Sawyer::Attribute::Storage< SyncTag >::attributeExists(), Sawyer::Container::BiMap< S, T >::BiMap(), Sawyer::Container::BiMap< S, T >::erase(), Sawyer::Container::BiMap< S, T >::eraseSource(), Sawyer::Container::BiMap< S, T >::eraseTarget(), Sawyer::Container::DistinctList< T, Cmp >::exists(), Sawyer::Container::DistinctList< T, Cmp >::position(), and Sawyer::Attribute::Storage< SyncTag >::setAttributeMaybe().
|
inline |
Find a node close to a key.
Finds the first node whose key is equal to or larger than the specified key and returns an iterator to that node. If no such node exists, then the end iterator is returned. The internal Comparator object is used to make the comparison. This method executes in logorithmic time based on the number of nodes in the container.
Definition at line 463 of file Sawyer/Map.h.
Referenced by Sawyer::Container::IntervalMap< Interval, int >::lowerBound().
|
inline |
Find a node close to a key.
Finds the first node whose key is equal to or larger than the specified key and returns an iterator to that node. If no such node exists, then the end iterator is returned. The internal Comparator object is used to make the comparison. This method executes in logorithmic time based on the number of nodes in the container.
Definition at line 466 of file Sawyer/Map.h.
|
inline |
Find a node close to a key.
Finds the first node whose key is larger than the specified key and returns an iterator to that node. If no such node exists, then the end iterator is returned. The internal Comparator object is used to make the comparison. This method executes in logorithmic time based on the number of nodes in the container.
Definition at line 480 of file Sawyer/Map.h.
Referenced by Sawyer::Container::IntervalMap< Interval, int >::upperBound().
|
inline |
Find a node close to a key.
Finds the first node whose key is larger than the specified key and returns an iterator to that node. If no such node exists, then the end iterator is returned. The internal Comparator object is used to make the comparison. This method executes in logorithmic time based on the number of nodes in the container.
Definition at line 483 of file Sawyer/Map.h.
|
inline |
Return a reference to an existing value.
Returns a reference to the value at the node with the specified key
. Unlike std::map
, this container does not instantiate a new key/value pair if the key
is not in the map's domain. In other words, the array operator for this class is more like an array operator on arrays or vectors–such objects are not automatically extended if dereferenced with an operand that is outside the domain.
If the key
is not part of this map's domain then an std:domain_error
is thrown.
Definition at line 506 of file Sawyer/Map.h.
|
inline |
Return a reference to an existing value.
Returns a reference to the value at the node with the specified key
. Unlike std::map
, this container does not instantiate a new key/value pair if the key
is not in the map's domain. In other words, the array operator for this class is more like an array operator on arrays or vectors–such objects are not automatically extended if dereferenced with an operand that is outside the domain.
If the key
is not part of this map's domain then an std:domain_error
is thrown.
Definition at line 509 of file Sawyer/Map.h.
|
inline |
Lookup and return an existing value.
Returns a reference to the value at the node with the specified key
, which must exist. If the key
is not part of this map's domain then an std:domain_error
is thrown.
Definition at line 522 of file Sawyer/Map.h.
Referenced by Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::operator[]().
|
inline |
Lookup and return an existing value.
Returns a reference to the value at the node with the specified key
, which must exist. If the key
is not part of this map's domain then an std:domain_error
is thrown.
Definition at line 528 of file Sawyer/Map.h.
|
inline |
Lookup and return a value or nothing.
Looks up the node with the specified key and returns either a copy of its value, or nothing. This method executes in logorithmic time.
Here's an example of one convenient way to use this:
The equivalent STL approach is:
Definition at line 559 of file Sawyer/Map.h.
Referenced by Sawyer::Attribute::Storage< SyncTag >::attributeOrElse(), Sawyer::Attribute::Storage< SyncTag >::getAttribute(), and Sawyer::Container::GraphBimapIndex< VertexOrEdgeKey, VertexOrEdgeConstIterator >::lookup().
|
inline |
Lookup and return a value or something else.
This is similar to the get method, except a default can be provided. If a node with the specified key
is present in this container, then a reference to that node's value is returned, otherwise the (reference to) supplied default is returned.
Definition at line 571 of file Sawyer/Map.h.
|
inline |
Lookup and return a value or something else.
This is similar to the get method, except a default can be provided. If a node with the specified key
is present in this container, then a reference to that node's value is returned, otherwise the (reference to) supplied default is returned.
Definition at line 575 of file Sawyer/Map.h.
|
inline |
Lookup and return a value or a default.
This is similar to the getOrElse method except when the key is not present in the map, a reference to a const, default-constructed value is returned.
Definition at line 586 of file Sawyer/Map.h.
Referenced by Sawyer::CommandLine::ParserResult::have().
|
inline |
Insert or update a key/value pair.
Inserts the key/value pair into the container. If a previous node already had the same key then it is replaced by the new node. This method executes in logorithmic time.
Definition at line 603 of file Sawyer/Map.h.
Referenced by Sawyer::Container::BiMap< S, T >::BiMap(), Sawyer::Container::IntervalMap< Interval, int >::erase(), Rose::Color::Gradient::Gradient(), Sawyer::Container::Algorithm::graphBreakCycles(), Sawyer::Container::BiMap< S, T >::insert(), Sawyer::Container::GraphBimapIndex< VertexOrEdgeKey, VertexOrEdgeConstIterator >::insert(), Rose::Color::Gradient::insert(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::insert(), Sawyer::Container::IntervalMap< Interval, int >::insert(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::insertMultiple(), Sawyer::MultiInstanceTls< T >::MultiInstanceTls(), Sawyer::MultiInstanceTls< T >::operator=(), Sawyer::Container::DistinctList< T, Cmp >::pushBack(), Sawyer::Container::DistinctList< T, Cmp >::pushFront(), Sawyer::Attribute::Storage< SyncTag >::setAttribute(), Sawyer::Attribute::Storage< SyncTag >::setAttributeMaybe(), and Sawyer::CommandLine::EnumParser< T >::with().
|
inline |
Insert or update a key with a default value.
The value associated with key
in the map is replaced with a default-constructed value. If the key does not exist then it is inserted with a default value. This operation is similar to the array operator of std::map
.
Definition at line 616 of file Sawyer/Map.h.
|
inline |
Insert multiple values.
Inserts copies of the nodes in the specified node iterator range. The iterators must iterate over objects that have key
and value
methods that return keys and values that are convertible to the types used by this container.
The normal way to insert the contents of one map into another is:
Definition at line 639 of file Sawyer/Map.h.
Referenced by Sawyer::Container::IntervalMap< Interval, int >::erase(), and Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::insertMultiple().
|
inline |
Insert multiple values.
Inserts copies of the nodes in the specified node iterator range. The iterators must iterate over objects that have key
and value
methods that return keys and values that are convertible to the types used by this container.
The normal way to insert the contents of one map into another is:
Definition at line 645 of file Sawyer/Map.h.
|
inline |
Conditionally insert a new key/value pair.
Inserts the key/value pair into the container if the container does not yet have a node with the same key. This method executes in logarithmic time. The return value is a reference to the value that is in the container, either the value that previously existed or a copy of the specified value
.
Definition at line 657 of file Sawyer/Map.h.
Referenced by Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::insertMaybeMultiple().
|
inline |
Conditionally insert a new key with default value.
Inserts a key/value pair into the container if the container does not yet have a node with the same key. The value is default-constructed. This method executes in logarithmic time. The return value is a reference to the value that is in the container, either the value that previously existed or the new default-constructed value.
Definition at line 668 of file Sawyer/Map.h.
Referenced by Sawyer::MultiInstanceTls< T >::get(), and Sawyer::MultiInstanceTls< T >::operator T().
|
inline |
Conditionally insert multiple key/value pairs.
Inserts each of the specified key/value pairs into this container where this container does not already contain a value for the key. The return value is a reference to the container itself so that this method can be chained with others.
Definition at line 679 of file Sawyer/Map.h.
|
inline |
Remove all nodes.
All nodes are removed from this container. This method executes in linear time in the number of nodes in this container.
Definition at line 689 of file Sawyer/Map.h.
Referenced by Sawyer::Container::DistinctList< T, Cmp >::clear(), Sawyer::Container::BiMap< S, T >::clear(), Sawyer::Container::GraphBimapIndex< VertexOrEdgeKey, VertexOrEdgeConstIterator >::clear(), Rose::Color::Gradient::clear(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::clear(), Sawyer::Container::IntervalMap< Interval, int >::clear(), Sawyer::Attribute::Storage< SyncTag >::clearAttributes(), and Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::operator=().
|
inline |
Remove a node with specified key.
Removes the node whose key is equal to the specified key, or does nothing if no such node exists. Two keys are considered equal if this container's Comparator object returns false reflexively. The method executes in logorithmic time based on the number of nodes in the container.
Definition at line 701 of file Sawyer/Map.h.
Referenced by Sawyer::Container::BiMap< S, T >::erase(), Sawyer::Container::GraphBimapIndex< VertexOrEdgeKey, VertexOrEdgeConstIterator >::erase(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::erase(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::eraseAt(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::eraseAtMultiple(), Sawyer::Attribute::Storage< SyncTag >::eraseAttribute(), Sawyer::Container::Map< VertexOrEdgeKey, VertexOrEdgeConstIterator >::eraseMultiple(), Sawyer::Container::BiMap< S, T >::eraseSource(), Sawyer::Container::BiMap< S, T >::eraseTarget(), Sawyer::Container::DistinctList< T, Cmp >::popBack(), and Sawyer::Container::DistinctList< T, Cmp >::popFront().
|
inline |
Remove keys stored in another Map.
All nodes of this container whose keys are equal to any key in the other
container are removed from this container. The keys of the other container must be convertible to the types used by this container, and two keys are considered equal if this container's Comparator object returns false reflexively. The method executes in N log(N+M) time.
Definition at line 715 of file Sawyer/Map.h.
|
inline |
Remove a node by iterator.
Removes the node referenced by iter
. The iterator must reference a valid node in this container.
Definition at line 728 of file Sawyer/Map.h.
Referenced by Sawyer::Container::DistinctList< T, Cmp >::erase(), and Sawyer::Container::IntervalMap< Interval, int >::insert().
|
inline |
Remove a node by iterator.
Removes the node referenced by iter
. The iterator must reference a valid node in this container.
Definition at line 732 of file Sawyer/Map.h.
|
inline |
Remove a node by iterator.
Removes the node referenced by iter
. The iterator must reference a valid node in this container.
Definition at line 740 of file Sawyer/Map.h.
|
inline |
Remove multiple nodes by iterator range.
The iterator range must contain iterators that point into this container.
Definition at line 754 of file Sawyer/Map.h.
Referenced by Sawyer::Container::IntervalMap< Interval, int >::erase().
|
inline |
Remove multiple nodes by iterator range.
The iterator range must contain iterators that point into this container.
Definition at line 759 of file Sawyer/Map.h.