Classes | Public Types | Public Member Functions | Protected Member Functions

CrossRefMap< GR, K, V > Class Template Reference


Detailed Description

template<typename GR, typename K, typename V>
class lemon::CrossRefMap< GR, K, V >

This class provides simple invertable graph maps. It wraps a standard graph map (NodeMap, ArcMap or EdgeMap) and if a key is set to a new value, then stores it in the inverse map. The graph items can be accessed by their values either using InverseMap or operator()(), and the values of the map can be accessed with an STL compatible forward iterator (ValueIt).

This map is intended to be used when all associated values are different (the map is actually invertable) or there are only a few items with the same value. Otherwise consider to use IterableValueMap, which is more suitable and more efficient for such cases. It provides iterators to traverse the items with the same associated value, but it does not have InverseMap.

This type is not reference map, so it cannot be modified with the subscript operator.

Template Parameters:
GRThe graph type.
KThe key type of the map (GR::Node, GR::Arc or GR::Edge).
VThe value type of the map.
See also:
IterableValueMap

#include <lemon/maps.h>

List of all members.

Classes

class  InverseMap
 The inverse map type of CrossRefMap. More...
class  ValueIt
 Forward iterator for values. More...

Public Types

typedef GR Graph
 The graph type of CrossRefMap.
typedef K Item
 The key type of CrossRefMap (Node, Arc or Edge).
typedef K Key
 The key type of CrossRefMap (Node, Arc or Edge).
typedef V Value
 The value type of CrossRefMap.
typedef ValueIt ValueIterator
 Alias for ValueIt.

Public Member Functions

 CrossRefMap (const Graph &graph)
 Constructor.
ValueIt beginValue () const
 Returns an iterator to the first value.
ValueIt endValue () const
 Returns an iterator after the last value.
void set (const Key &key, const Value &val)
MapTraits< Map >::ConstReturnValue operator[] (const Key &key) const
Key operator() (const Value &val) const
 Gives back an item by its value.
int count (const Value &val) const
 Returns the number of items with the given value.
InverseMap inverse () const
 Gives back the inverse of the map.

Protected Member Functions

virtual void erase (const Key &key)
 Erase the key from the map and the inverse map.
virtual void erase (const std::vector< Key > &keys)
 Erase more keys from the map and the inverse map.
virtual void clear ()
 Clear the keys from the map and the inverse map.

Constructor & Destructor Documentation

CrossRefMap ( const Graph graph) [inline, explicit]

Construct a new CrossRefMap for the given graph.


Member Function Documentation

ValueIt beginValue ( ) const [inline]

Returns an STL compatible iterator to the first value of the map. The values of the map can be accessed in the [beginValue, endValue) range.

ValueIt endValue ( ) const [inline]

Returns an STL compatible iterator after the last value of the map. The values of the map can be accessed in the [beginValue, endValue) range.

void set ( const Key key,
const Value val 
) [inline]

Sets the value associated with the given key.

MapTraits<Map>::ConstReturnValue operator[] ( const Key key) const [inline]

Returns the value associated with the given key.

Key operator() ( const Value val) const [inline]

This function gives back an item that is assigned to the given value or INVALID if no such item exists. If there are more items with the same associated value, only one of them is returned.

int count ( const Value val) const [inline]

This function returns the number of items with the given value associated with it.

virtual void erase ( const Key key) [inline, protected, virtual]

Erase the key from the map and the inverse map. It is called by the AlterationNotifier.

virtual void erase ( const std::vector< Key > &  keys) [inline, protected, virtual]

Erase more keys from the map and the inverse map. It is called by the AlterationNotifier.

virtual void clear ( ) [inline, protected, virtual]

Clear the keys from the map and the inverse map. It is called by the AlterationNotifier.

InverseMap inverse ( ) const [inline]

Gives back the inverse of the CrossRefMap.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines