#define NIL &sentinel /* all leafs are sentinels */
static rbnode_t sentinel = { NIL, NIL, NULL, BLACK, NULL};
+#define NOT_AT_ROOT(_node) ((_node) != NULL)
+
struct rbtree_t {
#ifndef NDEBUG
uint32_t magic;
/* establish y->parent link */
if (y != NIL) y->parent = x->parent;
- if (x->parent) {
+ if (NOT_AT_ROOT(x->parent)) {
if (x == x->parent->left) {
x->parent->left = y;
} else {
/* establish y->parent link */
if (y != NIL) y->parent = x->parent;
- if (x->parent) {
+ if (NOT_AT_ROOT(x->parent)) {
if (x == x->parent->right) {
x->parent->right = y;
} else {
x->colour = RED;
/* insert node in tree */
- if (parent) {
+ if (NOT_AT_ROOT(parent)) {
if (tree->compare(data, parent->data) <= 0) {
parent->left = x;
} else {
parent = y->parent;
if (x != NIL) x->parent = parent;
- if (parent) {
+ if (NOT_AT_ROOT(parent)) {
if (y == parent->left) {
parent->left = x;
} else {
z->data = y->data;
y->data = NULL;
- if ((y->colour == BLACK) && parent) {
+ if ((y->colour == BLACK) && NOT_AT_ROOT(parent)) {
delete_fixup(tree, x, parent);
}
*/
memcpy(y, z, sizeof(*y));
- if (y->parent) {
+ if (NOT_AT_ROOT(y->parent)) {
if (y->parent->left == z) y->parent->left = y;
if (y->parent->right == z) y->parent->right = y;
} else {
x = x->right;
goto descend;
}
- while (x->parent) {
+ while (NOT_AT_ROOT(x->parent)) {
if (x->parent->left == x) {
x = x->parent;
goto visit;