GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-bb27c0570b
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. */
29 typedef int avl_comparison_func(const void *avl_a, const void *avl_b,
30  void *avl_param);
31 typedef void avl_item_func(void *avl_item, void *avl_param);
32 typedef 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);
39  void (*libavl_free)(struct libavl_allocator *, void *libavl_block);
40 };
41 #endif
42 
43 /* Default memory allocator. */
45 void *avl_malloc(struct libavl_allocator *, size_t);
46 void 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. */
54 struct 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. */
64 struct 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. */
71 struct avl_traverser {
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. */
81 struct avl_table *avl_create(avl_comparison_func *, void *,
82  struct libavl_allocator *);
83 struct avl_table *avl_copy(const struct avl_table *, avl_copy_func *,
84  avl_item_func *, struct libavl_allocator *);
85 void avl_destroy(struct avl_table *, avl_item_func *);
86 void **avl_probe(struct avl_table *, void *);
87 void *avl_insert(struct avl_table *, void *);
88 void *avl_replace(struct avl_table *, void *);
89 void *avl_delete(struct avl_table *, const void *);
90 void *avl_find(const struct avl_table *, const void *);
91 void avl_assert_insert(struct avl_table *, void *);
92 void *avl_assert_delete(struct avl_table *, void *);
93 
94 #define avl_count(table) ((size_t)(table)->avl_count)
95 
96 /* Table traverser functions. */
97 void avl_t_init(struct avl_traverser *, struct avl_table *);
98 void *avl_t_first(struct avl_traverser *, struct avl_table *);
99 void *avl_t_last(struct avl_traverser *, struct avl_table *);
100 void *avl_t_find(struct avl_traverser *, struct avl_table *, void *);
101 void *avl_t_insert(struct avl_traverser *, struct avl_table *, void *);
102 void *avl_t_copy(struct avl_traverser *, const struct avl_traverser *);
103 void *avl_t_next(struct avl_traverser *);
104 void *avl_t_prev(struct avl_traverser *);
105 void *avl_t_cur(struct avl_traverser *);
106 void *avl_t_replace(struct avl_traverser *, void *);
107 
108 #endif /* avl.h */
struct avl_table * avl_create(avl_comparison_func *, void *, struct libavl_allocator *)
Definition: avl.c:38
void * avl_t_find(struct avl_traverser *, struct avl_table *, void *)
Definition: avl.c:484
void * avl_delete(struct avl_table *, const void *)
Definition: avl.c:230
void * avl_find(const struct avl_table *, const void *)
Definition: avl.c:64
void * avl_t_next(struct avl_traverser *)
Definition: avl.c:567
void * avl_t_replace(struct avl_traverser *, void *)
Definition: avl.c:665
void avl_destroy(struct avl_table *, avl_item_func *)
Definition: avl.c:785
void * avl_replace(struct avl_table *, void *)
Definition: avl.c:213
void avl_assert_insert(struct avl_table *, void *)
Definition: avl.c:833
struct avl_table * avl_copy(const struct avl_table *, avl_copy_func *, avl_item_func *, struct libavl_allocator *)
Definition: avl.c:698
void * avl_copy_func(void *avl_item, void *avl_param)
Definition: avl.h:32
#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_malloc(struct libavl_allocator *, size_t)
Definition: avl.c:812
void * avl_t_copy(struct avl_traverser *, const struct avl_traverser *)
Definition: avl.c:546
void * avl_t_insert(struct avl_traverser *, struct avl_table *, void *)
Definition: avl.c:520
void * avl_assert_delete(struct avl_table *, void *)
Definition: avl.c:842
void ** avl_probe(struct avl_table *, void *)
Definition: avl.c:87
void avl_t_init(struct avl_traverser *, struct avl_table *)
Definition: avl.c:421
void avl_free(struct libavl_allocator *, void *)
Definition: avl.c:820
void * avl_t_cur(struct avl_traverser *)
Definition: avl.c:655
void * avl_t_first(struct avl_traverser *, struct avl_table *)
Definition: avl.c:432
void * avl_insert(struct avl_table *, void *)
Definition: avl.c:202
int avl_comparison_func(const void *avl_a, const void *avl_b, void *avl_param)
Definition: avl.h:29
void * avl_t_prev(struct avl_traverser *)
Definition: avl.c:612
void * avl_t_last(struct avl_traverser *, struct avl_table *)
Definition: avl.c:457
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
Definition: avl.h:54
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_node * avl_stack[AVL_MAX_HEIGHT]
Definition: avl.h:74
struct avl_table * avl_table
Definition: avl.h:72
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