Archived
1
0
Fork 0

common/rbtree.c: some cleanup

This commit is contained in:
Henrik Hautakoski 2010-10-02 18:50:58 +02:00
parent 99066503f3
commit f44ada20b3

View file

@ -37,12 +37,12 @@ static rbnode* node_alloc(uint key, void *ptr, size_t len) {
*/ */
static void node_dealloc(rbnode *n, void (*action)(rbnode *)) { static void node_dealloc(rbnode *n, void (*action)(rbnode *)) {
if (n == NULL) if (!n)
return; return;
if (action != NULL) { if (action) {
action(n); action(n);
} else if (n->data != NULL) { } else if (n->data) {
xfree(n->data); xfree(n->data);
n->data = NULL; n->data = NULL;
} }
@ -83,7 +83,7 @@ static rbnode* rbcmp(rbnode *n, void *cmpdata, size_t len) {
rbnode *r; rbnode *r;
if (n == NULL) if (!n)
return NULL; return NULL;
dprint("CMP %s - %s\n", (char*)n->data, (char*)cmpdata); dprint("CMP %s - %s\n", (char*)n->data, (char*)cmpdata);
@ -134,7 +134,7 @@ rbnode* rbtree_search(rbtree *tree, uint key) {
n = tree->root; n = tree->root;
while(n != NULL) { while(n) {
dprint("SEARCH: check %u\n", n->key); dprint("SEARCH: check %u\n", n->key);
@ -235,7 +235,7 @@ int rbtree_insert(rbtree *tree, uint key, void *data, size_t len) {
last = dir; last = dir;
dir = q->key < key; dir = q->key < key;
if (g != NULL) if (g)
t = g; t = g;
g = p, p = q; g = p, p = q;
q = q->child[dir]; q = q->child[dir];
@ -278,7 +278,7 @@ void* rbtree_delete(rbtree *tree, uint key) {
/* more dragons (killed some of them though) */ /* more dragons (killed some of them though) */
while(q->child[dir] != NULL) { while(q->child[dir]) {
last = dir; last = dir;
g = p, p = q; g = p, p = q;
@ -318,7 +318,7 @@ void* rbtree_delete(rbtree *tree, uint key) {
} }
tree->root = head.child[1]; tree->root = head.child[1];
if (tree->root != NULL) if (tree->root)
tree->root->color = RB_BLACK; tree->root->color = RB_BLACK;
/* remove if found */ /* remove if found */