Changeset 1115:444f69240539 in lemon-0.x for src/work/deba/map_utils.h
- Timestamp:
- 02/01/05 16:56:37 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1514
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/map_utils.h
r1037 r1115 15 15 */ 16 16 17 ///\ingroup gutils17 ///\ingroup mutils 18 18 ///\file 19 19 ///\brief Map utilities. … … 50 50 typedef typename _Map::ConstReference ConstReference; 51 51 52 /// Constructor.53 52 /// \brief Constructor. 53 /// 54 54 /// Construct a new InversableMap for the graph. 55 55 /// 56 56 InversableMap(const Graph& graph) : Map(graph) {} 57 57 58 /// The setter function of the map.59 60 /// It sets the map and the inverse map 58 /// \brief The setter function of the map. 59 /// 60 /// It sets the map and the inverse map to given key-value pair. 61 61 void set(const Key& key, const Value& val) { 62 62 Value oldval = Map::operator[](key); … … 96 96 97 97 98 // unique, continous, mutable 98 99 /// \brief Provides a mutable, continous and unique descriptor for each 100 /// item in the graph. 101 /// 102 /// The DescriptorMap class provides a mutable, continous and immutable 103 /// mapping for each item in the graph. 104 /// 105 /// \param _Graph The graph class the \c DescriptorMap belongs to. 106 /// \param _Item The Item is the Key of the Map. It may be Node, Edge or 107 /// UndirEdge. 108 /// \param _Map A ReadWriteMap mapping from the item type to integer. 99 109 100 110 template < 101 111 typename _Graph, 102 112 typename _Item, 103 typename _ItemIt,104 113 typename _Map 105 114 > 106 115 class DescriptorMap : protected _Map { 116 117 typedef _Item Item; 118 typedef _Map Map; 119 107 120 public: 121 /// The graph class of DescriptorMap. 108 122 typedef _Graph Graph; 109 typedef _Item Item; 110 typedef _ItemIt ItemIt; 111 typedef _Map Map; 112 113 123 124 /// The key type of DescriptorMap (Node, Edge, UndirEdge). 114 125 typedef typename _Map::Key Key; 126 /// The value type of DescriptorMap. 115 127 typedef typename _Map::Value Value; 116 128 117 typedef vector<Item> InverseMap; 118 129 typedef std::vector<Item> InverseMap; 130 131 /// \brief Constructor. 132 /// 133 /// Constructor for creating descriptor map. 119 134 DescriptorMap(const Graph& _graph) : Map(_graph) { 120 135 build(); … … 135 150 virtual void build() { 136 151 Map::build(); 137 for (ItemIt it(*Map::getGraph()); it != INVALID; ++it) { 152 Item it; 153 for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) { 138 154 Map::set(it, inv_map.size()); 139 155 inv_map.push_back(it); … … 146 162 } 147 163 164 /// \brief Gives back the \e descriptor of the item. 165 /// 166 /// Gives back the mutable and unique \e descriptor of the map. 148 167 int operator[](const Item& item) const { 149 168 return Map::operator[](item); 150 169 } 151 152 170 171 /// \brief Gives back the inverse of the map. 172 /// 173 /// Gives back the inverse of the map. 153 174 const InverseMap inverse() const { 154 175 return inv_map; … … 158 179 vector<Item> inv_map; 159 180 }; 160 161 // unique, immutable => IDMap162 181 163 182 /// Provides an immutable and unique id for each item in the graph. 183 184 /// The IdMap class provides an unique and immutable mapping for each item 185 /// in the graph. 186 /// 187 template <typename _Graph, typename _Item> 188 class IdMap { 189 public: 190 typedef _Graph Graph; 191 typedef int Value; 192 typedef _Item Item; 193 194 /// \brief The class represents the inverse of the map. 195 /// 196 /// The class represents the inverse of the map. 197 /// \see inverse() 198 class InverseMap { 199 protected: 200 InverseMap(const Graph& _graph) : graph(_graph) {} 201 public: 202 /// \brief Gives back the given item by its id. 203 /// 204 /// Gives back the given item by its id. 205 /// 206 Item operator[](int id) const { return graph->fromId(id, Item());} 207 private: 208 Graph* graph; 209 }; 210 211 /// \brief Constructor. 212 /// 213 /// Constructor for creating id map. 214 IdMap(const Graph& _graph) : graph(&_graph) {} 215 216 /// \brief Gives back the \e id of the item. 217 /// 218 /// Gives back the immutable and unique \e id of the map. 219 int operator[](const Item& item) const { return graph->id(item);} 220 221 /// \brief Gives back the inverse of the map. 222 /// 223 /// Gives back the inverse of the map. 224 InverseMap inverse() const { return InverseMap(*graph);} 225 226 private: 227 const Graph* graph; 228 229 }; 230 231 164 232 165 233 }
Note: See TracChangeset
for help on using the changeset viewer.