mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 22:10:10 +01:00
util/rb_tree: Reverse the order of comparison functions
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>
This commit is contained in:
parent
d35d7346d2
commit
dae33052db
3 changed files with 9 additions and 9 deletions
|
|
@ -87,9 +87,9 @@ static inline int
|
||||||
cmp_uint64(uint64_t a, uint64_t b)
|
cmp_uint64(uint64_t a, uint64_t b)
|
||||||
{
|
{
|
||||||
if (a < b)
|
if (a < b)
|
||||||
return -1;
|
|
||||||
if (a > b)
|
|
||||||
return 1;
|
return 1;
|
||||||
|
if (a > b)
|
||||||
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ rb_tree_insert(struct rb_tree *T, struct rb_node *node,
|
||||||
bool left = false;
|
bool left = false;
|
||||||
while (x != NULL) {
|
while (x != NULL) {
|
||||||
y = x;
|
y = x;
|
||||||
left = cmp(node, x) < 0;
|
left = cmp(x, node) < 0;
|
||||||
if (left)
|
if (left)
|
||||||
x = x->left;
|
x = x->left;
|
||||||
else
|
else
|
||||||
|
|
@ -167,9 +167,9 @@ rb_tree_search(struct rb_tree *T, const void *key,
|
||||||
while (x != NULL) {
|
while (x != NULL) {
|
||||||
int c = cmp(x, key);
|
int c = cmp(x, key);
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
x = x->right;
|
|
||||||
else if (c > 0)
|
|
||||||
x = x->left;
|
x = x->left;
|
||||||
|
else if (c > 0)
|
||||||
|
x = x->right;
|
||||||
else
|
else
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
@ -205,9 +205,9 @@ rb_tree_search_sloppy(struct rb_tree *T, const void *key,
|
||||||
y = x;
|
y = x;
|
||||||
int c = cmp(x, key);
|
int c = cmp(x, key);
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
x = x->right;
|
|
||||||
else if (c > 0)
|
|
||||||
x = x->left;
|
x = x->left;
|
||||||
|
else if (c > 0)
|
||||||
|
x = x->right;
|
||||||
else
|
else
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ static int
|
||||||
rb_test_node_cmp_void(const struct rb_node *n, const void *v)
|
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);
|
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
|
static int
|
||||||
|
|
@ -65,7 +65,7 @@ rb_test_node_cmp(const struct rb_node *a, const struct rb_node *b)
|
||||||
struct rb_test_node *ta = rb_node_data(struct rb_test_node, a, node);
|
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);
|
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
|
static void
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue