Grafalgo
Library of useful data structures and algorithms
|
00001 00009 #ifndef RLISTSET_H 00010 #define RLISTSET_H 00011 00012 #include "Adt.h" 00013 00014 namespace grafalgo { 00015 00026 class RlistSet : public Adt { 00027 public: RlistSet(int=26); 00028 ~RlistSet(); 00029 00030 // common methods 00031 void clear(); 00032 void resize(int); 00033 void expand(int); 00034 void copyFrom(const RlistSet&); 00035 00036 index first(index) const; 00037 index last(index) const; 00038 index suc(index,index) const; 00039 index pred(index,index) const; 00040 void advance(index&,index&) const; 00041 void retreat(index&,index&) const; 00042 00043 index pop(index); 00044 index join(index,index); 00045 index reverse(index); 00046 00047 string& toString(string&) const; 00048 string& toString(index, string&) const; 00049 private: 00050 struct ListNode { 00051 int p1; // index of predecessor or successor 00052 int p2; // index of the other 00053 }; 00054 ListNode *node; 00055 bool *canon; 00056 00057 00058 void makeSpace(int); 00059 void freeSpace(); 00060 }; 00061 00066 inline index RlistSet::first(index x) const { return node[x].p1; } 00067 00072 inline index RlistSet::last(index x) const { return x; } 00073 00079 inline index RlistSet::suc(index x, index prev) const { 00080 return (prev == node[x].p2 ? node[x].p1 : node[x].p2); 00081 } 00082 00088 inline index RlistSet::pred(index x, index next) const { 00089 return (next == node[x].p2 ? node[x].p1 : node[x].p2); 00090 } 00091 00098 inline void RlistSet::advance(index& x, index& y) const { 00099 index xx = x; x = suc(x,y); y = xx; 00100 } 00101 00108 inline void RlistSet::retreat(index& x, index& y) const { 00109 index xx = x; x = pred(x,y); y = xx; 00110 } 00111 00112 } // ends namespace 00113 00114 #endif