ucx
UAP Common Extensions
Loading...
Searching...
No Matches
linked_list.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
38#ifndef UCX_LINKED_LIST_H
39#define UCX_LINKED_LIST_H
40
41#include "common.h"
42#include "list.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
53
68 CxAllocator const *allocator,
69 cx_compare_func comparator,
70 size_t item_size
71);
72
86#define cxLinkedListCreateSimple(item_size) \
87 cxLinkedListCreate(NULL, NULL, item_size)
88
107 void const *start,
108 size_t start_index,
109 ptrdiff_t loc_advance,
110 size_t index
111) __attribute__((__nonnull__));
112
124 void const *start,
125 ptrdiff_t loc_advance,
126 ptrdiff_t loc_data,
127 cx_compare_func cmp_func,
128 void const *elem
129) __attribute__((__nonnull__));
130
143 void const *node,
144 ptrdiff_t loc_prev
145) __attribute__((__nonnull__));
146
159 void const *node,
160 ptrdiff_t loc_next
161) __attribute__((__nonnull__));
162
174 void const *begin,
175 ptrdiff_t loc_next,
176 void const *node
177) __attribute__((__nonnull__));
178
192 void **begin,
193 void **end,
194 ptrdiff_t loc_prev,
195 ptrdiff_t loc_next,
196 void *new_node
197) __attribute__((__nonnull__(5)));
198
212 void **begin,
213 void **end,
214 ptrdiff_t loc_prev,
215 ptrdiff_t loc_next,
216 void *new_node
217) __attribute__((__nonnull__(5)));
218
228 void *left,
229 void *right,
230 ptrdiff_t loc_prev,
231 ptrdiff_t loc_next
232) __attribute__((__nonnull__));
233
245 void *left,
246 void *right,
247 ptrdiff_t loc_prev,
248 ptrdiff_t loc_next
249) __attribute__((__nonnull__));
250
266 void **begin,
267 void **end,
268 ptrdiff_t loc_prev,
269 ptrdiff_t loc_next,
270 void *node,
271 void *new_node
272) __attribute__((__nonnull__(6)));
273
295 void **begin,
296 void **end,
297 ptrdiff_t loc_prev,
298 ptrdiff_t loc_next,
299 void *node,
300 void *insert_begin,
301 void *insert_end
302) __attribute__((__nonnull__(6)));
303
324 void **begin,
325 void **end,
326 ptrdiff_t loc_prev,
327 ptrdiff_t loc_next,
328 void *node
329) __attribute__((__nonnull__(5)));
330
331
339 void const *node,
340 ptrdiff_t loc_next
341);
342
366 void **begin,
367 void **end,
368 ptrdiff_t loc_prev,
369 ptrdiff_t loc_next,
370 ptrdiff_t loc_data,
371 cx_compare_func cmp_func
372) __attribute__((__nonnull__(1, 6)));
373
374
389 void const *begin_left,
390 void const *begin_right,
391 ptrdiff_t loc_advance,
392 ptrdiff_t loc_data,
393 cx_compare_func cmp_func
394) __attribute__((__nonnull__(5)));
395
405 void **begin,
406 void **end,
407 ptrdiff_t loc_prev,
408 ptrdiff_t loc_next
409) __attribute__((__nonnull__(1)));
410
411#ifdef __cplusplus
412} // extern "C"
413#endif
414
415#endif // UCX_LINKED_LIST_H
int(* cx_compare_func)(void const *left, void const *right)
A comparator function comparing two collection elements.
Definition: collection.h:55
Common definitions and feature checks.
#define __attribute__(x)
Removes GNU C attributes where they are not supported.
Definition: common.h:127
bool CX_DISABLE_LINKED_LIST_SWAP_SBO
Set this flag to true, if you want to disable the use of SBO for linked list swap operations.
void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node)
Prepends a new node to a linked list.
void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Reverses the order of the nodes in a linked list.
void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, cx_compare_func cmp_func)
Sorts a linked list based on a comparison function.
ssize_t cx_linked_list_find(void const *start, ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func cmp_func, void const *elem)
Finds the index of an element within a linked list.
void cx_linked_list_unlink(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Unlinks two nodes.
void * cx_linked_list_last(void const *node, ptrdiff_t loc_next)
Finds the last node in a linked list.
void * cx_linked_list_at(void const *start, size_t start_index, ptrdiff_t loc_advance, size_t index)
Finds the node at a certain index.
CxList * cxLinkedListCreate(CxAllocator const *allocator, cx_compare_func comparator, size_t item_size)
Allocates a linked list for storing elements with item_size bytes each.
int cx_linked_list_compare(void const *begin_left, void const *begin_right, ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func cmp_func)
Compares two lists element wise.
void * cx_linked_list_first(void const *node, ptrdiff_t loc_prev)
Finds the first node in a linked list.
void cx_linked_list_remove(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node)
Removes a node from the linked list.
void cx_linked_list_insert_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *insert_begin, void *insert_end)
Inserts a chain of nodes after a given node of a linked list.
size_t cx_linked_list_size(void const *node, ptrdiff_t loc_next)
Determines the size of a linked list starting with node.
void * cx_linked_list_prev(void const *begin, ptrdiff_t loc_next, void const *node)
Finds the predecessor of a node in case it is not linked.
void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node)
Adds a new node to a linked list.
void cx_linked_list_link(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Links two nodes.
void cx_linked_list_insert(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *new_node)
Inserts a new node after a given node of a linked list.
Interface for list implementations.
Structure holding the data for an allocator.
Definition: allocator.h:86
Structure for holding the base data of a list.
Definition: list.h:55