gl_anytree_list1.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Sequential list data type implemented by a binary tree.
  2. Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc.
  3. Written by Bruno Haible <bruno@clisp.org>, 2006.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. /* Common code of gl_avltree_list.c, gl_rbtree_list.c,
  15. gl_avltreehash_list.c, gl_rbtreehash_list.c. */
  16. /* An item on the stack used for iterating across the elements. */
  17. typedef struct
  18. {
  19. gl_list_node_t node;
  20. size_t rightp;
  21. } iterstack_item_t;
  22. /* A stack used for iterating across the elements. */
  23. typedef iterstack_item_t iterstack_t[MAXHEIGHT];
  24. /* Frees a non-empty subtree recursively.
  25. This function is recursive and therefore not very fast. */
  26. static void
  27. free_subtree (gl_list_node_t node)
  28. {
  29. if (node->left != NULL)
  30. free_subtree (node->left);
  31. if (node->right != NULL)
  32. free_subtree (node->right);
  33. free (node);
  34. }