Grafalgo
Library of useful data structures and algorithms
|
00001 00008 // Header file for path set data structure used to implement 00009 // dynamic trees. Maintains a set of paths on nodes numbered 00010 // {1,...,n}. 00011 00012 #ifndef PATHSET_H 00013 #define PATHSET_H 00014 00015 #include "stdinc.h" 00016 #include "Adt.h" 00017 #include "Util.h" 00018 00019 namespace grafalgo { 00020 00021 typedef int path; // path 00022 typedef int cost; 00023 00032 class PathSet : public Adt { 00033 public: PathSet(int); 00034 ~PathSet(); 00035 00036 struct PathCostPair { 00037 index x; cost c; 00038 PathCostPair(index xx, cost cc) : x(xx), c(cc) {} 00039 }; 00040 struct PathPair { 00041 path p1, p2; 00042 PathPair(path pp1, path pp2) : p1(pp2), p2(pp2) {} 00043 }; 00044 00045 // common methods 00046 void clear(); 00047 void resize(int); 00048 void expand(int); 00049 void copyFrom(const PathSet&); 00050 00051 path findpath(index); 00052 index findtail(path); 00053 PathCostPair findpathcost(path); 00054 index findtreeroot(index); 00055 cost nodeCost(index) const; 00056 00057 void addpathcost(path,cost); 00058 path join(path,index,path); 00059 PathPair split(index); 00060 00061 string& path2string(path, string&) const; 00062 string& pathTree2string(path, string&) const; 00063 string& toString(string&) const; 00064 protected: 00065 struct PathNode { 00066 index left, right, p; // /<left child, right child, parent 00067 cost dcost, dmin; // /<delta cost and delta min 00068 }; 00069 PathNode *pnode; 00070 00071 index splay(index); 00072 void splaystep(index); 00073 void rotate(index); 00074 00075 void makeSpace(int); 00076 void freeSpace(); 00077 }; 00078 00079 } // ends namespace 00080 00081 #endif