src/cx/list.h

changeset 1424
563033aa998c
parent 1423
9a72258446cd
equal deleted inserted replaced
1423:9a72258446cd 1424:563033aa998c
80 */ 80 */
81 void (*deallocate)(struct cx_list_s *list); 81 void (*deallocate)(struct cx_list_s *list);
82 82
83 /** 83 /**
84 * Member function for inserting a single element. 84 * Member function for inserting a single element.
85 * The data pointer may be @c NULL in which case the function shall only allocate memory. 85 * The data pointer may be @c NULL, in which case the function shall only allocate memory.
86 * Returns a pointer to the allocated memory or @c NULL if allocation fails. 86 * Returns a pointer to the allocated memory or @c NULL if allocation fails.
87 */ 87 */
88 void *(*insert_element)( 88 void *(*insert_element)(
89 struct cx_list_s *list, 89 struct cx_list_s *list,
90 size_t index, 90 size_t index,
192 void (*sort)(struct cx_list_s *list); 192 void (*sort)(struct cx_list_s *list);
193 193
194 /** 194 /**
195 * Optional member function for comparing this list 195 * Optional member function for comparing this list
196 * to another list of the same type. 196 * to another list of the same type.
197 * If set to @c NULL, comparison won't be optimized. 197 * If set to @c NULL, the comparison won't be optimized.
198 */ 198 */
199 int (*compare)( 199 int (*compare)(
200 const struct cx_list_s *list, 200 const struct cx_list_s *list,
201 const struct cx_list_s *other 201 const struct cx_list_s *other
202 ); 202 );
224 /** 224 /**
225 * A shared instance of an empty list. 225 * A shared instance of an empty list.
226 * 226 *
227 * Writing to that list is not allowed. 227 * Writing to that list is not allowed.
228 * 228 *
229 * You can use this is a placeholder for initializing CxList pointers 229 * You can use this as a placeholder for initializing CxList pointers
230 * for which you do not want to reserve memory right from the beginning. 230 * for which you do not want to reserve memory right from the beginning.
231 */ 231 */
232 cx_attr_export 232 cx_attr_export
233 extern CxList *const cxEmptyList; 233 extern CxList *const cxEmptyList;
234 234
338 /** 338 /**
339 * Initializes a list struct. 339 * Initializes a list struct.
340 * 340 *
341 * Only use this function if you are creating your own list implementation. 341 * Only use this function if you are creating your own list implementation.
342 * The purpose of this function is to be called in the initialization code 342 * The purpose of this function is to be called in the initialization code
343 * of your list, to set certain members correctly. 343 * of your list to set certain members correctly.
344 * 344 *
345 * This is particularly important when you want your list to support 345 * This is particularly important when you want your list to support
346 * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list 346 * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list
347 * class accordingly and make sure that you can implement your list as if 347 * class accordingly and make sure that you can implement your list as if
348 * it was only storing objects and the wrapper will automatically enable 348 * it was only storing objects, and the wrapper will automatically enable
349 * the feature of storing pointers. 349 * the feature of storing pointers.
350 * 350 *
351 * @par Example 351 * @par Example
352 * 352 *
353 * @code 353 * @code
425 * This method is more efficient than invoking cxListAdd() multiple times. 425 * This method is more efficient than invoking cxListAdd() multiple times.
426 * 426 *
427 * If there is not enough memory to add all elements, the returned value is 427 * If there is not enough memory to add all elements, the returned value is
428 * less than @p n. 428 * less than @p n.
429 * 429 *
430 * If this list is storing pointers instead of objects @p array is expected to 430 * If this list is storing pointers instead of objects, @p array is expected to
431 * be an array of pointers. 431 * be an array of pointers.
432 * 432 *
433 * @param list the list 433 * @param list the list
434 * @param array a pointer to the elements to add 434 * @param array a pointer to the elements to add
435 * @param n the number of elements to add 435 * @param n the number of elements to add
446 } 446 }
447 447
448 /** 448 /**
449 * Inserts an item at the specified index. 449 * Inserts an item at the specified index.
450 * 450 *
451 * If @p index equals the list @c size, this is effectively cxListAdd(). 451 * If the @p index equals the list @c size, this is effectively cxListAdd().
452 * 452 *
453 * @param list the list 453 * @param list the list
454 * @param index the index the element shall have 454 * @param index the index the element shall have
455 * @param elem a pointer to the element to add 455 * @param elem a pointer to the element to add
456 * @retval zero success 456 * @retval zero success
545 return list->cl->insert_unique(list, data, 1) == 0; 545 return list->cl->insert_unique(list, data, 1) == 0;
546 } 546 }
547 547
548 /** 548 /**
549 * Inserts multiple items to the list at the specified index. 549 * Inserts multiple items to the list at the specified index.
550 * If @p index equals the list size, this is effectively cxListAddArray(). 550 * If the @p index equals the list size, this is effectively cxListAddArray().
551 * 551 *
552 * This method is usually more efficient than invoking cxListInsert() 552 * This method is usually more efficient than invoking cxListInsert()
553 * multiple times. 553 * multiple times.
554 * 554 *
555 * If there is not enough memory to add all elements, the returned value is 555 * If there is not enough memory to add all elements, the returned value is
556 * less than @p n. 556 * less than @p n.
557 * 557 *
558 * If this list is storing pointers instead of objects @p array is expected to 558 * If this list is storing pointers instead of objects, @p array is expected to
559 * be an array of pointers. 559 * be an array of pointers.
560 * 560 *
561 * @param list the list 561 * @param list the list
562 * @param index the index where to add the elements 562 * @param index the index where to add the elements
563 * @param array a pointer to the elements to add 563 * @param array a pointer to the elements to add
582 * because consecutive chunks of sorted data are inserted in one pass. 582 * because consecutive chunks of sorted data are inserted in one pass.
583 * 583 *
584 * If there is not enough memory to add all elements, the returned value is 584 * If there is not enough memory to add all elements, the returned value is
585 * less than @p n. 585 * less than @p n.
586 * 586 *
587 * If this list is storing pointers instead of objects @p array is expected to 587 * If this list is storing pointers instead of objects, @p array is expected to
588 * be an array of pointers. 588 * be an array of pointers.
589 * 589 *
590 * If the list is not sorted already, the behavior is undefined. 590 * If the list is not sorted already, the behavior is undefined.
591 * 591 *
592 * @param list the list 592 * @param list the list
746 * If the list is storing pointers, only the pointer is copied to @p targetbuf. 746 * If the list is storing pointers, only the pointer is copied to @p targetbuf.
747 * 747 *
748 * @param list the list 748 * @param list the list
749 * @param targetbuf a buffer where to copy the element 749 * @param targetbuf a buffer where to copy the element
750 * @retval zero success 750 * @retval zero success
751 * @retval non-zero list is empty 751 * @retval non-zero the list is empty
752 * @see cxListPopFront() 752 * @see cxListPopFront()
753 * @see cxListRemoveAndGetLast() 753 * @see cxListRemoveAndGetLast()
754 */ 754 */
755 cx_attr_nonnull 755 cx_attr_nonnull
756 cx_attr_access_w(2) 756 cx_attr_access_w(2)
771 * If the list is storing pointers, only the pointer is copied to @p targetbuf. 771 * If the list is storing pointers, only the pointer is copied to @p targetbuf.
772 * 772 *
773 * @param list (@c CxList*) the list 773 * @param list (@c CxList*) the list
774 * @param targetbuf (@c void*) a buffer where to copy the element 774 * @param targetbuf (@c void*) a buffer where to copy the element
775 * @retval zero success 775 * @retval zero success
776 * @retval non-zero list is empty 776 * @retval non-zero the list is empty
777 * @see cxListRemoveAndGetFirst() 777 * @see cxListRemoveAndGetFirst()
778 * @see cxListPop() 778 * @see cxListPop()
779 */ 779 */
780 #define cxListPopFront(list, targetbuf) cxListRemoveAndGetFirst((list), (targetbuf)) 780 #define cxListPopFront(list, targetbuf) cxListRemoveAndGetFirst((list), (targetbuf))
781 781
788 * If the list is storing pointers, only the pointer is copied to @p targetbuf. 788 * If the list is storing pointers, only the pointer is copied to @p targetbuf.
789 * 789 *
790 * @param list the list 790 * @param list the list
791 * @param targetbuf a buffer where to copy the element 791 * @param targetbuf a buffer where to copy the element
792 * @retval zero success 792 * @retval zero success
793 * @retval non-zero list is empty 793 * @retval non-zero the list is empty
794 */ 794 */
795 cx_attr_nonnull 795 cx_attr_nonnull
796 cx_attr_access_w(2) 796 cx_attr_access_w(2)
797 static inline int cxListRemoveAndGetLast( 797 static inline int cxListRemoveAndGetLast(
798 CxList *list, 798 CxList *list,
812 * If the list is storing pointers, only the pointer is copied to @p targetbuf. 812 * If the list is storing pointers, only the pointer is copied to @p targetbuf.
813 * 813 *
814 * @param list (@c CxList*) the list 814 * @param list (@c CxList*) the list
815 * @param targetbuf (@c void*) a buffer where to copy the element 815 * @param targetbuf (@c void*) a buffer where to copy the element
816 * @retval zero success 816 * @retval zero success
817 * @retval non-zero list is empty 817 * @retval non-zero the list is empty
818 * @see cxListRemoveAndGetLast() 818 * @see cxListRemoveAndGetLast()
819 * @see cxListPopFront() 819 * @see cxListPopFront()
820 */ 820 */
821 #define cxListPop(list, targetbuf) cxListRemoveAndGetLast((list), (targetbuf)) 821 #define cxListPop(list, targetbuf) cxListRemoveAndGetLast((list), (targetbuf))
822 822
1126 ) { 1126 ) {
1127 return list->cl->find_remove((CxList*)list, elem, false); 1127 return list->cl->find_remove((CxList*)list, elem, false);
1128 } 1128 }
1129 1129
1130 /** 1130 /**
1131 * Checks, if the list contains the specified element. 1131 * Checks if the list contains the specified element.
1132 * 1132 *
1133 * The elements are compared with the list's comparator function. 1133 * The elements are compared with the list's comparator function.
1134 * 1134 *
1135 * @param list the list 1135 * @param list the list
1136 * @param elem the element to find 1136 * @param elem the element to find
1231 /** 1231 /**
1232 * Deallocates the memory of the specified list structure. 1232 * Deallocates the memory of the specified list structure.
1233 * 1233 *
1234 * Also calls the content destructor functions for each element, if specified. 1234 * Also calls the content destructor functions for each element, if specified.
1235 * 1235 *
1236 * @param list the list which shall be freed 1236 * @param list the list that shall be freed
1237 */ 1237 */
1238 cx_attr_export 1238 cx_attr_export
1239 void cxListFree(CxList *list); 1239 void cxListFree(CxList *list);
1240 1240
1241 1241

mercurial