[Lemon-commits] [lemon_svn] deba: r1884 - hugo/trunk/src/lemon/bits
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:48:27 CET 2006
Author: deba
Date: Sat May 14 19:20:40 2005
New Revision: 1884
Modified:
hugo/trunk/src/lemon/bits/alteration_notifier.h
hugo/trunk/src/lemon/bits/array_map.h
hugo/trunk/src/lemon/bits/erasable_graph_extender.h
hugo/trunk/src/lemon/bits/extendable_graph_extender.h
Log:
Handling simultan edge adding.
Fixed bug: directed edge maps for undir graphs
Modified: hugo/trunk/src/lemon/bits/alteration_notifier.h
==============================================================================
--- hugo/trunk/src/lemon/bits/alteration_notifier.h (original)
+++ hugo/trunk/src/lemon/bits/alteration_notifier.h Sat May 14 19:20:40 2005
@@ -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<Item>& 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<Item>& 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<Item>& 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<Item>& 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() {
Modified: hugo/trunk/src/lemon/bits/array_map.h
==============================================================================
--- hugo/trunk/src/lemon/bits/array_map.h (original)
+++ hugo/trunk/src/lemon/bits/array_map.h Sat May 14 19:20:40 2005
@@ -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 <typename _Graph,
typename _Item,
@@ -68,8 +68,8 @@
public:
- /** Graph and Registry initialized map constructor.
- */
+ /// Graph and Registry initialized map constructor.
+
ArrayMap(const Graph& _g) : graph(&_g) {
Item it;
attach(_g.getNotifier(Item()));
@@ -94,8 +94,8 @@
}
}
- /** Constructor to copy a map of the same map type.
- */
+ /// Constructor to copy a map of the same map type.
+
ArrayMap(const ArrayMap& copy) : Parent() {
if (copy.attached()) {
attach(*copy.getRegistry());
@@ -114,8 +114,8 @@
using Parent::detach;
using Parent::attached;
- /** Assign operator to copy a map of the same map type.
- */
+ /// Assign operator to copy a map of the same map type.
+
ArrayMap& operator=(const ArrayMap& copy) {
if (© == this) return *this;
@@ -141,8 +141,8 @@
return *this;
}
- /** The destructor of the map.
- */
+ /// The destructor of the map.
+
virtual ~ArrayMap() {
if (attached()) {
clear();
@@ -151,33 +151,32 @@
}
- /**
- * The subscript operator. The map can be subscripted by the
- * actual keys of the graph.
- */
+ ///The subscript operator. The map can be subscripted by the
+ ///actual keys of the graph.
+
Value& operator[](const Key& key) {
int id = graph->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<Key>& 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<Key>& 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<ArrayMap> Iterator;
-// /// The stl compatible const pair iterator of the map.
-// typedef MapConstIterator<ArrayMap> 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<ArrayMap> ConstKeySet;
-
-// /// KeySet getter function.
-// ConstKeySet keySet() const {
-// return ConstKeySet(*this);
-// }
-
-// /// The ConstValueSet of the Map.
-// typedef MapConstValueSet<ArrayMap> ConstValueSet;
-
-// /// ConstValueSet getter function.
-// ConstValueSet valueSet() const {
-// return ConstValueSet(*this);
-// }
-
-// /// The ValueSet of the Map.
-// typedef MapValueSet<ArrayMap> ValueSet;
-
-// /// ValueSet getter function.
-// ValueSet valueSet() {
-// return ValueSet(*this);
-// }
-
private:
void allocate_memory() {
Modified: hugo/trunk/src/lemon/bits/erasable_graph_extender.h
==============================================================================
--- hugo/trunk/src/lemon/bits/erasable_graph_extender.h (original)
+++ hugo/trunk/src/lemon/bits/erasable_graph_extender.h Sat May 14 19:20:40 2005
@@ -3,6 +3,8 @@
#ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H
#define LEMON_ERASABLE_GRAPH_EXTENDER_H
+#include <vector>
+
#include <lemon/invalid.h>
@@ -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<Edge> 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);
}
Modified: hugo/trunk/src/lemon/bits/extendable_graph_extender.h
==============================================================================
--- hugo/trunk/src/lemon/bits/extendable_graph_extender.h (original)
+++ hugo/trunk/src/lemon/bits/extendable_graph_extender.h Sat May 14 19:20:40 2005
@@ -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<Edge> edges;
+ edges.push_back(Edge(uedge, true));
+ edges.push_back(Edge(uedge, false));
+ Parent::getNotifier(Edge()).add(edges);
return uedge;
}
More information about the Lemon-commits
mailing list