2 * src/hugo/sym_map.h - Part of HUGOlib, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef HUGO_SYM_MAP_H
18 #define HUGO_SYM_MAP_H
22 ///\brief Graph maps that construates and destruates
23 ///their elements dynamically.
27 /// \addtogroup graphmaps
30 /** The SymEdgeIt is wrapper class for the EdgeIt. It can be used to
31 * iterate on the symmetric maps when all of the edge - reverse edge pair
32 * has different parity.
36 template <typename Graph, typename Edge, typename EdgeIt>
37 class SymEdgeIt : public EdgeIt {
40 /** Default constructor.
45 /** Graph initialized constructor.
47 SymEdgeIt(const Graph& graph)
49 while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
54 /** Creating invelid SymEdgeIt.
56 SymEdgeIt(Invalid invalid)
59 /** SymEdgeIt from the given Edge.
61 SymEdgeIt(const Graph& graph, const Edge& edge)
62 : EdgeIt(graph, edge) {
63 while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
68 /** Increase operator.
70 SymEdgeIt& operator++() {
72 while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
79 /** The SymMap template class is graph map structure what
80 * wraps an other map structure to use as symmetric map structure.
82 * The template parameter is the MapRegistry that the maps
83 * will belong to and the ValueType.
85 template <template <typename, typename> class DynMap,
86 typename MapRegistry, typename Value>
87 class SymMap : public DynMap<MapRegistry, Value>{
91 typedef DynMap<MapRegistry, Value> MapImpl;
95 /// The graph type of the maps.
96 typedef typename MapRegistry::Graph Graph;
98 typedef typename MapImpl::KeyType KeyType;
103 /** Graph and Registry initialized map constructor.
105 SymMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
107 /** Constructor to use default value to initialize the map.
109 SymMap(const Graph& g, MapRegistry& r, const Value& v)
110 : MapImpl(g, r, v) {}
112 /** Constructor to copy a map of the same map type.
114 SymMap(const SymMap& copy)
115 : MapImpl(static_cast<const MapImpl&>(copy)) {}
117 /** Assign operator to copy a map of the same map type.
119 SymMap& operator=(const SymMap& copy) {
120 MapImpl::operator=(static_cast<const MapImpl&>(copy));
124 /** Add a new key to the map. It called by the map registry.
126 void add(const KeyType& key) {
127 int id = MapImpl::getGraph()->id(key);
132 /** Erase a key from the map. It called by the map registry.
134 void erase(const KeyType& key) {
135 int id = MapImpl::getGraph()->id(key);