ucx/list.h

changeset 225
a1a068c2c4ef
parent 220
1f57f196d221
child 228
9f385abc72fb
equal deleted inserted replaced
224:f9ba63fc6a80 225:a1a068c2c4ef
1 /* 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * 3 *
4 * Copyright 2015 Olaf Wintermann. All rights reserved. 4 * Copyright 2016 Olaf Wintermann. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
100 * @return a pointer to the copy 100 * @return a pointer to the copy
101 */ 101 */
102 UcxList *ucx_list_clone(UcxList *list, copy_func cpyfnc, void* data); 102 UcxList *ucx_list_clone(UcxList *list, copy_func cpyfnc, void* data);
103 103
104 /** 104 /**
105 * Creates an element-wise copy of a list using an UcxAllocator. 105 * Creates an element-wise copy of a list using a UcxAllocator.
106 * 106 *
107 * See ucx_list_clone() for details. 107 * See ucx_list_clone() for details.
108 * 108 *
109 * Keep in mind, that you might want to pass the allocator as an (part of the) 109 * You might want to pass the allocator via the <code>data</code> parameter,
110 * argument for the <code>data</code> parameter, if you want the copy_func() to 110 * to access it within the copy function for making deep copies.
111 * make use of the allocator.
112 * 111 *
113 * @param allocator the allocator to use 112 * @param allocator the allocator to use
114 * @param list the list to copy 113 * @param list the list to copy
115 * @param cpyfnc a pointer to the function that shall copy an element (may be 114 * @param cpyfnc a pointer to the function that shall copy an element (may be
116 * <code>NULL</code>) 115 * <code>NULL</code>)
156 * @see ucx_list_free_contents() 155 * @see ucx_list_free_contents()
157 */ 156 */
158 void ucx_list_free(UcxList *list); 157 void ucx_list_free(UcxList *list);
159 158
160 /** 159 /**
161 * Destroys the entire list using an UcxAllocator. 160 * Destroys the entire list using a UcxAllocator.
162 * 161 *
163 * See ucx_list_free() for details. 162 * See ucx_list_free() for details.
164 * 163 *
165 * @param allocator the allocator to use 164 * @param allocator the allocator to use
166 * @param list the list to free 165 * @param list the list to free
195 * the newly created list otherwise 194 * the newly created list otherwise
196 */ 195 */
197 UcxList *ucx_list_append(UcxList *list, void *data); 196 UcxList *ucx_list_append(UcxList *list, void *data);
198 197
199 /** 198 /**
200 * Inserts an element at the end of the list using an UcxAllocator. 199 * Inserts an element at the end of the list using a UcxAllocator.
201 * 200 *
202 * See ucx_list_append() for details. 201 * See ucx_list_append() for details.
203 * 202 *
204 * @param allocator the allocator to use 203 * @param allocator the allocator to use
205 * @param list the list where to append the data, or <code>NULL</code> to 204 * @param list the list where to append the data, or <code>NULL</code> to
226 * @return a pointer to the new list head 225 * @return a pointer to the new list head
227 */ 226 */
228 UcxList *ucx_list_prepend(UcxList *list, void *data); 227 UcxList *ucx_list_prepend(UcxList *list, void *data);
229 228
230 /** 229 /**
231 * Inserts an element at the beginning of the list using an UcxAllocator. 230 * Inserts an element at the beginning of the list using a UcxAllocator.
232 * 231 *
233 * See ucx_list_prepend() for details. 232 * See ucx_list_prepend() for details.
234 * 233 *
235 * @param allocator the allocator to use 234 * @param allocator the allocator to use
236 * @param list the list where to insert the data or <code>NULL</code> to create 235 * @param list the list where to insert the data or <code>NULL</code> to create
341 * @see ucx_list_find() 340 * @see ucx_list_find()
342 */ 341 */
343 int ucx_list_contains(UcxList *list, void *elem, cmp_func cmpfnc, void *data); 342 int ucx_list_contains(UcxList *list, void *elem, cmp_func cmpfnc, void *data);
344 343
345 /** 344 /**
346 * Sorts an UcxList with natural merge sort. 345 * Sorts a UcxList with natural merge sort.
347 * 346 *
348 * This function uses O(n) additional temporary memory for merge operations 347 * This function uses O(n) additional temporary memory for merge operations
349 * that is automatically freed after each merge. 348 * that is automatically freed after each merge.
350 * 349 *
351 * As the head of the list might change, you <b>MUST</b> call this function 350 * As the head of the list might change, you <b>MUST</b> call this function
371 * is now empty 370 * is now empty
372 */ 371 */
373 UcxList *ucx_list_remove(UcxList *list, UcxList *element); 372 UcxList *ucx_list_remove(UcxList *list, UcxList *element);
374 373
375 /** 374 /**
376 * Removes an element from the list using an UcxAllocator. 375 * Removes an element from the list using a UcxAllocator.
377 * 376 *
378 * See ucx_list_remove() for details. 377 * See ucx_list_remove() for details.
379 * 378 *
380 * @param allocator the allocator to use 379 * @param allocator the allocator to use
381 * @param list the list from which the element shall be removed 380 * @param list the list from which the element shall be removed

mercurial