Index: src/work/alpar/smart_graph.h
===================================================================
--- src/work/alpar/smart_graph.h	(revision 136)
+++ src/work/alpar/smart_graph.h	(revision 157)
@@ -4,19 +4,20 @@
 #define SMART_GRAPH_H
 
-#include <iostream>
 #include <vector>
 #include <limits.h>
 
+struct _Invalid {} Invalid;
+
 namespace hugo {
 
   class SmartGraph {
 
-    static const int INVALID_EDGE=-1;
-    static const int INVALID_NODE=INT_MAX;
+//     static const int INVALID=-1;
+//     static const int INVALID_NODE=INT_MAX;
 
     struct NodeT 
     {
       int first_in,first_out;      
-      NodeT() : first_in(INVALID_EDGE), first_out(INVALID_EDGE) {}
+      NodeT() : first_in(-1), first_out(-1) {}
     };
     struct EdgeT 
@@ -24,5 +25,5 @@
       int head, tail, next_in, next_out;      
       //FIXME: is this necessary?
-      EdgeT() : next_in(INVALID_EDGE), next_out(INVALID_EDGE) {}  
+      EdgeT() : next_in(-1), next_out(-1) {}  
     };
 
@@ -38,9 +39,8 @@
       virtual void add(const Key k) = NULL;
       virtual void erase(const Key k) = NULL;
-      DynMapBase(SmartGraph &_G) : G(&_G) {}
+      DynMapBase(const SmartGraph &_G) : G(&_G) {}
       virtual ~DynMapBase() {}
       friend class SmartGraph;
     };
-
   public:
     template <typename T> class DynEdgeMap;
@@ -51,6 +51,6 @@
 
   protected:
-    std::vector<DynMapBase<NodeIt> * > dyn_node_maps;
-    std::vector<DynMapBase<EdgeIt> * > dyn_edge_maps;
+    mutable std::vector<DynMapBase<NodeIt> * > dyn_node_maps;
+    mutable std::vector<DynMapBase<EdgeIt> * > dyn_edge_maps;
     
   public:
@@ -61,5 +61,5 @@
     class InEdgeIt;
     
-    //      class NodeIt { int n; };
+    //     class NodeIt { int n; };
     //     class EachNodeIt : public NodeIt { };
     //     class EdgeIt { int n; };
@@ -67,5 +67,5 @@
     //     class OutEdgeIt : public EdgeIt {};
     //     class InEdgeIt : public EdgeIt {};
-    //    class SymEdgeIt;
+    //     class SymEdgeIt;
     
     template <typename T> class NodeMap;
@@ -97,11 +97,11 @@
     NodeIt head(EdgeIt e) const { return edges[e.n].head; }
 
-    NodeIt aNode(const OutEdgeIt& e) const { return tail(e); }
-    NodeIt aNode(const InEdgeIt& e) const { return head(e); }
-    //NodeIt aNode(const SymEdgeIt& e) const { return e.aNode(); }
-
-    NodeIt bNode(const OutEdgeIt& e) const { return head(e); }
-    NodeIt bNode(const InEdgeIt& e) const { return tail(e); }
-    //NodeIt bNode(const SymEdgeIt& e) const { return e.bNode(); }
+//     NodeIt aNode(const OutEdgeIt& e) const { return tail(e); }
+//     NodeIt aNode(const InEdgeIt& e) const { return head(e); }
+//     //NodeIt aNode(const SymEdgeIt& e) const { return e.aNode(); }
+
+//     NodeIt bNode(const OutEdgeIt& e) const { return head(e); }
+//     NodeIt bNode(const InEdgeIt& e) const { return tail(e); }
+//     //NodeIt bNode(const SymEdgeIt& e) const { return e.bNode(); }
 
     EachNodeIt& getFirst(EachNodeIt& v) const { 
@@ -128,21 +128,21 @@
     }
 
-    bool valid(EdgeIt e) const { return e.n!=INVALID_EDGE; }
-    bool valid(EachEdgeIt e) const { return e.n<int(edges.size()); }
-    bool valid(NodeIt n) const { return n.n<int(nodes.size()); }
-    
-    void setInvalid(EdgeIt &e) { e.n=INVALID_EDGE; }
-    void setInvalid(NodeIt &n) { n.n=INVALID_NODE; }
-    
-    template <typename It> It next(It it) const
-      //    { It tmp(it); return goNext(tmp); }
-    { It tmp; tmp.n=it.n+1; return tmp; }
-
-    NodeIt& goNext(NodeIt& it) const { ++it.n; return it; }
-    OutEdgeIt& goNext(OutEdgeIt& it) const
+    bool valid(EdgeIt e) const { return e.n!=-1; }
+    //    bool valid(EachEdgeIt e) const { return e.n<int(edges.size()); }
+    bool valid(NodeIt n) const { return n.n!=-1; }
+    
+    void setInvalid(EdgeIt &e) { e.n=-1; }
+    void setInvalid(NodeIt &n) { n.n=-1; }
+    
+    template <typename It> It getNext(It it) const
+    { It tmp(it); return next(tmp); }
+    //{ It tmp; tmp.n=it.n+1; return tmp; }
+
+    NodeIt& next(NodeIt& it) const { it.n=(it.n+2)%nodes.size()-1; return it; }
+    OutEdgeIt& next(OutEdgeIt& it) const
     { it.n=edges[it.n].next_out; return it; }
-    InEdgeIt& goNext(InEdgeIt& it) const
+    InEdgeIt& next(InEdgeIt& it) const
     { it.n=edges[it.n].next_in; return it; }
-    EachEdgeIt& goNext(EachEdgeIt& it) const { ++it.n; return it; }
+    EachEdgeIt& next(EachEdgeIt& it) const { --it.n; return it; }
 
     int id(NodeIt v) const { return v.n; }
@@ -167,5 +167,5 @@
 
       for(std::vector<DynMapBase<EdgeIt> * >::iterator i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).add(e.n);
+	  i!=dyn_edge_maps.end(); ++i) (**i).add(e);
 
       return e;
@@ -187,9 +187,11 @@
       int n;
       friend int SmartGraph::id(NodeIt v) const; 
+      NodeIt(int nn) {n=nn;}
     public:
       NodeIt() {}
-      NodeIt(int nn) {n=nn;}
+      NodeIt (_Invalid i) { n=-1; }
       bool operator==(const NodeIt i) const {return n==i.n;}
       bool operator!=(const NodeIt i) const {return n!=i.n;}
+      bool operator<(const NodeIt i) const {return n<i.n;}
     };
     
@@ -197,5 +199,5 @@
       friend class SmartGraph;
     public:
-      EachNodeIt(const SmartGraph& G) : NodeIt(0) { }
+      EachNodeIt(const SmartGraph& G) : NodeIt(G.nodes.size()?0:-1) { }
       EachNodeIt() : NodeIt() { }
     };
@@ -211,9 +213,12 @@
       int n;
       friend int SmartGraph::id(EdgeIt e) const;
+
+      EdgeIt(int nn) {n=nn;}
     public:
       EdgeIt() { }
-      EdgeIt(int nn) {n=nn;}
+      EdgeIt (_Invalid i) { n=-1; }
       bool operator==(const EdgeIt i) const {return n==i.n;}
       bool operator!=(const EdgeIt i) const {return n!=i.n;}
+      bool operator<(const EdgeIt i) const {return n<i.n;}
     };
     
@@ -221,5 +226,6 @@
       friend class SmartGraph;
     public:
-      EachEdgeIt(const SmartGraph& G) : EdgeIt(0) { }
+      EachEdgeIt(const SmartGraph& G) : EdgeIt(G.edges.size()-1) { }
+      EachEdgeIt (_Invalid i) : EdgeIt(i) { }
       EachEdgeIt() : EdgeIt() { }
     };
@@ -229,4 +235,6 @@
     public: 
       OutEdgeIt() : EdgeIt() { }
+      OutEdgeIt (_Invalid i) : EdgeIt(i) { }
+
       OutEdgeIt(const SmartGraph& G,const NodeIt v)
 	: EdgeIt(G.nodes[v.n].first_out) {}
@@ -237,4 +245,5 @@
     public: 
       InEdgeIt() : EdgeIt() { }
+      InEdgeIt (_Invalid i) : EdgeIt(i) { }
       InEdgeIt(const SmartGraph& G,NodeIt v) :EdgeIt(G.nodes[v.n].first_in){}
     };
@@ -286,5 +295,5 @@
       typedef NodeIt KeyType;
 
-      DynNodeMap(SmartGraph &_G) :
+      DynNodeMap(const SmartGraph &_G) :
 	DynMapBase<NodeIt>(_G), container(_G.maxNodeId())
       {
@@ -312,8 +321,12 @@
 	if(k.n>=container.size()) container.resize(k.n+1);
       }
-      void erase(const NodeIt k)
-      {
-	//FIXME: Please implement me.
-      }
+//       void erase(const NodeIt k)
+//       {
+// 	//FIXME: Please implement me.
+//       }
+//       void erase(const EdgeIt k)
+//       {
+// 	//FIXME: Please implement me.
+//       }
       
       void set(NodeIt n, T a) { container[n.n]=a; }
@@ -334,5 +347,5 @@
       typedef EdgeIt KeyType;
 
-      DynEdgeMap(SmartGraph &_G) :
+      DynEdgeMap(const SmartGraph &_G) :
 	DynMapBase<EdgeIt>(_G), container(_G.maxEdgeId())
       {
@@ -377,3 +390,6 @@
 } //namespace hugo
 
+
+
+
 #endif //SMART_GRAPH_H
