1 /* Produced by texiweb from libavl.w. */
3 /* libavl - library for manipulation of binary trees.
4 Copyright (C) 1998-2002, 2004 Free Software Foundation, Inc.
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.
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.
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
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.
32 typedef int prb_comparison_func (const void *prb_a
, const void *prb_b
,
34 typedef void prb_item_func (void *prb_item
, void *prb_param
);
35 typedef void *prb_copy_func (void *prb_item
, void *prb_param
);
37 #ifndef LIBAVL_ALLOCATOR
38 #define LIBAVL_ALLOCATOR
39 /* Memory allocator. */
40 struct libavl_allocator
42 void *(*libavl_malloc
) (struct libavl_allocator
*, size_t libavl_size
);
43 void (*libavl_free
) (struct libavl_allocator
*, void *libavl_block
);
47 /* Default memory allocator. */
48 extern struct libavl_allocator prb_allocator_default
;
49 void *prb_malloc (struct libavl_allocator
*, size_t);
50 void prb_free (struct libavl_allocator
*, void *);
52 /* Maximum PRB height. */
53 #ifndef PRB_MAX_HEIGHT
54 #define PRB_MAX_HEIGHT 48
57 /* Tree data structure. */
60 struct prb_node
*prb_root
; /* Tree's root. */
61 prb_comparison_func
*prb_compare
; /* Comparison function. */
62 void *prb_param
; /* Extra argument to |prb_compare|. */
63 struct libavl_allocator
*prb_alloc
; /* Memory allocator. */
64 size_t prb_count
; /* Number of items in tree. */
67 /* Color of a red-black node. */
70 PRB_BLACK
, /* Black. */
74 /* A red-black tree with parent pointers node. */
77 struct prb_node
*prb_link
[2]; /* Subtrees. */
78 struct prb_node
*prb_parent
; /* Parent. */
79 void *prb_data
; /* Pointer to data. */
80 unsigned char prb_color
; /* Color. */
83 /* PRB traverser structure. */
86 struct prb_table
*prb_table
; /* Tree being traversed. */
87 struct prb_node
*prb_node
; /* Current node in tree. */
90 /* Table functions. */
91 struct prb_table
*prb_create (prb_comparison_func
*, void *,
92 struct libavl_allocator
*);
93 struct prb_table
*prb_copy (const struct prb_table
*, prb_copy_func
*,
94 prb_item_func
*, struct libavl_allocator
*);
95 void prb_destroy (struct prb_table
*, prb_item_func
*);
96 void **prb_probe (struct prb_table
*, void *);
97 void *prb_insert (struct prb_table
*, void *);
98 void *prb_replace (struct prb_table
*, void *);
99 void *prb_delete (struct prb_table
*, const void *);
100 void *prb_find (const struct prb_table
*, const void *);
101 void prb_assert_insert (struct prb_table
*, void *);
102 void *prb_assert_delete (struct prb_table
*, void *);
104 #define prb_count(table) ((size_t) (table)->prb_count)
106 /* Table traverser functions. */
107 void prb_t_init (struct prb_traverser
*, struct prb_table
*);
108 void *prb_t_first (struct prb_traverser
*, struct prb_table
*);
109 void *prb_t_last (struct prb_traverser
*, struct prb_table
*);
110 void *prb_t_find (struct prb_traverser
*, struct prb_table
*, void *);
111 void *prb_t_insert (struct prb_traverser
*, struct prb_table
*, void *);
112 void *prb_t_copy (struct prb_traverser
*, const struct prb_traverser
*);
113 void *prb_t_next (struct prb_traverser
*);
114 void *prb_t_prev (struct prb_traverser
*);
115 void *prb_t_cur (struct prb_traverser
*);
116 void *prb_t_replace (struct prb_traverser
*, void *);