kernel: restore setting KTS_NONE
[minix.git] / servers / vm / cavl_if.h
blob22881bad5de686c83a1bff3dbbaa1cd3e90d2ed9
1 /* Abstract AVL Tree Generic C Package.
2 ** Interface generation header file.
3 **
4 ** This code is in the public domain. See cavl_tree.html for interface
5 ** documentation.
6 **
7 ** Version: 1.5 Author: Walt Karas
8 */
10 /* This header contains the definition of CHAR_BIT (number of bits in a
11 ** char). */
12 #include <limits.h>
14 #undef L__
15 #undef L__EST_LONG_BIT
16 #undef L__SIZE
17 #undef L__SC
18 #undef L__LONG_BIT
19 #undef L__BIT_ARR_DEFN
21 #ifndef AVL_SEARCH_TYPE_DEFINED_
22 #define AVL_SEARCH_TYPE_DEFINED_
24 typedef enum
26 AVL_EQUAL = 1,
27 AVL_LESS = 2,
28 AVL_GREATER = 4,
29 AVL_LESS_EQUAL = AVL_EQUAL | AVL_LESS,
30 AVL_GREATER_EQUAL = AVL_EQUAL | AVL_GREATER
32 avl_search_type;
34 #endif
36 #ifdef AVL_UNIQUE
38 #define L__ AVL_UNIQUE
40 #else
42 #define L__(X) X
44 #endif
46 /* Determine storage class for function prototypes. */
47 #ifdef AVL_PRIVATE
49 #define L__SC static
51 #else
53 #define L__SC extern
55 #endif
57 #ifdef AVL_SIZE
59 #define L__SIZE AVL_SIZE
61 #else
63 #define L__SIZE unsigned long
65 #endif
67 typedef struct
69 #ifdef AVL_INSIDE_STRUCT
71 AVL_INSIDE_STRUCT
73 #endif
75 AVL_HANDLE root;
77 L__(avl);
79 /* Function prototypes. */
81 L__SC void L__(init)(L__(avl) *tree);
83 L__SC int L__(is_empty)(L__(avl) *tree);
85 L__SC AVL_HANDLE L__(insert)(L__(avl) *tree, AVL_HANDLE h);
87 L__SC AVL_HANDLE L__(search)(L__(avl) *tree, AVL_KEY k, avl_search_type st);
89 L__SC AVL_HANDLE L__(search_least)(L__(avl) *tree);
91 L__SC AVL_HANDLE L__(search_greatest)(L__(avl) *tree);
93 L__SC AVL_HANDLE L__(search_root)(L__(avl) *tree);
95 L__SC AVL_HANDLE L__(remove)(L__(avl) *tree, AVL_KEY k);
97 L__SC AVL_HANDLE L__(subst)(L__(avl) *tree, AVL_HANDLE new_node);
99 #ifdef AVL_BUILD_ITER_TYPE
101 L__SC int L__(build)(
102 L__(avl) *tree, AVL_BUILD_ITER_TYPE p, L__SIZE num_nodes);
104 #endif
106 /* ANSI C/ISO C++ require that a long have at least 32 bits. Set
107 ** L__EST_LONG_BIT to be the greatest multiple of 8 in the range
108 ** 32 - 64 (inclusive) that is less than or equal to the number of
109 ** bits in a long.
112 #if (((LONG_MAX >> 31) >> 7) == 0)
114 #define L__EST_LONG_BIT 32
116 #elif (((LONG_MAX >> 31) >> 15) == 0)
118 #define L__EST_LONG_BIT 40
120 #elif (((LONG_MAX >> 31) >> 23) == 0)
122 #define L__EST_LONG_BIT 48
124 #elif (((LONG_MAX >> 31) >> 31) == 0)
126 #define L__EST_LONG_BIT 56
128 #else
130 #define L__EST_LONG_BIT 64
132 #endif
134 /* Number of bits in a long. */
135 #define L__LONG_BIT (sizeof(long) * CHAR_BIT)
137 /* The macro L__BIT_ARR_DEFN defines a bit array whose index is a (0-based)
138 ** node depth. The definition depends on whether the maximum depth is more
139 ** or less than the number of bits in a single long.
142 #if ((AVL_MAX_DEPTH) > L__EST_LONG_BIT)
144 /* Maximum depth may be more than number of bits in a long. */
146 #define L__BIT_ARR_DEFN(NAME) \
147 unsigned long NAME[((AVL_MAX_DEPTH) + L__LONG_BIT - 1) / L__LONG_BIT];
149 #else
151 /* Maximum depth is definitely less than number of bits in a long. */
153 #define L__BIT_ARR_DEFN(NAME) unsigned long NAME;
155 #endif
157 /* Iterator structure. */
158 typedef struct
160 /* Tree being iterated over. */
161 L__(avl) *tree_;
163 /* Records a path into the tree. If bit n is true, indicates
164 ** take greater branch from the nth node in the path, otherwise
165 ** take the less branch. bit 0 gives branch from root, and
166 ** so on. */
167 L__BIT_ARR_DEFN(branch)
169 /* Zero-based depth of path into tree. */
170 unsigned depth;
172 /* Handles of nodes in path from root to current node (returned by *). */
173 AVL_HANDLE path_h[(AVL_MAX_DEPTH) - 1];
175 L__(iter);
177 /* Iterator function prototypes. */
179 L__SC void L__(start_iter)(
180 L__(avl) *tree, L__(iter) *iter, AVL_KEY k, avl_search_type st);
182 L__SC void L__(start_iter_least)(L__(avl) *tree, L__(iter) *iter);
184 L__SC void L__(start_iter_greatest)(L__(avl) *tree, L__(iter) *iter);
186 L__SC AVL_HANDLE L__(get_iter)(L__(iter) *iter);
188 L__SC void L__(incr_iter)(L__(iter) *iter);
190 L__SC void L__(decr_iter)(L__(iter) *iter);
192 L__SC void L__(init_iter)(L__(iter) *iter);
194 #define AVL_IMPL_INIT 1
195 #define AVL_IMPL_IS_EMPTY (1 << 1)
196 #define AVL_IMPL_INSERT (1 << 2)
197 #define AVL_IMPL_SEARCH (1 << 3)
198 #define AVL_IMPL_SEARCH_LEAST (1 << 4)
199 #define AVL_IMPL_SEARCH_GREATEST (1 << 5)
200 #define AVL_IMPL_REMOVE (1 << 6)
201 #define AVL_IMPL_BUILD (1 << 7)
202 #define AVL_IMPL_START_ITER (1 << 8)
203 #define AVL_IMPL_START_ITER_LEAST (1 << 9)
204 #define AVL_IMPL_START_ITER_GREATEST (1 << 10)
205 #define AVL_IMPL_GET_ITER (1 << 11)
206 #define AVL_IMPL_INCR_ITER (1 << 12)
207 #define AVL_IMPL_DECR_ITER (1 << 13)
208 #define AVL_IMPL_INIT_ITER (1 << 14)
209 #define AVL_IMPL_SUBST (1 << 15)
211 #define AVL_IMPL_ALL (~0)
213 #undef L__
214 #undef L__EST_LONG_BIT
215 #undef L__SIZE
216 #undef L__SC
217 #undef L__LONG_BIT
218 #undef L__BIT_ARR_DEFN