# HG changeset patch # User deba # Date 1116091240 0 # Node ID 01d9d6bc1284dfa59ea2cb5855f81c60bad633e5 # Parent 3f45d58969d4e81b61dfcc1c260ade1ab9e25657 Handling simultan edge adding. Fixed bug: directed edge maps for undir graphs diff -r 3f45d58969d4 -r 01d9d6bc1284 src/lemon/bits/alteration_notifier.h --- a/src/lemon/bits/alteration_notifier.h Wed May 11 17:36:25 2005 +0000 +++ b/src/lemon/bits/alteration_notifier.h Sat May 14 17:20:40 2005 +0000 @@ -29,8 +29,9 @@ /// \addtogroup graphmaps /// @{ - /// Registry class to register objects observes alterations in the graph. - + /// \brief Registry class to register objects observes alterations in + /// the graph. + /// /// This class is a registry for the objects which observe the /// alterations in a container. The alteration observers can be attached /// to and detached from the registry. The observers have to inherit @@ -38,8 +39,7 @@ /// the virtual functions in that. /// /// The most important application of the alteration observing is the - /// dynamic map implementation when the observers are observing the - /// alterations in the graph. + /// dynamic map implementation. /// /// \param _Item The item type what the observers are observing, usually /// edge or node. @@ -74,16 +74,16 @@ friend class AlterationNotifier; - /// Default constructor. - + /// \brief Default constructor. + /// /// Default constructor for ObserverBase. /// ObserverBase() : registry(0) {} virtual ~ObserverBase() {} - /// Attaches the observer into an AlterationNotifier. - + /// \brief Attaches the observer into an AlterationNotifier. + /// /// This member attaches the observer into an AlterationNotifier. /// void attach(AlterationNotifier& r) { @@ -91,8 +91,8 @@ registry->attach(*this); } - /// Detaches the observer into an AlterationNotifier. - + /// \brief Detaches the observer into an AlterationNotifier. + /// /// This member detaches the observer from an AlterationNotifier. /// void detach() { @@ -131,8 +131,20 @@ /// is added to the container. It have to be overrided in the /// subclasses. - virtual void add(const Item&) = 0; + virtual void add(const Item&) = 0; + /// \brief The member function to notificate the observer about + /// simulitem is added to the container. + /// + /// The add() member function notificates the observer about an item + /// is added to the container. It have to be overrided in the + /// subclasses. + + virtual void add(const std::vector& items) { + for (int i = 0; i < (int)items.size(); ++i) { + add(items[i]); + } + } /// \brief The member function to notificate the observer about an /// item is erased from the container. @@ -143,6 +155,12 @@ virtual void erase(const Item&) = 0; + virtual void erase(const std::vector& items) { + for (int i = 0; i < (int)items.size(); ++i) { + add(items[i]); + } + } + /// \brief The member function to notificate the observer about the /// container is built. /// @@ -228,20 +246,37 @@ public: - /// Notifies all the registered observers about an Item added to the container. - - /// It notifies all the registered observers about an Item added to the container. + /// \brief Notifies all the registered observers about an Item added to + /// the container. + /// + /// It notifies all the registered observers about an Item added to + /// the container. /// - void add(const Item& key) { + void add(const Item& item) { typename Container::iterator it; for (it = container.begin(); it != container.end(); ++it) { - (*it)->add(key); + (*it)->add(item); } } - /// Notifies all the registered observers about an Item erased from the container. - - /// It notifies all the registered observers about an Item erased from the container. + /// \brief Notifies all the registered observers about more Item added to + /// the container. + /// + /// It notifies all the registered observers about more Item added to + /// the container. + /// + void add(const std::vector& items) { + typename Container::iterator it; + for (it = container.begin(); it != container.end(); ++it) { + (*it)->add(items); + } + } + + /// \brief Notifies all the registered observers about an Item erased from + /// the container. + /// + /// It notifies all the registered observers about an Item erased from + /// the container. /// void erase(const Item& key) { typename Container::iterator it; @@ -249,10 +284,24 @@ (*it)->erase(key); } } + + /// \brief Notifies all the registered observers about more Item erased + /// from the container. + /// + /// It notifies all the registered observers about more Item erased from + /// the container. + /// + void erase(const std::vector& items) { + typename Container::iterator it; + for (it = container.begin(); it != container.end(); ++it) { + (*it)->erase(items); + } + } - /// Notifies all the registered observers about the container is built. - + /// \brief Notifies all the registered observers about the container is + /// built. + /// /// Notifies all the registered observers about the container is built /// from an empty container. void build() { @@ -263,8 +312,9 @@ } - /// Notifies all the registered observers about all Items are erased. - + /// \brief Notifies all the registered observers about all Items are + /// erased. + /// /// Notifies all the registered observers about all Items are erased /// from the container. void clear() { diff -r 3f45d58969d4 -r 01d9d6bc1284 src/lemon/bits/array_map.h --- a/src/lemon/bits/array_map.h Wed May 11 17:36:25 2005 +0000 +++ b/src/lemon/bits/array_map.h Sat May 14 17:20:40 2005 +0000 @@ -1,5 +1,5 @@ /* -*- C++ -*- - * src/lemon/array_map.h - Part of LEMON, a generic C++ optimization library + * src/lemon/bits/array_map.h - Part of LEMON, a generic C++ optimization library * * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). @@ -31,14 +31,14 @@ /// \addtogroup graphmaps /// @{ - /** The ArrayMap template class is graph map structure what - * automatically updates the map when a key is added to or erased from - * the map. This map factory uses the allocators to implement - * the container functionality. - * - * The template parameter is the AlterationNotifier that the maps - * will belong to and the Value. - */ + /// The ArrayMap template class is graph map structure what + /// automatically updates the map when a key is added to or erased from + /// the map. This map factory uses the allocators to implement + /// the container functionality. + /// + /// The template parameter is the AlterationNotifier that the maps + /// will belong to and the Value. + template id(key); return values[id]; } - /** - * The const subscript operator. The map can be subscripted by the - * actual keys of the graph. - */ + + ///The const subscript operator. The map can be subscripted by the + ///actual keys of the graph. + const Value& operator[](const Key& key) const { int id = graph->id(key); return values[id]; } - /** Setter function of the map. Equivalent with map[key] = val. - * This is a compatibility feature with the not dereferable maps. - */ + /// Setter function of the map. Equivalent with map[key] = val. + /// This is a compatibility feature with the not dereferable maps. + void set(const Key& key, const Value& val) { (*this)[key] = val; } - /** Add a new key to the map. It called by the map registry. - */ + /// Add a new key to the map. It called by the map registry. + void add(const Key& key) { int id = graph->id(key); if (id >= capacity) { @@ -200,14 +199,60 @@ } allocator.construct(&(values[id]), Value()); } + + void add(const std::vector& keys) { + int max_id = -1; + for (int i = 0; i < (int)keys.size(); ++i) { + int id = graph->id(keys[i]); + if (id > max_id) { + max_id = id; + } + } + if (max_id >= capacity) { + int new_capacity = (capacity == 0 ? 1 : capacity); + while (new_capacity <= max_id) { + new_capacity <<= 1; + } + Value* new_values = allocator.allocate(new_capacity); + Item it; + for (graph->first(it); it != INVALID; graph->next(it)) { + int id = graph->id(it); + bool found = false; + for (int i = 0; i < (int)keys.size(); ++i) { + int jd = graph->id(keys[i]); + if (id == jd) { + found = true; + break; + } + } + if (found) continue; + allocator.construct(&(new_values[id]), values[id]); + allocator.destroy(&(values[id])); + } + if (capacity != 0) allocator.deallocate(values, capacity); + values = new_values; + capacity = new_capacity; + } + for (int i = 0; i < (int)keys.size(); ++i) { + int id = graph->id(keys[i]); + allocator.construct(&(values[id]), Value()); + } + } - /** Erase a key from the map. It called by the map registry. - */ + /// Erase a key from the map. It called by the map registry. + void erase(const Key& key) { int id = graph->id(key); allocator.destroy(&(values[id])); } + void erase(const std::vector& keys) { + for (int i = 0; i < (int)keys.size(); ++i) { + int id = graph->id(keys[i]); + allocator.destroy(&(values[id])); + } + } + void build() { allocate_memory(); Item it; @@ -221,7 +266,7 @@ if (capacity != 0) { Item it; for (graph->first(it); it != INVALID; graph->next(it)) { - int id = graph->id(it);; + int id = graph->id(it); allocator.destroy(&(values[id])); } allocator.deallocate(values, capacity); @@ -233,59 +278,6 @@ return graph; } -// /// The stl compatible pair iterator of the map. -// typedef MapIterator Iterator; -// /// The stl compatible const pair iterator of the map. -// typedef MapConstIterator ConstIterator; - -// /** Returns the begin iterator of the map. -// */ -// Iterator begin() { -// return Iterator(*this, KeyIt(*MapBase::getGraph())); -// } - -// /** Returns the end iterator of the map. -// */ -// Iterator end() { -// return Iterator(*this, INVALID); -// } - -// /** Returns the begin ConstIterator of the map. -// */ -// ConstIterator begin() const { -// return ConstIterator(*this, KeyIt(*MapBase::getGraph())); -// } - -// /** Returns the end const_iterator of the map. -// */ -// ConstIterator end() const { -// return ConstIterator(*this, INVALID); -// } - -// /// The KeySet of the Map. -// typedef MapConstKeySet ConstKeySet; - -// /// KeySet getter function. -// ConstKeySet keySet() const { -// return ConstKeySet(*this); -// } - -// /// The ConstValueSet of the Map. -// typedef MapConstValueSet ConstValueSet; - -// /// ConstValueSet getter function. -// ConstValueSet valueSet() const { -// return ConstValueSet(*this); -// } - -// /// The ValueSet of the Map. -// typedef MapValueSet ValueSet; - -// /// ValueSet getter function. -// ValueSet valueSet() { -// return ValueSet(*this); -// } - private: void allocate_memory() { diff -r 3f45d58969d4 -r 01d9d6bc1284 src/lemon/bits/erasable_graph_extender.h --- a/src/lemon/bits/erasable_graph_extender.h Wed May 11 17:36:25 2005 +0000 +++ b/src/lemon/bits/erasable_graph_extender.h Sat May 14 17:20:40 2005 +0000 @@ -3,6 +3,8 @@ #ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H #define LEMON_ERASABLE_GRAPH_EXTENDER_H +#include + #include @@ -67,8 +69,10 @@ } void erase(const UndirEdge& uedge) { - Parent::getNotifier(Edge()).erase(Edge(uedge,true)); - Parent::getNotifier(Edge()).erase(Edge(uedge,false)); + std::vector edges; + edges.push_back(Edge(uedge,true)); + edges.push_back(Edge(uedge,false)); + Parent::getNotifier(Edge()).erase(edges); Parent::getNotifier(UndirEdge()).erase(uedge); Parent::erase(uedge); } diff -r 3f45d58969d4 -r 01d9d6bc1284 src/lemon/bits/extendable_graph_extender.h --- a/src/lemon/bits/extendable_graph_extender.h Wed May 11 17:36:25 2005 +0000 +++ b/src/lemon/bits/extendable_graph_extender.h Sat May 14 17:20:40 2005 +0000 @@ -50,10 +50,10 @@ UndirEdge uedge = Parent::addEdge(from, to); Parent::getNotifier(UndirEdge()).add(uedge); - Edge edge_forward(uedge, true); - Edge edge_backward(uedge, false); - Parent::getNotifier(Edge()).add(edge_forward); - Parent::getNotifier(Edge()).add(edge_backward); + std::vector edges; + edges.push_back(Edge(uedge, true)); + edges.push_back(Edge(uedge, false)); + Parent::getNotifier(Edge()).add(edges); return uedge; }