113 void *new_node, cx_compare_func cmp_func); |
113 void *new_node, cx_compare_func cmp_func); |
114 |
114 |
115 void cx_linked_list_insert_sorted_chain(void **begin, void **end, |
115 void cx_linked_list_insert_sorted_chain(void **begin, void **end, |
116 ptrdiff_t loc_prev, ptrdiff_t loc_next, |
116 ptrdiff_t loc_prev, ptrdiff_t loc_next, |
117 void *insert_begin, cx_compare_func cmp_func); |
117 void *insert_begin, cx_compare_func cmp_func); |
|
118 |
|
119 int cx_linked_list_insert_unique(void **begin, void **end, |
|
120 ptrdiff_t loc_prev, ptrdiff_t loc_next, |
|
121 void *new_node, cx_compare_func cmp_func); |
|
122 |
|
123 void *cx_linked_list_insert_unique_chain(void **begin, void **end, |
|
124 ptrdiff_t loc_prev, ptrdiff_t loc_next, |
|
125 void *insert_begin, cx_compare_func cmp_func); |
118 ``` |
126 ``` |
119 |
127 |
120 The above functions can be used to insert one or more elements into a linked list. |
128 The above functions can be used to insert one or more elements into a linked list. |
121 |
129 |
122 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. |
130 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. |
133 or `end` must be non-`NULL` and `loc_prev` must be available to determine the start of the list. |
141 or `end` must be non-`NULL` and `loc_prev` must be available to determine the start of the list. |
134 |
142 |
135 The functions `cx_linked_list_insert_sorted()` and `cx_linked_list_insert_sorted_chain()` are equivalent, |
143 The functions `cx_linked_list_insert_sorted()` and `cx_linked_list_insert_sorted_chain()` are equivalent, |
136 except that `begin` and `loc_next` are always required, and the target list must already be sorted. |
144 except that `begin` and `loc_next` are always required, and the target list must already be sorted. |
137 The order is determined by the `cmp_func` to which the pointers to the nodes are passed. |
145 The order is determined by the `cmp_func` to which the pointers to the nodes are passed. |
|
146 |
|
147 The functions `cx_linked_list_insert_unique()` and `cx_linked_list_insert_unique_chain()` are similar to |
|
148 `cx_linked_list_insert_sorted()` and `cx_linked_list_insert_sorted_chain()`, except that they only insert the node |
|
149 if it is not already contained in the list. |
|
150 When a duplicate is found, `cx_linked_list_insert_unique()` returns non-zero and `cx_linked_list_insert_unique_chain()` |
|
151 returns a pointer to a new chain starting with the first node that was not inserted. |
138 |
152 |
139 > The `cx_linked_list_insert_sorted_chain()` function does not have an `insert_end` argument, because |
153 > The `cx_linked_list_insert_sorted_chain()` function does not have an `insert_end` argument, because |
140 > it cannot take advantage of simply inserting the entire chain as-is, as the chain might need to be broken |
154 > it cannot take advantage of simply inserting the entire chain as-is, as the chain might need to be broken |
141 > to maintain the sort order. |
155 > to maintain the sort order. |
142 |
156 |