00001 #ifndef _CTBbtree_HXX
00002 #define _CTBbtree_HXX 1
00003
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CTBclone.hxx"
00017
00018 class CTBbtreeNode;
00019
00020 class CTBbtree {
00021
00022 friend class CTBbtreeNode;
00023
00024 public:
00025
00026 CTBbtree();
00027 CTBbtree(const CTBbtree& rhs);
00028
00029 virtual ~CTBbtree();
00030
00031 CTBbtreeNode* RNode() const;
00032 CTBbtreeNode* First() const;
00033 CTBbtreeNode* Last() const;
00034 CTBsize Size() const;
00035
00036 void Clear();
00037
00038 void TreeHeight(int& i_minh,int& i_maxh,float& f_avrp) const;
00039 bool TreeCheck(ostream* p_os = 0) const;
00040
00041 void Dump(int i_indent=0, ostream& os=cout,
00042 const char* p_text=0) const;
00043
00044 CTBbtreeNode* operator[](CTBint i_ind) const;
00045
00046 CTBbtree& operator=(const CTBbtree& rhs);
00047
00048 private:
00049
00050 CTBbtreeNode* mp_rnode;
00051 CTBbtreeNode* mp_first;
00052 CTBbtreeNode* mp_last;
00053 CTBint mi_size;
00054 };
00055
00056 class CTBbtreeNode {
00057
00058 friend class CTBbtree;
00059
00060 public:
00061
00062 CTBbtreeNode();
00063 virtual ~CTBbtreeNode();
00064
00065 virtual CTBbtreeNode* Clone() const;
00066
00067 CTBbtree* Head() const;
00068 CTBbtreeNode* Left() const;
00069 CTBbtreeNode* Right() const;
00070 CTBbtreeNode* Up() const;
00071 CTBbtreeNode* Next() const;
00072 CTBbtreeNode* Prev() const;
00073
00074 CTBbtreeNode* Skip(CTBint i_offset) const;
00075
00076 CTBint Rank() const;
00077
00078 CTBint LWeight() const;
00079
00080 bool IsRNode() const;
00081 bool IsLeftChild() const;
00082 bool IsRightChild() const;
00083
00084 bool IsBalanced() const;
00085 bool IsLeftHeavy() const;
00086 bool IsRightHeavy() const;
00087
00088 void Insert(CTBbtree& head,CTBbtreeNode* p_parent,int i_ctype);
00089
00090 void Remove();
00091
00092 private:
00093
00094 void LWeight(
00095 CTBint i_weight);
00096 void IncLWeight();
00097 void DecLWeight();
00098
00099 void SetRNode();
00100 void SetLeftChild();
00101 void SetRightChild();
00102
00103 void SetBalanced();
00104 void SetLeftHeavy();
00105 void SetRightHeavy();
00106
00107 void RotateLeft();
00108 void RotateRight();
00109 void RotateLeftRight();
00110 void RotateRightLeft();
00111
00112 void InsertFixup();
00113 void RemoveFixup();
00114
00115 void SubTreeHeight(
00116 int& i_minh,
00117 int& i_maxh,
00118 double& d_nnode,
00119 double& d_ncomp) const;
00120 bool SubTreeCheck(
00121 ostream* p_os,
00122 int& i_maxh) const;
00123
00124 CTBbtreeNode(
00125 const CTBbtreeNode& rhs);
00126 CTBbtreeNode& operator=(
00127 const CTBbtreeNode& rhs);
00128
00129 private:
00130
00131 static const CTBuint32 status_lchild = 0x2;
00132 static const CTBuint32 status_rchild = 0x1;
00133 static const CTBuint32 status_childmask = status_lchild | status_rchild;
00134 static const CTBuint32 status_lheavy = 0x8;
00135 static const CTBuint32 status_rheavy = 0x4;
00136 static const CTBuint32 status_heavymask = status_lheavy | status_rheavy;
00137 static const CTBuint32 status_bitmask = status_childmask|status_heavymask;
00138 static const CTBuint32 status_deltaw = 16;
00139
00140 CTBbtree* mp_head;
00141 CTBbtreeNode* mp_up;
00142 CTBbtreeNode* mp_left;
00143 CTBbtreeNode* mp_right;
00144 CTBuint32 mi_status;
00145 };
00146
00147 class CTBclone<CTBbtreeNode> : public CTBcloneable<CTBbtreeNode> {};
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 #if !(defined(CTB__OutLine) || defined(CTBbtree__OutLine))
00164 #include "CTBbtree.icc"
00165 #endif
00166
00167 #endif