[Lemon-commits] [lemon_svn] deba: r1075 - hugo/trunk/src/hugo

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:43:06 CET 2006


Author: deba
Date: Thu Sep  2 12:07:30 2004
New Revision: 1075

Added:
   hugo/trunk/src/hugo/array_map_factory.h
      - copied, changed from r1067, /hugo/trunk/src/work/deba/array_map_factory.h
   hugo/trunk/src/hugo/extended_pair.h
      - copied unchanged from r1067, /hugo/trunk/src/work/deba/extended_pair.h
   hugo/trunk/src/hugo/map_defines.h
      - copied, changed from r1067, /hugo/trunk/src/work/deba/map_defines.h
   hugo/trunk/src/hugo/map_registry.h
      - copied, changed from r1067, /hugo/trunk/src/work/deba/map_registry.h
   hugo/trunk/src/hugo/sym_map_factory.h
   hugo/trunk/src/hugo/vector_map_factory.h
      - copied, changed from r1067, /hugo/trunk/src/work/deba/vector_map_factory.h
Modified:
   hugo/trunk/src/hugo/full_graph.h
   hugo/trunk/src/hugo/list_graph.h
   hugo/trunk/src/hugo/smart_graph.h

Log:

	--This line, and those below, will be ignored--

A    hugo/sym_map_factory.h
M    hugo/list_graph.h
A    hugo/array_map_factory.h
A    hugo/map_registry.h
M    hugo/smart_graph.h
A    hugo/map_defines.h
A    hugo/extended_pair.h
M    hugo/full_graph.h
A    hugo/vector_map_factory.h


Copied: hugo/trunk/src/hugo/array_map_factory.h (from r1067, /hugo/trunk/src/work/deba/array_map_factory.h)
==============================================================================
--- /hugo/trunk/src/work/deba/array_map_factory.h	(original)
+++ hugo/trunk/src/hugo/array_map_factory.h	Thu Sep  2 12:07:30 2004
@@ -1,10 +1,10 @@
 // -*- c++ -*-
-#ifndef ARRAY_MAP_H
-#define ARRAY_MAP_H
+#ifndef ARRAY_MAP_FACTORY_H
+#define ARRAY_MAP_FACTORY_H
 
 #include <memory>
 
-#include "extended_pair.h"
+#include <hugo/extended_pair.h>
 
 namespace hugo {
 	
@@ -31,16 +31,16 @@
 			
       Map(const Graph& g, MapRegistry& r) : MapBase(g, r) {
 	allocate_memory();
-	for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-	  int id = getGraph()->id(it);
+	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
+	  int id = MapBase::getGraph()->id(it);
 	  allocator.construct(&(values[id]), Value());
 	}								
       }
 
       Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
 	allocate_memory();
-	for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-	  int id = getGraph()->id(it);
+	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
+	  int id = MapBase::getGraph()->id(it);
 	  allocator.construct(&(values[id]), v);
 	}								
       }
@@ -49,88 +49,90 @@
 	capacity = copy.capacity;
 	if (capacity == 0) return;
 	values = allocator.allocate(capacity);
-	for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-	  int id = getGraph()->id(it);
+	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
+	  int id = MapBase::getGraph()->id(it);
 	  allocator.construct(&(values[id]), copy.values[id]);
 	}
       }
 
       template <typename CMap> Map(const CMap& copy) 
 	: capacity(0), values(0), MapBase(copy) {
-	if (getGraph()) {
+	if (MapBase::getGraph()) {
 	  allocate_memory();
-	  for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
+	  for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
 	    set(it, copy[it]);
 	  }
 	}
       }
 
       Map& operator=(const Map& copy) {
-	if (&copy == this) return;
+	if (&copy == this) return *this;
 	if (capacity != 0) {
-	  destroy();
+	  MapBase::destroy();
 	  allocator.deallocate(values, capacity);
 	}
 	capacity = copy.capacity;
-	if (capacity == 0) return;
+	if (capacity == 0) return *this;
 	values = allocator.allocate(capacity);
-	for (KeyIt it(getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-	  int id = getGraph()->id(it);
+	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
+	  int id = MapBase::getGraph()->id(it);
 	  allocator.construct(&(values[id]), copy.values[id]);
 	}
+	return *this;
       }
 
       template <typename CMap> Map& operator=(const CMap& copy) {
-	if (getGraph()) {
-	  destroy();
+	if (MapBase::getGraph()) {
+	  MapBase::destroy();
 	} 
-	this->MapBase::operator=(copy);
-	if (getGraph()) {
+	MapBase::operator=(copy);
+	if (MapBase::getGraph()) {
 	  allocate_memory();
-	  for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
+	  for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
 	    set(it, copy[it]);
 	  }
 	}
+	return *this;
       }
 				
       virtual ~Map() {
 	if (capacity != 0) {
-	  destroy();
+	  MapBase::destroy();
 	  allocator.deallocate(values, capacity);
 	}
       }
 	
 	
       Value& operator[](const Key& key) {
-	int id = getGraph()->id(key);
+	int id = MapBase::getGraph()->id(key);
 	return values[id];
       } 
 		
       const Value& operator[](const Key& key) const {
-	int id = getGraph()->id(key);
+	int id = MapBase::getGraph()->id(key);
 	return values[id];
       }
 	
       const Value& get(const Key& key) const {
-	int id = getGraph()->id(key);
+	int id = MapBase::getGraph()->id(key);
 	return values[id];
       } 
 		
       void set(const Key& key, const Value& val) {
-	int id = getGraph()->id(key);
+	int id = MapBase::getGraph()->id(key);
 	values[id] = val;
       }
 		
       void add(const Key& key) {
-	int id = getGraph()->id(key);
+	int id = MapBase::getGraph()->id(key);
 	if (id >= capacity) {
 	  int new_capacity = (capacity == 0 ? 1 : capacity);
 	  while (new_capacity <= id) {
 	    new_capacity <<= 1;
 	  }
 	  Value* new_values = allocator.allocate(new_capacity);;
-	  for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-	    int jd = getGraph()->id(it);
+	  for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
+	    int jd = MapBase::getGraph()->id(it);
 	    if (id != jd) {
 	      allocator.construct(&(new_values[jd]), values[jd]);
 	      allocator.destroy(&(values[jd]));
@@ -144,9 +146,17 @@
       }
 		
       void erase(const Key& key) {
-	int id = getGraph()->id(key);
+	int id = MapBase::getGraph()->id(key);
 	allocator.destroy(&(values[id]));
       }
+
+      void clear() {	
+	if (capacity != 0) {
+	  MapBase::destroy();
+	  allocator.deallocate(values, capacity);
+	  capacity = 0;
+	}
+      }
 	
       class iterator {
 	friend class Map;
@@ -191,7 +201,7 @@
 	/** The pre increment operator of the map.
 	 */
 	iterator& operator++() { 
-	  map->getGraph()->next(it); 
+	  ++it; 
 	  return *this; 
 	}
 
@@ -199,7 +209,7 @@
 	 */
 	iterator operator++(int) { 
 	  iterator tmp(it); 
-	  map.getGraph()->next(it); 
+	  ++it; 
 	  return tmp; 
 	}
 
@@ -224,7 +234,7 @@
       /** Returns the begin iterator of the map.
        */
       iterator begin() {
-	return iterator(*this, KeyIt(*getGraph()));
+	return iterator(*this, KeyIt(*MapBase::getGraph()));
       }
 
       /** Returns the end iterator of the map.
@@ -282,7 +292,7 @@
 	/** The pre increment operator of the map.
 	 */
 	const_iterator& operator++() { 
-	  map->getGraph()->next(it); 
+	  ++it; 
 	  return *this; 
 	}
 
@@ -290,7 +300,7 @@
 	 */
 	const_iterator operator++(int) { 
 	  const_iterator tmp(it); 
-	  map->getGraph()->next(it); 
+	  ++it; 
 	  return tmp; 
 	}
 
@@ -315,7 +325,7 @@
       /** Returns the begin const_iterator of the map.
        */
       const_iterator begin() const {
-	return const_iterator(*this, KeyIt(*getGraph()));
+	return const_iterator(*this, KeyIt(*MapBase::getGraph()));
       }
 
       /** Returns the end const_iterator of the map.
@@ -328,8 +338,8 @@
       
       void allocate_memory() {
 	int max_id = -1;
-	for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-	  int id = getGraph()->id(it);
+	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
+	  int id = MapBase::getGraph()->id(it);
 	  if (id > max_id) {
 	    max_id = id;
 	  }			
@@ -345,6 +355,7 @@
 	}
 	values = allocator.allocate(capacity);	
       }      
+
       int capacity;
       Value* values;
       Allocator allocator;

Modified: hugo/trunk/src/hugo/full_graph.h
==============================================================================
--- hugo/trunk/src/hugo/full_graph.h	(original)
+++ hugo/trunk/src/hugo/full_graph.h	Thu Sep  2 12:07:30 2004
@@ -8,10 +8,13 @@
 ///\brief FullGraph and SymFullGraph classes.
 
 #include <vector>
-#include <limits.h>
+#include <climits>
 
 #include <hugo/invalid.h>
 
+#include <hugo/map_registry.h>
+#include <hugo/array_map_factory.h>
+
 namespace hugo {
 
 /// \addtogroup graphs
@@ -33,18 +36,19 @@
     int NodeNum;
     int EdgeNum;
   public:
-    template <typename T> class EdgeMap;
-    template <typename T> class NodeMap;
+
+    typedef FullGraph Graph;
 
     class Node;
     class Edge;
+
     class NodeIt;
     class EdgeIt;
     class OutEdgeIt;
     class InEdgeIt;
     
-    template <typename T> class NodeMap;
-    template <typename T> class EdgeMap;
+    CREATE_MAP_REGISTRIES;
+    CREATE_MAPS(ArrayMapFactory);
     
   public:
 
@@ -85,7 +89,7 @@
     /// \return The found edge or INVALID if there is no such an edge.
     Edge findEdge(Node u,Node v, Edge prev = INVALID) 
     {
-      return prev.n==-1?Edge(*this,u.n,v.n):INVALID;
+      return prev.n == -1 ? Edge(*this, u.n, v.n) : INVALID;
     }
     
       
@@ -187,110 +191,6 @@
       { if(!((++n)%G->NodeNum)) n=-1; return *this; }
     };
 
-    template <typename T> class NodeMap
-    {
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Node KeyType;
-
-      NodeMap(const FullGraph &_G) : container(_G.NodeNum) { }
-      NodeMap(const FullGraph &_G,const T &t) : container(_G.NodeNum,t) { }
-      NodeMap(const NodeMap<T> &m) : container(m.container) { }
-
-      template<typename TT> friend class NodeMap;
-      ///\todo It can copy between different types.
-      template<typename TT> NodeMap(const NodeMap<TT> &m)
-	: container(m.container.size())
-      {
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      void set(Node n, T a) { container[n.n]=a; }
-      //'T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::reference
-      operator[](Node n) { return container[n.n]; }
-      //'const T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::const_reference 
-      operator[](Node n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const NodeMap<T>& operator=(const NodeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const NodeMap<T>& operator=(const NodeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for Dynamic Maps
-      void update(T a) {}  //Useless for Dynamic Maps
-    };
-    
-    template <typename T> class EdgeMap
-    {
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
-
-      EdgeMap(const FullGraph &_G) : container(_G.EdgeNum) { }
-      EdgeMap(const FullGraph &_G,const T &t) : container(_G.EdgeNum,t) { } 
-      EdgeMap(const EdgeMap<T> &m) : container(m.container) { }
-
-      template<typename TT> friend class EdgeMap;
-      ///\todo It can copy between different types. 
-      ///\todo We could use 'copy'
-      template<typename TT> EdgeMap(const EdgeMap<TT> &m) :
-	container(m.container.size())
-      {
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      void set(Edge n, T a) { container[n.n]=a; }
-      //T get(Edge n) const { return container[n.n]; }
-      typename std::vector<T>::reference
-      operator[](Edge n) { return container[n.n]; }
-      typename std::vector<T>::const_reference
-      operator[](Edge n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const EdgeMap<T>& operator=(const EdgeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const EdgeMap<T>& operator=(const EdgeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-
-      void update() {}
-      void update(T a) {}
-    };
-
   };
 
   /// @}  

Modified: hugo/trunk/src/hugo/list_graph.h
==============================================================================
--- hugo/trunk/src/hugo/list_graph.h	(original)
+++ hugo/trunk/src/hugo/list_graph.h	Thu Sep  2 12:07:30 2004
@@ -8,16 +8,24 @@
 ///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
 
 #include <vector>
-#include <limits.h>
+#include <climits>
 
 #include <hugo/invalid.h>
 
+#include <hugo/map_registry.h>
+#include <hugo/array_map_factory.h>
+
+#include <hugo/sym_map_factory.h>
+
+#include <hugo/map_defines.h>
+
+
 namespace hugo {
 
 /// \addtogroup graphs
 /// @{
 
-  class SymListGraph;
+//  class SymListGraph;
 
   ///A list graph class.
 
@@ -56,36 +64,13 @@
     //The first free edge
     int first_free_edge;
     
-  protected:
-    
-    template <typename Key> class DynMapBase
-    {
-    protected:
-      const ListGraph* G; 
-    public:
-      virtual void add(const Key k) = 0;
-      virtual void erase(const Key k) = 0;
-      DynMapBase(const ListGraph &_G) : G(&_G) {}
-      virtual ~DynMapBase() {}
-      friend class ListGraph;
-    };
-    
   public:
-    template <typename T> class EdgeMap;
-    template <typename T> class NodeMap;
+    
+    typedef ListGraph Graph;
     
     class Node;
     class Edge;
 
-    //  protected:
-    // HELPME:
-  protected:
-    ///\bug It must be public because of SymEdgeMap.
-    ///
-    mutable std::vector<DynMapBase<Node> * > dyn_node_maps;
-    ///\bug It must be public because of SymEdgeMap.
-    ///
-    mutable std::vector<DynMapBase<Edge> * > dyn_edge_maps;
     
   public:
 
@@ -93,24 +78,21 @@
     class EdgeIt;
     class OutEdgeIt;
     class InEdgeIt;
-    
+
+    CREATE_MAP_REGISTRIES;
+    CREATE_MAPS(ArrayMapFactory);
+
   public:
 
-    ListGraph() : nodes(), first_node(-1),
-		  first_free_node(-1), edges(), first_free_edge(-1) {}
-    ListGraph(const ListGraph &_g) : nodes(_g.nodes), first_node(_g.first_node),
-				     first_free_node(_g.first_free_node),
-				     edges(_g.edges),
-				     first_free_edge(_g.first_free_edge) {}
+    ListGraph() 
+      : nodes(), first_node(-1),
+	first_free_node(-1), edges(), first_free_edge(-1) {}
+
+    ListGraph(const ListGraph &_g) 
+      : nodes(_g.nodes), first_node(_g.first_node),
+	first_free_node(_g.first_free_node), edges(_g.edges),
+	first_free_edge(_g.first_free_edge) {}
     
-    ~ListGraph()
-    {
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).G=NULL;
-      for(std::vector<DynMapBase<Edge> * >::iterator i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).G=NULL;
-    }
-
     int nodeNum() const { return nodes.size(); }  //FIXME: What is this?
     int edgeNum() const { return edges.size(); }  //FIXME: What is this?
 
@@ -170,8 +152,7 @@
       Node nn; nn.n=n;
 
       //Update dynamic maps
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).add(nn);
+      node_maps.add(nn);
 
       return nn;
     }
@@ -202,8 +183,7 @@
       Edge e; e.n=n;
 
       //Update dynamic maps
-      for(std::vector<DynMapBase<Edge> * >::iterator i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).add(e);
+      edge_maps.add(e);
 
       return e;
     }
@@ -244,8 +224,8 @@
 
       //Update dynamic maps
       Edge e; e.n=n;
-      for(std::vector<DynMapBase<Edge> * >::iterator i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).erase(e);
+      edge_maps.erase(e);
+
     }
       
   public:
@@ -265,16 +245,17 @@
       first_free_node = n;
 
       //Update dynamic maps
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).erase(nn);
+      node_maps.erase(nn);
+
     }
     
     void erase(Edge e) { eraseEdge(e.n); }
 
-    ///\bug Dynamic maps must be updated!
-    ///
     void clear() {
-      nodes.clear();edges.clear();
+      edge_maps.clear();
+      edges.clear();
+      node_maps.clear();
+      nodes.clear();
       first_node=first_free_node=first_free_edge=-1;
     }
 
@@ -410,188 +391,6 @@
       //      ///Validity check
       //      operator bool() { return Edge::operator bool(); }      
     };
-
-    template <typename T> class NodeMap : public DynMapBase<Node>
-    {
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Node KeyType;
-
-      NodeMap(const ListGraph &_G) :
-	DynMapBase<Node>(_G), container(_G.maxNodeId())
-      {
-	G->dyn_node_maps.push_back(this);
-      }
-      NodeMap(const ListGraph &_G,const T &t) :
-	DynMapBase<Node>(_G), container(_G.maxNodeId(),t)
-      {
-	G->dyn_node_maps.push_back(this);
-      }
-      
-      NodeMap(const NodeMap<T> &m) :
- 	DynMapBase<Node>(*m.G), container(m.container)
-      {
- 	G->dyn_node_maps.push_back(this);
-      }
-
-      template<typename TT> friend class NodeMap;
- 
-      ///\todo It can copy between different types.
-      ///
-      template<typename TT> NodeMap(const NodeMap<TT> &m) :
-	DynMapBase<Node>(*m.G), container(m.container.size())
-
-      {
-	G->dyn_node_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      ~NodeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Node>* >::iterator i;
-	  for(i=G->dyn_node_maps.begin();
-	      i!=G->dyn_node_maps.end() && *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_node_maps.erase(i); //FIXME: Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=G->dyn_node_maps.back();
-	    G->dyn_node_maps.pop_back();
-	  }
-	}
-      }
-
-      void add(const Node k) 
-      {
-	if(k.n>=int(container.size())) container.resize(k.n+1);
-      }
-
-      void erase(const Node) { }
-      
-      void set(Node n, T a) { container[n.n]=a; }
-      //'T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::reference
-      operator[](Node n) { return container[n.n]; }
-      //'const T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::const_reference 
-      operator[](Node n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const NodeMap<T>& operator=(const NodeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const NodeMap<T>& operator=(const NodeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for Dynamic Maps
-      void update(T a) {}  //Useless for Dynamic Maps
-    };
-    
-    template <typename T> class EdgeMap : public DynMapBase<Edge>
-    {
-    protected:
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
-
-      EdgeMap(const ListGraph &_G) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId())
-      {
-	//FIXME: What if there are empty Id's?
-	//FIXME: Can I use 'this' in a constructor?
-	G->dyn_edge_maps.push_back(this);
-      }
-      EdgeMap(const ListGraph &_G,const T &t) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId(),t)
-      {
-	G->dyn_edge_maps.push_back(this);
-      } 
-      EdgeMap(const EdgeMap<T> &m) :
- 	DynMapBase<Edge>(*m.G), container(m.container)
-      {
- 	G->dyn_edge_maps.push_back(this);
-      }
-
-      template<typename TT> friend class EdgeMap;
-
-      ///\todo It can copy between different types.
-      ///
-      template<typename TT> EdgeMap(const EdgeMap<TT> &m) :
-	DynMapBase<Edge>(*m.G), container(m.container.size())
-      {
-	G->dyn_edge_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      ~EdgeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Edge>* >::iterator i;
-	  for(i=G->dyn_edge_maps.begin();
-	      i!=G->dyn_edge_maps.end() && *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=G->dyn_edge_maps.back();
-	    G->dyn_edge_maps.pop_back();
-	  }
-	}
-      }
-      
-      void add(const Edge k) 
-      {
-	if(k.n>=int(container.size())) container.resize(k.n+1);
-      }
-      void erase(const Edge) { }
-      
-      void set(Edge n, T a) { container[n.n]=a; }
-      //T get(Edge n) const { return container[n.n]; }
-      typename std::vector<T>::reference
-      operator[](Edge n) { return container[n.n]; }
-      typename std::vector<T>::const_reference
-      operator[](Edge n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const EdgeMap<T>& operator=(const EdgeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const EdgeMap<T>& operator=(const EdgeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for DynMaps
-      void update(T a) {}  //Useless for DynMaps
-    };
-
   };
 
   ///Graph for bidirectional edges.
@@ -615,12 +414,19 @@
   ///
   ///\todo this date structure need some reconsiderations. Maybe it
   ///should be implemented independently from ListGraph.
-
+  
   class SymListGraph : public ListGraph
   {
   public:
-    template<typename T> class SymEdgeMap;
-    template<typename T> friend class SymEdgeMap;
+
+    typedef SymListGraph Graph;
+
+    KEEP_NODE_MAP(ListGraph);
+    KEEP_EDGE_MAP(ListGraph);
+
+    CREATE_SYM_EDGE_MAP_REGISTRY;
+    CREATE_SYM_EDGE_MAP_FACTORY(ArrayMapFactory);
+    IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
 
     SymListGraph() : ListGraph() { }
     SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
@@ -628,11 +434,14 @@
     Edge addEdge(Node u, Node v)
     {
       Edge e = ListGraph::addEdge(u,v);
-      ListGraph::addEdge(v,u);
+      Edge f = ListGraph::addEdge(v,u);
+      sym_edge_maps.add(e);
+      sym_edge_maps.add(f);
+      
       return e;
     }
 
-    void erase(Node n) { ListGraph::erase(n); }
+    void erase(Node n) { ListGraph::erase(n);}
     ///The oppositely directed edge.
 
     ///Returns the oppositely directed
@@ -646,109 +455,14 @@
     
     ///Removes a pair of oppositely directed edges to the graph.
     void erase(Edge e) {
-      ListGraph::erase(opposite(e));
+      Edge f = opposite(e);
+      sym_edge_maps.erase(e);
+      sym_edge_maps.erase(f);
+      ListGraph::erase(f);
       ListGraph::erase(e);
-    }
-    
-    ///Common data storage for the edge pairs.
-
-    ///This map makes it possible to store data shared by the oppositely
-    ///directed pairs of edges.
-    template <typename T> class SymEdgeMap : public DynMapBase<Edge>
-    {
-      std::vector<T> container;
-      
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
-
-      SymEdgeMap(const SymListGraph &_G) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId()/2)
-      {
-	static_cast<const SymListGraph*>(G)->dyn_edge_maps.push_back(this);
-      }
-      SymEdgeMap(const SymListGraph &_G,const T &t) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId()/2,t)
-      {
-	G->dyn_edge_maps.push_back(this);
-      }
-
-      SymEdgeMap(const SymEdgeMap<T> &m) :
- 	DynMapBase<SymEdge>(*m.G), container(m.container)
-      {
- 	G->dyn_node_maps.push_back(this);
-      }
-
-      //      template<typename TT> friend class SymEdgeMap;
-
-      ///\todo It can copy between different types.
-      ///
-
-      template<typename TT> SymEdgeMap(const SymEdgeMap<TT> &m) :
-	DynMapBase<SymEdge>(*m.G), container(m.container.size())
-      {
-	G->dyn_node_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
- 
-      ~SymEdgeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Edge>* >::iterator i;
-	  for(i=static_cast<const SymListGraph*>(G)->dyn_edge_maps.begin();
-	      i!=static_cast<const SymListGraph*>(G)->dyn_edge_maps.end()
-		&& *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=static_cast<const SymListGraph*>(G)->dyn_edge_maps.back();
-	    static_cast<const SymListGraph*>(G)->dyn_edge_maps.pop_back();
-	  }
-	}
-      }
-      
-      void add(const Edge k) 
-      {
-	if(!k.idref()%2&&k.idref()/2>=int(container.size()))
-	  container.resize(k.idref()/2+1);
-      }
-      void erase(const Edge k) { }
-      
-      void set(Edge n, T a) { container[n.idref()/2]=a; }
-      //T get(Edge n) const { return container[n.idref()/2]; }
-      typename std::vector<T>::reference
-      operator[](Edge n) { return container[n.idref()/2]; }
-      typename std::vector<T>::const_reference
-      operator[](Edge n) const { return container[n.idref()/2]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const SymEdgeMap<T>& operator=(const SymEdgeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const SymEdgeMap<T>& operator=(const SymEdgeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for DynMaps
-      void update(T a) {}  //Useless for DynMaps
-
-    };
-
+    }    
   };
-  
+
 
   ///A graph class containing only nodes.
 
@@ -779,35 +493,13 @@
     //The first free node
     int first_free_node;
     
-  protected:
-    
-    template <typename Key> class DynMapBase
-    {
-    protected:
-      const NodeSet* G; 
-    public:
-      virtual void add(const Key k) = 0;
-      virtual void erase(const Key k) = 0;
-      DynMapBase(const NodeSet &_G) : G(&_G) {}
-      virtual ~DynMapBase() {}
-      friend class NodeSet;
-    };
-    
   public:
-    template <typename T> class EdgeMap;
-    template <typename T> class NodeMap;
+
+    typedef NodeSet Graph;
     
     class Node;
     class Edge;
 
-    //  protected:
-    // HELPME:
-  protected:
-    ///\bug It must be public because of SymEdgeMap.
-    ///
-    mutable std::vector<DynMapBase<Node> * > dyn_node_maps;
-    //mutable std::vector<DynMapBase<Edge> * > dyn_edge_maps;
-    
   public:
 
     class NodeIt;
@@ -815,26 +507,19 @@
     class OutEdgeIt;
     class InEdgeIt;
     
-    template <typename T> class NodeMap;
-    template <typename T> class EdgeMap;
+    CREATE_MAP_REGISTRIES;
+    CREATE_MAPS(ArrayMapFactory);
     
   public:
 
     ///Default constructor
-    NodeSet() : nodes(), first_node(-1),
-		  first_free_node(-1) {}
+    NodeSet() 
+      : nodes(), first_node(-1), first_free_node(-1) {}
     ///Copy constructor
-    NodeSet(const NodeSet &_g) : nodes(_g.nodes), first_node(_g.first_node),
-				     first_free_node(_g.first_free_node) {}
+    NodeSet(const NodeSet &_g) 
+      : nodes(_g.nodes), first_node(_g.first_node),
+	first_free_node(_g.first_free_node) {}
     
-    ~NodeSet()
-    {
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).G=NULL;
-      //for(std::vector<DynMapBase<Edge> * >::iterator i=dyn_edge_maps.begin();
-      //	  i!=dyn_edge_maps.end(); ++i) (**i).G=NULL;
-    }
-
     int nodeNum() const { return nodes.size(); }  //FIXME: What is this?
     int edgeNum() const { return 0; }  //FIXME: What is this?
 
@@ -887,8 +572,7 @@
       Node nn; nn.n=n;
 
       //Update dynamic maps
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).add(nn);
+      node_maps.add(nn);
 
       return nn;
     }
@@ -904,8 +588,7 @@
       first_free_node = n;
 
       //Update dynamic maps
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).erase(nn);
+      node_maps.erase(nn);
     }
     
         
@@ -914,9 +597,8 @@
       return INVALID;
     }
     
-    ///\bug Dynamic maps must be updated!
-    ///
     void clear() {
+      node_maps.clear();
       nodes.clear();
       first_node = first_free_node = -1;
     }
@@ -1012,128 +694,6 @@
       InEdgeIt operator++() { return INVALID; }
     };
 
-    template <typename T> class NodeMap : public DynMapBase<Node>
-    {
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Node KeyType;
-
-      NodeMap(const NodeSet &_G) :
-	DynMapBase<Node>(_G), container(_G.maxNodeId())
-      {
-	G->dyn_node_maps.push_back(this);
-      }
-      NodeMap(const NodeSet &_G,const T &t) :
-	DynMapBase<Node>(_G), container(_G.maxNodeId(),t)
-      {
-	G->dyn_node_maps.push_back(this);
-      }
-      
-      NodeMap(const NodeMap<T> &m) :
- 	DynMapBase<Node>(*m.G), container(m.container)
-      {
- 	G->dyn_node_maps.push_back(this);
-      }
-
-      template<typename TT> friend class NodeMap;
- 
-      ///\todo It can copy between different types.
-      ///
-      template<typename TT> NodeMap(const NodeMap<TT> &m) :
-	DynMapBase<Node>(*m.G), container(m.container.size())
-      {
-	G->dyn_node_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      ~NodeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Node>* >::iterator i;
-	  for(i=G->dyn_node_maps.begin();
-	      i!=G->dyn_node_maps.end() && *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_node_maps.erase(i); //FIXME: Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=G->dyn_node_maps.back();
-	    G->dyn_node_maps.pop_back();
-	  }
-	}
-      }
-
-      void add(const Node k) 
-      {
-	if(k.n>=int(container.size())) container.resize(k.n+1);
-      }
-
-      void erase(const Node) { }
-      
-      void set(Node n, T a) { container[n.n]=a; }
-      //'T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::reference
-      operator[](Node n) { return container[n.n]; }
-      //'const T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::const_reference 
-      operator[](Node n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const NodeMap<T>& operator=(const NodeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const NodeMap<T>& operator=(const NodeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for Dynamic Maps
-      void update(T a) {}  //Useless for Dynamic Maps
-    };
-    
-    template <typename T> class EdgeMap
-    {
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
-
-      EdgeMap(const NodeSet &) { }
-      EdgeMap(const NodeSet &,const T &) { }
-      EdgeMap(const EdgeMap<T> &) { }
-      //      template<typename TT> friend class EdgeMap;
-
-      ///\todo It can copy between different types.
-      ///
-      template<typename TT> EdgeMap(const EdgeMap<TT> &) { }
-      ~EdgeMap() { }
-
-      void add(const Edge  ) { }
-      void erase(const Edge) { }
-      
-      void set(Edge, T) { }
-      //T get(Edge n) const { return container[n.n]; }
-      ValueType &operator[](Edge) { return *((T*)(NULL)); }
-      const ValueType &operator[](Edge) const { return *((T*)(NULL)); }
-
-      const EdgeMap<T>& operator=(const EdgeMap<T> &) { return *this; }
-    
-      template<typename TT>
-      const EdgeMap<T>& operator=(const EdgeMap<TT> &m) { return *this; }
-      
-      void update() {}
-      void update(T a) {}
-    };
   };
 
 
@@ -1166,11 +726,15 @@
     NodeGraphType &G;
 
   public:
+
     class Node;
     class Edge;
     class OutEdgeIt;
     class InEdgeIt;
     class SymEdge;
+
+    typedef EdgeSet Graph;
+
     int id(Node v) const; 
 
     class Node : public NodeGraphType::Node {
@@ -1229,44 +793,21 @@
     //The first free edge
     int first_free_edge;
     
-  protected:
-    
-    template <typename Key> class DynMapBase
-    {
-    protected:
-      const EdgeSet* G; 
-    public:
-      virtual void add(const Key k) = 0;
-      virtual void erase(const Key k) = 0;
-      DynMapBase(const EdgeSet &_G) : G(&_G) {}
-      virtual ~DynMapBase() {}
-      friend class EdgeSet;
-    };
-    
   public:
-    //template <typename T> class NodeMap;
-    template <typename T> class EdgeMap;
     
     class Node;
     class Edge;
 
-    //  protected:
-    // HELPME:
-  protected:
-    // mutable std::vector<DynMapBase<Node> * > dyn_node_maps;
-    ///\bug It must be public because of SymEdgeMap.
-    ///
-    mutable std::vector<DynMapBase<Edge> * > dyn_edge_maps;
-    
-  public:
-
     class NodeIt;
     class EdgeIt;
     class OutEdgeIt;
     class InEdgeIt;
+
+
+    CREATE_EDGE_MAP_REGISTRY;
+    CREATE_EDGE_MAP_FACTORY(ArrayMapFactory);
+    IMPORT_EDGE_MAP(EdgeMapFactory);
     
-    template <typename T> class NodeMap;
-    template <typename T> class EdgeMap;
     
   public:
 
@@ -1275,25 +816,17 @@
     ///Construates a new graph based on the nodeset of an existing one.
     ///\param _G the base graph.
     ///\todo It looks like a copy constructor, but it isn't.
-    EdgeSet(NodeGraphType &_G) : G(_G),
-				 nodes(_G), edges(),
-				 first_free_edge(-1) { }
+    EdgeSet(NodeGraphType &_G) 
+      : G(_G), nodes(_G), edges(),
+	first_free_edge(-1) {}
     ///Copy constructor
 
     ///Makes a copy of an EdgeSet.
     ///It will be based on the same graph.
-    EdgeSet(const EdgeSet &_g) : G(_g.G), nodes(_g.G), edges(_g.edges),
-				 first_free_edge(_g.first_free_edge) { }
+    EdgeSet(const EdgeSet &_g) 
+      : G(_g.G), nodes(_g.G), edges(_g.edges),
+	first_free_edge(_g.first_free_edge) {}
     
-    ~EdgeSet()
-    {
-      // for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-      //  i!=dyn_node_maps.end(); ++i) (**i).G=NULL;
-      for(typename std::vector<DynMapBase<Edge> * >::iterator
-	    i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).G=NULL;
-    }
-
     int nodeNum() const { return G.nodeNum(); }  //FIXME: What is this?
     int edgeNum() const { return edges.size(); }  //FIXME: What is this?
 
@@ -1347,9 +880,7 @@
       Edge e; e.n=n;
 
       //Update dynamic maps
-      for(typename std::vector<DynMapBase<Edge> * >::iterator
-	    i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).add(e);
+      edge_maps.add(e);
 
       return e;
     }
@@ -1389,10 +920,8 @@
       first_free_edge = -1;      
 
       //Update dynamic maps
-      Edge e; e.n=n;
-      for(typename std::vector<DynMapBase<Edge> * >::iterator
-	    i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).erase(e);
+      Edge e; e.n = n;
+      edge_maps.erase(e);
     }
       
   public:
@@ -1408,22 +937,12 @@
 
     ///Clear all edges. (Doesn't clear the nodes!)
     void clear() {
+      edge_maps.clear();
       edges.clear();
       first_free_edge=-1;
     }
 
 
-//     //\bug Dynamic maps must be updated!
-//     //
-//     void clear() {
-//       nodes.clear();edges.clear();
-//       first_node=first_free_node=first_free_edge=-1;
-//     }
-
-  public:
-    template <typename T> class EdgeMap;
-    
-    ///
     class Edge {
     public:
       friend class EdgeSet;
@@ -1490,7 +1009,7 @@
 
       OutEdgeIt(const EdgeSet& _G,const Node v) :
 	Edge(_G.nodes[v].first_out), G(&_G) { }
-      OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
+      OutEdgeIt &operator++() { n = G->edges[n].next_out; return *this; }
     };
     
     class InEdgeIt : public Edge {
@@ -1505,126 +1024,41 @@
       InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
     };
 
-    template <typename T> class NodeMap : 
-      public NodeGraphType::template NodeMap<T>
+    
+    template <typename V> class NodeMap 
+      : public NodeGraphType::template NodeMap<V>
     {
       //This is a must, the constructors need it.
-      typedef typename NodeGraphType::template NodeMap<T> ParentNodeMap;
+      typedef typename NodeGraphType::template NodeMap<V> MapImpl;
+      typedef V Value;
     public:
-      NodeMap(const EdgeSet &_G) : ParentNodeMap(_G.G) { }
-      NodeMap(const EdgeSet &_G,const T &t) : ParentNodeMap(_G.G,t) { }
-      //It is unnecessary
-      NodeMap(const typename NodeGraphType::template NodeMap<T> &m) :
-	ParentNodeMap(m) { }
+      NodeMap() : MapImpl() {}
+      
+      NodeMap(const EdgeSet& graph) 
+	: MapImpl(graph.G) { }
 
-      ///\todo It can copy between different types.
-      ///
-      template<typename TT>
-      NodeMap(const typename NodeGraphType::template NodeMap<TT> &m)
-	: ParentNodeMap(m) { }
-    };
-    
-    ///
-    template <typename T> class EdgeMap : public DynMapBase<Edge>
-    {
-    protected:
-    public:
-      ///\bug It should be at least protected
-      ///
-      std::vector<T> container;
+      NodeMap(const EdgeSet& graph, const Value& value) 
+	: MapImpl(graph.G, value) { }
 
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
+      NodeMap(const NodeMap& copy) 
+	: MapImpl(static_cast<const MapImpl&>(copy)) {}
 
-      EdgeMap(const EdgeSet &_G) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId())
-      {
-	//FIXME: What if there are empty Id's?
-	//FIXME: Can I use 'this' in a constructor?
-	this->G->dyn_edge_maps.push_back(this);
-      }
-      EdgeMap(const EdgeSet &_G,const T &t) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId(),t)
-      {
-	this->G->dyn_edge_maps.push_back(this);
-      } 
-      EdgeMap(const EdgeMap<T> &m) :
- 	DynMapBase<Edge>(*m.G), container(m.container)
-      {
- 	this->G->dyn_edge_maps.push_back(this);
-      }
+      template<typename CMap>
+      NodeMap(const CMap& copy)
+	: MapImpl(copy) { }
 
-      ///\todo It can copy between different types.
-      ///
-      template<typename TT> EdgeMap(const EdgeMap<TT> &m) :
-	DynMapBase<Edge>(*m.G), container(m.container.size())
-      {
-	this->G->dyn_edge_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      ~EdgeMap()
-      {
-	if(this->G) {
-	  typename std::vector<DynMapBase<Edge>* >::iterator i;
-	  for(i=this->G->dyn_edge_maps.begin();
-	      i!=this->G->dyn_edge_maps.end() && *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=this->G->dyn_edge_maps.back();
-	    this->G->dyn_edge_maps.pop_back();
-	  }
-	}
-      }
-      
-      void add(const Edge k) 
-      {
-	if(k.n>=int(container.size())) container.resize(k.n+1);
-      }
-      void erase(const Edge) { }
-      
-      ///\bug This doesn't work. Why?
-      ///      void set(Edge n, T a) { container[n.n]=a; }
-      void set(Edge n, T a) { container[this->G->id(n)]=a; }
-      //T get(Edge n) const { return container[n.n]; }
-      typename std::vector<T>::reference
-      ///\bug This doesn't work. Why?
-      ///      operator[](Edge n) { return container[n.n]; }
-      operator[](Edge n) { return container[this->G->id(n)]; }
-      typename std::vector<T>::const_reference
-      ///\bug This doesn't work. Why?
-      ///      operator[](Edge n) const { return container[n.n]; }
-      operator[](Edge n) const { return container[this->G->id(n)]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const EdgeMap<T>& operator=(const EdgeMap<T> &m)
-      {
-	container = m.container;
+      NodeMap& operator=(const NodeMap& copy) {
+	MapImpl::operator=(static_cast<const MapImpl&>(copy));
 	return *this;
       }
-      
-      template<typename TT> friend class EdgeMap;
 
-      template<typename TT>
-      const EdgeMap<T>& operator=(const EdgeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
+      template <typename CMap>
+      NodeMap& operator=(const CMap& copy) {
+	MapImpl::operator=(copy);
 	return *this;
       }
-      
-      void update() {}    //Useless for DynMaps
-      void update(T a) {}  //Useless for DynMaps
-    };
 
+    };
   };
 
   template<typename GG>

Copied: hugo/trunk/src/hugo/map_defines.h (from r1067, /hugo/trunk/src/work/deba/map_defines.h)
==============================================================================
--- /hugo/trunk/src/work/deba/map_defines.h	(original)
+++ hugo/trunk/src/hugo/map_defines.h	Thu Sep  2 12:07:30 2004
@@ -22,13 +22,13 @@
 CREATE_NODE_MAP_REGISTRY \
 CREATE_EDGE_MAP_REGISTRY
 
-/** Creates a map a concrete factory type from a template map
+/** Creates a concrete factory type from a template map
  *  factory to use as node map factory.
  */
 #define CREATE_NODE_MAP_FACTORY(TemplateFactory) \
 typedef TemplateFactory<NodeMapRegistry> NodeMapFactory;
 
-/** Creates a map a concrete factory type from a template map
+/** Creates a concrete factory type from a template map
  *  factory to use as edge map factory.
  */
 #define CREATE_EDGE_MAP_FACTORY(TemplateFactory) \
@@ -48,20 +48,20 @@
  */
 #define IMPORT_NODE_MAP(Factory) \
 template <typename V> \
-class NodeMap : public Factory::Map<V> { \
+class NodeMap : public Factory::template Map<V> { \
+typedef typename Factory::template Map<V> MapImpl; \
 public: \
 NodeMap() {} \
-NodeMap(const Graph& g) : Factory::Map<V>(&g, &(g.node_maps)) {} \
-NodeMap(const Graph& g, const V& v) : Factory::Map<V>(g, g.node_maps, v) {} \
-NodeMap(const NodeMap& copy) \
-  : Factory::Map<V>(static_cast<const Factory::Map<V>&>(copy)) {} \
-template <typename CMap> NodeMap(const CMap& copy) : Factory::Map<V>(copy) {} \
+NodeMap(const Graph& g) : MapImpl(g, g.node_maps) {} \
+NodeMap(const Graph& g, const V& v) : MapImpl(g, g.node_maps, v) {} \
+NodeMap(const NodeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
+template <typename CMap> NodeMap(const CMap& copy) : MapImpl(copy) {} \
 NodeMap& operator=(const NodeMap& copy) { \
-  this->Factory::Map<V>::operator=(static_cast<Factory::Map<V>&>(copy)); \
+  MapImpl::operator=(static_cast<const MapImpl&>(copy));\
   return *this; \
 } \
-template <typename CMap>NodeMap& operator=(const CMap& copy) { \
-  this->Factory::Map<V>::operator=<CMap>(copy); \
+template <typename CMap> NodeMap& operator=(const CMap& copy) { \
+  MapImpl::operator=(copy);\
   return *this; \
 } \
 };
@@ -74,20 +74,20 @@
  */
 #define IMPORT_EDGE_MAP(Factory) \
 template <typename V> \
-class EdgeMap : public Factory::Map<V> { \
+class EdgeMap : public Factory::template Map<V> { \
+typedef typename Factory::template Map<V> MapImpl; \
 public: \
 EdgeMap() {} \
-EdgeMap(const Graph& g) : Factory::Map<V>(g, g.edge_maps) {} \
-EdgeMap(const Graph& g, const V& v) : Factory::Map<V>(g, g.node_maps, v) {} \
-EdgeMap(const EdgeMap& copy) \
-  : Factory::Map<V>(static_cast<Factory::Map<V>&>(copy)) {} \
-template <typename CMap> EdgeMap(const CMap& copy) : Factory::Map<V>(copy) {} \
+EdgeMap(const Graph& g) : MapImpl(g, g.edge_maps) {} \
+EdgeMap(const Graph& g, const V& v) : MapImpl(g, g.edge_maps, v) {} \
+EdgeMap(const EdgeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
+template <typename CMap> EdgeMap(const CMap& copy) : MapImpl(copy) {} \
 EdgeMap& operator=(const EdgeMap& copy) { \
-  this->Factory::Map<V>::operator=(static_cast<Factory::Map<V>&>(copy)); \
+  MapImpl::operator=(static_cast<const MapImpl&>(copy));\
   return *this; \
 } \
-template <typename CMap>EdgeMap& operator=(const CMap& copy) { \
-  this->Factory::Map<V>::operator=<CMap>(copy); \
+template <typename CMap> EdgeMap& operator=(const CMap& copy) { \
+  MapImpl::operator=(copy);\
   return *this; \
 } \
 };
@@ -99,4 +99,114 @@
 IMPORT_NODE_MAP(NodeMapFactory) \
 IMPORT_EDGE_MAP(EdgeMapFactory)
 
+/** This macro creates MapRegistry for Symmetric Edge Maps.
+ */
+#define CREATE_SYM_EDGE_MAP_REGISTRY \
+typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
+typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
+mutable EdgeMapRegistry sym_edge_maps;
+
+/** Creates a concrete factory type from a template map
+ *  factory to use as edge map factory.
+ */
+#define CREATE_SYM_EDGE_MAP_FACTORY(TemplateFactory) \
+typedef SymMapFactory<SymEdgeMapRegistry, TemplateFactory > \
+SymEdgeMapFactory;
+
+/** Import a map from a concrete map factory. The import method is
+ *  an overloading of the map type.
+ *  The reason to use these macro is that the c++ does not support
+ *  the template typedefs. If a future release of the c++ 
+ *  supports this feature it should be fixed.
+ */
+#define IMPORT_SYM_EDGE_MAP(Factory) \
+template <typename V> \
+class SymEdgeMap : public Factory::template Map<V> { \
+typedef typename Factory::template Map<V> MapImpl; \
+public: \
+SymEdgeMap() {} \
+SymEdgeMap(const Graph& g) : MapImpl(g, g.sym_edge_maps) {} \
+SymEdgeMap(const Graph& g, const V& v) : MapImpl(g, g.sym_edge_maps, v) {} \
+SymEdgeMap(const SymEdgeMap& copy) \
+  : MapImpl(static_cast<const MapImpl&>(copy)) {} \
+template <typename CMap> SymEdgeMap(const CMap& copy) : MapImpl(copy) {} \
+SymEdgeMap& operator=(const SymEdgeMap& copy) { \
+  MapImpl::operator=(static_cast<const MapImpl&>(copy));\
+  return *this; \
+} \
+template <typename CMap> SymEdgeMap& operator=(const CMap& copy) { \
+  MapImpl::operator=(copy);\
+  return *this; \
+} \
+};
+
+
+#define KEEP_NODE_MAP(GraphBase) \
+    template <typename V> class NodeMap \
+      : public GraphBase::template NodeMap<V> \
+    { \
+      typedef typename GraphBase::template NodeMap<V> MapImpl; \
+      typedef V Value; \
+    public: \
+      NodeMap() : MapImpl() {} \
+\
+      NodeMap(const Graph& graph) \
+	: MapImpl(static_cast<const GraphBase&>(graph)) { } \
+\
+      NodeMap(const Graph& graph, const Value& value) \
+	: MapImpl(static_cast<const GraphBase&>(graph), value) { } \
+\
+      NodeMap(const NodeMap& copy) \
+	: MapImpl(static_cast<const MapImpl&>(copy)) {} \
+\
+      template<typename CMap> \
+      NodeMap(const CMap& copy) \
+	: MapImpl(copy) {} \
+\
+      NodeMap& operator=(const NodeMap& copy) { \
+	MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
+	return *this; \
+      } \
+\
+      template <typename CMap> \
+      NodeMap& operator=(const CMap& copy) { \
+	MapImpl::operator=(copy); \
+	return *this; \
+      } \
+    };
+
+#define KEEP_EDGE_MAP(GraphBase) \
+    template <typename V> class EdgeMap \
+      : public GraphBase::template EdgeMap<V> \
+    { \
+      typedef typename GraphBase::template EdgeMap<V> MapImpl; \
+      typedef V Value; \
+    public: \
+      EdgeMap() : MapImpl() {} \
+\
+      EdgeMap(const Graph& graph) \
+	: MapImpl(static_cast<const GraphBase&>(graph)) { } \
+\
+      EdgeMap(const Graph& graph, const Value& value) \
+	: MapImpl(static_cast<const GraphBase&>(graph), value) { } \
+\
+      EdgeMap(const EdgeMap& copy) \
+	: MapImpl(static_cast<const MapImpl&>(copy)) {} \
+\
+      template<typename CMap> \
+      EdgeMap(const CMap& copy) \
+	: MapImpl(copy) {} \
+\
+      EdgeMap& operator=(const EdgeMap& copy) { \
+	MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
+	return *this; \
+      } \
+\
+      template <typename CMap> \
+      EdgeMap& operator=(const CMap& copy) { \
+	MapImpl::operator=(copy); \
+	return *this; \
+      } \
+    };
+
 #endif

Copied: hugo/trunk/src/hugo/map_registry.h (from r1067, /hugo/trunk/src/work/deba/map_registry.h)
==============================================================================
--- /hugo/trunk/src/work/deba/map_registry.h	(original)
+++ hugo/trunk/src/hugo/map_registry.h	Thu Sep  2 12:07:30 2004
@@ -1,3 +1,4 @@
+// -*- c++ -*-
 #ifndef MAP_REGISTRY_H
 #define MAP_REGISTRY_H
 
@@ -30,11 +31,12 @@
     class MapBase {
     public:
       typedef G Graph;
-      typedef MapRegistry<G, K, KIt> Registry;
       typedef K Key;
       typedef KIt KeyIt;
+
+      typedef MapRegistry<G, K, KIt> Registry;
 	
-      friend class Registry;
+      friend class MapRegistry<G, K, KIt>;
 
       /**
        * Default constructor for MapBase.
@@ -105,7 +107,7 @@
       */
 	
       virtual void init() {
-	for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
+	for (KeyIt it(*graph); it != INVALID; ++it) {
 	  add(it);
 	}
       }
@@ -115,7 +117,7 @@
       */
 	
       virtual void destroy() {
-	for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
+	for (KeyIt it(*getGraph()); it != INVALID; ++it) {
 	  erase(it);
 	}
       }
@@ -132,6 +134,13 @@
       */
 	
       virtual void erase(const Key&) = 0;
+
+      /**
+       *  The clear member function should be overloaded in the subclasses.
+       *  \e Clear makes empty the data structure.
+       */
+
+      virtual void clear() = 0;
 	
       /**
 	 Exception class to throw at unsupported operation.
@@ -172,6 +181,7 @@
      * from the right value. The left value will be an empty registry.
      */
     MapRegistry& operator=(const MapRegistry&) {
+      typename Container::iterator it;
       for (it = container.begin(); it != container.end(); ++it) {
 	(*it)->destroy();
 	(*it)->graph = 0;
@@ -239,6 +249,15 @@
       }
     }
 
+    /**
+     * Notify all the registered maps about the map should be cleared.
+     */ 
+    virtual void clear() {
+      typename Container::iterator it;
+      for (it = container.begin(); it != container.end(); ++it) {
+	(*it)->clear();
+      }
+    }
   };
 
 }

Modified: hugo/trunk/src/hugo/smart_graph.h
==============================================================================
--- hugo/trunk/src/hugo/smart_graph.h	(original)
+++ hugo/trunk/src/hugo/smart_graph.h	Thu Sep  2 12:07:30 2004
@@ -8,15 +8,21 @@
 ///\brief SmartGraph and SymSmartGraph classes.
 
 #include <vector>
-#include <limits.h>
+#include <climits>
 
 #include <hugo/invalid.h>
 
+#include <hugo/array_map_factory.h>
+#include <hugo/sym_map_factory.h>
+#include <hugo/map_registry.h>
+
+#include <hugo/map_defines.h>
+
 namespace hugo {
 
 /// \addtogroup graphs
 /// @{
-  class SymSmartGraph;
+//  class SymSmartGraph;
 
   ///A smart graph class.
 
@@ -53,61 +59,27 @@
 
     std::vector<EdgeT> edges;
     
-    protected:
-    
-    template <typename Key> class DynMapBase
-    {
-    protected:
-      const SmartGraph* G; 
-    public:
-      virtual void add(const Key k) = 0;
-      virtual void erase(const Key k) = 0;
-      DynMapBase(const SmartGraph &_G) : G(&_G) {}
-      virtual ~DynMapBase() {}
-      friend class SmartGraph;
-    };
     
   public:
-    template <typename T> class EdgeMap;
-    template <typename T> class NodeMap;
+
+    typedef SmartGraph Graph;
 
     class Node;
     class Edge;
 
-    //  protected:
-    // HELPME:
-  protected:
-    ///\bug It must be public because of SymEdgeMap.
-    ///
-    mutable std::vector<DynMapBase<Node> * > dyn_node_maps;
-    ///\bug It must be public because of SymEdgeMap.
-    ///
-    mutable std::vector<DynMapBase<Edge> * > dyn_edge_maps;
-    
-  public:
-
-
     class NodeIt;
     class EdgeIt;
     class OutEdgeIt;
     class InEdgeIt;
     
-    template <typename T> class NodeMap;
-    template <typename T> class EdgeMap;
+    CREATE_MAP_REGISTRIES;
+    CREATE_MAPS(ArrayMapFactory);
     
   public:
 
     SmartGraph() : nodes(), edges() { }
     SmartGraph(const SmartGraph &_g) : nodes(_g.nodes), edges(_g.edges) { }
     
-    ~SmartGraph()
-    {
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).G=NULL;
-      for(std::vector<DynMapBase<Edge> * >::iterator i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).G=NULL;
-    }
-
     int nodeNum() const { return nodes.size(); }  //FIXME: What is this?
     int edgeNum() const { return edges.size(); }  //FIXME: What is this?
 
@@ -137,9 +109,8 @@
       Node n; n.n=nodes.size();
       nodes.push_back(NodeT()); //FIXME: Hmmm...
 
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).add(n);
-
+      
+      node_maps.add(n);
       return n;
     }
     
@@ -150,8 +121,7 @@
       edges[e.n].next_in=nodes[v.n].first_in;
       nodes[u.n].first_out=nodes[v.n].first_in=e.n;
 
-      for(std::vector<DynMapBase<Edge> * >::iterator i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).add(e);
+      edge_maps.add(e);
 
       return e;
     }
@@ -172,7 +142,12 @@
       return prev;
     }
     
-    void clear() {nodes.clear();edges.clear();}
+    void clear() {
+      edge_maps.clear();
+      edges.clear();
+      node_maps.clear();
+      nodes.clear();
+    }
 
     class Node {
       friend class SmartGraph;
@@ -290,184 +265,6 @@
 //       operator bool() { return Edge::operator bool(); }      
     };
 
-    template <typename T> class NodeMap : public DynMapBase<Node>
-    {
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Node KeyType;
-
-      NodeMap(const SmartGraph &_G) :
-	DynMapBase<Node>(_G), container(_G.maxNodeId())
-      {
-	G->dyn_node_maps.push_back(this);
-      }
-      NodeMap(const SmartGraph &_G,const T &t) :
-	DynMapBase<Node>(_G), container(_G.maxNodeId(),t)
-      {
-	G->dyn_node_maps.push_back(this);
-      }
-      
-      NodeMap(const NodeMap<T> &m) :
- 	DynMapBase<Node>(*m.G), container(m.container)
-      {
- 	G->dyn_node_maps.push_back(this);
-      }
-
-      template<typename TT> friend class NodeMap;
- 
-      ///\todo It can copy between different types.
-      ///\todo We could use 'copy'
-      template<typename TT> NodeMap(const NodeMap<TT> &m) :
-	DynMapBase<Node>(*m.G), container(m.container.size())
-      {
-	G->dyn_node_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      ~NodeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Node>* >::iterator i;
-	  for(i=G->dyn_node_maps.begin();
-	      i!=G->dyn_node_maps.end() && *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_node_maps.erase(i); //FIXME: Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=G->dyn_node_maps.back();
-	    G->dyn_node_maps.pop_back();
-	  }
-	}
-      }
-
-      void add(const Node k) 
-      {
-	if(k.n>=int(container.size())) container.resize(k.n+1);
-      }
-
-      void erase(const Node) { }
-      
-      void set(Node n, T a) { container[n.n]=a; }
-      //'T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::reference
-      operator[](Node n) { return container[n.n]; }
-      //'const T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::const_reference 
-      operator[](Node n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const NodeMap<T>& operator=(const NodeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const NodeMap<T>& operator=(const NodeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for Dynamic Maps
-      void update(T a) {}  //Useless for Dynamic Maps
-    };
-    
-    template <typename T> class EdgeMap : public DynMapBase<Edge>
-    {
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
-
-      EdgeMap(const SmartGraph &_G) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId())
-      {
-	//FIXME: What if there are empty Id's?
-	//FIXME: Can I use 'this' in a constructor?
-	G->dyn_edge_maps.push_back(this);
-      }
-      EdgeMap(const SmartGraph &_G,const T &t) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId(),t)
-      {
-	G->dyn_edge_maps.push_back(this);
-      } 
-      EdgeMap(const EdgeMap<T> &m) :
- 	DynMapBase<Edge>(*m.G), container(m.container)
-      {
- 	G->dyn_edge_maps.push_back(this);
-      }
-
-      template<typename TT> friend class EdgeMap;
-
-      ///\todo It can copy between different types.
-      template<typename TT> EdgeMap(const EdgeMap<TT> &m)
-	: DynMapBase<Edge>(*m.G), container(m.container.size())
-      {
-	G->dyn_edge_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      ~EdgeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Edge>* >::iterator i;
-	  for(i=G->dyn_edge_maps.begin();
-	      i!=G->dyn_edge_maps.end() && *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=G->dyn_edge_maps.back();
-	    G->dyn_edge_maps.pop_back();
-	  }
-	}
-      }
-      
-      void add(const Edge k) 
-      {
-	if(k.n>=int(container.size())) container.resize(k.n+1);
-      }
-      void erase(const Edge) { }
-      
-      void set(Edge n, T a) { container[n.n]=a; }
-      //T get(Edge n) const { return container[n.n]; }
-      typename std::vector<T>::reference
-      operator[](Edge n) { return container[n.n]; }
-      typename std::vector<T>::const_reference
-      operator[](Edge n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const EdgeMap<T>& operator=(const EdgeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const EdgeMap<T>& operator=(const EdgeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for DynMaps
-      void update(T a) {}  //Useless for DynMaps
-    };
-
   };
 
   ///Graph for bidirectional edges.
@@ -493,8 +290,14 @@
   class SymSmartGraph : public SmartGraph
   {
   public:
-    template<typename T> class SymEdgeMap;
-    template<typename T> friend class SymEdgeMap;
+    typedef SymSmartGraph Graph;
+
+    KEEP_NODE_MAP(SmartGraph);
+    KEEP_EDGE_MAP(SmartGraph);
+
+    CREATE_SYM_EDGE_MAP_REGISTRY;
+    CREATE_SYM_EDGE_MAP_FACTORY(ArrayMapFactory);
+    IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
 
     SymSmartGraph() : SmartGraph() { }
     SymSmartGraph(const SmartGraph &_g) : SmartGraph(_g) { }
@@ -517,107 +320,10 @@
       return f;
     }
     
-    ///Common data storage for the edge pairs.
-
-    ///This map makes it possible to store data shared by the oppositely
-    ///directed pairs of edges.
-    template <typename T> class SymEdgeMap : public DynMapBase<Edge>
-    {
-      std::vector<T> container;
-      
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
-
-      SymEdgeMap(const SymSmartGraph &_G) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId()/2)
-      {
-	static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.push_back(this);
-      }
-      SymEdgeMap(const SymSmartGraph &_G,const T &t) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId()/2,t)
-      {
-	G->dyn_edge_maps.push_back(this);
-      }
-
-      SymEdgeMap(const SymEdgeMap<T> &m) :
- 	DynMapBase<SymEdge>(*m.G), container(m.container)
-      {
- 	G->dyn_node_maps.push_back(this);
-      }
-
-      //      template<typename TT> friend class SymEdgeMap;
-
-      ///\todo It can copy between different types.
-      ///
-
-      template<typename TT> SymEdgeMap(const SymEdgeMap<TT> &m)
-	: DynMapBase<SymEdge>(*m.G), container(m.container.size())
-      {
-	G->dyn_node_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
- 
-      ~SymEdgeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Edge>* >::iterator i;
-	  for(i=static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.begin();
-	      i!=static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.end()
-		&& *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.back();
-	    static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.pop_back();
-	  }
-	}
-      }
-      
-      void add(const Edge k) 
-      {
-	if(!k.idref()%2&&k.idref()/2>=int(container.size()))
-	  container.resize(k.idref()/2+1);
-      }
-      void erase(const Edge k) { }
-      
-      void set(Edge n, T a) { container[n.idref()/2]=a; }
-      //T get(Edge n) const { return container[n.idref()/2]; }
-      typename std::vector<T>::reference
-      operator[](Edge n) { return container[n.idref()/2]; }
-      typename std::vector<T>::const_reference
-      operator[](Edge n) const { return container[n.idref()/2]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const SymEdgeMap<T>& operator=(const SymEdgeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const SymEdgeMap<T>& operator=(const SymEdgeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for DynMaps
-      void update(T a) {}  //Useless for DynMaps
-
-    };
 
   };
   
   /// @}  
-
 } //namespace hugo
 
 

Added: hugo/trunk/src/hugo/sym_map_factory.h
==============================================================================
--- (empty file)
+++ hugo/trunk/src/hugo/sym_map_factory.h	Thu Sep  2 12:07:30 2004
@@ -0,0 +1,107 @@
+// -*- c++ -*-
+#ifndef SYM_MAP_FACTORY_H
+#define SYM_MAP_FACTORY_H
+
+namespace hugo {
+
+  template <typename Graph, typename Edge, typename EdgeIt>
+  class SymEdgeIt : public EdgeIt {
+  public:
+
+    SymEdgeIt() 
+      : EdgeIt() {}
+
+    SymEdgeIt(const Graph& graph) 
+      : EdgeIt(graph) {}
+
+    SymEdgeIt(Invalid invalid) 
+      : EdgeIt(invalid) {}
+
+    SymEdgeIt(const Graph& graph, Edge edge)
+      : EdgeIt(graph, edge) {}
+
+    SymEdgeIt& operator++() {
+      EdgeIt::operator++();
+      while ( n != -1 && (n & 1)) {
+	EdgeIt::operator++();
+      }
+      return *this;
+    }
+  };
+
+  template <typename MapRegistry, template <typename> class MapFactory>
+  class SymMapFactory {
+
+  public:
+		
+    typedef typename MapRegistry::Graph Graph;
+    typedef typename MapRegistry::Key Key;
+    typedef typename MapRegistry::KeyIt KeyIt;
+
+    typedef typename MapRegistry::MapBase MapBase;
+
+    template <typename V>
+    class Map : public MapFactory<MapRegistry>::template Map<V> {
+
+      typedef typename MapFactory<MapRegistry>::template Map<V> MapImpl;
+    public:
+
+      typedef V Value;
+
+      Map() : MapImpl() {}
+
+      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
+
+      Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
+
+      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
+
+      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
+
+      Map& operator=(const Map& copy) {
+	MapImpl::operator=(static_cast<const MapImpl&>(copy));
+	return *this;
+      }
+
+      template <typename CMap> Map& operator=(const CMap& copy) {
+	MapImpl::operator=(copy);
+	return *this;
+      }
+   
+      Value& operator[](const Key& key) {
+	int id = MapBase::getGraph()->id(key);	
+	return MapImpl::operator[](id >> 1);
+      } 
+		
+      const Value& operator[](const Key& key) const {
+	int id = MapBase::getGraph()->id(key);
+	return MapImpl::operator[](id >> 1);
+      }
+	
+      const Value& get(const Key& key) const {
+	int id = MapBase::getGraph()->id(key);
+	return MapImpl::operator[](id >> 1);
+      } 
+		
+      void set(const Key& key, const Value& val) {
+	int id = MapBase::getGraph()->id(key);
+	MapImpl::operator[](id >> 1) = val;
+      }
+		
+      void add(const Key& key) {
+	int id = MapBase::getGraph()->id(key);
+	if (id & 1) return;
+	MapImpl::add(key);
+      }
+		
+      void erase(const Key& key) {
+	int id = MapBase::getGraph()->id(key);
+	if (id & 1) return;
+	MapImpl::add(key);
+      }
+
+
+    };  
+  };
+}
+#endif

Copied: hugo/trunk/src/hugo/vector_map_factory.h (from r1067, /hugo/trunk/src/work/deba/vector_map_factory.h)
==============================================================================
--- /hugo/trunk/src/work/deba/vector_map_factory.h	(original)
+++ hugo/trunk/src/hugo/vector_map_factory.h	Thu Sep  2 12:07:30 2004
@@ -4,7 +4,7 @@
 
 #include <vector>
 
-#include "extended_pair.h"
+#include <hugo/extended_pair.h>
 
 namespace hugo {
 
@@ -55,9 +55,9 @@
       /** Constructor to use default value to initialize the map. 
        */
       Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
-	for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-          int id = getGraph->id(it);
-	  if (id >= container.size) {
+	for (KeyIt it(*getGraph()); it != INVALID; ++it) {
+          int id = getGraph()->id(it);
+	  if (id >= container.size()) {
 	    container.resize(id + 1);
 	  }
 	  set(it, v);
@@ -68,9 +68,9 @@
        */
       template <typename CMap> Map(const CMap& copy) : MapBase(copy) {
 	if (getGraph()) {
-	  for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-	    int id = getGraph->id(it);
-	    if (id >= container.size) {
+	  for (KeyIt it(*getGraph()); it != INVALID; ++it) {
+	    int id = getGraph()->id(it);
+	    if (id >= container.size()) {
 	      container.resize(id + 1);
 	    }
 	    set(it, copy[it]);
@@ -86,9 +86,9 @@
 	} 
 	this->MapBase::operator=(copy);
 	if (getGraph()) {
-	  for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
-	    int id = getGraph->id(it);
-	    if (id >= container.size) {
+	  for (KeyIt it(*getGraph()); it != INVALID; ++it) {
+	    int id = getGraph()->id(it);
+	    if (id >= container.size()) {
 	      container.resize(id + 1);
 	    }
 	    set(it, copy[it]);
@@ -136,10 +136,16 @@
 	}
       }
 		
-      /** Erease 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) {}
 
+      /** Clear the data structure.
+       */
+      void clear() { 
+	container.clear();
+      }
+
       /** Compatible iterator with the stl maps' iterators.
        *  It iterates on pairs of a key and a value.
        */
@@ -186,7 +192,7 @@
 	/** The pre increment operator of the map.
 	 */
 	iterator& operator++() { 
-	  map->getGraph()->next(it); 
+	  ++it; 
 	  return *this; 
 	}
 
@@ -194,7 +200,7 @@
 	 */
 	iterator operator++(int) { 
 	  iterator tmp(it); 
-	  map.getGraph()->next(it); 
+	  ++it; 
 	  return tmp; 
 	}
 
@@ -277,7 +283,7 @@
 	/** The pre increment operator of the map.
 	 */
 	const_iterator& operator++() { 
-	  map->getGraph()->next(it); 
+	  ++it; 
 	  return *this; 
 	}
 
@@ -285,7 +291,7 @@
 	 */
 	const_iterator operator++(int) { 
 	  const_iterator tmp(it); 
-	  map->getGraph()->next(it); 
+	  ++it; 
 	  return tmp; 
 	}
 



More information about the Lemon-commits mailing list