docs/Writerside/topics/linked_list.h.md

changeset 1639
5c3e6477aab4
parent 1618
ef7cab6eb131
equal deleted inserted replaced
1638:14ae6a039af7 1639:5c3e6477aab4
135 void *new_node, cx_compare_func cmp_func); 135 void *new_node, cx_compare_func cmp_func);
136 136
137 void *cx_linked_list_insert_unique_chain(void **begin, void **end, 137 void *cx_linked_list_insert_unique_chain(void **begin, void **end,
138 ptrdiff_t loc_prev, ptrdiff_t loc_next, 138 ptrdiff_t loc_prev, ptrdiff_t loc_next,
139 void *insert_begin, cx_compare_func cmp_func); 139 void *insert_begin, cx_compare_func cmp_func);
140
141 void cx_linked_list_insert_sorted_c(void **begin, void **end,
142 ptrdiff_t loc_prev, ptrdiff_t loc_next,
143 void *new_node, cx_compare_func2 cmp_func, void *context);
144
145 void cx_linked_list_insert_sorted_chain_c(void **begin, void **end,
146 ptrdiff_t loc_prev, ptrdiff_t loc_next,
147 void *insert_begin, cx_compare_func2 cmp_func, void *context);
148
149 int cx_linked_list_insert_unique_c(void **begin, void **end,
150 ptrdiff_t loc_prev, ptrdiff_t loc_next,
151 void *new_node, cx_compare_func2 cmp_func, void *context);
152
153 void *cx_linked_list_insert_unique_chain_c(void **begin, void **end,
154 ptrdiff_t loc_prev, ptrdiff_t loc_next,
155 void *insert_begin, cx_compare_func2 cmp_func, void *context);
140 ``` 156 ```
141 157
142 The above functions can be used to insert one or more elements into a linked list. 158 The above functions can be used to insert one or more elements into a linked list.
143 159
144 The functions `cx_linked_list_add()` and `cx_linked_list_prepend()` add the `new_node` to the beginning, or the end, of the list, respectively. 160 The functions `cx_linked_list_add()` and `cx_linked_list_prepend()` add the `new_node` to the beginning, or the end, of the list, respectively.
165 returns a pointer to a new chain starting with the first node that was not inserted. 181 returns a pointer to a new chain starting with the first node that was not inserted.
166 182
167 > The `cx_linked_list_insert_sorted_chain()` function does not have an `insert_end` argument, because 183 > The `cx_linked_list_insert_sorted_chain()` function does not have an `insert_end` argument, because
168 > it cannot take advantage of simply inserting the entire chain as-is, as the chain might need to be broken 184 > it cannot take advantage of simply inserting the entire chain as-is, as the chain might need to be broken
169 > to maintain the sort order. 185 > to maintain the sort order.
186
187 The functions with the `_c` suffix are equivalent, except that they accept a `cx_compare_func2` with additional `context`.
170 188
171 ## Access and Find 189 ## Access and Find
172 190
173 ```C 191 ```C
174 #include <cx/linked_list.h> 192 #include <cx/linked_list.h>
296 ptrdiff_t loc_advance, ptrdiff_t loc_data, 314 ptrdiff_t loc_advance, ptrdiff_t loc_data,
297 cx_compare_func2 cmp_func, void *context 315 cx_compare_func2 cmp_func, void *context
298 ); 316 );
299 ``` 317 ```
300 318
301 For comparing two linked list, you need to specify where to start, 319 For comparing two linked lists, you need to specify where to start,
302 and the offsets for the pointer to the next node and the data. 320 and the offsets for the pointer to the next node and the data.
303 321
304 In the natural case, `begin_left` and `begin_right` point to the first node of either list, 322 In the natural case, `begin_left` and `begin_right` point to the first node of either list,
305 and `loc_advance` is the offset of the `next` pointer. 323 and `loc_advance` is the offset of the `next` pointer.
306 But it is also possible to start with the _last_ node of both lists and use the `prev` pointer to compare them backwards. 324 But it is also possible to start with the _last_ node of both lists and use the `prev` pointer to compare them backwards.
307 325
308 The `loc_data` offset is used to calculate the pointer that is passed to the `cmp_fnc`. 326 The `loc_data` offset is used to calculate the pointer that is passed to the `cmp_func`.
309 This can either be the offset of a specific field in the struct or simply zero, in which case the pointers to the nodes themselves are passed to the compare function. 327 This can either be the offset of a specific field in the struct or simply zero, in which case the pointers to the nodes themselves are passed to the compare function.
310 328
311 The function `cx_linked_list_compare_c()` allows additional `context` for the compare function. 329 The function `cx_linked_list_compare_c()` allows additional `context` for the compare function.
312 330
313 <seealso> 331 <seealso>

mercurial