src/cx/list.h

changeset 1418
5e1579713bcf
parent 1349
b1696d0d598b
child 1419
e46406fd1b3c
equal deleted inserted replaced
1417:b97faf8b7ab7 1418:5e1579713bcf
37 #define UCX_LIST_H 37 #define UCX_LIST_H
38 38
39 #include "common.h" 39 #include "common.h"
40 #include "collection.h" 40 #include "collection.h"
41 41
42 #include <assert.h>
43
42 #ifdef __cplusplus 44 #ifdef __cplusplus
43 extern "C" { 45 extern "C" {
44 #endif 46 #endif
45 47
46 /** 48 /**
479 cx_attr_nonnull 481 cx_attr_nonnull
480 static inline int cxListInsertSorted( 482 static inline int cxListInsertSorted(
481 CxList *list, 483 CxList *list,
482 const void *elem 484 const void *elem
483 ) { 485 ) {
484 list->collection.sorted = true; // guaranteed by definition 486 assert(list->collection.sorted || list->collection.size == 0);
487 list->collection.sorted = true;
485 const void *data = list->collection.store_pointer ? &elem : elem; 488 const void *data = list->collection.store_pointer ? &elem : elem;
486 return list->cl->insert_sorted(list, data, 1) == 0; 489 return list->cl->insert_sorted(list, data, 1) == 0;
487 } 490 }
488 491
489 /** 492 /**
539 static inline size_t cxListInsertSortedArray( 542 static inline size_t cxListInsertSortedArray(
540 CxList *list, 543 CxList *list,
541 const void *array, 544 const void *array,
542 size_t n 545 size_t n
543 ) { 546 ) {
544 list->collection.sorted = true; // guaranteed by definition 547 assert(list->collection.sorted || list->collection.size == 0);
548 list->collection.sorted = true;
545 return list->cl->insert_sorted(list, array, n); 549 return list->cl->insert_sorted(list, array, n);
546 } 550 }
547 551
548 /** 552 /**
549 * Inserts an element after the current location of the specified iterator. 553 * Inserts an element after the current location of the specified iterator.
777 * 781 *
778 * @param list the list 782 * @param list the list
779 */ 783 */
780 cx_attr_nonnull 784 cx_attr_nonnull
781 static inline void cxListClear(CxList *list) { 785 static inline void cxListClear(CxList *list) {
786 list->cl->clear(list);
782 list->collection.sorted = true; // empty lists are always sorted 787 list->collection.sorted = true; // empty lists are always sorted
783 list->cl->clear(list);
784 } 788 }
785 789
786 /** 790 /**
787 * Swaps two items in the list. 791 * Swaps two items in the list.
788 * 792 *

mercurial