Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/bits/vector_map.h
- Timestamp:
- 07/13/08 20:51:02 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/vector_map.h
r157 r209 1 /* -*- C++-*-2 * 3 * This file is a part of LEMON, a generic C++ optimization library 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 50 50 /// \todo Fix the doc: there is _Graph parameter instead of _Notifier. 51 51 template <typename _Graph, typename _Item, typename _Value> 52 class VectorMap 52 class VectorMap 53 53 : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { 54 54 private: 55 55 56 56 /// The container type of the map. 57 typedef std::vector<_Value> Container; 57 typedef std::vector<_Value> Container; 58 58 59 59 public: 60 60 61 /// The graph type of the map. 61 /// The graph type of the map. 62 62 typedef _Graph Graph; 63 63 /// The item type of the map. … … 94 94 } 95 95 96 /// \brief Constructor uses given value to initialize the map. 97 /// 98 /// It constructs a map uses a given value to initialize the map. 96 /// \brief Constructor uses given value to initialize the map. 97 /// 98 /// It constructs a map uses a given value to initialize the map. 99 99 /// It adds all the items of the graph to the map. 100 100 VectorMap(const Graph& graph, const Value& value) { … … 108 108 VectorMap(const VectorMap& _copy) : Parent() { 109 109 if (_copy.attached()) { 110 111 110 Parent::attach(*_copy.notifier()); 111 container = _copy.container; 112 112 } 113 113 } … … 116 116 /// 117 117 /// This operator assigns for each item in the map the 118 /// value mapped to the same item in the copied map. 118 /// value mapped to the same item in the copied map. 119 119 /// The parameter map should be indiced with the same 120 120 /// itemset because this assign operator does not change 121 /// the container of the map. 121 /// the container of the map. 122 122 VectorMap& operator=(const VectorMap& cmap) { 123 123 return operator=<VectorMap>(cmap); … … 130 130 /// concecpt and could be indiced by the current item set of 131 131 /// the NodeMap. In this case the value for each item 132 /// is assigned by the value of the given ReadMap. 132 /// is assigned by the value of the given ReadMap. 133 133 template <typename CMap> 134 134 VectorMap& operator=(const CMap& cmap) { … … 141 141 return *this; 142 142 } 143 143 144 144 public: 145 145 … … 147 147 /// 148 148 /// The subscript operator. The map can be subscripted by the 149 /// actual items of the graph. 149 /// actual items of the graph. 150 150 Reference operator[](const Key& key) { 151 151 return container[Parent::notifier()->id(key)]; 152 } 153 152 } 153 154 154 /// \brief The const subcript operator. 155 155 /// 156 156 /// The const subscript operator. The map can be subscripted by the 157 /// actual items of the graph. 157 /// actual items of the graph. 158 158 ConstReference operator[](const Key& key) const { 159 159 return container[Parent::notifier()->id(key)]; … … 171 171 172 172 /// \brief Adds a new key to the map. 173 /// 173 /// 174 174 /// It adds a new key to the map. It called by the observer notifier 175 /// and it overrides the add() member function of the observer base. 175 /// and it overrides the add() member function of the observer base. 176 176 virtual void add(const Key& key) { 177 177 int id = Parent::notifier()->id(key); 178 178 if (id >= int(container.size())) { 179 179 container.resize(id + 1); 180 180 } 181 181 } 182 182 183 183 /// \brief Adds more new keys to the map. 184 /// 184 /// 185 185 /// It adds more new keys to the map. It called by the observer notifier 186 /// and it overrides the add() member function of the observer base. 186 /// and it overrides the add() member function of the observer base. 187 187 virtual void add(const std::vector<Key>& keys) { 188 188 int max = container.size() - 1; … … 199 199 /// 200 200 /// Erase a key from the map. It called by the observer notifier 201 /// and it overrides the erase() member function of the observer base. 201 /// and it overrides the erase() member function of the observer base. 202 202 virtual void erase(const Key& key) { 203 203 container[Parent::notifier()->id(key)] = Value(); … … 207 207 /// 208 208 /// Erase more keys from the map. It called by the observer notifier 209 /// and it overrides the erase() member function of the observer base. 209 /// and it overrides the erase() member function of the observer base. 210 210 virtual void erase(const std::vector<Key>& keys) { 211 211 for (int i = 0; i < int(keys.size()); ++i) { 212 213 } 214 } 215 212 container[Parent::notifier()->id(keys[i])] = Value(); 213 } 214 } 215 216 216 /// \brief Buildes the map. 217 /// 217 /// 218 218 /// It buildes the map. It called by the observer notifier 219 219 /// and it overrides the build() member function of the observer base. 220 virtual void build() { 220 virtual void build() { 221 221 int size = Parent::notifier()->maxId() + 1; 222 222 container.reserve(size); … … 227 227 /// 228 228 /// It erase all items from the map. It called by the observer notifier 229 /// and it overrides the clear() member function of the observer base. 230 virtual void clear() { 229 /// and it overrides the clear() member function of the observer base. 230 virtual void clear() { 231 231 container.clear(); 232 232 } 233 233 234 234 private: 235 235 236 236 Container container; 237 237
Note: See TracChangeset
for help on using the changeset viewer.