src/cx/linked_list.h

changeset 1605
55b13f583356
parent 1532
313fd460d264
equal deleted inserted replaced
1604:68b75c091028 1605:55b13f583356
85 /** 85 /**
86 * Allocates a linked list for storing elements with @p elem_size bytes each. 86 * Allocates a linked list for storing elements with @p elem_size bytes each.
87 * 87 *
88 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of 88 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
89 * copies of the added elements, and the compare function will be automatically set 89 * copies of the added elements, and the compare function will be automatically set
90 * to cx_cmp_ptr() if none is given. 90 * to cx_cmp_ptr().
91 * 91 *
92 * @param allocator the allocator for allocating the list nodes 92 * @param allocator the allocator for allocating the list nodes
93 * (if @c NULL, the cxDefaultAllocator will be used) 93 * (if @c NULL, the cxDefaultAllocator will be used)
94 * @param comparator the comparator for the elements
95 * (if @c NULL, and the list is not storing pointers, sort and find
96 * functions will not work)
97 * @param elem_size the size of each element in bytes 94 * @param elem_size the size of each element in bytes
98 * @return the created list 95 * @return the created list
99 */ 96 */
100 cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1) 97 cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1)
101 CX_EXPORT CxList *cxLinkedListCreate(const CxAllocator *allocator, 98 CX_EXPORT CxList *cxLinkedListCreate(const CxAllocator *allocator,
102 cx_compare_func comparator, size_t elem_size); 99 size_t elem_size);
103
104 /**
105 * Allocates a linked list for storing elements with @p elem_size bytes each.
106 *
107 * The list will use cxDefaultAllocator and no comparator function. If you want
108 * to call functions that need a comparator, you must either set one immediately
109 * after list creation or use cxLinkedListCreate().
110 *
111 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
112 * copies of the added elements, and the compare function will be automatically set
113 * to cx_cmp_ptr().
114 *
115 * @param elem_size (@c size_t) the size of each element in bytes
116 * @return (@c CxList*) the created list
117 */
118 #define cxLinkedListCreateSimple(elem_size) \
119 cxLinkedListCreate(NULL, NULL, elem_size)
120 100
121 /** 101 /**
122 * Instructs the linked list to reserve extra data in each node. 102 * Instructs the linked list to reserve extra data in each node.
123 * 103 *
124 * The extra data will be aligned and placed behind the element data. 104 * The extra data will be aligned and placed behind the element data.

mercurial