Changeset 1267:a93f94dbe3d3 in lemon-0.x for src/lemon/array_map.h
- Timestamp:
- 03/26/05 00:31:57 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1694
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/lemon/array_map.h
r1164 r1267 19 19 20 20 #include <memory> 21 #include <lemon/map_iterator.h> 21 22 22 23 ///\ingroup graphmaps … … 36 37 * the container functionality. 37 38 * 38 * The template parameter is the MapRegistrythat the maps39 * The template parameter is the AlterationNotifier that the maps 39 40 * will belong to and the Value. 40 41 */ … … 42 43 template <typename _Graph, 43 44 typename _Item, 44 typename _ItemIt,45 45 typename _Value> 46 46 class ArrayMap : public AlterationNotifier<_Item>::ObserverBase { 47 47 48 typedef _Item Item; 48 49 public: 49 50 … … 55 56 typedef AlterationNotifier<_Item> Registry; 56 57 57 private:58 /// The iterator to iterate on the keys.59 typedef _ItemIt KeyIt;60 61 58 /// The MapBase of the Map which imlements the core regisitry function. 62 59 typedef typename Registry::ObserverBase Parent; 63 60 64 65 public:66 67 61 /// The value type of the map. 68 62 typedef _Value Value; 69 /// The reference type of the map;70 typedef Value& Reference;71 /// The pointer type of the map;72 typedef Value* Pointer;73 74 /// The const value type of the map.75 typedef const Value ConstValue;76 /// The const reference type of the map;77 typedef const Value& ConstReference;78 /// The pointer type of the map;79 typedef const Value* ConstPointer;80 63 81 64 … … 89 72 */ 90 73 ArrayMap(const Graph& _g) : graph(&_g) { 74 Item it; 75 attach(_g.getNotifier(Item())); 76 allocate_memory(); 77 for (graph->first(it); it != INVALID; graph->next(it)) { 78 int id = graph->id(it);; 79 allocator.construct(&(values[id]), Value()); 80 } 81 } 82 83 /// Constructor to use default value to initialize the map. 84 85 /// It constrates a map and initialize all of the the map. 86 87 ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) { 88 Item it; 91 89 attach(_g.getNotifier(_Item())); 92 90 allocate_memory(); 93 for (KeyIt it(*graph); it != INVALID; ++it) { 94 int id = graph->id(it);; 95 allocator.construct(&(values[id]), Value()); 96 } 97 } 98 99 /// Constructor to use default value to initialize the map. 100 101 /// It constrates a map and initialize all of the the map. 102 103 ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) { 104 attach(_g.getNotifier(_Item())); 105 allocate_memory(); 106 for (KeyIt it(*graph); it != INVALID; ++it) { 91 for (graph->first(it); it != INVALID; graph->next(it)) { 107 92 int id = graph->id(it);; 108 93 allocator.construct(&(values[id]), _v); … … 119 104 if (capacity == 0) return; 120 105 values = allocator.allocate(capacity); 121 for (KeyIt it(*graph); it != INVALID; ++it) { 106 Item it; 107 for (graph->first(it); it != INVALID; graph->next(it)) { 122 108 int id = graph->id(it);; 123 109 allocator.construct(&(values[id]), copy.values[id]); … … 147 133 } 148 134 149 for (KeyIt it(*graph); it != INVALID; ++it) { 135 Item it; 136 for (graph->first(it); it != INVALID; graph->next(it)) { 150 137 int id = graph->id(it);; 151 138 allocator.construct(&(values[id]), copy.values[id]); … … 169 156 * actual keys of the graph. 170 157 */ 171 Referenceoperator[](const Key& key) {158 Value& operator[](const Key& key) { 172 159 int id = graph->id(key); 173 160 return values[id]; … … 178 165 * actual keys of the graph. 179 166 */ 180 ConstReferenceoperator[](const Key& key) const {167 const Value& operator[](const Key& key) const { 181 168 int id = graph->id(key); 182 169 return values[id]; … … 200 187 } 201 188 Value* new_values = allocator.allocate(new_capacity); 202 for (KeyIt it(*graph); it != INVALID; ++it) { 189 Item it; 190 for (graph->first(it); it != INVALID; graph->next(it)) { 203 191 int jd = graph->id(it);; 204 192 if (id != jd) { … … 223 211 void build() { 224 212 allocate_memory(); 225 for (KeyIt it(*graph); it != INVALID; ++it) { 213 Item it; 214 for (graph->first(it); it != INVALID; graph->next(it)) { 226 215 int id = graph->id(it);; 227 216 allocator.construct(&(values[id]), Value()); … … 231 220 void clear() { 232 221 if (capacity != 0) { 233 for (KeyIt it(*graph); it != INVALID; ++it) { 222 Item it; 223 for (graph->first(it); it != INVALID; graph->next(it)) { 234 224 int id = graph->id(it);; 235 225 allocator.destroy(&(values[id])); … … 314 304 Allocator allocator; 315 305 316 public:317 // // STL compatibility typedefs.318 // typedef Iterator iterator;319 // typedef ConstIterator const_iterator;320 // typedef typename Iterator::PairValue value_type;321 // typedef typename Iterator::Key key_type;322 // typedef typename Iterator::Value data_type;323 // typedef typename Iterator::PairReference reference;324 // typedef typename Iterator::PairPointer pointer;325 // typedef typename ConstIterator::PairReference const_reference;326 // typedef typename ConstIterator::PairPointer const_pointer;327 // typedef int difference_type;328 306 }; 329 307 … … 346 324 347 325 template <typename _Value> 348 class NodeMap : public ArrayMap<Graph, Node, NodeIt, _Value> { 326 class NodeMap 327 : public IterableMapExtender<ArrayMap<Graph, Node, _Value> > { 349 328 public: 350 329 typedef ArrayMappableGraphExtender<_Base> Graph; … … 353 332 typedef typename Graph::NodeIt NodeIt; 354 333 355 typedef ArrayMap<Graph, Node, NodeIt, _Value> Parent;334 typedef IterableMapExtender<ArrayMap<Graph, Node, _Value> > Parent; 356 335 357 336 //typedef typename Parent::Graph Graph; … … 366 345 367 346 template <typename _Value> 368 class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, _Value> { 347 class EdgeMap 348 : public IterableMapExtender<ArrayMap<Graph, Edge, _Value> > { 369 349 public: 370 350 typedef ArrayMappableGraphExtender<_Base> Graph; … … 373 353 typedef typename Graph::EdgeIt EdgeIt; 374 354 375 typedef ArrayMap<Graph, Edge, EdgeIt, _Value> Parent;355 typedef IterableMapExtender<ArrayMap<Graph, Edge, _Value> > Parent; 376 356 377 357 //typedef typename Parent::Graph Graph;
Note: See TracChangeset
for help on using the changeset viewer.