diff options
-rw-r--r-- | libcrystfel/src/reflist.c | 26 | ||||
-rw-r--r-- | tests/list_check.c | 11 |
2 files changed, 29 insertions, 8 deletions
diff --git a/libcrystfel/src/reflist.c b/libcrystfel/src/reflist.c index b3b9f85b..a450d8fa 100644 --- a/libcrystfel/src/reflist.c +++ b/libcrystfel/src/reflist.c @@ -992,12 +992,20 @@ Reflection *first_refl(RefList *list, RefListIterator **piter) **/ Reflection *next_refl(Reflection *refl, RefListIterator *iter) { - int returned = 1; + /* Are there more reflections with the same indices? */ + if ( refl->next != NULL ) { + return refl->next; + } else { - do { + /* No, so rewind back to the head of the list */ + while ( refl->prev != NULL ) { + refl = refl->prev; + } + + } - if ( returned ) refl = refl->child[1]; - returned = 0; + refl = refl->child[1]; + do { if ( refl != NULL ) { @@ -1041,13 +1049,21 @@ static int recursive_depth(Reflection *refl) static int recursive_count(Reflection *refl) { int count_left, count_right; + Reflection *probe; + int n_this = 1; if ( refl == NULL ) return 0; + probe = refl; + while ( probe->next != NULL ) { + probe = probe->next; + n_this++; + } + count_left = recursive_count(refl->child[0]); count_right = recursive_count(refl->child[1]); - return 1 + count_left + count_right; + return n_this + count_left + count_right; } diff --git a/tests/list_check.c b/tests/list_check.c index b1b8814d..9656dd1a 100644 --- a/tests/list_check.c +++ b/tests/list_check.c @@ -3,7 +3,11 @@ * * Unit test for the reflection list module * - * Copyright © 2012 Thomas White <taw@physics.org> + * Copyright © 2012-2013 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. + * + * Authors: + * 2011-2013 Thomas White <taw@physics.org> * * This file is part of CrystFEL. * @@ -99,8 +103,8 @@ static int test_lists(int num_items) } - printf("num_reflections is %i, tree depth is %i\n", - num_reflections(list), tree_depth(list)); + printf("Created %i items, num_reflections is %i, tree depth is %i\n", + num_items, num_reflections(list), tree_depth(list)); /* Iterate over the list and check we find everything */ int count = 0; @@ -118,6 +122,7 @@ static int test_lists(int num_items) && (check[i].l == l) && (check[i].found == 0) ) { check[i].found = 1; + break; } } |