The new order matches that of the comparison functions accepted by the C
standard library qsort() functions. Being consistent with qsort will
hopefully help avoid developer confusion.
The only current user of the red-black tree is aub_mem.c which is pretty
easy to fix up.
Reviewed-by: Lionel Landwerlin <lionel.g.lndwerlin@intel.com>
cmp_uint64(uint64_t a, uint64_t b)
{
if (a < b)
- return -1;
- if (a > b)
return 1;
+ if (a > b)
+ return -1;
return 0;
}
bool left = false;
while (x != NULL) {
y = x;
- left = cmp(node, x) < 0;
+ left = cmp(x, node) < 0;
if (left)
x = x->left;
else
while (x != NULL) {
int c = cmp(x, key);
if (c < 0)
- x = x->right;
- else if (c > 0)
x = x->left;
+ else if (c > 0)
+ x = x->right;
else
return x;
}
y = x;
int c = cmp(x, key);
if (c < 0)
- x = x->right;
- else if (c > 0)
x = x->left;
+ else if (c > 0)
+ x = x->right;
else
return x;
}
rb_test_node_cmp_void(const struct rb_node *n, const void *v)
{
struct rb_test_node *tn = rb_node_data(struct rb_test_node, n, node);
- return tn->key - *(int *)v;
+ return *(int *)v - tn->key;
}
static int
struct rb_test_node *ta = rb_node_data(struct rb_test_node, a, node);
struct rb_test_node *tb = rb_node_data(struct rb_test_node, b, node);
- return ta->key - tb->key;
+ return tb->key - ta->key;
}
static void