123 /** |
123 /** |
124 * Initializes a new UcxAVLTree with the specified allocator. |
124 * Initializes a new UcxAVLTree with the specified allocator. |
125 * |
125 * |
126 * The cmpfunc should be capable of comparing two keys within this AVL tree. |
126 * The cmpfunc should be capable of comparing two keys within this AVL tree. |
127 * So if you want to use null terminated strings as keys, you could use the |
127 * So if you want to use null terminated strings as keys, you could use the |
128 * ucx_strcmp() function here. |
128 * ucx_cmp_str() function here. |
129 * |
129 * |
130 * @param cmpfunc the compare function that shall be used |
130 * @param cmpfunc the compare function that shall be used |
131 * @param allocator the UcxAllocator that shall be used |
131 * @param allocator the UcxAllocator that shall be used |
132 * @return a new UcxAVLTree object |
132 * @return a new UcxAVLTree object |
133 */ |
133 */ |
134 UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator); |
134 UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator); |
135 |
135 |
136 /** |
136 /** |
137 * Destroys a UcxAVLTree. |
137 * Destroys a UcxAVLTree. |
|
138 * |
|
139 * Note, that the contents are not automatically freed. |
|
140 * Use may use #ucx_avl_free_content() before calling this function. |
|
141 * |
138 * @param tree the tree to destroy |
142 * @param tree the tree to destroy |
|
143 * @see ucx_avl_free_content() |
139 */ |
144 */ |
140 void ucx_avl_free(UcxAVLTree *tree); |
145 void ucx_avl_free(UcxAVLTree *tree); |
141 |
146 |
142 /** |
147 /** |
|
148 * Frees the contents of a UcxAVLTree. |
|
149 * |
|
150 * This is a convenience function that iterates over the tree and passes all |
|
151 * values to the specified destructor function. |
|
152 * |
|
153 * If no destructor is specified (<code>NULL</code>), the free() function of |
|
154 * the tree's own allocator is used. |
|
155 * |
|
156 * You must ensure, that it is valid to pass each value in the map to the same |
|
157 * destructor function. |
|
158 * |
|
159 * You should free the entire tree afterwards, as the contents will be invalid. |
|
160 * |
|
161 * @param tree for which the contents shall be freed |
|
162 * @param destr optional pointer to a destructor function |
|
163 * @see ucx_avl_free() |
|
164 */ |
|
165 void ucx_avl_free_content(UcxAVLTree *tree, ucx_destructor destr); |
|
166 |
|
167 /** |
143 * Macro for initializing a new UcxAVLTree with the default allocator and a |
168 * Macro for initializing a new UcxAVLTree with the default allocator and a |
144 * ucx_ptrcmp() compare function. |
169 * ucx_cmp_ptr() compare function. |
145 * |
170 * |
146 * @return a new default UcxAVLTree object |
171 * @return a new default UcxAVLTree object |
147 */ |
172 */ |
148 #define ucx_avl_default_new() ucx_avl_new_a(ucx_ptrcmp, ucx_default_allocator()) |
173 #define ucx_avl_default_new() \ |
|
174 ucx_avl_new_a(ucx_cmp_ptr, ucx_default_allocator()) |
149 |
175 |
150 /** |
176 /** |
151 * Gets the node from the tree, that is associated with the specified key. |
177 * Gets the node from the tree, that is associated with the specified key. |
152 * @param tree the UcxAVLTree |
178 * @param tree the UcxAVLTree |
153 * @param key the key |
179 * @param key the key |