source: subversion/applications/utils/coastcheck/rb.h @ 34318

Last change on this file since 34318 was 6729, checked in by martinvoosterhout, 12 years ago

Initial commit of the coastline checker. It's been used for a while now
successfully.

File size: 4.4 KB
Line 
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 RB_H
27#define RB_H 1
28
29#include <stddef.h>
30
31/* Function types. */
32typedef int rb_comparison_func (const void *rb_a, const void *rb_b,
33                                 void *rb_param);
34typedef void rb_item_func (void *rb_item, void *rb_param);
35typedef void *rb_copy_func (void *rb_item, void *rb_param);
36
37#ifndef LIBAVL_ALLOCATOR
38#define LIBAVL_ALLOCATOR
39/* Memory allocator. */
40struct 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. */
48extern struct libavl_allocator rb_allocator_default;
49void *rb_malloc (struct libavl_allocator *, size_t);
50void rb_free (struct libavl_allocator *, void *);
51
52/* Maximum RB height. */
53#ifndef RB_MAX_HEIGHT
54#define RB_MAX_HEIGHT 48
55#endif
56
57/* Tree data structure. */
58struct rb_table
59  {
60    struct rb_node *rb_root;          /* Tree's root. */
61    rb_comparison_func *rb_compare;   /* Comparison function. */
62    void *rb_param;                    /* Extra argument to |rb_compare|. */
63    struct libavl_allocator *rb_alloc; /* Memory allocator. */
64    size_t rb_count;                   /* Number of items in tree. */
65    unsigned long rb_generation;       /* Generation number. */
66  };
67
68/* Color of a red-black node. */
69enum rb_color
70  {
71    RB_BLACK,   /* Black. */
72    RB_RED      /* Red. */
73  };
74
75/* A red-black tree node. */
76struct rb_node
77  {
78    struct rb_node *rb_link[2];   /* Subtrees. */
79    void *rb_data;                /* Pointer to data. */
80    unsigned char rb_color;       /* Color. */
81  };
82
83/* RB traverser structure. */
84struct rb_traverser
85  {
86    struct rb_table *rb_table;        /* Tree being traversed. */
87    struct rb_node *rb_node;          /* Current node in tree. */
88    struct rb_node *rb_stack[RB_MAX_HEIGHT];
89                                        /* All the nodes above |rb_node|. */
90    size_t rb_height;                  /* Number of nodes in |rb_parent|. */
91    unsigned long rb_generation;       /* Generation number. */
92  };
93
94/* Table functions. */
95struct rb_table *rb_create (rb_comparison_func *, void *,
96                              struct libavl_allocator *);
97struct rb_table *rb_copy (const struct rb_table *, rb_copy_func *,
98                            rb_item_func *, struct libavl_allocator *);
99void rb_destroy (struct rb_table *, rb_item_func *);
100void **rb_probe (struct rb_table *, void *);
101void *rb_insert (struct rb_table *, void *);
102void *rb_replace (struct rb_table *, void *);
103void *rb_delete (struct rb_table *, const void *);
104void *rb_find (const struct rb_table *, const void *);
105void rb_assert_insert (struct rb_table *, void *);
106void *rb_assert_delete (struct rb_table *, void *);
107
108#define rb_count(table) ((size_t) (table)->rb_count)
109
110/* Table traverser functions. */
111void rb_t_init (struct rb_traverser *, struct rb_table *);
112void *rb_t_first (struct rb_traverser *, struct rb_table *);
113void *rb_t_last (struct rb_traverser *, struct rb_table *);
114void *rb_t_find (struct rb_traverser *, struct rb_table *, void *);
115void *rb_t_insert (struct rb_traverser *, struct rb_table *, void *);
116void *rb_t_copy (struct rb_traverser *, const struct rb_traverser *);
117void *rb_t_next (struct rb_traverser *);
118void *rb_t_prev (struct rb_traverser *);
119void *rb_t_cur (struct rb_traverser *);
120void *rb_t_replace (struct rb_traverser *, void *);
121
122#endif /* rb.h */
Note: See TracBrowser for help on using the repository browser.