Changeset 980:0f1044b7a3af in lemon0.x for src/lemon/array_map.h
 Timestamp:
 11/11/04 10:31:55 (19 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1368
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/lemon/array_map.h
r979 r980 45 45 typename _Item, 46 46 typename _ItemIt, 47 typename _IdMap,48 47 typename _Value> 49 48 class ArrayMap : public AlterationObserverRegistry<_Item>::ObserverBase { … … 61 60 /// The iterator to iterate on the keys. 62 61 typedef _ItemIt KeyIt; 63 64 typedef _IdMap IdMap;65 62 66 63 typedef _Value Value; … … 95 92 /** Graph and Registry initialized map constructor. 96 93 */ 97 ArrayMap(const Graph& _g , Registry& _r) : graph(&_g) {98 attach(_ r);94 ArrayMap(const Graph& _g) : graph(&_g) { 95 attach(_g.getObserverRegistry(_Item())); 99 96 allocate_memory(); 100 97 for (KeyIt it(*graph); it != INVALID; ++it) { 101 int id = IdMap(*graph)[it];98 int id = graph>id(it);; 102 99 allocator.construct(&(values[id]), Value()); 103 100 } … … 108 105 /// It constrates a map and initialize all of the the map. 109 106 110 ArrayMap(const Graph& _g, Registry& _r,const Value& _v) : graph(&_g) {111 attach(_ r);107 ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) { 108 attach(_g.getObserverRegistry(_Item())); 112 109 allocate_memory(); 113 110 for (KeyIt it(*graph); it != INVALID; ++it) { 114 int id = IdMap(*graph)[it];111 int id = graph>id(it);; 115 112 allocator.construct(&(values[id]), _v); 116 113 } … … 127 124 values = allocator.allocate(capacity); 128 125 for (KeyIt it(*graph); it != INVALID; ++it) { 129 int id = IdMap(*graph)[it];126 int id = graph>id(it);; 130 127 allocator.construct(&(values[id]), copy.values[id]); 131 128 } … … 155 152 156 153 for (KeyIt it(*graph); it != INVALID; ++it) { 157 int id = IdMap(*graph)[it];154 int id = graph>id(it);; 158 155 allocator.construct(&(values[id]), copy.values[id]); 159 156 } … … 177 174 */ 178 175 ReferenceType operator[](const KeyType& key) { 179 int id = IdMap(*graph)[key];176 int id = graph>id(key); 180 177 return values[id]; 181 178 } … … 186 183 */ 187 184 ConstReferenceType operator[](const KeyType& key) const { 188 int id = IdMap(*graph)[key];185 int id = graph>id(key); 189 186 return values[id]; 190 187 } … … 200 197 */ 201 198 void add(const KeyType& key) { 202 int id = IdMap(*graph)[key];199 int id = graph>id(key); 203 200 if (id >= capacity) { 204 201 int new_capacity = (capacity == 0 ? 1 : capacity); … … 208 205 Value* new_values = allocator.allocate(new_capacity); 209 206 for (KeyIt it(*graph); it != INVALID; ++it) { 210 int jd = IdMap(*graph)[it];207 int jd = graph>id(it);; 211 208 if (id != jd) { 212 209 allocator.construct(&(new_values[jd]), values[jd]); … … 224 221 */ 225 222 void erase(const KeyType& key) { 226 int id = IdMap(*graph)[key];223 int id = graph>id(key); 227 224 allocator.destroy(&(values[id])); 228 225 } … … 231 228 allocate_memory(); 232 229 for (KeyIt it(*graph); it != INVALID; ++it) { 233 int id = IdMap(*graph)[it];230 int id = graph>id(it);; 234 231 allocator.construct(&(values[id]), Value()); 235 232 } … … 239 236 if (capacity != 0) { 240 237 for (KeyIt it(*graph); it != INVALID; ++it) { 241 int id = IdMap(*graph)[it];238 int id = graph>id(it);; 242 239 allocator.destroy(&(values[id])); 243 240 } … … 303 300 304 301 void allocate_memory() { 305 int max_id = IdMap(*graph).maxId();302 int max_id = graph>maxId(_Item()); 306 303 if (max_id == 1) { 307 304 capacity = 0; … … 344 341 typedef typename Parent::Node Node; 345 342 typedef typename Parent::NodeIt NodeIt; 346 typedef typename Parent::NodeIdMap NodeIdMap;347 343 typedef typename Parent::NodeObserverRegistry NodeObserverRegistry; 348 344 349 345 typedef typename Parent::Edge Edge; 350 346 typedef typename Parent::EdgeIt EdgeIt; 351 typedef typename Parent::EdgeIdMap EdgeIdMap;352 347 typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry; 353 348 … … 355 350 356 351 template <typename _Value> 357 class NodeMap : public ArrayMap<Graph, Node, NodeIt, NodeIdMap,_Value> {352 class NodeMap : public ArrayMap<Graph, Node, NodeIt, _Value> { 358 353 public: 359 354 typedef ArrayMappableGraphExtender<_Base> Graph; … … 361 356 typedef typename Graph::Node Node; 362 357 typedef typename Graph::NodeIt NodeIt; 363 typedef typename Graph::NodeIdMap NodeIdMap; 364 365 typedef ArrayMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent; 358 359 typedef ArrayMap<Graph, Node, NodeIt, _Value> Parent; 366 360 367 361 //typedef typename Parent::Graph Graph; … … 369 363 370 364 NodeMap(const Graph& g) 371 : Parent(g , g.getNodeObserverRegistry()) {}365 : Parent(g) {} 372 366 NodeMap(const Graph& g, const Value& v) 373 : Parent(g, g.getNodeObserverRegistry(),v) {}367 : Parent(g, v) {} 374 368 375 369 }; 376 370 377 371 template <typename _Value> 378 class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, EdgeIdMap,_Value> {372 class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, _Value> { 379 373 public: 380 374 typedef ArrayMappableGraphExtender<_Base> Graph; … … 382 376 typedef typename Graph::Edge Edge; 383 377 typedef typename Graph::EdgeIt EdgeIt; 384 typedef typename Graph::EdgeIdMap EdgeIdMap; 385 386 typedef ArrayMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent; 378 379 typedef ArrayMap<Graph, Edge, EdgeIt, _Value> Parent; 387 380 388 381 //typedef typename Parent::Graph Graph; … … 390 383 391 384 EdgeMap(const Graph& g) 392 : Parent(g , g.getEdgeObserverRegistry()) {}385 : Parent(g) {} 393 386 EdgeMap(const Graph& g, const Value& v) 394 : Parent(g, g.getEdgeObserverRegistry(),v) {}387 : Parent(g, v) {} 395 388 396 389 };
Note: See TracChangeset
for help on using the changeset viewer.