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

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


Author: deba
Date: Fri Jul  9 09:33:12 2004
New Revision: 949

Added:
   hugo/trunk/src/work/deba/bin_heap.h
      - copied unchanged from r948, /hugo/trunk/src/hugo/bin_heap.h
   hugo/trunk/src/work/deba/dijkstra.h
      - copied unchanged from r948, /hugo/trunk/src/hugo/dijkstra.h
   hugo/trunk/src/work/deba/list_graph.h
      - copied, changed from r948, /hugo/trunk/src/hugo/list_graph.h
Removed:
   hugo/trunk/src/work/deba/invalid.h
   hugo/trunk/src/work/deba/test_graph.h
Modified:
   hugo/trunk/src/work/deba/main.cpp
   hugo/trunk/src/work/deba/vector_map_factory.h

Log:


Copied: hugo/trunk/src/work/deba/list_graph.h (from r948, /hugo/trunk/src/hugo/list_graph.h)
==============================================================================
--- /hugo/trunk/src/hugo/list_graph.h	(original)
+++ hugo/trunk/src/work/deba/list_graph.h	Fri Jul  9 09:33:12 2004
@@ -8,17 +8,20 @@
 ///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
 
 #include <vector>
-#include <limits.h>
+#include <climits>
 
-#include <hugo/invalid.h>
+#include "invalid.h"
+
+#include "vector_map_factory.h"
+#include "map_registry.h"
+
+#include "map_defines.h"
 
 namespace hugo {
 
 /// \addtogroup graphs
 /// @{
 
-  class SymListGraph;
-
   ///A list graph class.
 
   ///This is a simple and fast erasable graph implementation.
@@ -58,35 +61,13 @@
     
   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;
     
     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;
-    
+    typedef ListGraph Graph;
+
   public:
 
     class NodeIt;
@@ -94,6 +75,9 @@
     class OutEdgeIt;
     class InEdgeIt;
     
+    CREATE_MAP_REGISTRIES;
+    CREATE_MAPS(VectorMapFactory);
+
   public:
 
     ListGraph() : nodes(), first_node(-1),
@@ -103,13 +87,6 @@
 				     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?
@@ -213,8 +190,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;
     }
@@ -245,8 +221,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;
     }
@@ -271,8 +246,6 @@
 
       //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);
     }
       
   public:
@@ -292,11 +265,13 @@
       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); }
+    void erase(Edge e) { 
+      edge_maps.erase(e);
+      eraseEdge(e.n); 
+    }
 
     ///\bug Dynamic maps must be updated!
     ///
@@ -396,187 +371,6 @@
       InEdgeIt(const ListGraph& G,Node v) :Edge(G.nodes[v.n].first_in) {}
     };
 
-    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.
@@ -601,137 +395,6 @@
   ///\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;
-
-    SymListGraph() : ListGraph() { }
-    SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
-    ///Adds a pair of oppositely directed edges to the graph.
-    Edge addEdge(Node u, Node v)
-    {
-      Edge e = ListGraph::addEdge(u,v);
-      ListGraph::addEdge(v,u);
-      return e;
-    }
-
-    void erase(Node n) { ListGraph::erase(n); }
-    ///The oppositely directed edge.
-
-    ///Returns the oppositely directed
-    ///pair of the edge \c e.
-    Edge opposite(Edge e) const
-    {
-      Edge f;
-      f.idref() = e.idref() - 2*(e.idref()%2) + 1;
-      return f;
-    }
-    
-    ///Removes a pair of oppositely directed edges to the graph.
-    void erase(Edge e) {
-      ListGraph::erase(opposite(e));
-      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
-
-    };
-
   };
   
 

Modified: hugo/trunk/src/work/deba/main.cpp
==============================================================================
--- hugo/trunk/src/work/deba/main.cpp	(original)
+++ hugo/trunk/src/work/deba/main.cpp	Fri Jul  9 09:33:12 2004
@@ -1,6 +1,6 @@
 #include <iostream>
 #include <cstdlib>
-#include "test_graph.h"
+#include "list_graph.h"
 
 using namespace std;
 using namespace hugo;

Modified: hugo/trunk/src/work/deba/vector_map_factory.h
==============================================================================
--- hugo/trunk/src/work/deba/vector_map_factory.h	(original)
+++ hugo/trunk/src/work/deba/vector_map_factory.h	Fri Jul  9 09:33:12 2004
@@ -3,25 +3,25 @@
 
 #include <vector>
 
-#include "map_registry.h"
-
 namespace hugo {
 	
   template <typename MapRegistry>
-  class VectorMapFactory {
-  public:
+    class VectorMapFactory {
+    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 MapBase {
       public:
       typedef V Value;
 	
+      typedef std::vector<Value> Container;
       Map() {}
 			
       Map(Graph& g, MapRegistry& r) : MapBase(g, r) {
@@ -34,21 +34,16 @@
       }
 	
 	
-      Value& operator[](const Key& key) {
+      typename Container::reference operator[](const Key& key) {
 	int id = graph->id(key);
 	return container[id];
       } 
 		
-      const Value& operator[](const Key& key) const {
+      typename Container::const_reference operator[](const Key& key) const {
 	int id = graph->id(key);
 	return container[id];
       }
 	
-      const Value& get(const Key& key) const {
-	int id = graph->id(key);
-	return container[id];
-      } 
-		
       void set(const Key& key, const Value& val) {
 	int id = graph->id(key);
 	container[id] = val;
@@ -63,11 +58,37 @@
 		
       void erase(const Key& key) {}
 	
+      class const_iterator {
+
+      private:
+      
+      };
+
+      class iterator {
+      public:
+	iterator() {}
+      
+	std::pair<const Key&, Value&> operator*() {
+	  return std::pair<const Key&, Value&>(static_cast<Key&>(it), map[it]);
+	}
+
+	iterator& operator++() { ++it; return *this; }
+	iterator operator++(int) { iterator tmp(it); ++it; return tmp; }
+      private:
+	Map& map;
+	KeyIt it;
+      };
+
       private:
       typedef std::vector<Value> Container;
 		
       Container container;
+
+
     };
+
+    
+
 		
   };
 }



More information about the Lemon-commits mailing list