GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
tavl.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 TAVL_H
24 #define TAVL_H 1
25 
26 #include <stddef.h>
27 
28 /* Function types. */
29 typedef int tavl_comparison_func(const void *tavl_a, const void *tavl_b,
30  void *tavl_param);
31 typedef void tavl_item_func(void *tavl_item, void *tavl_param);
32 typedef void *tavl_copy_func(void *tavl_item, void *tavl_param);
33 
34 #ifndef LIBAVL_ALLOCATOR
35 #define LIBAVL_ALLOCATOR
36 /* Memory allocator. */
37 struct libavl_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 *tavl_malloc(struct libavl_allocator *, size_t);
46 void tavl_free(struct libavl_allocator *, void *);
47 
48 /* Maximum TAVL height. */
49 #ifndef TAVL_MAX_HEIGHT
50 #define TAVL_MAX_HEIGHT 92
51 #endif
52 
53 /* Tree data structure. */
54 struct tavl_table {
55  struct tavl_node *tavl_root; /* Tree's root. */
56  tavl_comparison_func *tavl_compare; /* Comparison function. */
57  void *tavl_param; /* Extra argument to |tavl_compare|. */
58  struct libavl_allocator *tavl_alloc; /* Memory allocator. */
59  size_t tavl_count; /* Number of items in tree. */
60 };
61 
62 /* Characterizes a link as a child pointer or a thread. */
63 enum tavl_tag {
64  TAVL_CHILD, /* Child pointer. */
65  TAVL_THREAD /* Thread. */
66 };
67 
68 /* An TAVL tree node. */
69 struct tavl_node {
70  struct tavl_node *tavl_link[2]; /* Subtrees. */
71  void *tavl_data; /* Pointer to data. */
72  unsigned char tavl_tag[2]; /* Tag fields. */
73  signed char tavl_balance; /* Balance factor. */
74 };
75 
76 /* TAVL traverser structure. */
78  struct tavl_table *tavl_table; /* Tree being traversed. */
79  struct tavl_node *tavl_node; /* Current node in tree. */
80 };
81 
82 /* Table functions. */
84  struct libavl_allocator *);
85 struct tavl_table *tavl_copy(const struct tavl_table *, tavl_copy_func *,
86  tavl_item_func *, struct libavl_allocator *);
87 void tavl_destroy(struct tavl_table *, tavl_item_func *);
88 void **tavl_probe(struct tavl_table *, void *);
89 void *tavl_insert(struct tavl_table *, void *);
90 void *tavl_replace(struct tavl_table *, void *);
91 void *tavl_delete(struct tavl_table *, const void *);
92 void *tavl_find(const struct tavl_table *, const void *);
93 void tavl_assert_insert(struct tavl_table *, void *);
94 void *tavl_assert_delete(struct tavl_table *, void *);
95 
96 #define tavl_count(table) ((size_t)(table)->tavl_count)
97 
98 /* Table traverser functions. */
99 void tavl_t_init(struct tavl_traverser *, struct tavl_table *);
100 void *tavl_t_first(struct tavl_traverser *, struct tavl_table *);
101 void *tavl_t_last(struct tavl_traverser *, struct tavl_table *);
102 void *tavl_t_find(struct tavl_traverser *, struct tavl_table *, void *);
103 void *tavl_t_insert(struct tavl_traverser *, struct tavl_table *, void *);
104 void *tavl_t_copy(struct tavl_traverser *, const struct tavl_traverser *);
105 void *tavl_t_next(struct tavl_traverser *);
106 void *tavl_t_prev(struct tavl_traverser *);
107 void *tavl_t_cur(struct tavl_traverser *);
108 void *tavl_t_replace(struct tavl_traverser *, void *);
109 
110 #endif /* tavl.h */
void(* libavl_free)(struct libavl_allocator *, void *libavl_block)
Definition: avl.h:39
Definition: tavl.h:69
struct tavl_node * tavl_link[2]
Definition: tavl.h:70
void * tavl_data
Definition: tavl.h:71
signed char tavl_balance
Definition: tavl.h:73
tavl_comparison_func * tavl_compare
Definition: tavl.h:56
void * tavl_param
Definition: tavl.h:57
struct libavl_allocator * tavl_alloc
Definition: tavl.h:58
struct tavl_node * tavl_root
Definition: tavl.h:55
size_t tavl_count
Definition: tavl.h:59
struct tavl_node * tavl_node
Definition: tavl.h:79
struct tavl_table * tavl_table
Definition: tavl.h:78
void * tavl_insert(struct tavl_table *, void *)
Definition: tavl.c:243
void * tavl_t_prev(struct tavl_traverser *)
Definition: tavl.c:690
void tavl_assert_insert(struct tavl_table *, void *)
Definition: tavl.c:902
void * tavl_t_next(struct tavl_traverser *)
Definition: tavl.c:669
struct libavl_allocator tavl_allocator_default
Definition: tavl.c:896
void tavl_item_func(void *tavl_item, void *tavl_param)
Definition: tavl.h:31
void * tavl_find(const struct tavl_table *, const void *)
Definition: tavl.c:62
void * tavl_t_find(struct tavl_traverser *, struct tavl_table *, void *)
Definition: tavl.c:593
void * tavl_t_cur(struct tavl_traverser *)
Definition: tavl.c:709
void ** tavl_probe(struct tavl_table *, void *)
Definition: tavl.c:90
struct tavl_table * tavl_copy(const struct tavl_table *, tavl_copy_func *, tavl_item_func *, struct libavl_allocator *)
Definition: tavl.c:787
void tavl_t_init(struct tavl_traverser *, struct tavl_table *)
Definition: tavl.c:546
void * tavl_t_replace(struct tavl_traverser *, void *)
Definition: tavl.c:719
void * tavl_t_first(struct tavl_traverser *, struct tavl_table *)
Definition: tavl.c:555
void * tavl_assert_delete(struct tavl_table *, void *)
Definition: tavl.c:911
tavl_tag
Definition: tavl.h:63
@ TAVL_CHILD
Definition: tavl.h:64
@ TAVL_THREAD
Definition: tavl.h:65
int tavl_comparison_func(const void *tavl_a, const void *tavl_b, void *tavl_param)
Definition: tavl.h:29
void * tavl_replace(struct tavl_table *, void *)
Definition: tavl.c:254
void * tavl_t_last(struct tavl_traverser *, struct tavl_table *)
Definition: tavl.c:573
void * tavl_copy_func(void *tavl_item, void *tavl_param)
Definition: tavl.h:32
void tavl_free(struct libavl_allocator *, void *)
Definition: tavl.c:889
void * tavl_t_insert(struct tavl_traverser *, struct tavl_table *, void *)
Definition: tavl.c:633
void tavl_destroy(struct tavl_table *, tavl_item_func *)
Definition: tavl.c:853
void * tavl_malloc(struct libavl_allocator *, size_t)
Definition: tavl.c:882
void * tavl_t_copy(struct tavl_traverser *, const struct tavl_traverser *)
Definition: tavl.c:656
struct tavl_table * tavl_create(tavl_comparison_func *, void *, struct libavl_allocator *)
Definition: tavl.c:37
void * tavl_delete(struct tavl_table *, const void *)
Definition: tavl.c:305