Parallel Plane Sweep  0.1
Shared memory multithreaded version of the plane sweep algorithm
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-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 
34 #ifndef AVL_H
35 #define AVL_H 1
36 
37 #include <stddef.h>
38 
39 /* Function types. */
40 typedef int avl_comparison_func (const void *avl_a, const void *avl_b,
41  void *avl_param);
42 typedef void avl_item_func (void *avl_item, void *avl_param);
43 typedef void *avl_copy_func (void *avl_item, void *avl_param);
44 
45 #ifndef LIBAVL_ALLOCATOR
46 #define LIBAVL_ALLOCATOR
47 /* Memory allocator. */
49  {
50  void *(*libavl_malloc) (struct libavl_allocator *, size_t libavl_size);
51  void (*libavl_free) (struct libavl_allocator *, void *libavl_block);
52  };
53 #endif
54 
55 /* Default memory allocator. */
57 void *avl_malloc (struct libavl_allocator *, size_t);
58 void avl_free (struct libavl_allocator *, void *);
59 
60 /* Maximum AVL height. */
61 #ifndef AVL_MAX_HEIGHT
62 #define AVL_MAX_HEIGHT 32
63 #endif
64 
65 /* Tree data structure. */
66 struct avl_table
67  {
68  struct avl_node *avl_root; /* Tree's root. */
69  avl_comparison_func *avl_compare; /* Comparison function. */
70  void *avl_param; /* Extra argument to |avl_compare|. */
71  struct libavl_allocator *avl_alloc; /* Memory allocator. */
72  size_t avl_count; /* Number of items in tree. */
73  unsigned long avl_generation; /* Generation number. */
74  };
75 
76 /* An AVL tree node. */
77 struct avl_node
78  {
79  struct avl_node *avl_link[2]; /* Subtrees. */
80  void *avl_data; /* Pointer to data. */
81  signed char avl_balance; /* Balance factor. */
82  };
83 
84 /* AVL traverser structure. */
86  {
87  struct avl_table *avl_table; /* Tree being traversed. */
88  struct avl_node *avl_node; /* Current node in tree. */
89  struct avl_node *avl_stack[AVL_MAX_HEIGHT];
90  /* All the nodes above |avl_node|. */
91  size_t avl_height; /* Number of nodes in |avl_parent|. */
92  unsigned long avl_generation; /* Generation number. */
93  };
94 
95 /* Table functions. */
96 struct avl_table *avl_create (avl_comparison_func *, void *,
97  struct libavl_allocator *);
98 struct avl_table *avl_copy (const struct avl_table *, avl_copy_func *,
99  avl_item_func *, struct libavl_allocator *);
100 void avl_destroy (struct avl_table *, avl_item_func *);
101 void **avl_probe (struct avl_table *, void *);
102 void *avl_insert (struct avl_table *, void *);
103 void *avl_replace (struct avl_table *, void *);
104 void *avl_delete (struct avl_table *, const void *);
105 void *avl_find (const struct avl_table *, const void *);
106 void avl_assert_insert (struct avl_table *, void *);
107 void *avl_assert_delete (struct avl_table *, void *);
108 
109 #define avl_count(table) ((size_t) (table)->avl_count)
110 
111 /* Table traverser functions. */
112 void avl_t_init (struct avl_traverser *, struct avl_table *);
113 void *avl_t_first (struct avl_traverser *, struct avl_table *);
114 void *avl_t_last (struct avl_traverser *, struct avl_table *);
115 void *avl_t_find (struct avl_traverser *, struct avl_table *, void *);
116 void *avl_t_insert (struct avl_traverser *, struct avl_table *, void *);
117 void *avl_t_copy (struct avl_traverser *, const struct avl_traverser *);
118 void *avl_t_next (struct avl_traverser *);
119 void *avl_t_prev (struct avl_traverser *);
120 void *avl_t_cur (struct avl_traverser *);
121 void *avl_t_replace (struct avl_traverser *, void *);
122 
123 #endif /* avl.h */
struct avl_table * avl_create(avl_comparison_func *, void *, struct libavl_allocator *)
Definition: avl.c:46
void * avl_t_first(struct avl_traverser *, struct avl_table *)
Definition: avl.c:446
void * avl_delete(struct avl_table *, const void *)
Definition: avl.c:237
void avl_free(struct libavl_allocator *, void *)
Definition: avl.c:869
void avl_item_func(void *avl_item, void *avl_param)
Definition: avl.h:42
struct avl_node * avl_node
Definition: avl.h:88
size_t avl_count
Definition: avl.h:72
void ** avl_probe(struct avl_table *, void *)
Definition: avl.c:98
unsigned long avl_generation
Definition: avl.h:73
struct avl_node * avl_link[2]
Definition: avl.h:79
void * avl_t_prev(struct avl_traverser *)
Definition: avl.c:643
Definition: avl.h:77
unsigned long avl_generation
Definition: avl.h:92
void * avl_copy_func(void *avl_item, void *avl_param)
Definition: avl.h:43
void * avl_find(const struct avl_table *, const void *)
Definition: avl.c:73
void avl_t_init(struct avl_traverser *, struct avl_table *)
Definition: avl.c:434
void * avl_t_find(struct avl_traverser *, struct avl_table *, void *)
Definition: avl.c:502
void * avl_t_insert(struct avl_traverser *, struct avl_table *, void *)
Definition: avl.c:541
struct avl_node * avl_stack[AVL_MAX_HEIGHT]
Definition: avl.h:89
void * avl_malloc(struct libavl_allocator *, size_t)
Definition: avl.c:861
int avl_comparison_func(const void *avl_a, const void *avl_b, void *avl_param)
Definition: avl.h:40
void * avl_t_last(struct avl_traverser *, struct avl_table *)
Definition: avl.c:473
void * avl_replace(struct avl_table *, void *)
Definition: avl.c:221
struct avl_node * avl_root
Definition: avl.h:68
void * avl_assert_delete(struct avl_table *, void *)
Definition: avl.c:896
void avl_destroy(struct avl_table *, avl_item_func *)
Definition: avl.c:834
#define AVL_MAX_HEIGHT
Definition: avl.h:62
Definition: avl.h:66
void * avl_t_next(struct avl_traverser *)
Definition: avl.c:590
void(* libavl_free)(struct libavl_allocator *, void *libavl_block)
Definition: avl.h:51
signed char avl_balance
Definition: avl.h:81
void * avl_data
Definition: avl.h:80
avl_comparison_func * avl_compare
Definition: avl.h:69
void * avl_param
Definition: avl.h:70
struct libavl_allocator avl_allocator_default
Definition: avl.c:876
size_t avl_height
Definition: avl.h:91
void * avl_t_cur(struct avl_traverser *)
Definition: avl.c:694
struct libavl_allocator * avl_alloc
Definition: avl.h:71
void * avl_insert(struct avl_table *, void *)
Definition: avl.c:210
void avl_assert_insert(struct avl_table *, void *)
Definition: avl.c:887
struct avl_table * avl_table
Definition: avl.h:87
struct avl_table * avl_copy(const struct avl_table *, avl_copy_func *, avl_item_func *, struct libavl_allocator *)
Definition: avl.c:739
void * avl_t_copy(struct avl_traverser *, const struct avl_traverser *)
Definition: avl.c:566
void * avl_t_replace(struct avl_traverser *, void *)
Definition: avl.c:705