src/cx/linked_list.h

changeset 468
75ae1dccd101
parent 467
95e42a963520
child 473
1bd4b8c28722
equal deleted inserted replaced
467:95e42a963520 468:75ae1dccd101
120 * @param loc_next the location of a \c next pointer within your node struct (negative if your struct does not have one) 120 * @param loc_next the location of a \c next pointer within your node struct (negative if your struct does not have one)
121 * @param new_node a pointer to the node that shall be appended 121 * @param new_node a pointer to the node that shall be appended
122 */ 122 */
123 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); 123 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node);
124 124
125 /**
126 * Determines the size of a linked list starting with \p node.
127 * @param node the first node
128 * @param loc_next the location of the \c next pointer within the node struct
129 * @return the size of the list or zero if \p node is \c NULL
130 */
131 size_t cx_linked_list_size(void *node, ptrdiff_t loc_next);
132
133 /**
134 * Sorts a linked list based on a comparison function.
135 *
136 * This function can work with linked lists of the following structures:
137 * \code
138 * typedef struct node node;
139 * struct node {
140 * node* prev;
141 * node* next;
142 * my_payload data; // in this case set follow_ptr = 0
143 * }
144 *
145 * typedef struct ptr_node ptr_node;
146 * struct ptr_node {
147 * ptr_node* prev;
148 * ptr_node* next;
149 * my_payload* data; // in this case set follow_ptr = 1
150 * }
151 * \endcode
152 *
153 * @param begin a pointer to the begin node pointer (required)
154 * @param end a pointer to the end node pointer (optional)
155 * @param loc_prev the location of a \c prev pointer within your node struct (negative if not present)
156 * @param loc_next the location of a \c next pointer within your node struct (required)
157 * @param loc_data the location of the \c data pointer within your node struct
158 * @param follow_ptr \c false if the pointer denoted by \p loc_data shall be passed to the \p cmp_func.
159 * If \c true, the data at \p loc_data is dereferenced, assuming to be a pointer, and then passed to \p cmp_func.
160 * @param cmp_func the compare function defining the sort order
161 */
162 void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next,
163 ptrdiff_t loc_data, int follow_ptr, CxListComparator cmp_func);
164
125 #ifdef __cplusplus 165 #ifdef __cplusplus
126 } /* extern "C" */ 166 } /* extern "C" */
127 #endif 167 #endif
128 168
129 #endif /* UCX_LINKED_LIST_H */ 169 #endif /* UCX_LINKED_LIST_H */

mercurial