pavl.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Produced by texiweb from libavl.w. */
  2. /* libavl - library for manipulation of binary trees.
  3. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software
  4. Foundation, Inc.
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA.
  17. */
  18. #ifndef PAVL_H
  19. #define PAVL_H 1
  20. #include <stddef.h>
  21. /* Function types. */
  22. typedef int pavl_comparison_func(const void *pavl_a, const void *pavl_b);
  23. typedef void pavl_item_func(void *pavl_item);
  24. typedef void *pavl_copy_func(void *pavl_item);
  25. #ifndef LIBAVL_ALLOCATOR
  26. #define LIBAVL_ALLOCATOR
  27. /* Memory allocator. */
  28. struct libavl_allocator
  29. {
  30. void *(*libavl_malloc) (size_t libavl_size);
  31. void (*libavl_free) (void *libavl_block);
  32. };
  33. #endif
  34. /* Default memory allocator. */
  35. extern struct libavl_allocator pavl_allocator_default;
  36. void *pavl_malloc(size_t);
  37. void pavl_free(void *);
  38. /* Maximum PAVL height, unused. */
  39. #ifndef PAVL_MAX_HEIGHT
  40. #define PAVL_MAX_HEIGHT 32
  41. #endif
  42. /* Tree data structure. */
  43. struct pavl_table
  44. {
  45. struct pavl_node *pavl_root; /* Tree's root. */
  46. pavl_comparison_func *pavl_compare; /* Comparison function. */
  47. struct libavl_allocator *pavl_alloc; /* Memory allocator. */
  48. size_t pavl_count; /* Number of items in tree. */
  49. };
  50. /* An PAVL tree node. */
  51. struct pavl_node
  52. {
  53. struct pavl_node *pavl_link[2]; /* Subtrees. */
  54. struct pavl_node *pavl_parent; /* Parent node. */
  55. void *pavl_data; /* Pointer to data. */
  56. signed char pavl_balance; /* Balance factor. */
  57. };
  58. /* PAVL traverser structure. */
  59. struct pavl_traverser
  60. {
  61. struct pavl_table *pavl_table; /* Tree being traversed. */
  62. struct pavl_node *pavl_node; /* Current node in tree. */
  63. };
  64. /* Table functions. */
  65. struct pavl_table *pavl_create(pavl_comparison_func *,
  66. struct libavl_allocator *);
  67. struct pavl_table *pavl_copy(const struct pavl_table *, pavl_copy_func *,
  68. pavl_item_func *, struct libavl_allocator *);
  69. void pavl_destroy(struct pavl_table *, pavl_item_func *);
  70. void **pavl_probe(struct pavl_table *, void *);
  71. void *pavl_insert(struct pavl_table *, void *);
  72. void *pavl_replace(struct pavl_table *, void *);
  73. void *pavl_delete(struct pavl_table *, const void *);
  74. void *pavl_find(const struct pavl_table *, const void *);
  75. void pavl_assert_insert(struct pavl_table *, void *);
  76. void *pavl_assert_delete(struct pavl_table *, void *);
  77. #define pavl_count(table) ((size_t) (table)->pavl_count)
  78. /* Table traverser functions. */
  79. void pavl_t_init(struct pavl_traverser *, struct pavl_table *);
  80. void *pavl_t_first(struct pavl_traverser *, struct pavl_table *);
  81. void *pavl_t_last(struct pavl_traverser *, struct pavl_table *);
  82. void *pavl_t_find(struct pavl_traverser *, struct pavl_table *, void *);
  83. void *pavl_t_insert(struct pavl_traverser *, struct pavl_table *, void *);
  84. void *pavl_t_copy(struct pavl_traverser *, const struct pavl_traverser *);
  85. void *pavl_t_next(struct pavl_traverser *);
  86. void *pavl_t_prev(struct pavl_traverser *);
  87. void *pavl_t_cur(struct pavl_traverser *);
  88. void *pavl_t_replace(struct pavl_traverser *, void *);
  89. #endif /* pavl.h */