28 #define compLT(a, b) (a < b)
29 #define compEQ(a, b) (a == b)
33 typedef enum {
BLACK,
RED } nodeColor;
37 typedef struct Node_ {
47 #define parent parent_
80 if (
i->left_ &&
i->left !=
NIL) {
83 if (
i->right_ &&
i->right !=
NIL) {
99 for (
i = 0;
i < level; ++
i) {
132 tpool_ =
new TQItemPool(1000);
137 #if COLLECT_TQueue_STATISTICS
182 #if !FAST_LEAST || DOCHECK
186 for (; b->left_ !=
NIL; b = b->left_) {
235 #if COLLECT_TQueue_STATISTICS
236 Printf(
"insertions=%lu moves=%lu fastmoves=%lu removals=%lu calls to least=%lu\n",
245 Printf(
"Turn on COLLECT_TQueue_STATISTICS_ in tqueue.h\n");
249 void RBTQueue::rotateLeft(
Node* x) {
263 y->parent = x->parent;
265 if (x == x->parent->left)
268 x->parent->right = y;
279 void RBTQueue::rotateRight(
Node* x) {
289 y->right->parent = x;
293 y->parent = x->parent;
295 if (x == x->parent->right)
296 x->parent->right = y;
309 void RBTQueue::insertFixup(
Node* x) {
316 while (x !=
root && x->parent->color ==
RED) {
318 if (x->parent == x->parent->parent->left) {
319 Node* y = x->parent->parent->right;
320 if (y->color ==
RED) {
322 x->parent->color =
BLACK;
324 x->parent->parent->color =
RED;
325 x = x->parent->parent;
328 if (x == x->parent->right) {
335 x->parent->color =
BLACK;
336 x->parent->parent->color =
RED;
341 Node* y = x->parent->parent->left;
342 if (y->color ==
RED) {
344 x->parent->color =
BLACK;
346 x->parent->parent->color =
RED;
347 x = x->parent->parent;
350 if (x == x->parent->left) {
354 x->parent->color =
BLACK;
355 x->parent->parent->color =
RED;
370 void RBTQueue::insertNode(
T data,
Node* x) {
399 if ((x = malloc (
sizeof(*x))) == 0) {
400 printf (
"insufficient memory (insertNode)\n");
423 void RBTQueue::deleteFixup(
Node* x) {
430 if (x == x->parent->left) {
431 Node* w = x->parent->right;
432 if (w->color ==
RED) {
434 x->parent->color =
RED;
436 w = x->parent->right;
438 if (w->left->color ==
BLACK && w->right->color ==
BLACK) {
442 if (w->right->color ==
BLACK) {
443 w->left->color =
BLACK;
446 w = x->parent->right;
448 w->color = x->parent->color;
449 x->parent->color =
BLACK;
450 w->right->color =
BLACK;
455 Node* w = x->parent->left;
456 if (w->color ==
RED) {
458 x->parent->color =
RED;
462 if (w->right->color ==
BLACK && w->left->color ==
BLACK) {
466 if (w->left->color ==
BLACK) {
467 w->right->color =
BLACK;
472 w->color = x->parent->color;
473 x->parent->color =
BLACK;
474 w->left->color =
BLACK;
490 void RBTQueue::deleteNode(
Node* z) {
508 if (z->left ==
NIL || z->right ==
NIL) {
514 while (y->left !=
NIL)
525 x->parent = y->parent;
527 if (y == y->parent->left)
530 y->parent->right = x;
536 if (y != z) z->data = y->data;
539 if (y->color ==
BLACK)
548 y->parent_ = z->parent_;
550 y->right_ = z->right_;
551 if (z->left_ !=
NIL) {
552 z->left_->parent_ = y;
554 if (z->right_ !=
NIL) {
555 z->right_->parent_ = y;
557 if (z->parent && z->parent_ !=
NIL) {
558 if (z->parent_->left_ == z) {
559 z->parent_->left_ = y;
561 z->parent_->right_ = y;
void t_iterate(void(*)(const TQItem *, int), int)
void deleteFixup(TQItem *)
void deleteitem(TQItem *)
void check(const char *errmess)
void insertNode(double t, TQItem *)
void rotateLeft(TQItem *)
void move(TQItem *, double tnew)
void rotateRight(TQItem *)
void insertFixup(TQItem *)
void forall_callback(void(*)(const TQItem *, int))
void deleteNode(TQItem *)
void move_least(double tnew)
void hoc_execerror(const char *, const char *)
static double remove(void *v)
static void deleteitem(TQItem *i)
static void prnt(const TQItem *b, int level)
static void chk(TQItem *b, int level)
int find(const int, const int, const int, const int, const int)
static const char * errmess_
static double insert(void *v)