Commit 6a13cea6 authored by Rusty Russell's avatar Rusty Russell

rbtree: vary insert and delete orders in test

This covers more code than simply doing an ordered delete/insert.
parent c520b4ad
...@@ -24,20 +24,27 @@ static bool lookup_all(trbt_tree_t *rb, bool exist) ...@@ -24,20 +24,27 @@ static bool lookup_all(trbt_tree_t *rb, bool exist)
return true; return true;
} }
static bool add_one(trbt_tree_t *rb, bool exist, unsigned int i)
{
int *p = trbt_insert32(rb, i, talloc_memdup(rb, &i, sizeof(i)));
if (p) {
if (!exist)
return false;
if (*p != i)
return false;
} else
if (exist)
return false;
return true;
}
static bool insert_all(trbt_tree_t *rb, bool exist) static bool insert_all(trbt_tree_t *rb, bool exist)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < NUM_ELEMS; i++) { for (i = 0; i < NUM_ELEMS; i++) {
int *p = trbt_insert32(rb, i, talloc_memdup(rb, &i, sizeof(i))); if (!add_one(rb, exist, i))
if (p) { return false;
if (!exist)
return false;
if (*p != i)
return false;
} else
if (exist)
return false;
} }
return true; return true;
} }
...@@ -46,7 +53,12 @@ static void delete_all(trbt_tree_t *rb) ...@@ -46,7 +53,12 @@ static void delete_all(trbt_tree_t *rb)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < NUM_ELEMS; i++) { /* Don't delete them in the obvious order. */
for (i = 0; i < NUM_ELEMS / 2; i++) {
trbt_delete32(rb, i);
}
for (i = NUM_ELEMS-1; i >= NUM_ELEMS / 2; i--) {
trbt_delete32(rb, i); trbt_delete32(rb, i);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment