Changeset 844:9bf990cb066d in lemon-0.x for src/hugo/vector_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/vector_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 … … 74 75 /** Graph and Registry initialized map constructor. 75 76 */ 76 VectorMap(const Graph& g, MapRegistry& r) : MapBase(g, r) { 77 init(); 78 } 77 VectorMap(const Graph& g, MapRegistry& r) 78 : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1) {} 79 79 80 80 /** Constructor to use default value to initialize the map. 81 81 */ 82 82 VectorMap(const Graph& g, MapRegistry& r, const Value& v) 83 : MapBase(g, r) { 84 for (KeyIt it(*getGraph()); it != INVALID; ++it) { 85 int id = getGraph()->id(it); 86 if (id >= (int)container.size()) { 87 container.resize(id + 1); 88 } 89 set(it, v); 90 } 91 } 83 : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {} 92 84 93 85 /** Constructor to copy a map of an other map type. 94 86 */ 95 87 template <typename CMap> VectorMap(const CMap& copy) : MapBase(copy) { 96 if (getGraph()) { 97 for (KeyIt it(*getGraph()); it != INVALID; ++it) { 98 int id = getGraph()->id(it); 99 if (id >= (int)container.size()) { 100 container.resize(id + 1); 101 } 88 if (MapBase::getGraph()) { 89 container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1); 90 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 102 91 set(it, copy[it]); 103 92 } … … 108 97 */ 109 98 template <typename CMap> VectorMap& operator=(const CMap& copy) { 110 if (getGraph()) { 111 destroy(); 112 } 99 container.clear(); 113 100 this->MapBase::operator=(copy); 114 if (getGraph()) { 115 for (KeyIt it(*getGraph()); it != INVALID; ++it) { 116 int id = getGraph()->id(it); 117 if (id >= (int)container.size()) { 118 container.resize(id + 1); 119 } 101 if (MapBase::getGraph()) { 102 container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1); 103 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 120 104 set(it, copy[it]); 121 105 } … … 134 118 */ 135 119 ReferenceType operator[](const KeyType& key) { 136 int id = getGraph()->id(key);120 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 137 121 return container[id]; 138 122 } … … 143 127 */ 144 128 ConstReferenceType operator[](const KeyType& key) const { 145 int id = getGraph()->id(key);129 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 146 130 return container[id]; 147 131 } … … 151 135 */ 152 136 void set(const KeyType& key, const ValueType& val) { 153 int id = getGraph()->id(key);137 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 154 138 container[id] = val; 155 139 } … … 158 142 */ 159 143 void add(const KeyType& key) { 160 int id = getGraph()->id(key);144 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key); 161 145 if (id >= (int)container.size()) { 162 146 container.resize(id + 1); … … 232 216 Container container; 233 217 234 218 public: 219 // STL compatibility typedefs. 220 typedef Iterator iterator; 221 typedef ConstIterator const_iterator; 222 typedef typename Iterator::PairValueType value_type; 223 typedef typename Iterator::KeyType key_type; 224 typedef typename Iterator::ValueType data_type; 225 typedef typename Iterator::PairReferenceType reference; 226 typedef typename Iterator::PairPointerType pointer; 227 typedef typename ConstIterator::PairReferenceType const_reference; 228 typedef typename ConstIterator::PairPointerType const_pointer; 229 typedef int difference_type; 235 230 }; 236 231
Note: See TracChangeset
for help on using the changeset viewer.