/* Checks that the current item at |trav| is |i| and that its previous and next items are as they should be. |label| is a name for the traverser used in reporting messages. There should be |n| items in the tree numbered |0|@dots{}|n - 1|. Returns nonzero only if there is an error. */ static int check_traverser (struct avl_traverser *trav, int i, int n, const char *label) { int okay = 1; int *cur, *prev, *next; prev = avl_t_prev (trav); if ((i == 0 && prev != NULL) || (i > 0 && (prev == NULL || *prev != i - 1))) { printf (" %s traverser ahead of %d, but should be ahead of %d.\n", label, prev != NULL ? *prev : -1, i == 0 ? -1 : i - 1); okay = 0; } avl_t_next (trav); cur = avl_t_cur (trav); if (cur == NULL || *cur != i) { printf (" %s traverser at %d, but should be at %d.\n", label, cur != NULL ? *cur : -1, i); okay = 0; } next = avl_t_next (trav); if ((i == n - 1 && next != NULL) || (i != n - 1 && (next == NULL || *next != i + 1))) { printf (" %s traverser behind %d, but should be behind %d.\n", label, next != NULL ? *next : -1, i == n - 1 ? -1 : i + 1); okay = 0; } avl_t_prev (trav); return okay; }
intptr_t get_valeur( Table_iterateur it ) { Table_association * asso = ( Table_association * ) avl_t_cur( &it ); return asso->valeur; }
/* Checks that |tree| is well-formed and verifies that the values in |array[]| are actually in |tree|. There must be |n| elements in |array[]| and |tree|. Returns nonzero only if no errors detected. */ static int verify_tree (struct avl_table *tree, int array[], size_t n) { int okay = 1; /* Check |tree|'s bst_count against that supplied. */ if (avl_count (tree) != n) { printf (" Tree count is %lu, but should be %lu.\n", (unsigned long) avl_count (tree), (unsigned long) n); okay = 0; } if (okay) { /* Recursively verify tree structure. */ size_t count; int height; recurse_verify_tree (tree->avl_root, &okay, &count, 0, INT_MAX, &height); if (count != n) { printf (" Tree has %lu nodes, but should have %lu.\n", (unsigned long) count, (unsigned long) n); okay = 0; } } if (okay) { /* Check that all the values in |array[]| are in |tree|. */ size_t i; for (i = 0; i < n; i++) if (avl_find (tree, &array[i]) == NULL) { printf (" Tree does not contain expected value %d.\n", array[i]); okay = 0; } } if (okay) { /* Check that |avl_t_first()| and |avl_t_next()| work properly. */ struct avl_traverser trav; size_t i; int prev = -1; int *item; for (i = 0, item = avl_t_first (&trav, tree); i < 2 * n && item != NULL; i++, item = avl_t_next (&trav)) { if (*item <= prev) { printf (" Tree out of order: %d follows %d in traversal\n", *item, prev); okay = 0; } prev = *item; } if (i != n) { printf (" Tree should have %lu items, but has %lu in traversal\n", (unsigned long) n, (unsigned long) i); okay = 0; } } if (okay) { /* Check that |avl_t_last()| and |avl_t_prev()| work properly. */ struct avl_traverser trav; size_t i; int next = INT_MAX; int *item; for (i = 0, item = avl_t_last (&trav, tree); i < 2 * n && item != NULL; i++, item = avl_t_prev (&trav)) { if (*item >= next) { printf (" Tree out of order: %d precedes %d in traversal\n", *item, next); okay = 0; } next = *item; } if (i != n) { printf (" Tree should have %lu items, but has %lu in reverse\n", (unsigned long) n, (unsigned long) i); okay = 0; } } if (okay) { /* Check that |avl_t_init()| works properly. */ struct avl_traverser init, first, last; int *cur, *prev, *next; avl_t_init (&init, tree); avl_t_first (&first, tree); avl_t_last (&last, tree); cur = avl_t_cur (&init); if (cur != NULL) { printf (" Inited traverser should be null, but is actually %d.\n", *cur); okay = 0; } next = avl_t_next (&init); if (next != avl_t_cur (&first)) { printf (" Next after null should be %d, but is actually %d.\n", *(int *) avl_t_cur (&first), *next); okay = 0; } avl_t_prev (&init); prev = avl_t_prev (&init); if (prev != avl_t_cur (&last)) { printf (" Previous before null should be %d, but is actually %d.\n", *(int *) avl_t_cur (&last), *prev); okay = 0; } avl_t_next (&init); } return okay; }
const intptr_t get_cle( Table_iterateur it ) { const Table_association * asso = ( const Table_association * ) avl_t_cur( &it ); return (const intptr_t) asso->cle; }