GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
avl.h
Go to the documentation of this file.
1/* Produced by texiweb from libavl.w. */
2
3/* libavl - library for manipulation of binary trees.
4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software
5 Foundation, Inc.
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA.
21 */
22
23#ifndef AVL_H
24#define AVL_H 1
25
26#include <stddef.h>
27
28/* Function types. */
29typedef int avl_comparison_func(const void *avl_a, const void *avl_b,
30 void *avl_param);
31typedef void avl_item_func(void *avl_item, void *avl_param);
32typedef void *avl_copy_func(void *avl_item, void *avl_param);
33
34#ifndef LIBAVL_ALLOCATOR
35#define LIBAVL_ALLOCATOR
36/* Memory allocator. */
38 void *(*libavl_malloc)(struct libavl_allocator *, size_t libavl_size);
40};
41#endif
42
43/* Default memory allocator. */
45void *avl_malloc(struct libavl_allocator *, size_t);
46void avl_free(struct libavl_allocator *, void *);
47
48/* Maximum AVL tree height. */
49#ifndef AVL_MAX_HEIGHT
50#define AVL_MAX_HEIGHT 92
51#endif
52
53/* Tree data structure. */
54struct avl_table {
55 struct avl_node *avl_root; /* Tree's root. */
56 avl_comparison_func *avl_compare; /* Comparison function. */
57 void *avl_param; /* Extra argument to |avl_compare|. */
58 struct libavl_allocator *avl_alloc; /* Memory allocator. */
59 size_t avl_count; /* Number of items in tree. */
60 unsigned long avl_generation; /* Generation number. */
61};
62
63/* An AVL tree node. */
64struct avl_node {
65 struct avl_node *avl_link[2]; /* Subtrees. */
66 void *avl_data; /* Pointer to data. */
67 signed char avl_balance; /* Balance factor. */
68};
69
70/* AVL traverser structure. */
72 struct avl_table *avl_table; /* Tree being traversed. */
73 struct avl_node *avl_node; /* Current node in tree. */
75 /* All the nodes above |avl_node|. */
76 size_t avl_height; /* Number of nodes in |avl_parent|. */
77 unsigned long avl_generation; /* Generation number. */
78};
79
80/* Table functions. */
82 struct libavl_allocator *);
83struct avl_table *avl_copy(const struct avl_table *, avl_copy_func *,
85void avl_destroy(struct avl_table *, avl_item_func *);
86void **avl_probe(struct avl_table *, void *);
87void *avl_insert(struct avl_table *, void *);
88void *avl_replace(struct avl_table *, void *);
89void *avl_delete(struct avl_table *, const void *);
90void *avl_find(const struct avl_table *, const void *);
91void avl_assert_insert(struct avl_table *, void *);
92void *avl_assert_delete(struct avl_table *, void *);
93
94#define avl_count(table) ((size_t)(table)->avl_count)
95
96/* Table traverser functions. */
97void avl_t_init(struct avl_traverser *, struct avl_table *);
98void *avl_t_first(struct avl_traverser *, struct avl_table *);
99void *avl_t_last(struct avl_traverser *, struct avl_table *);
100void *avl_t_find(struct avl_traverser *, struct avl_table *, void *);
101void *avl_t_insert(struct avl_traverser *, struct avl_table *, void *);
102void *avl_t_copy(struct avl_traverser *, const struct avl_traverser *);
103void *avl_t_next(struct avl_traverser *);
104void *avl_t_prev(struct avl_traverser *);
105void *avl_t_cur(struct avl_traverser *);
106void *avl_t_replace(struct avl_traverser *, void *);
107
108#endif /* avl.h */
void * avl_copy_func(void *avl_item, void *avl_param)
Definition avl.h:32
void * avl_malloc(struct libavl_allocator *, size_t)
Definition avl.c:812
#define AVL_MAX_HEIGHT
Definition avl.h:50
struct libavl_allocator avl_allocator_default
Definition avl.c:827
void avl_item_func(void *avl_item, void *avl_param)
Definition avl.h:31
void avl_free(struct libavl_allocator *, void *)
Definition avl.c:820
int avl_comparison_func(const void *avl_a, const void *avl_b, void *avl_param)
Definition avl.h:29
Definition avl.h:64
void * avl_data
Definition avl.h:66
struct avl_node * avl_link[2]
Definition avl.h:65
signed char avl_balance
Definition avl.h:67
avl_comparison_func * avl_compare
Definition avl.h:56
void * avl_param
Definition avl.h:57
size_t avl_count
Definition avl.h:59
struct libavl_allocator * avl_alloc
Definition avl.h:58
unsigned long avl_generation
Definition avl.h:60
struct avl_node * avl_root
Definition avl.h:55
unsigned long avl_generation
Definition avl.h:77
struct avl_table * avl_table
Definition avl.h:72
struct avl_node * avl_stack[92]
Definition avl.h:74
struct avl_node * avl_node
Definition avl.h:73
size_t avl_height
Definition avl.h:76
void(* libavl_free)(struct libavl_allocator *, void *libavl_block)
Definition avl.h:39
#define avl_find
Definition tree.h:38
#define avl_probe
Definition tree.h:34
#define avl_copy
Definition tree.h:32
#define avl_t_replace
Definition tree.h:50
#define avl_create
Definition tree.h:31
#define avl_t_cur
Definition tree.h:49
#define avl_t_insert
Definition tree.h:45
#define avl_t_next
Definition tree.h:47
#define avl_t_prev
Definition tree.h:48
#define avl_t_find
Definition tree.h:44
#define avl_assert_insert
Definition tree.h:39
#define avl_replace
Definition tree.h:36
#define avl_assert_delete
Definition tree.h:40
#define avl_insert
Definition tree.h:35
#define avl_t_first
Definition tree.h:42
#define avl_t_last
Definition tree.h:43
#define avl_destroy
Definition tree.h:33
#define avl_t_copy
Definition tree.h:46
#define avl_t_init
Definition tree.h:41
#define avl_delete
Definition tree.h:37