Index: src/work/jacint/dijkstra.h
===================================================================
--- src/work/jacint/dijkstra.h	(revision 171)
+++ src/work/jacint/dijkstra.h	(revision 211)
@@ -1,118 +1,119 @@
 // -*- C++ -*-
-
-//ha predecessor az elejen nem invalid, akkor hagyd csak ugy
-//scanned mutatja hogy jo ertek van-e benne vagy szemet
-
 /* 
- *template <Graph, T, Heap=FibHeap>
+ *template <Graph, T, Heap=FibHeap, LengthMap=Graph::EdgeMap<T> >
  *
  *Constructor: 
  *
- *Dijkstra(Graph G, NodeIt s, Graph::EdgeMap<T> length)
+ *Dijkstra(Graph G, LengthMap length)
  *
  *
- *Member functions:
+ *Methods:
  *
- *void run()
+ *void run(Node s)
  *
- *  The following function should be used after run() was already run.
+ *T dist(Node v) : After run(s) was run, it returns the distance from s to v. 
+ *   Returns T() if v is not reachable from s.
  *
- *T dist(NodeIt v) : returns the distance from s to v. 
- *   It is 0 if v is not reachable from s.
+ *Edge pred(Node v) : After run(s) was run, it returns the last 
+ *   edge of a shortest s-v path. It is INVALID for s and for 
+ *   the nodes not reachable from s.
  *
- *EdgeIt pred(NodeIt v) : returns the last edge 
- *   of a shortest s-v path. Returns an invalid iterator 
- *   if v=s or v is not reachable from s.
- *
- *bool reach(NodeIt v) : true iff v is reachable from s
+ *bool reached(Node v) : After run(s) was run, it is true iff v is 
+ *   reachable from s
  *
  */
 
-#ifndef DIJKSTRA_H
-#define DIJKSTRA_H
+#ifndef HUGO_DIJKSTRA_H
+#define HUGO_DIJKSTRA_H
 
 #include <fib_heap.h>
+#include <invalid.h>
 
 namespace hugo {
-
+  
   template <typename Graph, typename T, 
-    typename Heap=FibHeap<typename Graph::NodeIt, T, 
-    typename Graph::NodeMap<int> > >
-    class Dijkstra{
-      typedef typename Graph::NodeIt NodeIt;
-      typedef typename Graph::EdgeIt EdgeIt;
-      typedef typename Graph::OutEdgeIt OutEdgeIt;
-      
-      Graph& G;
-      NodeIt s;
-      typename Graph::NodeMap<EdgeIt> predecessor;
-      typename Graph::NodeMap<T> distance;
-      typename Graph::EdgeMap<T>& length;
-      typename Graph::NodeMap<bool> reached;
-          
+    typename Heap=FibHeap<typename Graph::Node, T, 
+    typename Graph::NodeMap<int> >, 
+    typename LengthMap=typename Graph::EdgeMap<T> >
+  class Dijkstra{
+    typedef typename Graph::Node Node;
+    typedef typename Graph::NodeIt NodeIt;
+    typedef typename Graph::Edge Edge;
+    typedef typename Graph::OutEdgeIt OutEdgeIt;
+    
+    const Graph& G;
+    const LengthMap& length;
+    typename Graph::NodeMap<Edge> predecessor;
+    typename Graph::NodeMap<T> distance;
+    typename Graph::NodeMap<bool> reach;
+    
   public :
-
+    
     /*
       The distance of the nodes is 0.
     */
-    Dijkstra(Graph& _G, NodeIt const _s, 
-	     typename Graph::EdgeMap<T>& _length) : 
-      G(_G), s(_s), predecessor(G), distance(G), 
-      length(_length), reached(G, false) { }
+    Dijkstra(Graph& _G, LengthMap& _length) : G(_G), 
+      length(_length), predecessor(_G), distance(_G), reach(_G) { }
     
+
+    void run(Node s) {
       
-      void run() {
+      NodeIt u;
+      for ( G.first(u) ; G.valid(u) ; G.next(u) ) {
+	predecessor.set(u,INVALID);
+	distance.set(u,0);
+	reach.set(u,false);
+      }
+     
+      typename Graph::NodeMap<bool> scanned(G,false);
+      typename Graph::NodeMap<int> heap_map(G,-1);
+      
+      Heap heap(heap_map);
+
+      heap.push(s,0); 
+      reach.set(s, true);
+
+      while ( !heap.empty() ) {
 	
-	typename Graph::NodeMap<bool> scanned(G, false);
-	typename Graph::NodeMap<int> heap_map(G,-1);
+	Node v=heap.top(); 
+	T oldvalue=heap.get(v);
+	heap.pop();
+	distance.set(v, oldvalue);
+	scanned.set(v,true);
 
-	Heap heap(heap_map);
-
-	heap.push(s,0); 
-	reached.set(s, true);
-
-	while ( !heap.empty() ) {
-
-	  NodeIt v=heap.top(); 
-	  T oldvalue=heap.get(v);
-	  heap.pop();
-	  distance.set(v, oldvalue);
-	  scanned.set(v,true);
-
-	  OutEdgeIt e;
-	  for( G.getFirst(e,v); G.valid(e); G.next(e)) {
-	    NodeIt w=G.bNode(e); 
+	OutEdgeIt e;
+	for( G.first(e,v); G.valid(e); G.next(e)) {
+	  Node w=G.head(e); 
 	    
-	    if ( !scanned.get(w) ) {
-	      if ( !reached.get(w) ) {
-		reached.set(w,true);
-		heap.push(w,oldvalue+length.get(e)); 
-		predecessor.set(w,e);
-	      } else if ( oldvalue+length.get(e) < heap.get(w) ) {
-		predecessor.set(w,e);
-		heap.decrease(w, oldvalue+length.get(e)); 
-	      }
+	  if ( !scanned[w] ) {
+	    if ( !reach[w] ) {
+	      reach.set(w,true);
+	      heap.push(w,oldvalue+length[e]); 
+	      predecessor.set(w,e);
+	    } else if ( oldvalue+length[e] < heap.get(w) ) {
+	      predecessor.set(w,e);
+	      heap.decrease(w, oldvalue+length[e]); 
 	    }
 	  }
 	}
-      } 
-      
+      }
+    } 
+    
 
-      T dist(NodeIt v) {
-	return distance.get(v);
-      }
+    T dist(Node v) {
+      return distance[v];
+    }
 
 
-      EdgeIt pred(NodeIt v) {
-	if ( v!=s ) return predecessor.get(v);
-	else return EdgeIt();
-      }
+    Edge pred(Node v) {
+      return predecessor[v];
+    }
      
 
-      bool reach(NodeIt v) {
-	return reached.get(v);
-      }
-      
-    };
+    bool reached(Node v) {
+      return reach[v];
+    }
+    
+  };
   
 }
