| 424 #define cx_array_add_sorted(target, size, capacity, elem_size, elem, cmp_func, reallocator) \ |
424 #define cx_array_add_sorted(target, size, capacity, elem_size, elem, cmp_func, reallocator) \ |
| 425 cx_array_insert_sorted((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator) |
425 cx_array_insert_sorted((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator) |
| 426 |
426 |
| 427 /** |
427 /** |
| 428 * Convenience macro for cx_array_add_sorted() with a default |
428 * Convenience macro for cx_array_add_sorted() with a default |
| 429 * layout and the default reallocator. |
429 * layout and the specified reallocator. |
| 430 * |
430 * |
| |
431 * @param reallocator the array reallocator to use |
| 431 * @param array the name of the array (NOT a pointer to the array) |
432 * @param array the name of the array (NOT a pointer to the array) |
| 432 * @param elem the element to add (NOT a pointer, address is automatically taken) |
433 * @param elem the element to add (NOT a pointer, address is automatically taken) |
| 433 * @param cmp_func the compare function for the elements |
434 * @param cmp_func the compare function for the elements |
| 434 * @return zero on success, non-zero on failure |
435 * @return zero on success, non-zero on failure |
| 435 * @see CX_ARRAY_DECLARE() |
436 * @see CX_ARRAY_DECLARE() |
| |
437 * @see cx_array_simple_add_sorted() |
| |
438 */ |
| |
439 #define cx_array_simple_add_sorted_a(reallocator, array, elem, cmp_func) \ |
| |
440 cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \ |
| |
441 sizeof((array)[0]), &(elem), cmp_func, reallocator) |
| |
442 |
| |
443 /** |
| |
444 * Convenience macro for cx_array_add_sorted() with a default |
| |
445 * layout and the default reallocator. |
| |
446 * |
| |
447 * @param array the name of the array (NOT a pointer to the array) |
| |
448 * @param elem the element to add (NOT a pointer, address is automatically taken) |
| |
449 * @param cmp_func the compare function for the elements |
| |
450 * @return zero on success, non-zero on failure |
| |
451 * @see CX_ARRAY_DECLARE() |
| |
452 * @see cx_array_simple_add_sorted_a() |
| 436 */ |
453 */ |
| 437 #define cx_array_simple_add_sorted(array, elem, cmp_func) \ |
454 #define cx_array_simple_add_sorted(array, elem, cmp_func) \ |
| 438 cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \ |
455 cx_array_simple_add_sorted_a(cx_array_default_reallocator, array, elem, cmp_func) |
| 439 sizeof((array)[0]), &(elem), cmp_func, cx_array_default_reallocator) |
|
| 440 |
456 |
| 441 /** |
457 /** |
| 442 * Convenience macro for cx_array_insert_sorted() with a default |
458 * Convenience macro for cx_array_insert_sorted() with a default |
| 443 * layout and the default reallocator. |
459 * layout and the specified reallocator. |
| 444 * |
460 * |
| |
461 * @param reallocator the array reallocator to use |
| 445 * @param array the name of the array (NOT a pointer to the array) |
462 * @param array the name of the array (NOT a pointer to the array) |
| 446 * @param src pointer to the source array |
463 * @param src pointer to the source array |
| 447 * @param n number of elements in the source array |
464 * @param n number of elements in the source array |
| 448 * @param cmp_func the compare function for the elements |
465 * @param cmp_func the compare function for the elements |
| 449 * @return zero on success, non-zero on failure |
466 * @return zero on success, non-zero on failure |
| 450 * @see CX_ARRAY_DECLARE() |
467 * @see CX_ARRAY_DECLARE() |
| |
468 * @see cx_array_simple_insert_sorted() |
| |
469 */ |
| |
470 #define cx_array_simple_insert_sorted_a(reallocator, array, src, n, cmp_func) \ |
| |
471 cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \ |
| |
472 cmp_func, src, sizeof((array)[0]), n, reallocator) |
| |
473 |
| |
474 /** |
| |
475 * Convenience macro for cx_array_insert_sorted() with a default |
| |
476 * layout and the default reallocator. |
| |
477 * |
| |
478 * @param array the name of the array (NOT a pointer to the array) |
| |
479 * @param src pointer to the source array |
| |
480 * @param n number of elements in the source array |
| |
481 * @param cmp_func the compare function for the elements |
| |
482 * @return zero on success, non-zero on failure |
| |
483 * @see CX_ARRAY_DECLARE() |
| |
484 * @see cx_array_simple_insert_sorted_a() |
| 451 */ |
485 */ |
| 452 #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \ |
486 #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \ |
| 453 cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \ |
487 cx_array_simple_insert_sorted_a(cx_array_default_reallocator, array, src, n, cmp_func) |
| 454 cmp_func, src, sizeof((array)[0]), n, cx_array_default_reallocator) |
|
| 455 |
|
| 456 |
488 |
| 457 /** |
489 /** |
| 458 * Searches the largest lower bound in a sorted array. |
490 * Searches the largest lower bound in a sorted array. |
| 459 * |
491 * |
| 460 * In other words, this function returns the index of the largest element |
492 * In other words, this function returns the index of the largest element |