aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-02-08 23:40:09 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:13 +0100
commit09f4f09239da980928dc3fc52494b44382bcbca4 (patch)
treeff11a210b50777538dedefd058868c30ea28788d /src
parent06ce382d160021fbc8083d0bd48b2735504a39d5 (diff)
More unsuccessful work on lists
Diffstat (limited to 'src')
-rw-r--r--src/reflist.c48
1 files changed, 25 insertions, 23 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);