| 278 * |
278 * |
| 279 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
279 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 280 * |
280 * |
| 281 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
281 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 282 * @param array the name of the array where the element shall be added |
282 * @param array the name of the array where the element shall be added |
| 283 * @param element (@c void*) a pointer to the element that shall be added |
283 * @param element the element that shall be added |
| 284 * @retval zero success |
284 * @retval zero success |
| 285 * @retval non-zero a re-allocation was necessary but failed |
285 * @retval non-zero a re-allocation was necessary but failed |
| 286 */ |
286 */ |
| 287 #define cx_array_add_a(allocator, array, element) \ |
287 #define cx_array_add_a(allocator, array, element) \ |
| 288 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, element, 1) |
288 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, (void*)&(element), 1) |
| 289 |
289 |
| 290 /** |
290 /** |
| 291 * Appends an element to an array. |
291 * Appends an element to an array. |
| 292 * |
292 * |
| 293 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
293 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 306 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
306 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 307 * |
307 * |
| 308 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
308 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 309 * @param array the name of the array where the element shall be inserted |
309 * @param array the name of the array where the element shall be inserted |
| 310 * @param index (@c size_t) the index where to insert the @p element |
310 * @param index (@c size_t) the index where to insert the @p element |
| 311 * @param element (@c void*) a pointer to the element that shall be inserted |
311 * @param element the element that shall be inserted |
| 312 * @retval zero success |
312 * @retval zero success |
| 313 * @retval non-zero a re-allocation was necessary but failed |
313 * @retval non-zero a re-allocation was necessary but failed |
| 314 */ |
314 */ |
| 315 #define cx_array_insert_a(allocator, array, index, element) \ |
315 #define cx_array_insert_a(allocator, array, index, element) \ |
| 316 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, element, 1) |
316 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, (void*)&(element), 1) |
| 317 |
317 |
| 318 /** |
318 /** |
| 319 * Inserts an element into an array. |
319 * Inserts an element into an array. |
| 320 * |
320 * |
| 321 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
321 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 416 * |
416 * |
| 417 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
417 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 418 * |
418 * |
| 419 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
419 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 420 * @param array the name of the array where the elements shall be inserted |
420 * @param array the name of the array where the elements shall be inserted |
| 421 * @param element (@c void*) a pointer to element that shall be inserted |
421 * @param element the element that shall be inserted |
| 422 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
422 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 423 * @retval zero success |
423 * @retval zero success |
| 424 * @retval non-zero a re-allocation was necessary but failed |
424 * @retval non-zero a re-allocation was necessary but failed |
| 425 */ |
425 */ |
| 426 #define cx_array_insert_sorted_a(allocator, array, element, cmp_func) \ |
426 #define cx_array_insert_sorted_a(allocator, array, element, cmp_func) \ |
| 427 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), element, 1, cmp_func, true) |
427 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, true) |
| 428 |
428 |
| 429 /** |
429 /** |
| 430 * Inserts an element into a sorted array. |
430 * Inserts an element into a sorted array. |
| 431 * |
431 * |
| 432 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
432 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 433 * |
433 * |
| 434 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
434 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 435 * |
435 * |
| 436 * @param array the name of the array where the elements shall be inserted |
436 * @param array the name of the array where the elements shall be inserted |
| 437 * @param element (@c void*) a pointer to element that shall be inserted |
437 * @param element the element that shall be inserted |
| 438 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
438 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 439 * @retval zero success |
439 * @retval zero success |
| 440 * @retval non-zero a re-allocation was necessary but failed |
440 * @retval non-zero a re-allocation was necessary but failed |
| 441 */ |
441 */ |
| 442 #define cx_array_insert_sorted(array, element, cmp_func) \ |
442 #define cx_array_insert_sorted(array, element, cmp_func) \ |
| 484 * |
484 * |
| 485 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
485 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 486 * |
486 * |
| 487 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
487 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 488 * @param array the name of the array where the elements shall be inserted |
488 * @param array the name of the array where the elements shall be inserted |
| 489 * @param element (@c void*) a pointer to element that shall be inserted |
489 * @param element the element that shall be inserted |
| 490 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
490 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 491 * @retval zero success |
491 * @retval zero success |
| 492 * @retval non-zero a re-allocation was necessary but failed |
492 * @retval non-zero a re-allocation was necessary but failed |
| 493 */ |
493 */ |
| 494 #define cx_array_insert_unique_a(allocator, array, element, cmp_func) \ |
494 #define cx_array_insert_unique_a(allocator, array, element, cmp_func) \ |
| 495 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), element, 1, cmp_func, false) |
495 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, false) |
| 496 |
496 |
| 497 /** |
497 /** |
| 498 * Inserts an element into a sorted array if it is not already contained. |
498 * Inserts an element into a sorted array if it is not already contained. |
| 499 * |
499 * |
| 500 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
500 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 501 * |
501 * |
| 502 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
502 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 503 * |
503 * |
| 504 * @param array the name of the array where the elements shall be inserted |
504 * @param array the name of the array where the elements shall be inserted |
| 505 * @param element (@c void*) a pointer to element that shall be inserted |
505 * @param element the element that shall be inserted |
| 506 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
506 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 507 * @retval zero success |
507 * @retval zero success |
| 508 * @retval non-zero a re-allocation was necessary but failed |
508 * @retval non-zero a re-allocation was necessary but failed |
| 509 */ |
509 */ |
| 510 #define cx_array_insert_unique(array, element, cmp_func) \ |
510 #define cx_array_insert_unique(array, element, cmp_func) \ |
| 573 * |
573 * |
| 574 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
574 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 575 * |
575 * |
| 576 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
576 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 577 * @param array the name of the array where the elements shall be inserted |
577 * @param array the name of the array where the elements shall be inserted |
| 578 * @param element (@c void*) a pointer to element that shall be inserted |
578 * @param element the element that shall be inserted |
| 579 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
579 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
| 580 * @param context (@c void*) additional context for the compare function |
580 * @param context (@c void*) additional context for the compare function |
| 581 * @retval zero success |
581 * @retval zero success |
| 582 * @retval non-zero a re-allocation was necessary but failed |
582 * @retval non-zero a re-allocation was necessary but failed |
| 583 */ |
583 */ |
| 584 #define cx_array_insert_sorted_ca(allocator, array, element, cmp_func) \ |
584 #define cx_array_insert_sorted_ca(allocator, array, element, cmp_func) \ |
| 585 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), element, 1, cmp_func, context, true) |
585 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, true) |
| 586 |
586 |
| 587 /** |
587 /** |
| 588 * Inserts an element into a sorted array. |
588 * Inserts an element into a sorted array. |
| 589 * |
589 * |
| 590 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
590 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 591 * |
591 * |
| 592 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
592 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 593 * |
593 * |
| 594 * @param array the name of the array where the elements shall be inserted |
594 * @param array the name of the array where the elements shall be inserted |
| 595 * @param element (@c void*) a pointer to element that shall be inserted |
595 * @param element the element that shall be inserted |
| 596 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
596 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
| 597 * @param context (@c void*) additional context for the compare function |
597 * @param context (@c void*) additional context for the compare function |
| 598 * @retval zero success |
598 * @retval zero success |
| 599 * @retval non-zero a re-allocation was necessary but failed |
599 * @retval non-zero a re-allocation was necessary but failed |
| 600 */ |
600 */ |
| 645 * |
645 * |
| 646 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
646 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 647 * |
647 * |
| 648 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
648 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 649 * @param array the name of the array where the elements shall be inserted |
649 * @param array the name of the array where the elements shall be inserted |
| 650 * @param element (@c void*) a pointer to element that shall be inserted |
650 * @param element the element that shall be inserted |
| 651 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
651 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
| 652 * @param context (@c void*) additional context for the compare function |
652 * @param context (@c void*) additional context for the compare function |
| 653 * @retval zero success |
653 * @retval zero success |
| 654 * @retval non-zero a re-allocation was necessary but failed |
654 * @retval non-zero a re-allocation was necessary but failed |
| 655 */ |
655 */ |
| 656 #define cx_array_insert_unique_ca(allocator, array, element, cmp_func, context) \ |
656 #define cx_array_insert_unique_ca(allocator, array, element, cmp_func, context) \ |
| 657 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), element, 1, cmp_func, context, false) |
657 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, false) |
| 658 |
658 |
| 659 /** |
659 /** |
| 660 * Inserts an element into a sorted array if it is not already contained. |
660 * Inserts an element into a sorted array if it is not already contained. |
| 661 * |
661 * |
| 662 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
662 * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 663 * |
663 * |
| 664 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
664 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 665 * |
665 * |
| 666 * @param array the name of the array where the elements shall be inserted |
666 * @param array the name of the array where the elements shall be inserted |
| 667 * @param element (@c void*) a pointer to element that shall be inserted |
667 * @param element the element that shall be inserted |
| 668 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
668 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
| 669 * @param context (@c void*) additional context for the compare function |
669 * @param context (@c void*) additional context for the compare function |
| 670 * @retval zero success |
670 * @retval zero success |
| 671 * @retval non-zero a re-allocation was necessary but failed |
671 * @retval non-zero a re-allocation was necessary but failed |
| 672 */ |
672 */ |