Public Member Functions | Public Attributes | List of all members
QMapPrivateBase Class Reference

#include <qmap.h>

Inheritance diagram for QMapPrivateBase:
QShared QMapPrivate< Key, T >

Public Member Functions

 QMapPrivateBase ()
 
 QMapPrivateBase (const QMapPrivateBase *_map)
 
void rotateLeft (QMapNodeBase *x, QMapNodeBase *&root)
 
void rotateRight (QMapNodeBase *x, QMapNodeBase *&root)
 
void rebalance (QMapNodeBase *x, QMapNodeBase *&root)
 
QMapNodeBaseremoveAndRebalance (QMapNodeBase *z, QMapNodeBase *&root, QMapNodeBase *&leftmost, QMapNodeBase *&rightmost)
 
- Public Member Functions inherited from QShared
 QShared ()
 
void ref ()
 
bool deref ()
 

Public Attributes

int node_count
 
- Public Attributes inherited from QShared
uint count
 

Detailed Description

Definition at line 283 of file qmap.h.

Constructor & Destructor Documentation

QMapPrivateBase::QMapPrivateBase ( )
inline

Definition at line 286 of file qmap.h.

286  {
287  node_count = 0;
288  }
int node_count
Definition: qmap.h:306
QMapPrivateBase::QMapPrivateBase ( const QMapPrivateBase _map)
inline

Definition at line 289 of file qmap.h.

289  {
290  node_count = _map->node_count;
291  }
int node_count
Definition: qmap.h:306

Member Function Documentation

void QMapPrivateBase::rebalance ( QMapNodeBase x,
QMapNodeBase *&  root 
)

Definition at line 80 of file qmap.cpp.

81 {
82  x->color = Node::Red;
83  while ( x != root && x->parent->color == Node::Red ) {
84  if ( x->parent == x->parent->parent->left ) {
85  NodePtr y = x->parent->parent->right;
86  if (y && y->color == Node::Red) {
87  x->parent->color = Node::Black;
88  y->color = Node::Black;
90  x = x->parent->parent;
91  } else {
92  if (x == x->parent->right) {
93  x = x->parent;
94  rotateLeft( x, root );
95  }
96  x->parent->color = Node::Black;
98  rotateRight (x->parent->parent, root );
99  }
100  } else {
101  NodePtr y = x->parent->parent->left;
102  if ( y && y->color == Node::Red ) {
103  x->parent->color = Node::Black;
104  y->color = Node::Black;
105  x->parent->parent->color = Node::Red;
106  x = x->parent->parent;
107  } else {
108  if (x == x->parent->left) {
109  x = x->parent;
110  rotateRight( x, root );
111  }
112  x->parent->color = Node::Black;
113  x->parent->parent->color = Node::Red;
114  rotateLeft( x->parent->parent, root );
115  }
116  }
117  }
118  root->color = Node::Black;
119 }
QMapNodeBase * left
Definition: qmap.h:51
void rotateLeft(QMapNodeBase *x, QMapNodeBase *&root)
Definition: qmap.cpp:44
QMapNodeBase * parent
Definition: qmap.h:53
void rotateRight(QMapNodeBase *x, QMapNodeBase *&root)
Definition: qmap.cpp:62
QMapNodeBase * right
Definition: qmap.h:52
Color color
Definition: qmap.h:55
NodePtr QMapPrivateBase::removeAndRebalance ( QMapNodeBase z,
QMapNodeBase *&  root,
QMapNodeBase *&  leftmost,
QMapNodeBase *&  rightmost 
)

Definition at line 122 of file qmap.cpp.

125 {
126  NodePtr y = z;
127  NodePtr x;
128  NodePtr x_parent;
129  if (y->left == 0) {
130  x = y->right;
131  } else {
132  if (y->right == 0)
133  x = y->left;
134  else
135  {
136  y = y->right;
137  while (y->left != 0)
138  y = y->left;
139  x = y->right;
140  }
141  }
142  if (y != z) {
143  z->left->parent = y;
144  y->left = z->left;
145  if (y != z->right) {
146  x_parent = y->parent;
147  if (x)
148  x->parent = y->parent;
149  y->parent->left = x;
150  y->right = z->right;
151  z->right->parent = y;
152  } else {
153  x_parent = y;
154  }
155  if (root == z)
156  root = y;
157  else if (z->parent->left == z)
158  z->parent->left = y;
159  else
160  z->parent->right = y;
161  y->parent = z->parent;
162  // Swap the colors
163  Node::Color c = y->color;
164  y->color = z->color;
165  z->color = c;
166  y = z;
167  } else {
168  x_parent = y->parent;
169  if (x)
170  x->parent = y->parent;
171  if (root == z)
172  root = x;
173  else if (z->parent->left == z)
174  z->parent->left = x;
175  else
176  z->parent->right = x;
177  if ( leftmost == z ) {
178  if (z->right == 0)
179  leftmost = z->parent;
180  else
181  leftmost = x->minimum();
182  }
183  if (rightmost == z) {
184  if (z->left == 0)
185  rightmost = z->parent;
186  else
187  rightmost = x->maximum();
188  }
189  }
190  if (y->color != Node::Red) {
191  while (x != root && (x == 0 || x->color == Node::Black)) {
192  if (x == x_parent->left) {
193  NodePtr w = x_parent->right;
194  if (w->color == Node::Red) {
195  w->color = Node::Black;
196  x_parent->color = Node::Red;
197  rotateLeft(x_parent, root);
198  w = x_parent->right;
199  }
200  if ((w->left == 0 || w->left->color == Node::Black) &&
201  (w->right == 0 || w->right->color == Node::Black)) {
202  w->color = Node::Red;
203  x = x_parent;
204  x_parent = x_parent->parent;
205  } else {
206  if (w->right == 0 || w->right->color == Node::Black) {
207  if (w->left)
208  w->left->color = Node::Black;
209  w->color = Node::Red;
210  rotateRight(w, root);
211  w = x_parent->right;
212  }
213  w->color = x_parent->color;
214  x_parent->color = Node::Black;
215  if (w->right)
216  w->right->color = Node::Black;
217  rotateLeft(x_parent, root);
218  break;
219  }
220  } else {
221  NodePtr w = x_parent->left;
222  if (w->color == Node::Red) {
223  w->color = Node::Black;
224  x_parent->color = Node::Red;
225  rotateRight(x_parent, root);
226  w = x_parent->left;
227  }
228  if ((w->right == 0 || w->right->color == Node::Black) &&
229  (w->left == 0 || w->left->color == Node::Black)) {
230  w->color = Node::Red;
231  x = x_parent;
232  x_parent = x_parent->parent;
233  } else {
234  if (w->left == 0 || w->left->color == Node::Black) {
235  if (w->right)
236  w->right->color = Node::Black;
237  w->color = Node::Red;
238  rotateLeft(w, root);
239  w = x_parent->left;
240  }
241  w->color = x_parent->color;
242  x_parent->color = Node::Black;
243  if (w->left)
244  w->left->color = Node::Black;
245  rotateRight(x_parent, root);
246  break;
247  }
248  }
249  }
250  if (x)
251  x->color = Node::Black;
252  }
253  return y;
254 }
QMapNodeBase * left
Definition: qmap.h:51
void rotateLeft(QMapNodeBase *x, QMapNodeBase *&root)
Definition: qmap.cpp:44
QMapNodeBase * parent
Definition: qmap.h:53
QMapNodeBase * maximum()
Definition: qmap.h:64
void rotateRight(QMapNodeBase *x, QMapNodeBase *&root)
Definition: qmap.cpp:62
list x
Definition: train.py:276
QMapNodeBase * right
Definition: qmap.h:52
QMapNodeBase * minimum()
Definition: qmap.h:57
Color color
Definition: qmap.h:55
void QMapPrivateBase::rotateLeft ( QMapNodeBase x,
QMapNodeBase *&  root 
)

Implementations of basic tree algorithms

Definition at line 44 of file qmap.cpp.

45 {
46  NodePtr y = x->right;
47  x->right = y->left;
48  if (y->left !=0)
49  y->left->parent = x;
50  y->parent = x->parent;
51  if (x == root)
52  root = y;
53  else if (x == x->parent->left)
54  x->parent->left = y;
55  else
56  x->parent->right = y;
57  y->left = x;
58  x->parent = y;
59 }
QMapNodeBase * left
Definition: qmap.h:51
QMapNodeBase * parent
Definition: qmap.h:53
list x
Definition: train.py:276
QMapNodeBase * right
Definition: qmap.h:52
void QMapPrivateBase::rotateRight ( QMapNodeBase x,
QMapNodeBase *&  root 
)

Definition at line 62 of file qmap.cpp.

63 {
64  NodePtr y = x->left;
65  x->left = y->right;
66  if (y->right != 0)
67  y->right->parent = x;
68  y->parent = x->parent;
69  if (x == root)
70  root = y;
71  else if (x == x->parent->right)
72  x->parent->right = y;
73  else
74  x->parent->left = y;
75  y->right = x;
76  x->parent = y;
77 }
QMapNodeBase * left
Definition: qmap.h:51
QMapNodeBase * parent
Definition: qmap.h:53
list x
Definition: train.py:276
QMapNodeBase * right
Definition: qmap.h:52

Member Data Documentation

int QMapPrivateBase::node_count

Variables

Definition at line 306 of file qmap.h.


The documentation for this class was generated from the following files: