Close parens in gamma calculation in manual's timescale discussion.
[sawsim.git] / src / tavl.h
1 /* Produced by texiweb from libavl.w. */
2
3 /* libavl - library for manipulation of binary trees.
4    Copyright (C) 1998-2002, 2004 Free Software Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    License, or (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14    See the GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19    02111-1307, USA.
20
21    The author may be contacted at <blp@gnu.org> on the Internet, or
22    write to Ben Pfaff, Stanford University, Computer Science Dept., 353
23    Serra Mall, Stanford CA 94305, USA.
24 */
25
26 #ifndef TAVL_H
27 #define TAVL_H 1
28
29 #include <stddef.h>
30
31 /* Function types. */
32 typedef int tavl_comparison_func (const void *tavl_a, const void *tavl_b,
33                                  void *tavl_param);
34 typedef void tavl_item_func (void *tavl_item, void *tavl_param);
35 typedef void *tavl_copy_func (void *tavl_item, void *tavl_param);
36
37 #ifndef LIBAVL_ALLOCATOR
38 #define LIBAVL_ALLOCATOR
39 /* Memory allocator. */
40 struct libavl_allocator
41   {
42     void *(*libavl_malloc) (struct libavl_allocator *, size_t libavl_size);
43     void (*libavl_free) (struct libavl_allocator *, void *libavl_block);
44   };
45 #endif
46
47 /* Default memory allocator. */
48 extern struct libavl_allocator tavl_allocator_default;
49 void *tavl_malloc (struct libavl_allocator *, size_t);
50 void tavl_free (struct libavl_allocator *, void *);
51
52 /* Maximum TAVL height. */
53 #ifndef TAVL_MAX_HEIGHT
54 #define TAVL_MAX_HEIGHT 32
55 #endif
56
57 /* Tree data structure. */
58 struct tavl_table
59   {
60     struct tavl_node *tavl_root;        /* Tree's root. */
61     tavl_comparison_func *tavl_compare; /* Comparison function. */
62     void *tavl_param;                   /* Extra argument to |tavl_compare|. */
63     struct libavl_allocator *tavl_alloc; /* Memory allocator. */
64     size_t tavl_count;                  /* Number of items in tree. */
65   };
66
67 /* Characterizes a link as a child pointer or a thread. */
68 enum tavl_tag
69   {
70     TAVL_CHILD,                     /* Child pointer. */
71     TAVL_THREAD                     /* Thread. */
72   };
73
74 /* An TAVL tree node. */
75 struct tavl_node
76   {
77     struct tavl_node *tavl_link[2]; /* Subtrees. */
78     void *tavl_data;                /* Pointer to data. */
79     unsigned char tavl_tag[2];      /* Tag fields. */
80     signed char tavl_balance;       /* Balance factor. */
81   };
82
83 /* TAVL traverser structure. */
84 struct tavl_traverser
85   {
86     struct tavl_table *tavl_table;        /* Tree being traversed. */
87     struct tavl_node *tavl_node;          /* Current node in tree. */
88   };
89
90 /* Table functions. */
91 struct tavl_table *tavl_create (tavl_comparison_func *, void *,
92                               struct libavl_allocator *);
93 struct tavl_table *tavl_copy (const struct tavl_table *, tavl_copy_func *,
94                             tavl_item_func *, struct libavl_allocator *);
95 void tavl_destroy (struct tavl_table *, tavl_item_func *);
96 void **tavl_probe (struct tavl_table *, void *);
97 void *tavl_insert (struct tavl_table *, void *);
98 void *tavl_replace (struct tavl_table *, void *);
99 void *tavl_delete (struct tavl_table *, const void *);
100 void *tavl_find (const struct tavl_table *, const void *);
101 void tavl_assert_insert (struct tavl_table *, void *);
102 void *tavl_assert_delete (struct tavl_table *, void *);
103
104 #define tavl_count(table) ((size_t) (table)->tavl_count)
105
106 /* Table traverser functions. */
107 void tavl_t_init (struct tavl_traverser *, struct tavl_table *);
108 void *tavl_t_first (struct tavl_traverser *, struct tavl_table *);
109 void *tavl_t_last (struct tavl_traverser *, struct tavl_table *);
110 void *tavl_t_find (struct tavl_traverser *, struct tavl_table *, void *);
111 void *tavl_t_insert (struct tavl_traverser *, struct tavl_table *, void *);
112 void *tavl_t_copy (struct tavl_traverser *, const struct tavl_traverser *);
113 void *tavl_t_next (struct tavl_traverser *);
114 void *tavl_t_prev (struct tavl_traverser *);
115 void *tavl_t_cur (struct tavl_traverser *);
116 void *tavl_t_replace (struct tavl_traverser *, void *);
117 void *tavl_bracket (const struct tavl_table *tree, const void *item, const void **predecessor, const void **successor);
118
119
120
121 #endif /* tavl.h */