Code Fragment: Dijkstra1



template <typename Graph>
class Dijkstra {
protected: 						// local types
  typedef typename Graph::Vertex	    Vertex;
  // ... (other graph types omitted)
  typedef PriorityQueue::Locator	    Locator;
  // ... (insert LocatorX here)
  enum { INFINITE = INT_MAX };				// infinite weight
protected: 						// member data
  const Graph&	    graph;				// the graph
  PriorityQueue	    Q;					// the priority queue
public:
  Dijkstra(const Graph& g) : graph(g) { }		// constructor
  int getDist(const Vertex& u) const 			// final distance to u
    { return u.get("dist")->intValue(); }
protected: 						// local utilities
  int weight(const Edge& e) const 			// get edge weight
    { return e.get("weight")->intValue(); }
  void setDist(const Vertex& v, int d)			// set vertex distance
    { v.set("dist", new Integer(d)); }
  void setLoc(const Vertex& v, const Locator& loc)	// set v's locator
    { v.set("loc", new LocatorX(loc)); }
  bool hasLoc(const Vertex& v) const 			// does v have locator?
    { return v.has("loc"); }
  Locator getLoc(const Vertex& v) const 		// get v's locator
    { return dynamic_cast<LocatorX*>(v.get("loc"))->getValue(); }
  void destroyLoc(const Vertex& v) {			// remove locator attrib
    LocatorX* p = dynamic_cast<LocatorX*>(v.get("loc"));
    delete p;						// delete locator object
    v.destroy("loc");					// delete attribute
  }
  Vertex getVertex(const Locator& loc) const 		// get locator vertex
    { return loc.element(); }
  int getDist(const Locator& loc) const			// get vertex distance
    { return loc.key(); }
// ... (insert run() here)
};