Table_iterateur dernier_iterateur_table(
    const Table_iterateur * iterator, Table* table
) {
    Table_iterateur it;
    avl_t_last( &it, table->root );
    return it;
}
示例#2
0
void *stSortedSet_getLast(stSortedSet *items) {
    struct avl_traverser traverser;
    avl_t_init(&traverser, items->sortedSet);
    return avl_t_last(&traverser, items->sortedSet);
}
示例#3
0
文件: avl-test.c 项目: Lichtavat/TCAX
/* 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;
}