This repository was archived by the owner on May 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathavl.h
189 lines (168 loc) · 5.44 KB
/
avl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* libavl
* - manipulates AVL trees.
*
* Copyright (c) 2003
* German Federal Agency for Cartography and Geodesy (BKG)
*
* Developed for Networked Transport of RTCM via Internet Protocol (NTRIP)
* for streaming GNSS data over the Internet.
*
* Designed by Informatik Centrum Dortmund http://www.icd.de
*
* NTRIP is currently an experimental technology.
* The BKG disclaims any liability nor responsibility to any person or entity
* with respect to any loss or damage caused, or alleged to be caused,
* directly or indirectly by the use and application of the NTRIP technology.
*
* For latest information and updates, access:
* http://igs.ifag.de/index_ntrip.htm
*
* Georg Weber
* BKG, Frankfurt, Germany, June 2003-06-13
* E-mail: [email protected]
*
* Based on the GNU General Public License published Icecast 1.3.12
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if !avl_h
#define avl_h 1
#ifndef AVL_MAX_HEIGHT
#define AVL_MAX_HEIGHT 32
#endif
#ifndef __EXTENSIONS__
#define __EXTENSIONS__
#endif
#ifndef __USE_BSD
#define __USE_BSD
#endif
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include "threads.h"
extern void internal_lock_mutex(mutex_t *mutex);
extern void internal_unlock_mutex(mutex_t *mutex);
/* Structure for a node in an AVL tree. */
typedef struct avl_node
{
void *data; /* Pointer to data. */
struct avl_node *link[2]; /* Subtrees. */
signed char bal; /* Balance factor. */
char cache; /* Used during insertion. */
signed char pad[2]; /* Unused. Reserved for threaded trees. */
}
avl_node;
/* Used for traversing an AVL tree. */
typedef struct avl_traverser
{
int init; /* Initialized? */
int nstack; /* Top of stack. */
const avl_node *p; /* Used for traversal. */
const avl_node *stack[AVL_MAX_HEIGHT];/* Descended trees. */
}
avl_traverser;
/* Function types. */
#if !AVL_FUNC_TYPES
#define AVL_FUNC_TYPES 1
typedef int (*avl_comparison_func) (const void *a, const void *b, void *param);
typedef void (*avl_node_func) (void *data, void *param);
typedef void *(*avl_copy_func) (void *data, void *param);
#endif
/* Structure which holds information about an AVL tree. */
typedef struct avl_tree
{
#if PSPP
struct arena **owner; /* Arena to store nodes. */
#endif
avl_node root; /* Tree root node. */
avl_comparison_func cmp; /* Used to compare keys. */
int count; /* Number of nodes in the tree. */
void *param; /* Arbitary user data. */
mutex_t mutex; /* to protect the tree */
}
avl_tree;
#if PSPP
#define MAYBE_ARENA struct arena **owner,
#else
#define MAYBE_ARENA
#endif
/* General functions. */
avl_tree *avl_create (MAYBE_ARENA avl_comparison_func, void *param);
avl_tree *avl_create_nl (MAYBE_ARENA avl_comparison_func, void *param);
void avl_destroy (avl_tree *, avl_node_func);
int avl_count (const avl_tree *);
avl_tree *avl_copy (MAYBE_ARENA avl_tree *, avl_copy_func);
void *avl_traverse (avl_tree *, avl_traverser *);
void **avl_probe (avl_tree *, void *);
void *avl_delete (avl_tree *, const void *);
void *avl_find ( avl_tree *, const void *);
void *avl_find_close ( avl_tree *, const void *);
#if __GCC__ >= 2
extern inline void *
avl_insert (avl_tree *tree, void *item)
{
void **p = avl_probe (tree, item);
return (*p == item) ? NULL : *p;
}
extern inline void *
avl_replace (avl_tree *tree, void *item)
{
void **p = avl_probe (tree, item);
if (*p == item)
return NULL;
else
{
void *r = *p;
*p = item;
return r;
}
}
#else
void *avl_insert (avl_tree *tree, void *item);
void *avl_replace (avl_tree *tree, void *item);
#endif
#ifndef NDEBUG
#define avl_force_insert(A, B) \
do \
{ \
void *r = avl_insert (A, B); \
assert (r == NULL); \
} \
while (0)
void *avl_force_delete (avl_tree *, void *);
#else
#define avl_force_insert(A, B) \
avl_insert (A, B)
#define avl_force_delete(A, B) \
avl_delete (A, B)
#endif
#endif
/* avl_functions.h. ajd ************************************************/
#ifndef __AVL_FUNCTIONS_H
#define __AVL_FUNCTIONS_H
int compare_users (const void *first, const void *second, void *param);
int compare_mounts (const void *first, const void *second, void *param);
int compare_vars (const void *first, const void *second, void *param);
int compare_strings (const void *first, const void *second, void *param);
int compare_connection(const void *first, const void *second, void *param);
int compare_threads(const void *first, const void *second, void *param);
int compare_mutexes(const void *first, const void *second, void *param);
int compare_mem (const void *first, const void *second, void *param);
int compare_sockets (const void *first, const void *second, void *param);
void free_connection(void *data, void *param);
void zero_trav(avl_traverser *trav);
void *avl_get_any_node (avl_tree *tree);
#endif
/* avl_h */