Changeset 1414:01d9d6bc1284 in lemon-0.x for src
- Timestamp:
- 05/14/05 19:20:40 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1884
- Location:
- src/lemon/bits
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/lemon/bits/alteration_notifier.h
r1359 r1414 30 30 /// @{ 31 31 32 /// Registry class to register objects observes alterations in the graph. 33 32 /// \brief Registry class to register objects observes alterations in 33 /// the graph. 34 /// 34 35 /// This class is a registry for the objects which observe the 35 36 /// alterations in a container. The alteration observers can be attached … … 39 40 /// 40 41 /// The most important application of the alteration observing is the 41 /// dynamic map implementation when the observers are observing the 42 /// alterations in the graph. 42 /// dynamic map implementation. 43 43 /// 44 44 /// \param _Item The item type what the observers are observing, usually … … 75 75 friend class AlterationNotifier; 76 76 77 /// Default constructor.78 77 /// \brief Default constructor. 78 /// 79 79 /// Default constructor for ObserverBase. 80 80 /// … … 83 83 virtual ~ObserverBase() {} 84 84 85 /// Attaches the observer into an AlterationNotifier.86 85 /// \brief Attaches the observer into an AlterationNotifier. 86 /// 87 87 /// This member attaches the observer into an AlterationNotifier. 88 88 /// … … 92 92 } 93 93 94 /// Detaches the observer into an AlterationNotifier.95 94 /// \brief Detaches the observer into an AlterationNotifier. 95 /// 96 96 /// This member detaches the observer from an AlterationNotifier. 97 97 /// … … 132 132 /// subclasses. 133 133 134 virtual void add(const Item&) = 0; 135 134 virtual void add(const Item&) = 0; 135 136 /// \brief The member function to notificate the observer about 137 /// simulitem is added to the container. 138 /// 139 /// The add() member function notificates the observer about an item 140 /// is added to the container. It have to be overrided in the 141 /// subclasses. 142 143 virtual void add(const std::vector<Item>& items) { 144 for (int i = 0; i < (int)items.size(); ++i) { 145 add(items[i]); 146 } 147 } 136 148 137 149 /// \brief The member function to notificate the observer about an … … 143 155 144 156 virtual void erase(const Item&) = 0; 157 158 virtual void erase(const std::vector<Item>& items) { 159 for (int i = 0; i < (int)items.size(); ++i) { 160 add(items[i]); 161 } 162 } 145 163 146 164 /// \brief The member function to notificate the observer about the … … 229 247 public: 230 248 231 /// Notifies all the registered observers about an Item added to the container. 232 233 /// It notifies all the registered observers about an Item added to the container. 249 /// \brief Notifies all the registered observers about an Item added to 250 /// the container. 251 /// 252 /// It notifies all the registered observers about an Item added to 253 /// the container. 234 254 /// 235 void add(const Item& key) {236 typename Container::iterator it; 237 for (it = container.begin(); it != container.end(); ++it) { 238 (*it)->add( key);255 void add(const Item& item) { 256 typename Container::iterator it; 257 for (it = container.begin(); it != container.end(); ++it) { 258 (*it)->add(item); 239 259 } 240 260 } 241 261 242 /// Notifies all the registered observers about an Item erased from the container. 243 244 /// It notifies all the registered observers about an Item erased from the container. 262 /// \brief Notifies all the registered observers about more Item added to 263 /// the container. 264 /// 265 /// It notifies all the registered observers about more Item added to 266 /// the container. 267 /// 268 void add(const std::vector<Item>& items) { 269 typename Container::iterator it; 270 for (it = container.begin(); it != container.end(); ++it) { 271 (*it)->add(items); 272 } 273 } 274 275 /// \brief Notifies all the registered observers about an Item erased from 276 /// the container. 277 /// 278 /// It notifies all the registered observers about an Item erased from 279 /// the container. 245 280 /// 246 281 void erase(const Item& key) { … … 250 285 } 251 286 } 287 288 /// \brief Notifies all the registered observers about more Item erased 289 /// from the container. 290 /// 291 /// It notifies all the registered observers about more Item erased from 292 /// the container. 293 /// 294 void erase(const std::vector<Item>& items) { 295 typename Container::iterator it; 296 for (it = container.begin(); it != container.end(); ++it) { 297 (*it)->erase(items); 298 } 299 } 252 300 253 301 254 /// Notifies all the registered observers about the container is built. 255 302 /// \brief Notifies all the registered observers about the container is 303 /// built. 304 /// 256 305 /// Notifies all the registered observers about the container is built 257 306 /// from an empty container. … … 264 313 265 314 266 /// Notifies all the registered observers about all Items are erased. 267 315 /// \brief Notifies all the registered observers about all Items are 316 /// erased. 317 /// 268 318 /// Notifies all the registered observers about all Items are erased 269 319 /// from the container. -
src/lemon/bits/array_map.h
r1374 r1414 1 1 /* -*- C++ -*- 2 * src/lemon/ array_map.h - Part of LEMON, a generic C++ optimization library2 * src/lemon/bits/array_map.h - Part of LEMON, a generic C++ optimization library 3 3 * 4 4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport … … 32 32 /// @{ 33 33 34 / **The ArrayMap template class is graph map structure what35 *automatically updates the map when a key is added to or erased from36 *the map. This map factory uses the allocators to implement37 *the container functionality.38 *39 *The template parameter is the AlterationNotifier that the maps40 *will belong to and the Value.41 */34 /// The ArrayMap template class is graph map structure what 35 /// automatically updates the map when a key is added to or erased from 36 /// the map. This map factory uses the allocators to implement 37 /// the container functionality. 38 /// 39 /// The template parameter is the AlterationNotifier that the maps 40 /// will belong to and the Value. 41 42 42 43 43 template <typename _Graph, … … 69 69 public: 70 70 71 / **Graph and Registry initialized map constructor.72 */71 /// Graph and Registry initialized map constructor. 72 73 73 ArrayMap(const Graph& _g) : graph(&_g) { 74 74 Item it; … … 95 95 } 96 96 97 / **Constructor to copy a map of the same map type.98 */97 /// Constructor to copy a map of the same map type. 98 99 99 ArrayMap(const ArrayMap& copy) : Parent() { 100 100 if (copy.attached()) { … … 115 115 using Parent::attached; 116 116 117 / **Assign operator to copy a map of the same map type.118 */117 /// Assign operator to copy a map of the same map type. 118 119 119 ArrayMap& operator=(const ArrayMap& copy) { 120 120 if (© == this) return *this; … … 142 142 } 143 143 144 / **The destructor of the map.145 */144 /// The destructor of the map. 145 146 146 virtual ~ArrayMap() { 147 147 if (attached()) { … … 152 152 153 153 154 /** 155 * The subscript operator. The map can be subscripted by the 156 * actual keys of the graph. 157 */ 154 ///The subscript operator. The map can be subscripted by the 155 ///actual keys of the graph. 156 158 157 Value& operator[](const Key& key) { 159 158 int id = graph->id(key); … … 161 160 } 162 161 163 /** 164 *The const subscript operator. The map can be subscripted by the165 *actual keys of the graph.166 */162 163 ///The const subscript operator. The map can be subscripted by the 164 ///actual keys of the graph. 165 167 166 const Value& operator[](const Key& key) const { 168 167 int id = graph->id(key); … … 170 169 } 171 170 172 / **Setter function of the map. Equivalent with map[key] = val.173 *This is a compatibility feature with the not dereferable maps.174 */171 /// Setter function of the map. Equivalent with map[key] = val. 172 /// This is a compatibility feature with the not dereferable maps. 173 175 174 void set(const Key& key, const Value& val) { 176 175 (*this)[key] = val; 177 176 } 178 177 179 / **Add a new key to the map. It called by the map registry.180 */178 /// Add a new key to the map. It called by the map registry. 179 181 180 void add(const Key& key) { 182 181 int id = graph->id(key); … … 201 200 allocator.construct(&(values[id]), Value()); 202 201 } 203 204 /** Erase a key from the map. It called by the map registry. 205 */ 202 203 void add(const std::vector<Key>& keys) { 204 int max_id = -1; 205 for (int i = 0; i < (int)keys.size(); ++i) { 206 int id = graph->id(keys[i]); 207 if (id > max_id) { 208 max_id = id; 209 } 210 } 211 if (max_id >= capacity) { 212 int new_capacity = (capacity == 0 ? 1 : capacity); 213 while (new_capacity <= max_id) { 214 new_capacity <<= 1; 215 } 216 Value* new_values = allocator.allocate(new_capacity); 217 Item it; 218 for (graph->first(it); it != INVALID; graph->next(it)) { 219 int id = graph->id(it); 220 bool found = false; 221 for (int i = 0; i < (int)keys.size(); ++i) { 222 int jd = graph->id(keys[i]); 223 if (id == jd) { 224 found = true; 225 break; 226 } 227 } 228 if (found) continue; 229 allocator.construct(&(new_values[id]), values[id]); 230 allocator.destroy(&(values[id])); 231 } 232 if (capacity != 0) allocator.deallocate(values, capacity); 233 values = new_values; 234 capacity = new_capacity; 235 } 236 for (int i = 0; i < (int)keys.size(); ++i) { 237 int id = graph->id(keys[i]); 238 allocator.construct(&(values[id]), Value()); 239 } 240 } 241 242 /// Erase a key from the map. It called by the map registry. 243 206 244 void erase(const Key& key) { 207 245 int id = graph->id(key); 208 246 allocator.destroy(&(values[id])); 247 } 248 249 void erase(const std::vector<Key>& keys) { 250 for (int i = 0; i < (int)keys.size(); ++i) { 251 int id = graph->id(keys[i]); 252 allocator.destroy(&(values[id])); 253 } 209 254 } 210 255 … … 222 267 Item it; 223 268 for (graph->first(it); it != INVALID; graph->next(it)) { 224 int id = graph->id(it); ;269 int id = graph->id(it); 225 270 allocator.destroy(&(values[id])); 226 271 } … … 233 278 return graph; 234 279 } 235 236 // /// The stl compatible pair iterator of the map.237 // typedef MapIterator<ArrayMap> Iterator;238 // /// The stl compatible const pair iterator of the map.239 // typedef MapConstIterator<ArrayMap> ConstIterator;240 241 // /** Returns the begin iterator of the map.242 // */243 // Iterator begin() {244 // return Iterator(*this, KeyIt(*MapBase::getGraph()));245 // }246 247 // /** Returns the end iterator of the map.248 // */249 // Iterator end() {250 // return Iterator(*this, INVALID);251 // }252 253 // /** Returns the begin ConstIterator of the map.254 // */255 // ConstIterator begin() const {256 // return ConstIterator(*this, KeyIt(*MapBase::getGraph()));257 // }258 259 // /** Returns the end const_iterator of the map.260 // */261 // ConstIterator end() const {262 // return ConstIterator(*this, INVALID);263 // }264 265 // /// The KeySet of the Map.266 // typedef MapConstKeySet<ArrayMap> ConstKeySet;267 268 // /// KeySet getter function.269 // ConstKeySet keySet() const {270 // return ConstKeySet(*this);271 // }272 273 // /// The ConstValueSet of the Map.274 // typedef MapConstValueSet<ArrayMap> ConstValueSet;275 276 // /// ConstValueSet getter function.277 // ConstValueSet valueSet() const {278 // return ConstValueSet(*this);279 // }280 281 // /// The ValueSet of the Map.282 // typedef MapValueSet<ArrayMap> ValueSet;283 284 // /// ValueSet getter function.285 // ValueSet valueSet() {286 // return ValueSet(*this);287 // }288 280 289 281 private: -
src/lemon/bits/erasable_graph_extender.h
r1307 r1414 3 3 #ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H 4 4 #define LEMON_ERASABLE_GRAPH_EXTENDER_H 5 6 #include <vector> 5 7 6 8 #include <lemon/invalid.h> … … 68 70 69 71 void erase(const UndirEdge& uedge) { 70 Parent::getNotifier(Edge()).erase(Edge(uedge,true)); 71 Parent::getNotifier(Edge()).erase(Edge(uedge,false)); 72 std::vector<Edge> edges; 73 edges.push_back(Edge(uedge,true)); 74 edges.push_back(Edge(uedge,false)); 75 Parent::getNotifier(Edge()).erase(edges); 72 76 Parent::getNotifier(UndirEdge()).erase(uedge); 73 77 Parent::erase(uedge); -
src/lemon/bits/extendable_graph_extender.h
r1307 r1414 51 51 Parent::getNotifier(UndirEdge()).add(uedge); 52 52 53 Edge edge_forward(uedge, true);54 Edge edge_backward(uedge, false);55 Parent::getNotifier(Edge()).add(edge_forward);56 Parent::getNotifier(Edge()).add(edge _backward);53 std::vector<Edge> edges; 54 edges.push_back(Edge(uedge, true)); 55 edges.push_back(Edge(uedge, false)); 56 Parent::getNotifier(Edge()).add(edges); 57 57 58 58 return uedge;
Note: See TracChangeset
for help on using the changeset viewer.