aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-02-08 19:24:13 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:13 +0100
commitde518c82717f8d07a6721e01200deb2437335a5d (patch)
treee2aa6fefc373ac82c66303a0389e787fc103815d
parente980ed54dc29e025587aba47390727c500aec8f1 (diff)
Make iteration work
-rw-r--r--src/reflist.c12
-rw-r--r--tests/list_check.c3
2 files changed, 8 insertions, 7 deletions
diff --git a/src/reflist.c b/src/reflist.c
index 4b08b3af..20021ed3 100644
--- a/src/reflist.c
+++ b/src/reflist.c
@@ -432,7 +432,7 @@ Reflection *first_refl(RefList *list, RefListIterator **piter)
return NULL;
}
- refl = iter->stack[iter->stack_ptr--];
+ refl = iter->stack[--iter->stack_ptr];
return refl;
@@ -442,11 +442,15 @@ Reflection *first_refl(RefList *list, RefListIterator **piter)
Reflection *next_refl(Reflection *refl, RefListIterator *iter)
{
+ int returned = 1;
+
do {
- refl = refl->child[1];;
+ if ( returned ) refl = refl->child[1];
+ returned = 0;
if ( refl != NULL ) {
+
iter->stack[iter->stack_ptr++] = refl;
if ( iter->stack_ptr == iter->stack_size ) {
iter->stack_size += 32;
@@ -455,15 +459,15 @@ Reflection *next_refl(Reflection *refl, RefListIterator *iter)
}
refl = refl->child[0];
continue;
+
}
if ( iter->stack_ptr == 0 ) {
free(iter->stack);
free(iter);
return NULL;
}
- refl = iter->stack[iter->stack_ptr--];
- return refl;
+ return iter->stack[--iter->stack_ptr];
} while ( 1 );
}
diff --git a/tests/list_check.c b/tests/list_check.c
index ffae8d12..22ef01e1 100644
--- a/tests/list_check.c
+++ b/tests/list_check.c
@@ -45,8 +45,6 @@ static int test_lists(int num_items)
check = malloc(num_items * sizeof(struct refltemp));
list = reflist_new();
- printf("Testing with %i\n", num_items);
-
h = RANDOM_INDEX;
k = RANDOM_INDEX;
l = RANDOM_INDEX;
@@ -98,7 +96,6 @@ static int test_lists(int num_items)
signed int h, k, l;
get_indices(refl, &h, &k, &l);
- printf("%3i %3i %3i\n", h, k, l);
for ( i=0; i<num_items; i++ ) {
if ( (check[i].h == h)