228 return ((intmax_t)a)-((intmax_t)b); |
228 return ((intmax_t)a)-((intmax_t)b); |
229 } |
229 } |
230 |
230 |
231 UCX_TEST(test_ucx_avl_find) { |
231 UCX_TEST(test_ucx_avl_find) { |
232 UcxAVLTree *tree = ucx_avl_new(ucx_cmp_ptr); |
232 UcxAVLTree *tree = ucx_avl_new(ucx_cmp_ptr); |
|
233 UcxAVLTree *tree2 = ucx_avl_new(ucx_cmp_ptr); |
|
234 UcxAVLTree *tree3 = ucx_avl_new(ucx_cmp_ptr); |
233 |
235 |
234 size_t len = 12; |
236 size_t len = 12; |
235 int val[] = {10, 15, 3, 4, -30, 20, 14, -11, 12, -5, 1, 13}; |
237 int val[] = {10, 15, 3, 4, -30, 20, 14, -11, 12, -5, 1, 13}; |
236 |
238 |
237 for (size_t i = 0 ; i < len ; i++) { |
239 for (size_t i = 0 ; i < len ; i++) { |
276 ret = ucx_avl_find(tree,(intptr_t)7, dist_int, UCX_AVL_FIND_LOWER_BOUNDED); |
278 ret = ucx_avl_find(tree,(intptr_t)7, dist_int, UCX_AVL_FIND_LOWER_BOUNDED); |
277 UCX_TEST_ASSERT(ret && *((int*)ret) == 10, "AVL find LB failed"); |
279 UCX_TEST_ASSERT(ret && *((int*)ret) == 10, "AVL find LB failed"); |
278 ret = ucx_avl_find(tree,(intptr_t)7, dist_int, UCX_AVL_FIND_UPPER_BOUNDED); |
280 ret = ucx_avl_find(tree,(intptr_t)7, dist_int, UCX_AVL_FIND_UPPER_BOUNDED); |
279 UCX_TEST_ASSERT(ret && *((int*)ret) == 4, "AVL find UB failed"); |
281 UCX_TEST_ASSERT(ret && *((int*)ret) == 4, "AVL find UB failed"); |
280 |
282 |
|
283 int val2[] = { 10, 15 }; |
|
284 ucx_avl_put(tree2, val2[0], &(val2[0])); |
|
285 ucx_avl_put(tree2, val2[1], &(val2[1])); |
|
286 ret = ucx_avl_find(tree2,(intptr_t)11, dist_int, UCX_AVL_FIND_UPPER_BOUNDED); |
|
287 UCX_TEST_ASSERT(ret && *((int*)ret) == 10, "AVL find LB failed"); |
|
288 |
|
289 int val3[] = { 15, 16, 1 }; |
|
290 ucx_avl_put(tree3, val3[0], &(val3[0])); |
|
291 ucx_avl_put(tree3, val3[1], &(val3[1])); |
|
292 ucx_avl_put(tree3, val3[2], &(val3[2])); |
|
293 |
|
294 ret = ucx_avl_find(tree3, (intptr_t)13, dist_int, UCX_AVL_FIND_CLOSEST); |
|
295 UCX_TEST_ASSERT(ret && *((int*)ret) == 15, "AVL find closest failed"); |
|
296 |
281 UCX_TEST_END |
297 UCX_TEST_END |
282 |
298 |
283 ucx_avl_free(tree); |
299 ucx_avl_free(tree); |
|
300 ucx_avl_free(tree2); |
|
301 ucx_avl_free(tree3); |
284 } |
302 } |
285 |
303 |
286 UCX_TEST(test_ucx_avl_traverse) { |
304 UCX_TEST(test_ucx_avl_traverse) { |
287 UcxAVLTree *tree = ucx_avl_new(ucx_cmp_ptr); |
305 UcxAVLTree *tree = ucx_avl_new(ucx_cmp_ptr); |
288 |
306 |