00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef cxx_ip_graph_trav_INCLUDED
00043 #define cxx_ip_graph_trav_INCLUDED
00044
00045 #ifndef CXX_MEMORY_INCLUDED
00046 #include "cxx_memory.h"
00047 #endif
00048
00049
00050 extern INT IPA_CG_Max_Depth;
00051
00052
00053
00054 class VVECTOR
00055 {
00056 private:
00057 UINT size;
00058 UINT count;
00059 NODE_INDEX *a;
00060 MEM_POOL *mm;
00061
00062 public:
00063 VVECTOR(UINT sz) {
00064 size = sz;
00065 mm = Malloc_Mem_Pool;
00066 a = CXX_NEW_ARRAY(NODE_INDEX, sz+1, Malloc_Mem_Pool);
00067 count = 0;
00068 };
00069
00070 ~VVECTOR (void) { CXX_DELETE (a, Malloc_Mem_Pool); };
00071
00072 void Append(NODE_INDEX vtx) {
00073 FmtAssert(count <= size,
00074 ("Too many vertices, size = %d, count = %d \n", size,count));
00075 a[count++] = vtx;
00076 };
00077
00078 void Append(NODE_INDEX vtx, INT pos)
00079 {
00080 FmtAssert(count <= size,
00081 ("Too many vertices, size = %d, count = %d \n",
00082 size,count));
00083
00084 FmtAssert(pos <= size, ("Illegal position %d for append vertex \n", pos));
00085 a[pos] = vtx;
00086 count++;
00087 }
00088
00089 UINT Cnt() {
00090 return count;
00091 };
00092
00093 NODE_INDEX& operator[](UINT i) {
00094 FmtAssert(i < size, ("vertex out of range "));
00095 return a[i];
00096 };
00097
00098 };
00099
00100
00101
00102
00103
00104 class EVECTOR
00105 {
00106 private:
00107 UINT size;
00108 UINT count;
00109 void **a;
00110
00111 public:
00112 EVECTOR(UINT sz) {
00113 size = sz;
00114 a = CXX_NEW_ARRAY(void*, sz+1, Malloc_Mem_Pool);
00115 count = 0;
00116 };
00117
00118 void Append(void* e) {
00119 FmtAssert(count <= size,
00120 ("Too many edges, size = %d, count = %d \n", size,count));
00121 a[count++] = e;
00122 };
00123
00124 UINT Cnt() {
00125 return count;
00126 };
00127
00128 void* & operator[](UINT i) {
00129 FmtAssert(i < size, ("edge %d out of range %d \n ", i, size));
00130 return a[i];
00131 };
00132
00133 ~EVECTOR() {
00134 CXX_DELETE_ARRAY(a, Malloc_Mem_Pool);
00135 };
00136 };
00137
00138
00139
00140
00141
00142
00143 typedef enum traveral_order
00144 {
00145 POSTORDER = 0,
00146 PREORDER = 1,
00147
00148 LEVELORDER = 2,
00149 DONTCARE = 3,
00150 ORDER_LAST = 4
00151
00152 } TRAVERSAL_ORDER;
00153
00154
00155
00156
00157 class ORDERED_NODE_ITER {
00158
00159 private:
00160 GRAPH *g;
00161 INT cur_v;
00162 VVECTOR *v;
00163 TRAVERSAL_ORDER order;
00164 MEM_POOL *m;
00165
00166 void Walk (NODE_INDEX r, mUINT8 *visit);
00167 void BuildVector(TRAVERSAL_ORDER);
00168 void MarkRecursive (mUINT8 visit[], NODE_INDEX r);
00169 void Build_Level_Order();
00170
00171 public:
00172
00173 ORDERED_NODE_ITER (GRAPH *gr, TRAVERSAL_ORDER o, MEM_POOL *mm) {
00174 g = gr;
00175 order = o;
00176 m = mm;
00177 cur_v = 0;
00178 BuildVector(order);
00179 };
00180
00181 ~ORDERED_NODE_ITER (void) {
00182 if (v != 0)
00183 CXX_DELETE (v, Malloc_Mem_Pool);
00184 }
00185
00186 void operator ++() { ++cur_v; }
00187 NODE_INDEX Current() const { return (*v)[cur_v]; }
00188 BOOL Is_Empty() const { return (cur_v >= v->Cnt()); }
00189 void Reset() { cur_v = 0; }
00190 void Print(FILE*);
00191 void Compute_Node_Level(NODE_INDEX);
00192
00193 };
00194
00195 #endif // cxx_ip_graph_trav_INCLUDED