Changeset 844:9bf990cb066d in lemon-0.x for src/hugo/array_map.h
- Timestamp:
- 09/13/04 22:05:13 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1143
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/hugo/array_map.h
r830 r844 6 6 7 7 #include <hugo/map_iterator.h> 8 #include <hugo/map_bits.h> 8 9 9 10 ///\ingroup graphmaps … … 72 73 allocate_memory(); 73 74 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 74 int id = MapBase::getGraph()->id(it);75 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 75 76 allocator.construct(&(values[id]), Value()); 76 77 } … … 83 84 allocate_memory(); 84 85 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 85 int id = MapBase::getGraph()->id(it);86 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 86 87 allocator.construct(&(values[id]), v); 87 88 } … … 95 96 values = allocator.allocate(capacity); 96 97 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 97 int id = MapBase::getGraph()->id(it);98 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 98 99 allocator.construct(&(values[id]), copy.values[id]); 99 100 } … … 124 125 values = allocator.allocate(capacity); 125 126 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 126 int id = MapBase::getGraph()->id(it);127 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 127 128 allocator.construct(&(values[id]), copy.values[id]); 128 129 } … … 133 134 */ 134 135 template <typename CMap> ArrayMap& operator=(const CMap& copy) { 135 if ( MapBase::getGraph()) {136 if (capacity != 0) { 136 137 MapBase::destroy(); 137 } 138 allocator.deallocate(values, capacity); 139 } 138 140 MapBase::operator=(copy); 139 141 if (MapBase::getGraph()) { … … 161 163 */ 162 164 ReferenceType operator[](const KeyType& key) { 163 int id = MapBase::getGraph()->id(key);165 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 164 166 return values[id]; 165 167 } … … 170 172 */ 171 173 ConstReferenceType operator[](const KeyType& key) const { 172 int id = MapBase::getGraph()->id(key);174 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 173 175 return values[id]; 174 176 } … … 178 180 */ 179 181 void set(const KeyType& key, const ValueType& val) { 180 int id = MapBase::getGraph()->id(key);182 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 181 183 values[id] = val; 182 184 } … … 185 187 */ 186 188 void add(const KeyType& key) { 187 int id = MapBase::getGraph()->id(key);189 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 188 190 if (id >= capacity) { 189 191 int new_capacity = (capacity == 0 ? 1 : capacity); … … 193 195 Value* new_values = allocator.allocate(new_capacity);; 194 196 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 195 int jd = MapBase::getGraph()->id(it);197 int jd = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 196 198 if (id != jd) { 197 199 allocator.construct(&(new_values[jd]), values[jd]); … … 209 211 */ 210 212 void erase(const KeyType& key) { 211 int id = MapBase::getGraph()->id(key);213 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 212 214 allocator.destroy(&(values[id])); 213 215 } … … 279 281 280 282 void allocate_memory() { 281 int max_id = -1; 282 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 283 int id = MapBase::getGraph()->id(it); 284 if (id > max_id) { 285 max_id = id; 286 } 287 } 283 int max_id = KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph()); 288 284 if (max_id == -1) { 289 285 capacity = 0; … … 301 297 Value* values; 302 298 Allocator allocator; 299 300 public: 301 // STL compatibility typedefs. 302 typedef Iterator iterator; 303 typedef ConstIterator const_iterator; 304 typedef typename Iterator::PairValueType value_type; 305 typedef typename Iterator::KeyType key_type; 306 typedef typename Iterator::ValueType data_type; 307 typedef typename Iterator::PairReferenceType reference; 308 typedef typename Iterator::PairPointerType pointer; 309 typedef typename ConstIterator::PairReferenceType const_reference; 310 typedef typename ConstIterator::PairPointerType const_pointer; 311 typedef int difference_type; 303 312 }; 304 313
Note: See TracChangeset
for help on using the changeset viewer.