SparseMap

Declared in lemon/maps.h, in the group Maps; the same class on the Doxygen site.

template< typename K , typename V , typename Comp = std::less< K > >
class SparseMap : public lemon::MapBase< K , V >

Map type based on std::map.

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.

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 True ReferenceMapTag

Public Functions

inline SparseMap( const Value & value = Value() )

Constructor with specified default value.

template< typename V1 , typename Comp1 >
inline 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 >
inline SparseMap(
const SparseMap< Key , V1 , Comp1 > & c
)

Constructs the map from another SparseMap.

SparseMap( const SparseMap & ) = default

Copy constructor.

inline Reference operator[]( const Key & k )

inline ConstReference operator[]( const Key & k ) const

inline void set( const Key & k , const Value & v )

inline void setAll( const Value & v )