Grafalgo
Library of useful data structures and algorithms
|
00001 00009 #ifndef DTREES_H 00010 #define DTREES_H 00011 00012 #include "stdinc.h" 00013 #include "Adt.h" 00014 #include "Util.h" 00015 #include "PathSet.h" 00016 00017 namespace grafalgo { 00018 00019 typedef int tree; 00020 typedef PathSet::PathCostPair NodeCostPair; 00021 00028 class Dtrees : public Adt { 00029 public: Dtrees(int=100); 00030 ~Dtrees(); 00031 00032 // common methods 00033 void clear(); 00034 void resize(int); 00035 void expand(int); 00036 void copyFrom(const Dtrees&); 00037 00038 index findroot(index); 00039 NodeCostPair findcost(path); 00040 void addcost(index,cost); 00041 void link(tree,index); 00042 void cut(index); 00043 00044 cost nodeCost(index) const; 00045 index parent(index) const; 00046 00047 string& path2string(path,string&) const; 00048 string& toString(string&) const; 00049 private: 00050 index *parentOf; 00051 index *successor; 00052 PathSet *ps; 00053 00054 struct PathNodePair { 00055 path p; index i; 00056 PathNodePair(path pp, index ii) : p(pp), i(ii) {} 00057 }; 00058 path expose(index); 00059 PathNodePair splice(PathNodePair); 00060 00061 void makeSpace(int); 00062 void freeSpace(); 00063 }; 00064 00069 inline index Dtrees::parent(index i) const { return parentOf[i]; } 00070 00075 inline cost Dtrees::nodeCost(index i) const { return ps->nodeCost(i); } 00076 00077 } // ends namespace 00078 00079 #endif