| 142 |
142 |
| 143 ```C |
143 ```C |
| 144 #include <cx/array_list.h> |
144 #include <cx/array_list.h> |
| 145 |
145 |
| 146 int cx_array_insert_sorted(CxArray array, |
146 int cx_array_insert_sorted(CxArray array, |
| 147 cx_compare_func cmp_func, const void *element); |
147 const void *element, |
| |
148 cx_compare_func cmp_func); |
| 148 |
149 |
| 149 int cx_array_insert_sorted_array(CxArray array, |
150 int cx_array_insert_sorted_array(CxArray array, |
| 150 cx_compare_func cmp_func, const void *sorted_data, size_t n); |
151 const void *sorted_data, size_t n, |
| |
152 cx_compare_func cmp_func); |
| 151 |
153 |
| 152 int cx_array_insert_sorted_a(const CxAllocator *allocator, |
154 int cx_array_insert_sorted_a(const CxAllocator *allocator, |
| 153 CxArray array, cx_compare_func cmp_func, const void *element); |
155 CxArray array, const void *element, |
| |
156 cx_compare_func cmp_func); |
| 154 |
157 |
| 155 int cx_array_insert_sorted_array_a(const CxAllocator *allocator, |
158 int cx_array_insert_sorted_array_a(const CxAllocator *allocator, |
| 156 CxArray array, cx_compare_func cmp_func, |
159 CxArray array, const void *sorted_data, size_t n, |
| 157 const void *sorted_data, size_t n); |
160 cx_compare_func cmp_func); |
| |
161 |
| |
162 int cx_array_insert_sorted_c(CxArray array, |
| |
163 const void *element, |
| |
164 cx_compare_func2 cmp_func, void *context); |
| |
165 |
| |
166 int cx_array_insert_sorted_array_c(CxArray array, |
| |
167 const void *sorted_data, size_t n, |
| |
168 cx_compare_func2 cmp_func, void *context); |
| |
169 |
| |
170 int cx_array_insert_sorted_ca(const CxAllocator *allocator, |
| |
171 CxArray array, const void *element, |
| |
172 cx_compare_func2 cmp_func, void *context); |
| |
173 |
| |
174 int cx_array_insert_sorted_array_ca(const CxAllocator *allocator, |
| |
175 CxArray array, const void *sorted_data, size_t n, |
| |
176 cx_compare_func2 cmp_func, void *context); |
| 158 ``` |
177 ``` |
| 159 |
178 |
| 160 The above functions are equivalent to `cx_array_insert()` and `cx_array_insert_array()`, |
179 The above functions are equivalent to `cx_array_insert()` and `cx_array_insert_array()`, |
| 161 except that they only work on sorted arrays and insert the element at the correct position with respect to the sort order. |
180 except that they only work on sorted arrays and insert the element at the correct position with respect to the sort order. |
| 162 If either the array or the `sorted_data` is not sorted according to the given `cmp_func`, the behavior is undefined. |
181 If either the array or the `sorted_data` is not sorted according to the given `cmp_func`, the behavior is undefined. |
| 165 |
184 |
| 166 ```C |
185 ```C |
| 167 #include <cx/array_list.h> |
186 #include <cx/array_list.h> |
| 168 |
187 |
| 169 int cx_array_insert_unique(CxArray array, |
188 int cx_array_insert_unique(CxArray array, |
| 170 cx_compare_func cmp_func, const void *element); |
189 const void *element, |
| |
190 cx_compare_func cmp_func); |
| 171 |
191 |
| 172 int cx_array_insert_unique_array(CxArray array, |
192 int cx_array_insert_unique_array(CxArray array, |
| 173 cx_compare_func cmp_func, const void *sorted_data, size_t n); |
193 const void *sorted_data, size_t n, |
| |
194 cx_compare_func cmp_func); |
| 174 |
195 |
| 175 int cx_array_insert_unique_a(const CxAllocator *allocator, |
196 int cx_array_insert_unique_a(const CxAllocator *allocator, |
| 176 CxArray array, cx_compare_func cmp_func, const void *element); |
197 CxArray array, const void *element, |
| |
198 cx_compare_func cmp_func); |
| 177 |
199 |
| 178 int cx_array_insert_unique_array_a(const CxAllocator *allocator, |
200 int cx_array_insert_unique_array_a(const CxAllocator *allocator, |
| 179 CxArray array, cx_compare_func cmp_func, |
201 CxArray array, const void *sorted_data, size_t n, |
| 180 const void *sorted_data, size_t n); |
202 cx_compare_func cmp_func); |
| |
203 |
| |
204 int cx_array_insert_unique_c(CxArray array, |
| |
205 const void *element, |
| |
206 cx_compare_func2 cmp_func, void *context); |
| |
207 |
| |
208 int cx_array_insert_unique_array_c(CxArray array, |
| |
209 const void *sorted_data, size_t n, |
| |
210 cx_compare_func2 cmp_func, void *context); |
| |
211 |
| |
212 int cx_array_insert_unique_ca(const CxAllocator *allocator, |
| |
213 CxArray array, const void *element, |
| |
214 cx_compare_func2 cmp_func, void *context); |
| |
215 |
| |
216 int cx_array_insert_unique_array_ca(const CxAllocator *allocator, |
| |
217 CxArray array, const void *sorted_data, size_t n, |
| |
218 cx_compare_func2 cmp_func, void *context); |
| 181 ``` |
219 ``` |
| 182 |
220 |
| 183 The above functions are similar to the functions for insertion sort, |
221 The above functions are similar to the functions for insertion sort, |
| 184 except that they only insert elements that are not already present in the array. |
222 except that they only insert elements that are not already present in the array. |
| 185 |
223 |