ROSE 0.11.145.192
|
Container associating values with keys.
This container is similar to TL's unordered_map
in that it stores a value for each key using a hash-based mechanism, although it works for C++ versions before C++11. The naming scheme is similar to other Sawyer containers. If you're used to the STL, the main differences are described in the documentation for the Sawyer::Container name space.
See also, Map.
#include <Sawyer/HashMap.h>
Classes | |
class | ConstKeyIterator |
Forward iterator over keys. More... | |
class | ConstNodeIterator |
Forward iterator over key/value nodes. More... | |
class | ConstValueIterator |
Forward iterator over values. More... | |
class | Node |
Type for stored nodes. More... | |
class | NodeIterator |
Forward iterator over key/value nodes. More... | |
class | ValueIterator |
Forward iterator over values. More... | |
Public Types | |
typedef K | Key |
Type of keys. | |
typedef T | Value |
Type of values. | |
typedef H | Hasher |
Functor for hashing keys. | |
typedef C | Comparator |
Functor for comparing keys. | |
typedef A | Allocator |
Functor for allocating node memory. | |
Public Member Functions | |
HashMap () | |
Default constructor. | |
HashMap (size_t n, const Hasher &hasher=Hasher(), const Comparator &cmp=Comparator(), const Allocator &alloc=Allocator()) | |
Constructs a hash map with at least n buckets. | |
HashMap (const HashMap &other) | |
Copy constructor. | |
template<class K2 , class T2 , class H2 , class C2 , class A2 > | |
HashMap (const HashMap< K2, T2, H2, C2, A2 > &other) | |
Copy constructor. | |
template<class K2 , class T2 , class H2 , class C2 , class A2 > | |
HashMap & | operator= (const HashMap< K2, T2, H2, C2, A2 > &other) |
Assignment operator. | |
bool | isEmpty () const |
Determine whether this container is empty. | |
size_t | size () const |
Number of nodes, keys, or values in this container. | |
size_t | nBuckets () const |
Number of buckets. | |
double | loadFactor () const |
Average number of nodes per bucket. | |
void | rehash (size_t nBuckets) |
Change number of buckets. | |
bool | exists (const Key &key) const |
Determine if a key exists. | |
Optional< Value > | getOptional (const Key &key) const |
Lookup and return a value or nothing. | |
const Value & | getOrDefault (const Key &key) const |
Lookup and return a value or a default. | |
HashMap & | insert (const Key &key, const Value &value) |
Insert or update a key/value pair. | |
HashMap & | insertDefault (const Key &key) |
Insert or update a key with a default value. | |
Value & | insertMaybe (const Key &key, const Value &value) |
Conditionally insert a new key/value pair. | |
Value & | insertMaybeDefault (const Key &key) |
Conditionally insert a new key with default value. | |
template<class OtherNodeIterator > | |
HashMap & | insertMaybeMultiple (const boost::iterator_range< OtherNodeIterator > &range) |
Conditionally insert multiple key/value pairs. | |
HashMap & | clear () |
Remove all nodes. | |
HashMap & | erase (const Key &key) |
Remove a node with specified key. | |
template<class OtherKeyIterator > | |
HashMap & | eraseMultiple (const boost::iterator_range< OtherKeyIterator > &range) |
Remove keys stored in another HashMap. | |
boost::iterator_range< NodeIterator > | nodes () |
Iterators for container nodes. | |
boost::iterator_range< ConstNodeIterator > | nodes () const |
Iterators for container nodes. | |
boost::iterator_range< ConstKeyIterator > | keys () |
Iterators for container keys. | |
boost::iterator_range< ConstKeyIterator > | keys () const |
Iterators for container keys. | |
boost::iterator_range< ValueIterator > | values () |
Iterators for container values. | |
boost::iterator_range< ConstValueIterator > | values () const |
Iterators for container values. | |
double | maxLoadFactor () const |
Property: Maximum allowed load faster before automatic rehash. | |
void | maxLoadFactor (double mlf) |
Property: Maximum allowed load faster before automatic rehash. | |
NodeIterator | find (const Key &key) |
Find a node by key. | |
ConstNodeIterator | find (const Key &key) const |
Find a node by key. | |
Value & | operator[] (const Key &key) |
Return a reference to an existing value. | |
const Value & | operator[] (const Key &key) const |
Return a reference to an existing value. | |
Value & | get (const Key &key) |
Lookup and retun an existing value. | |
const Value & | get (const Key &key) const |
Lookup and retun an existing value. | |
Value & | getOrElse (const Key &key, Value &dflt) |
Lookup and return a value or something else. | |
const Value & | getOrElse (const Key &key, const Value &dflt) const |
Lookup and return a value or something else. | |
template<class OtherNodeIterator > | |
HashMap & | insertMultiple (const OtherNodeIterator &begin, const OtherNodeIterator &end) |
Insert multiple values. | |
template<class OtherNodeIterator > | |
HashMap & | insertMultiple (const boost::iterator_range< OtherNodeIterator > &range) |
Insert multiple values. | |
HashMap & | eraseAt (const NodeIterator &iter) |
Remove a node by iterator. | |
HashMap & | eraseAt (const ConstKeyIterator &iter) |
Remove a node by iterator. | |
HashMap & | eraseAt (const ValueIterator &iter) |
Remove a node by iterator. | |
template<class Iter > | |
HashMap & | eraseAtMultiple (const Iter &begin, const Iter &end) |
Remove multiple nodes by iterator range. | |
template<class Iter > | |
HashMap & | eraseAtMultiple (const boost::iterator_range< Iter > &range) |
Remove multiple nodes by iterator range. | |
typedef K Sawyer::Container::HashMap< K, T, H, C, A >::Key |
typedef T Sawyer::Container::HashMap< K, T, H, C, A >::Value |
typedef H Sawyer::Container::HashMap< K, T, H, C, A >::Hasher |
typedef C Sawyer::Container::HashMap< K, T, H, C, A >::Comparator |
typedef A Sawyer::Container::HashMap< K, T, H, C, A >::Allocator |
|
inline |
|
inline |
|
inline |
|
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 ohter map to this map.
Definition at line 268 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::nodes().
|
inline |
Assignment operator.
Definition at line 277 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::clear(), and Sawyer::Container::HashMap< K, T, H, C, A >::nodes().
|
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 296 of file HashMap.h.
Referenced by Sawyer::Container::HashMap< K, T, H, C, A >::HashMap(), and Sawyer::Container::HashMap< K, T, H, C, A >::operator=().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Number of nodes, keys, or values in this container.
Returns the number of nodes currently stored in this container. A node is a key + value pair. This method executes in constant time.
Definition at line 347 of file HashMap.h.
Referenced by Rose::BinaryAnalysis::InstructionProvider::nCached().
|
inline |
Number of buckets.
Definition at line 352 of file HashMap.h.
Referenced by Sawyer::Container::HashMap< K, T, H, C, A >::rehash().
|
inline |
|
inline |
|
inline |
|
inline |
Change number of buckets.
Definition at line 373 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::nBuckets().
|
inline |
|
inline |
|
inline |
|
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 421 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::get().
|
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 424 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::get().
|
inline |
Lookup and retun 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 437 of file HashMap.h.
Referenced by Sawyer::Container::HashMap< K, T, H, C, A >::operator[](), and Sawyer::Container::HashMap< K, T, H, C, A >::operator[]().
|
inline |
Lookup and retun 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.
|
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.
Here's an example of one convenient way to use this:
The equivalent STL approach is:
|
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.
|
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.
|
inline |
|
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.
Definition at line 516 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::insert().
Referenced by Sawyer::Container::HashMap< K, T, H, C, A >::insert(), Sawyer::Container::HashMap< K, T, H, C, A >::insertDefault(), and Sawyer::Container::HashMap< K, T, H, C, A >::insertMultiple().
|
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 529 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::insert().
|
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 551 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::insert().
Referenced by Sawyer::Container::HashMap< K, T, H, C, A >::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 557 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::insertMultiple().
|
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. 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 569 of file HashMap.h.
Referenced by Sawyer::Container::HashMap< K, T, H, C, A >::insertMaybeDefault(), and Sawyer::Container::HashMap< K, T, H, C, A >::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. 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 580 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::insertMaybe().
|
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 591 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::insertMaybe().
|
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 601 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::clear().
Referenced by Sawyer::Container::HashMap< K, T, H, C, A >::clear(), and Sawyer::Container::HashMap< K, T, H, C, A >::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.
Definition at line 612 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::erase().
Referenced by Sawyer::Container::HashMap< K, T, H, C, A >::erase(), Sawyer::Container::HashMap< K, T, H, C, A >::eraseAt(), Sawyer::Container::HashMap< K, T, H, C, A >::eraseAt(), Sawyer::Container::HashMap< K, T, H, C, A >::eraseAt(), Sawyer::Container::HashMap< K, T, H, C, A >::eraseAtMultiple(), Sawyer::Container::HashMap< K, T, H, C, A >::eraseAtMultiple(), and Sawyer::Container::HashMap< K, T, H, C, A >::eraseMultiple().
|
inline |
Remove keys stored in another HashMap.
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.
Definition at line 625 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::erase().
|
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 638 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::erase().
|
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 642 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::erase().
|
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 646 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::erase().
|
inline |
Remove multiple nodes by iterator range.
The iterator range must contain iterators that point into this container.
Definition at line 660 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::erase().
|
inline |
Remove multiple nodes by iterator range.
The iterator range must contain iterators that point into this container.
Definition at line 665 of file HashMap.h.
References Sawyer::Container::HashMap< K, T, H, C, A >::erase().