| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #undef L_ | 25 #undef L_ |
| 26 #undef L_EST_LONG_BIT | 26 #undef L_EST_LONG_BIT |
| 27 #undef L_SIZE | 27 #undef L_SIZE |
| 28 #undef L_SC | 28 #undef L_SC |
| 29 #undef L_LONG_BIT | 29 #undef L_LONG_BIT |
| 30 #undef L_BIT_ARR_DEFN | 30 #undef L_BIT_ARR_DEFN |
| 31 | 31 |
| 32 #ifndef AVL_SEARCH_TYPE_DEFINED_ | 32 #ifndef AVL_SEARCH_TYPE_DEFINED_ |
| 33 #define AVL_SEARCH_TYPE_DEFINED_ | 33 #define AVL_SEARCH_TYPE_DEFINED_ |
| 34 | 34 |
| 35 typedef enum | 35 typedef enum { |
| 36 { | 36 AVL_EQUAL = 1, |
| 37 AVL_EQUAL = 1, | 37 AVL_LESS = 2, |
| 38 AVL_LESS = 2, | 38 AVL_GREATER = 4, |
| 39 AVL_GREATER = 4, | 39 AVL_LESS_EQUAL = AVL_EQUAL | AVL_LESS, |
| 40 AVL_LESS_EQUAL = AVL_EQUAL | AVL_LESS, | 40 AVL_GREATER_EQUAL = AVL_EQUAL | AVL_GREATER |
| 41 AVL_GREATER_EQUAL = AVL_EQUAL | AVL_GREATER | |
| 42 } | 41 } |
| 43 avl_search_type; | 42 avl_search_type; |
| 44 | 43 |
| 45 #endif | 44 #endif |
| 46 | 45 |
| 47 #ifdef AVL_UNIQUE | 46 #ifdef AVL_UNIQUE |
| 48 | 47 |
| 49 #define L_ AVL_UNIQUE | 48 #define L_ AVL_UNIQUE |
| 50 | 49 |
| 51 #else | 50 #else |
| (...skipping 16 matching lines...) Expand all Loading... |
| 68 #ifdef AVL_SIZE | 67 #ifdef AVL_SIZE |
| 69 | 68 |
| 70 #define L_SIZE AVL_SIZE | 69 #define L_SIZE AVL_SIZE |
| 71 | 70 |
| 72 #else | 71 #else |
| 73 | 72 |
| 74 #define L_SIZE unsigned long | 73 #define L_SIZE unsigned long |
| 75 | 74 |
| 76 #endif | 75 #endif |
| 77 | 76 |
| 78 typedef struct | 77 typedef struct { |
| 79 { | |
| 80 #ifdef AVL_INSIDE_STRUCT | 78 #ifdef AVL_INSIDE_STRUCT |
| 81 | 79 |
| 82 AVL_INSIDE_STRUCT | 80 AVL_INSIDE_STRUCT |
| 83 | 81 |
| 84 #endif | 82 #endif |
| 85 | 83 |
| 86 AVL_HANDLE root; | 84 AVL_HANDLE root; |
| 87 } | 85 } |
| 88 L_(avl); | 86 L_(avl); |
| 89 | 87 |
| 90 /* Function prototypes. */ | 88 /* Function prototypes. */ |
| 91 | 89 |
| 92 L_SC void L_(init)(L_(avl) *tree); | 90 L_SC void L_(init)(L_(avl) *tree); |
| 93 | 91 |
| 94 L_SC int L_(is_empty)(L_(avl) *tree); | 92 L_SC int L_(is_empty)(L_(avl) *tree); |
| 95 | 93 |
| 96 L_SC AVL_HANDLE L_(insert)(L_(avl) *tree, AVL_HANDLE h); | 94 L_SC AVL_HANDLE L_(insert)(L_(avl) *tree, AVL_HANDLE h); |
| 97 | 95 |
| 98 L_SC AVL_HANDLE L_(search)(L_(avl) *tree, AVL_KEY k, avl_search_type st); | 96 L_SC AVL_HANDLE L_(search)(L_(avl) *tree, AVL_KEY k, avl_search_type st); |
| 99 | 97 |
| 100 L_SC AVL_HANDLE L_(search_least)(L_(avl) *tree); | 98 L_SC AVL_HANDLE L_(search_least)(L_(avl) *tree); |
| 101 | 99 |
| 102 L_SC AVL_HANDLE L_(search_greatest)(L_(avl) *tree); | 100 L_SC AVL_HANDLE L_(search_greatest)(L_(avl) *tree); |
| 103 | 101 |
| 104 L_SC AVL_HANDLE L_(remove)(L_(avl) *tree, AVL_KEY k); | 102 L_SC AVL_HANDLE L_(remove)(L_(avl) *tree, AVL_KEY k); |
| 105 | 103 |
| 106 L_SC AVL_HANDLE L_(subst)(L_(avl) *tree, AVL_HANDLE new_node); | 104 L_SC AVL_HANDLE L_(subst)(L_(avl) *tree, AVL_HANDLE new_node); |
| 107 | 105 |
| 108 #ifdef AVL_BUILD_ITER_TYPE | 106 #ifdef AVL_BUILD_ITER_TYPE |
| 109 | 107 |
| 110 L_SC int L_(build)( | 108 L_SC int L_(build)( |
| 111 L_(avl) *tree, AVL_BUILD_ITER_TYPE p, L_SIZE num_nodes); | 109 L_(avl) *tree, AVL_BUILD_ITER_TYPE p, L_SIZE num_nodes); |
| 112 | 110 |
| 113 #endif | 111 #endif |
| 114 | 112 |
| 115 /* ANSI C/ISO C++ require that a long have at least 32 bits. Set | 113 /* 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 | 114 ** 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 | 115 ** 32 - 64 (inclusive) that is less than or equal to the number of |
| 118 ** bits in a long. | 116 ** bits in a long. |
| 119 */ | 117 */ |
| 120 | 118 |
| 121 #if (((LONG_MAX >> 31) >> 7) == 0) | 119 #if (((LONG_MAX >> 31) >> 7) == 0) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 146 /* The macro L_BIT_ARR_DEFN defines a bit array whose index is a (0-based) | 144 /* 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 | 145 ** node depth. The definition depends on whether the maximum depth is more |
| 148 ** or less than the number of bits in a single long. | 146 ** or less than the number of bits in a single long. |
| 149 */ | 147 */ |
| 150 | 148 |
| 151 #if ((AVL_MAX_DEPTH) > L_EST_LONG_BIT) | 149 #if ((AVL_MAX_DEPTH) > L_EST_LONG_BIT) |
| 152 | 150 |
| 153 /* Maximum depth may be more than number of bits in a long. */ | 151 /* Maximum depth may be more than number of bits in a long. */ |
| 154 | 152 |
| 155 #define L_BIT_ARR_DEFN(NAME) \ | 153 #define L_BIT_ARR_DEFN(NAME) \ |
| 156 unsigned long NAME[((AVL_MAX_DEPTH) + L_LONG_BIT - 1) / L_LONG_BIT]; | 154 unsigned long NAME[((AVL_MAX_DEPTH) + L_LONG_BIT - 1) / L_LONG_BIT]; |
| 157 | 155 |
| 158 #else | 156 #else |
| 159 | 157 |
| 160 /* Maximum depth is definitely less than number of bits in a long. */ | 158 /* Maximum depth is definitely less than number of bits in a long. */ |
| 161 | 159 |
| 162 #define L_BIT_ARR_DEFN(NAME) unsigned long NAME; | 160 #define L_BIT_ARR_DEFN(NAME) unsigned long NAME; |
| 163 | 161 |
| 164 #endif | 162 #endif |
| 165 | 163 |
| 166 /* Iterator structure. */ | 164 /* Iterator structure. */ |
| 167 typedef struct | 165 typedef struct { |
| 168 { | 166 /* Tree being iterated over. */ |
| 169 /* Tree being iterated over. */ | 167 L_(avl) *tree_; |
| 170 L_(avl) *tree_; | |
| 171 | 168 |
| 172 /* Records a path into the tree. If bit n is true, indicates | 169 /* Records a path into the tree. If bit n is true, indicates |
| 173 ** take greater branch from the nth node in the path, otherwise | 170 ** take greater branch from the nth node in the path, otherwise |
| 174 ** take the less branch. bit 0 gives branch from root, and | 171 ** take the less branch. bit 0 gives branch from root, and |
| 175 ** so on. */ | 172 ** so on. */ |
| 176 L_BIT_ARR_DEFN(branch) | 173 L_BIT_ARR_DEFN(branch) |
| 177 | 174 |
| 178 /* Zero-based depth of path into tree. */ | 175 /* Zero-based depth of path into tree. */ |
| 179 unsigned depth; | 176 unsigned depth; |
| 180 | 177 |
| 181 /* Handles of nodes in path from root to current node (returned by *). */ | 178 /* Handles of nodes in path from root to current node (returned by *). */ |
| 182 AVL_HANDLE path_h[(AVL_MAX_DEPTH) - 1]; | 179 AVL_HANDLE path_h[(AVL_MAX_DEPTH) - 1]; |
| 183 } | 180 } |
| 184 L_(iter); | 181 L_(iter); |
| 185 | 182 |
| 186 /* Iterator function prototypes. */ | 183 /* Iterator function prototypes. */ |
| 187 | 184 |
| 188 L_SC void L_(start_iter)( | 185 L_SC void L_(start_iter)( |
| 189 L_(avl) *tree, L_(iter) *iter, AVL_KEY k, avl_search_type st); | 186 L_(avl) *tree, L_(iter) *iter, AVL_KEY k, avl_search_type st); |
| 190 | 187 |
| 191 L_SC void L_(start_iter_least)(L_(avl) *tree, L_(iter) *iter); | 188 L_SC void L_(start_iter_least)(L_(avl) *tree, L_(iter) *iter); |
| 192 | 189 |
| 193 L_SC void L_(start_iter_greatest)(L_(avl) *tree, L_(iter) *iter); | 190 L_SC void L_(start_iter_greatest)(L_(avl) *tree, L_(iter) *iter); |
| 194 | 191 |
| 195 L_SC AVL_HANDLE L_(get_iter)(L_(iter) *iter); | 192 L_SC AVL_HANDLE L_(get_iter)(L_(iter) *iter); |
| 196 | 193 |
| 197 L_SC void L_(incr_iter)(L_(iter) *iter); | 194 L_SC void L_(incr_iter)(L_(iter) *iter); |
| 198 | 195 |
| 199 L_SC void L_(decr_iter)(L_(iter) *iter); | 196 L_SC void L_(decr_iter)(L_(iter) *iter); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 218 #define AVL_IMPL_SUBST (1 << 15) | 215 #define AVL_IMPL_SUBST (1 << 15) |
| 219 | 216 |
| 220 #define AVL_IMPL_ALL (~0) | 217 #define AVL_IMPL_ALL (~0) |
| 221 | 218 |
| 222 #undef L_ | 219 #undef L_ |
| 223 #undef L_EST_LONG_BIT | 220 #undef L_EST_LONG_BIT |
| 224 #undef L_SIZE | 221 #undef L_SIZE |
| 225 #undef L_SC | 222 #undef L_SC |
| 226 #undef L_LONG_BIT | 223 #undef L_LONG_BIT |
| 227 #undef L_BIT_ARR_DEFN | 224 #undef L_BIT_ARR_DEFN |
| OLD | NEW |