Added vp8_update_zbin_extra
[libvpx.git] / vpx_mem / memory_manager / include / cavl_if.h
blob1b2c9b7388a76e5b3292af0bce22e003232ccb44
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 /* Abstract AVL Tree Generic C Package.
13 ** Interface generation header file.
15 ** This code is in the public domain. See cavl_tree.html for interface
16 ** documentation.
18 ** Version: 1.5 Author: Walt Karas
21 /* This header contains the definition of CHAR_BIT (number of bits in a
22 ** char). */
23 #include <limits.h>
25 #undef L_
26 #undef L_EST_LONG_BIT
27 #undef L_SIZE
28 #undef L_SC
29 #undef L_LONG_BIT
30 #undef L_BIT_ARR_DEFN
32 #ifndef AVL_SEARCH_TYPE_DEFINED_
33 #define AVL_SEARCH_TYPE_DEFINED_
35 typedef enum
37 AVL_EQUAL = 1,
38 AVL_LESS = 2,
39 AVL_GREATER = 4,
40 AVL_LESS_EQUAL = AVL_EQUAL | AVL_LESS,
41 AVL_GREATER_EQUAL = AVL_EQUAL | AVL_GREATER
43 avl_search_type;
45 #endif
47 #ifdef AVL_UNIQUE
49 #define L_ AVL_UNIQUE
51 #else
53 #define L_(X) X
55 #endif
57 /* Determine storage class for function prototypes. */
58 #ifdef AVL_PRIVATE
60 #define L_SC static
62 #else
64 #define L_SC extern
66 #endif
68 #ifdef AVL_SIZE
70 #define L_SIZE AVL_SIZE
72 #else
74 #define L_SIZE unsigned long
76 #endif
78 typedef struct
80 #ifdef AVL_INSIDE_STRUCT
82 AVL_INSIDE_STRUCT
84 #endif
86 AVL_HANDLE root;
88 L_(avl);
90 /* Function prototypes. */
92 L_SC void L_(init)(L_(avl) *tree);
94 L_SC int L_(is_empty)(L_(avl) *tree);
96 L_SC AVL_HANDLE L_(insert)(L_(avl) *tree, AVL_HANDLE h);
98 L_SC AVL_HANDLE L_(search)(L_(avl) *tree, AVL_KEY k, avl_search_type st);
100 L_SC AVL_HANDLE L_(search_least)(L_(avl) *tree);
102 L_SC AVL_HANDLE L_(search_greatest)(L_(avl) *tree);
104 L_SC AVL_HANDLE L_(remove)(L_(avl) *tree, AVL_KEY k);
106 L_SC AVL_HANDLE L_(subst)(L_(avl) *tree, AVL_HANDLE new_node);
108 #ifdef AVL_BUILD_ITER_TYPE
110 L_SC int L_(build)(
111 L_(avl) *tree, AVL_BUILD_ITER_TYPE p, L_SIZE num_nodes);
113 #endif
115 /* ANSI C/ISO C++ require that a long have at least 32 bits. Set
116 ** L_EST_LONG_BIT to be the greatest multiple of 8 in the range
117 ** 32 - 64 (inclusive) that is less than or equal to the number of
118 ** bits in a long.
121 #if (((LONG_MAX >> 31) >> 7) == 0)
123 #define L_EST_LONG_BIT 32
125 #elif (((LONG_MAX >> 31) >> 15) == 0)
127 #define L_EST_LONG_BIT 40
129 #elif (((LONG_MAX >> 31) >> 23) == 0)
131 #define L_EST_LONG_BIT 48
133 #elif (((LONG_MAX >> 31) >> 31) == 0)
135 #define L_EST_LONG_BIT 56
137 #else
139 #define L_EST_LONG_BIT 64
141 #endif
143 /* Number of bits in a long. */
144 #define L_LONG_BIT (sizeof(long) * CHAR_BIT)
146 /* The macro L_BIT_ARR_DEFN defines a bit array whose index is a (0-based)
147 ** node depth. The definition depends on whether the maximum depth is more
148 ** or less than the number of bits in a single long.
151 #if ((AVL_MAX_DEPTH) > L_EST_LONG_BIT)
153 /* Maximum depth may be more than number of bits in a long. */
155 #define L_BIT_ARR_DEFN(NAME) \
156 unsigned long NAME[((AVL_MAX_DEPTH) + L_LONG_BIT - 1) / L_LONG_BIT];
158 #else
160 /* Maximum depth is definitely less than number of bits in a long. */
162 #define L_BIT_ARR_DEFN(NAME) unsigned long NAME;
164 #endif
166 /* Iterator structure. */
167 typedef struct
169 /* Tree being iterated over. */
170 L_(avl) *tree_;
172 /* Records a path into the tree. If bit n is true, indicates
173 ** take greater branch from the nth node in the path, otherwise
174 ** take the less branch. bit 0 gives branch from root, and
175 ** so on. */
176 L_BIT_ARR_DEFN(branch)
178 /* Zero-based depth of path into tree. */
179 unsigned depth;
181 /* Handles of nodes in path from root to current node (returned by *). */
182 AVL_HANDLE path_h[(AVL_MAX_DEPTH) - 1];
184 L_(iter);
186 /* Iterator function prototypes. */
188 L_SC void L_(start_iter)(
189 L_(avl) *tree, L_(iter) *iter, AVL_KEY k, avl_search_type st);
191 L_SC void L_(start_iter_least)(L_(avl) *tree, L_(iter) *iter);
193 L_SC void L_(start_iter_greatest)(L_(avl) *tree, L_(iter) *iter);
195 L_SC AVL_HANDLE L_(get_iter)(L_(iter) *iter);
197 L_SC void L_(incr_iter)(L_(iter) *iter);
199 L_SC void L_(decr_iter)(L_(iter) *iter);
201 L_SC void L_(init_iter)(L_(iter) *iter);
203 #define AVL_IMPL_INIT 1
204 #define AVL_IMPL_IS_EMPTY (1 << 1)
205 #define AVL_IMPL_INSERT (1 << 2)
206 #define AVL_IMPL_SEARCH (1 << 3)
207 #define AVL_IMPL_SEARCH_LEAST (1 << 4)
208 #define AVL_IMPL_SEARCH_GREATEST (1 << 5)
209 #define AVL_IMPL_REMOVE (1 << 6)
210 #define AVL_IMPL_BUILD (1 << 7)
211 #define AVL_IMPL_START_ITER (1 << 8)
212 #define AVL_IMPL_START_ITER_LEAST (1 << 9)
213 #define AVL_IMPL_START_ITER_GREATEST (1 << 10)
214 #define AVL_IMPL_GET_ITER (1 << 11)
215 #define AVL_IMPL_INCR_ITER (1 << 12)
216 #define AVL_IMPL_DECR_ITER (1 << 13)
217 #define AVL_IMPL_INIT_ITER (1 << 14)
218 #define AVL_IMPL_SUBST (1 << 15)
220 #define AVL_IMPL_ALL (~0)
222 #undef L_
223 #undef L_EST_LONG_BIT
224 #undef L_SIZE
225 #undef L_SC
226 #undef L_LONG_BIT
227 #undef L_BIT_ARR_DEFN