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,11 +24,8 @@ static bool lookup_all(trbt_tree_t *rb, bool exist) ...@@ -24,11 +24,8 @@ static bool lookup_all(trbt_tree_t *rb, bool exist)
return true; return true;
} }
static bool insert_all(trbt_tree_t *rb, bool exist) static bool add_one(trbt_tree_t *rb, bool exist, unsigned int i)
{ {
unsigned int i;
for (i = 0; i < NUM_ELEMS; i++) {
int *p = trbt_insert32(rb, i, talloc_memdup(rb, &i, sizeof(i))); int *p = trbt_insert32(rb, i, talloc_memdup(rb, &i, sizeof(i)));
if (p) { if (p) {
if (!exist) if (!exist)
...@@ -38,6 +35,16 @@ static bool insert_all(trbt_tree_t *rb, bool exist) ...@@ -38,6 +35,16 @@ static bool insert_all(trbt_tree_t *rb, bool exist)
} else } else
if (exist) if (exist)
return false; return false;
return true;
}
static bool insert_all(trbt_tree_t *rb, bool exist)
{
unsigned int i;
for (i = 0; i < NUM_ELEMS; i++) {
if (!add_one(rb, exist, i))
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