diff options
-rw-r--r-- | src/reflist.c | 48 | ||||
-rw-r--r-- | tests/list_check.c | 5 |
2 files changed, 26 insertions, 27 deletions
diff --git a/src/reflist.c b/src/reflist.c index 9dcff1cd..f11e3e97 100644 --- a/src/reflist.c +++ b/src/reflist.c @@ -319,7 +319,6 @@ Reflection *add_refl(RefList *list, INDICES) void delete_refl(Reflection *refl) { int i; - Reflection **parent_pos = NULL; /* Is this a duplicate, and not the first one? */ if ( refl->prev != NULL ) { @@ -334,12 +333,16 @@ void delete_refl(Reflection *refl) refl->next->parent = refl->parent; refl->next->child[0] = refl->child[0]; refl->next->child[1] = refl->child[1]; + assert(refl->next->prev == refl); refl->next->prev = NULL; for ( i=0; i<2; i++ ) { if ( refl->parent->child[i] == refl ) { refl->parent->child[i] = refl->next; } + if ( refl->child[i] != NULL ) { + refl->child[i]->parent = refl->next; + } } free(refl); @@ -348,51 +351,50 @@ void delete_refl(Reflection *refl) } - /* Remove parent's reference */ - for ( i=0; i<2; i++ ) { - if ( refl->parent->child[i] == refl ) { - parent_pos = &refl->parent->child[i]; - *parent_pos = NULL; - } - } - assert(parent_pos != NULL); - /* Two child nodes? */ if ( (refl->child[0] != NULL) && (refl->child[1] != NULL ) ) { - if ( random() > RAND_MAX/2 ) { + //if ( random() > RAND_MAX/2 ) { - Reflection *pre; - pre = refl->child[0]; + Reflection *pre = refl->child[0]; while ( pre->child[1] != NULL ) pre = pre->child[1]; refl->data = pre->data; refl->serial = pre->serial; + if ( refl->next != NULL ) refl->next->prev = refl; delete_refl(pre); - } else { + //} else { - Reflection *pre; - pre = refl->child[1]; - while ( pre->child[0] != NULL ) pre = pre->child[0]; + // Reflection *pre = refl->child[1]; + // while ( pre->child[0] != NULL ) pre = pre->child[0]; - refl->data = pre->data; - refl->serial = pre->serial; - delete_refl(pre); + // refl->data = pre->data; + // refl->serial = pre->serial; + // if ( refl->next != NULL ) refl->next->prev = refl; + // delete_refl(pre); - } + //} } else if ( refl->child[0] != NULL ) { /* One child, left */ - *parent_pos = refl->child[0]; + for ( i=0; i<2; i++ ) { + if ( refl->parent->child[i] == refl ) { + refl->parent->child[i] = refl->child[0]; + } + } refl->child[0]->parent = refl->parent; free(refl); } else if (refl->child[1] != NULL ) { /* One child, right */ - *parent_pos = refl->child[1]; + for ( i=0; i<2; i++ ) { + if ( refl->parent->child[i] == refl ) { + refl->parent->child[i] = refl->child[1]; + } + } refl->child[1]->parent = refl->parent; free(refl); diff --git a/tests/list_check.c b/tests/list_check.c index a50a8d70..5e593d0f 100644 --- a/tests/list_check.c +++ b/tests/list_check.c @@ -86,7 +86,7 @@ static int test_lists(int num_items) check[i].dup = duplicate; check[i].found = 0; - if ( (h==-178) && (k==-45) && (l==55)) { + if ( (h==-45) && (k==55) && (l==73)) { printf("added, now %i %i\n", check[i].dup, i); } @@ -154,9 +154,6 @@ static int test_lists(int num_items) delete_refl(refl); check[i].del = 1; - if ( (h==-119) && (k==20) && (l==-69)) { - printf("deleting, now %i\n", check[j].dup); - } /* Update all counts */ for ( j=0; j<num_items; j++ ) { |