This map is essentially a wrapper for std::map
with addition that you can specify a default value for the keys that are not stored actually. This value can be different from the default contructed value (i.e. Value
()). This type conforms to the ReferenceMap concept.
This map is useful if a default value should be assigned to most of the keys and different values should be assigned only to a few keys (i.e. the map is "sparse"). The name of this type also refers to this important usage.
Apart form that, this map can be used in many other cases since it is based on std::map
, which is a general associative container. However, keep in mind that it is usually not as efficient as other maps.
The simplest way of using this map is through the sparseMap() function.
#include <lemon/maps.h>
Public Types | |
typedef K | Key |
Key type. | |
typedef V | Value |
Value type. | |
typedef Value & | Reference |
Reference type. | |
typedef const Value & | ConstReference |
Const reference type. | |
![]() | |
typedef K | Key |
The key type of the map. | |
typedef V | Value |
The value type of the map. (The type of objects associated with the keys). | |
Public Member Functions | |
SparseMap (const Value &value=Value()) | |
Constructor with specified default value. | |
template<typename V1 , typename Comp1 > | |
SparseMap (const std::map< Key, V1, Comp1 > &map, const Value &value=Value()) | |
Constructs the map from an appropriate std::map , and explicitly specifies a default value. | |
template<typename V1 , typename Comp1 > | |
SparseMap (const SparseMap< Key, V1, Comp1 > &c) | |
Constructs the map from another SparseMap . | |
Reference | operator[] (const Key &k) |
| |
ConstReference | operator[] (const Key &k) const |
| |
void | set (const Key &k, const Value &v) |
| |
void | setAll (const Value &v) |
| |
Related Functions | |
(Note that these are not member functions.) | |
template<typename K , typename V , typename Compare > | |
SparseMap< K, V, Compare > | sparseMap (const V &value=V()) |
Returns a SparseMap class. | |
template<typename K , typename V , typename Compare > | |
SparseMap< K, V, Compare > | sparseMap (const std::map< K, V, Compare > &map, const V &value=V()) |
Returns a SparseMap class created from an appropriate std::map . | |