Mon, 26 May 2025 21:02:14 +0200
extend postgresql vfs resource table
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 579 | 29 | * @file list.h |
| 30 | * @brief Interface for list implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #ifndef UCX_LIST_H |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #define UCX_LIST_H |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "common.h" |
| 490 | 40 | #include "collection.h" |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #ifdef __cplusplus |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | extern "C" { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #endif |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | * List class type. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | typedef struct cx_list_class_s cx_list_class; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | * Structure for holding the base data of a list. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | struct cx_list_s { |
| 579 | 55 | /** |
| 56 | * Common members for collections. | |
| 57 | */ | |
| 58 | CX_COLLECTION_BASE; | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | * The list class definition. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | */ |
| 579 | 62 | const cx_list_class *cl; |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | /** |
| 490 | 64 | * The actual implementation in case the list class is delegating. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | */ |
| 579 | 66 | const cx_list_class *climpl; |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | * The class definition for arbitrary lists. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | struct cx_list_class_s { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | * Destructor function. |
| 504 | 75 | * |
| 76 | * Implementations SHALL invoke the content destructor functions if provided | |
| 579 | 77 | * and SHALL deallocate the entire list memory. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | */ |
| 579 | 79 | void (*deallocate)(struct cx_list_s *list); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | /** |
| 504 | 82 | * Member function for inserting a single element. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | */ |
| 490 | 84 | int (*insert_element)( |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | struct cx_list_s *list, |
| 490 | 86 | size_t index, |
| 579 | 87 | const void *data |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | /** |
| 490 | 91 | * Member function for inserting multiple elements. |
| 579 | 92 | * |
| 93 | * @see cx_list_default_insert_array() | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
94 | */ |
| 490 | 95 | size_t (*insert_array)( |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | struct cx_list_s *list, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | size_t index, |
| 579 | 98 | const void *data, |
| 99 | size_t n | |
| 100 | ); | |
| 101 | ||
| 102 | /** | |
| 103 | * Member function for inserting sorted elements into a sorted list. | |
| 104 | * | |
| 105 | * @see cx_list_default_insert_sorted() | |
| 106 | */ | |
| 107 | size_t (*insert_sorted)( | |
| 108 | struct cx_list_s *list, | |
| 109 | const void *sorted_data, | |
| 490 | 110 | size_t n |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | * Member function for inserting an element relative to an iterator position. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | int (*insert_iter)( |
| 579 | 117 | struct cx_iterator_s *iter, |
| 118 | const void *elem, | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | int prepend |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | /** |
| 579 | 123 | * Member function for removing elements. |
| 124 | * | |
| 125 | * Implementations SHALL check if @p targetbuf is set and copy the elements | |
| 126 | * to the buffer without invoking any destructor. | |
| 127 | * When @p targetbuf is not set, the destructors SHALL be invoked. | |
| 128 | * | |
| 129 | * The function SHALL return the actual number of elements removed, which | |
| 130 | * might be lower than @p num when going out of bounds. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | */ |
| 579 | 132 | size_t (*remove)( |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | struct cx_list_s *list, |
| 579 | 134 | size_t index, |
| 135 | size_t num, | |
| 136 | void *targetbuf | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | /** |
| 490 | 140 | * Member function for removing all elements. |
| 141 | */ | |
| 142 | void (*clear)(struct cx_list_s *list); | |
| 143 | ||
| 144 | /** | |
| 145 | * Member function for swapping two elements. | |
| 579 | 146 | * |
| 147 | * @see cx_list_default_swap() | |
| 490 | 148 | */ |
| 149 | int (*swap)( | |
| 150 | struct cx_list_s *list, | |
| 151 | size_t i, | |
| 152 | size_t j | |
| 153 | ); | |
| 154 | ||
| 155 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | * Member function for element lookup. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | void *(*at)( |
| 579 | 159 | const struct cx_list_s *list, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | size_t index |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | /** |
| 579 | 164 | * Member function for finding and optionally removing an element. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | */ |
| 579 | 166 | size_t (*find_remove)( |
| 167 | struct cx_list_s *list, | |
| 168 | const void *elem, | |
| 169 | bool remove | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | /** |
| 579 | 173 | * Member function for sorting the list. |
| 174 | * | |
| 175 | * @see cx_list_default_sort() | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | void (*sort)(struct cx_list_s *list); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | /** |
| 579 | 180 | * Optional member function for comparing this list |
| 181 | * to another list of the same type. | |
| 182 | * If set to @c NULL, comparison won't be optimized. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | */ |
| 579 | 184 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | int (*compare)( |
| 579 | 186 | const struct cx_list_s *list, |
| 187 | const struct cx_list_s *other | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | * Member function for reversing the order of the items. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | void (*reverse)(struct cx_list_s *list); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | /** |
| 490 | 196 | * Member function for returning an iterator pointing to the specified index. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | struct cx_iterator_s (*iterator)( |
| 579 | 199 | const struct cx_list_s *list, |
| 490 | 200 | size_t index, |
| 201 | bool backward | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | /** |
| 579 | 206 | * Default implementation of an array insert. |
| 207 | * | |
| 208 | * This function uses the element insert function for each element of the array. | |
| 209 | * | |
| 210 | * Use this in your own list class if you do not want to implement an optimized | |
| 211 | * version for your list. | |
| 212 | * | |
| 213 | * @param list the list | |
| 214 | * @param index the index where to insert the data | |
| 215 | * @param data a pointer to the array of data to insert | |
| 216 | * @param n the number of elements to insert | |
| 217 | * @return the number of elements actually inserted | |
| 218 | */ | |
| 219 | cx_attr_nonnull | |
| 220 | cx_attr_export | |
| 221 | size_t cx_list_default_insert_array( | |
| 222 | struct cx_list_s *list, | |
| 223 | size_t index, | |
| 224 | const void *data, | |
| 225 | size_t n | |
| 226 | ); | |
| 227 | ||
| 228 | /** | |
| 229 | * Default implementation of a sorted insert. | |
| 230 | * | |
| 231 | * This function uses the array insert function to insert consecutive groups | |
| 232 | * of sorted data. | |
| 233 | * | |
| 234 | * The source data @em must already be sorted wrt. the list's compare function. | |
| 235 | * | |
| 236 | * Use this in your own list class if you do not want to implement an optimized | |
| 237 | * version for your list. | |
| 238 | * | |
| 239 | * @param list the list | |
| 240 | * @param sorted_data a pointer to the array of pre-sorted data to insert | |
| 241 | * @param n the number of elements to insert | |
| 242 | * @return the number of elements actually inserted | |
| 243 | */ | |
| 244 | cx_attr_nonnull | |
| 245 | cx_attr_export | |
| 246 | size_t cx_list_default_insert_sorted( | |
| 247 | struct cx_list_s *list, | |
| 248 | const void *sorted_data, | |
| 249 | size_t n | |
| 250 | ); | |
| 251 | ||
| 252 | /** | |
| 253 | * Default unoptimized sort implementation. | |
| 254 | * | |
| 255 | * This function will copy all data to an array, sort the array with standard | |
| 256 | * qsort, and then copy the data back to the list memory. | |
| 257 | * | |
| 258 | * Use this in your own list class if you do not want to implement an optimized | |
| 259 | * version for your list. | |
| 260 | * | |
| 261 | * @param list the list that shall be sorted | |
| 262 | */ | |
| 263 | cx_attr_nonnull | |
| 264 | cx_attr_export | |
| 265 | void cx_list_default_sort(struct cx_list_s *list); | |
| 266 | ||
| 267 | /** | |
| 268 | * Default unoptimized swap implementation. | |
| 269 | * | |
| 270 | * Use this in your own list class if you do not want to implement an optimized | |
| 271 | * version for your list. | |
| 272 | * | |
| 273 | * @param list the list in which to swap | |
| 274 | * @param i index of one element | |
| 275 | * @param j index of the other element | |
| 276 | * @retval zero success | |
| 277 | * @retval non-zero when indices are out of bounds or memory | |
| 278 | * allocation for the temporary buffer fails | |
| 279 | */ | |
| 280 | cx_attr_nonnull | |
| 281 | cx_attr_export | |
| 282 | int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j); | |
| 283 | ||
| 284 | /** | |
| 285 | * Initializes a list struct. | |
| 286 | * | |
| 287 | * Only use this function if you are creating your own list implementation. | |
| 288 | * The purpose of this function is to be called in the initialization code | |
| 289 | * of your list, to set certain members correctly. | |
| 290 | * | |
| 291 | * This is particularly important when you want your list to support | |
| 292 | * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list | |
| 293 | * class accordingly and make sure that you can implement your list as if | |
| 294 | * it was only storing objects and the wrapper will automatically enable | |
| 295 | * the feature of storing pointers. | |
| 296 | * | |
| 297 | * @par Example | |
| 298 | * | |
| 299 | * @code | |
| 300 | * CxList *myCustomListCreate( | |
| 301 | * const CxAllocator *allocator, | |
| 302 | * cx_compare_func comparator, | |
| 303 | * size_t elem_size | |
| 304 | * ) { | |
| 305 | * if (allocator == NULL) { | |
| 306 | * allocator = cxDefaultAllocator; | |
| 307 | * } | |
| 308 | * | |
| 309 | * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); | |
| 310 | * if (list == NULL) return NULL; | |
| 311 | * | |
| 312 | * // initialize | |
| 313 | * cx_list_init((CxList*)list, &my_custom_list_class, | |
| 314 | * allocator, comparator, elem_size); | |
| 315 | * | |
| 316 | * // ... some more custom stuff ... | |
| 317 | * | |
| 318 | * return (CxList *) list; | |
| 319 | * } | |
| 320 | * @endcode | |
| 321 | * | |
| 322 | * @param list the list to initialize | |
| 323 | * @param cl the list class | |
| 324 | * @param allocator the allocator for the elements | |
| 325 | * @param comparator a compare function for the elements | |
| 326 | * @param elem_size the size of one element | |
| 327 | */ | |
| 328 | cx_attr_nonnull_arg(1, 2, 3) | |
| 329 | cx_attr_export | |
| 330 | void cx_list_init( | |
| 331 | struct cx_list_s *list, | |
| 332 | struct cx_list_class_s *cl, | |
| 333 | const struct cx_allocator_s *allocator, | |
| 334 | cx_compare_func comparator, | |
| 335 | size_t elem_size | |
| 336 | ); | |
| 337 | ||
| 338 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | * Common type for all list implementations. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | typedef struct cx_list_s CxList; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | /** |
| 490 | 344 | * Returns the number of elements currently stored in the list. |
| 345 | * | |
| 346 | * @param list the list | |
| 347 | * @return the number of currently stored elements | |
| 348 | */ | |
| 579 | 349 | cx_attr_nonnull |
| 350 | static inline size_t cxListSize(const CxList *list) { | |
| 351 | return list->collection.size; | |
| 490 | 352 | } |
| 353 | ||
| 354 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | * Adds an item to the end of the list. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | * @param elem a pointer to the element to add |
| 579 | 359 | * @retval zero success |
| 360 | * @retval non-zero memory allocation failure | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
361 | * @see cxListAddArray() |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | */ |
| 579 | 363 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | static inline int cxListAdd( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | CxList *list, |
| 579 | 366 | const void *elem |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | ) { |
| 579 | 368 | list->collection.sorted = false; |
| 369 | return list->cl->insert_element(list, list->collection.size, elem); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | /** |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
373 | * Adds multiple items to the end of the list. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
374 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
375 | * This method is more efficient than invoking cxListAdd() multiple times. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
376 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
377 | * If there is not enough memory to add all elements, the returned value is |
| 579 | 378 | * less than @p n. |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
379 | * |
| 579 | 380 | * If this list is storing pointers instead of objects @p array is expected to |
| 490 | 381 | * be an array of pointers. |
| 382 | * | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
383 | * @param list the list |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
384 | * @param array a pointer to the elements to add |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
385 | * @param n the number of elements to add |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
386 | * @return the number of added elements |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
387 | */ |
| 579 | 388 | cx_attr_nonnull |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
389 | static inline size_t cxListAddArray( |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
390 | CxList *list, |
| 579 | 391 | const void *array, |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
392 | size_t n |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
393 | ) { |
| 579 | 394 | list->collection.sorted = false; |
| 395 | return list->cl->insert_array(list, list->collection.size, array, n); | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
396 | } |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
397 | |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
398 | /** |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | * Inserts an item at the specified index. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | * |
| 579 | 401 | * If @p index equals the list @c size, this is effectively cxListAdd(). |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | * @param index the index the element shall have |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | * @param elem a pointer to the element to add |
| 579 | 406 | * @retval zero success |
| 407 | * @retval non-zero memory allocation failure or the index is out of bounds | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | * @see cxListInsertAfter() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | * @see cxListInsertBefore() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | */ |
| 579 | 411 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | static inline int cxListInsert( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | CxList *list, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | size_t index, |
| 579 | 415 | const void *elem |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | ) { |
| 579 | 417 | list->collection.sorted = false; |
| 490 | 418 | return list->cl->insert_element(list, index, elem); |
| 419 | } | |
| 420 | ||
| 421 | /** | |
| 579 | 422 | * Inserts an item into a sorted list. |
| 423 | * | |
| 424 | * If the list is not sorted already, the behavior is undefined. | |
| 425 | * | |
| 426 | * @param list the list | |
| 427 | * @param elem a pointer to the element to add | |
| 428 | * @retval zero success | |
| 429 | * @retval non-zero memory allocation failure | |
| 430 | */ | |
| 431 | cx_attr_nonnull | |
| 432 | static inline int cxListInsertSorted( | |
| 433 | CxList *list, | |
| 434 | const void *elem | |
| 435 | ) { | |
| 436 | list->collection.sorted = true; // guaranteed by definition | |
| 437 | const void *data = list->collection.store_pointer ? &elem : elem; | |
| 438 | return list->cl->insert_sorted(list, data, 1) == 0; | |
| 439 | } | |
| 440 | ||
| 441 | /** | |
| 490 | 442 | * Inserts multiple items to the list at the specified index. |
| 579 | 443 | * If @p index equals the list size, this is effectively cxListAddArray(). |
| 490 | 444 | * |
| 445 | * This method is usually more efficient than invoking cxListInsert() | |
| 446 | * multiple times. | |
| 447 | * | |
| 448 | * If there is not enough memory to add all elements, the returned value is | |
| 579 | 449 | * less than @p n. |
| 490 | 450 | * |
| 579 | 451 | * If this list is storing pointers instead of objects @p array is expected to |
| 490 | 452 | * be an array of pointers. |
| 453 | * | |
| 454 | * @param list the list | |
| 455 | * @param index the index where to add the elements | |
| 456 | * @param array a pointer to the elements to add | |
| 457 | * @param n the number of elements to add | |
| 458 | * @return the number of added elements | |
| 459 | */ | |
| 579 | 460 | cx_attr_nonnull |
| 490 | 461 | static inline size_t cxListInsertArray( |
| 462 | CxList *list, | |
| 463 | size_t index, | |
| 579 | 464 | const void *array, |
| 490 | 465 | size_t n |
| 466 | ) { | |
| 579 | 467 | list->collection.sorted = false; |
| 490 | 468 | return list->cl->insert_array(list, index, array, n); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | /** |
| 579 | 472 | * Inserts a sorted array into a sorted list. |
| 473 | * | |
| 474 | * This method is usually more efficient than inserting each element separately, | |
| 475 | * because consecutive chunks of sorted data are inserted in one pass. | |
| 476 | * | |
| 477 | * If there is not enough memory to add all elements, the returned value is | |
| 478 | * less than @p n. | |
| 479 | * | |
| 480 | * If this list is storing pointers instead of objects @p array is expected to | |
| 481 | * be an array of pointers. | |
| 482 | * | |
| 483 | * If the list is not sorted already, the behavior is undefined. | |
| 484 | * | |
| 485 | * @param list the list | |
| 486 | * @param array a pointer to the elements to add | |
| 487 | * @param n the number of elements to add | |
| 488 | * @return the number of added elements | |
| 489 | */ | |
| 490 | cx_attr_nonnull | |
| 491 | static inline size_t cxListInsertSortedArray( | |
| 492 | CxList *list, | |
| 493 | const void *array, | |
| 494 | size_t n | |
| 495 | ) { | |
| 496 | list->collection.sorted = true; // guaranteed by definition | |
| 497 | return list->cl->insert_sorted(list, array, n); | |
| 498 | } | |
| 499 | ||
| 500 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
501 | * Inserts an element after the current location of the specified iterator. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
502 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503 | * The used iterator remains operational, but all other active iterators should |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504 | * be considered invalidated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | * |
| 579 | 506 | * If @p iter is not a list iterator, the behavior is undefined. |
| 507 | * If @p iter is a past-the-end iterator, the new element gets appended to the list. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | * @param iter an iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | * @param elem the element to insert |
| 579 | 511 | * @retval zero success |
| 512 | * @retval non-zero memory allocation failure | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | * @see cxListInsert() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514 | * @see cxListInsertBefore() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | */ |
| 579 | 516 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517 | static inline int cxListInsertAfter( |
| 579 | 518 | CxIterator *iter, |
| 519 | const void *elem | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520 | ) { |
| 579 | 521 | CxList* list = (CxList*)iter->src_handle.m; |
| 522 | list->collection.sorted = false; | |
| 523 | return list->cl->insert_iter(iter, elem, 0); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
525 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
527 | * Inserts an element before the current location of the specified iterator. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
528 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
529 | * The used iterator remains operational, but all other active iterators should |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530 | * be considered invalidated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
531 | * |
| 579 | 532 | * If @p iter is not a list iterator, the behavior is undefined. |
| 533 | * If @p iter is a past-the-end iterator, the new element gets appended to the list. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
535 | * @param iter an iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
536 | * @param elem the element to insert |
| 579 | 537 | * @retval zero success |
| 538 | * @retval non-zero memory allocation failure | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
539 | * @see cxListInsert() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
540 | * @see cxListInsertAfter() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
541 | */ |
| 579 | 542 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
543 | static inline int cxListInsertBefore( |
| 579 | 544 | CxIterator *iter, |
| 545 | const void *elem | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
546 | ) { |
| 579 | 547 | CxList* list = (CxList*)iter->src_handle.m; |
| 548 | list->collection.sorted = false; | |
| 549 | return list->cl->insert_iter(iter, elem, 1); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
550 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
551 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
552 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
553 | * Removes the element at the specified index. |
| 490 | 554 | * |
| 555 | * If an element destructor function is specified, it is called before | |
| 556 | * removing the element. | |
| 557 | * | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
558 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
559 | * @param index the index of the element |
| 579 | 560 | * @retval zero success |
| 561 | * @retval non-zero index out of bounds | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562 | */ |
| 579 | 563 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | static inline int cxListRemove( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565 | CxList *list, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | size_t index |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567 | ) { |
| 579 | 568 | return list->cl->remove(list, index, 1, NULL) == 0; |
| 569 | } | |
| 570 | ||
| 571 | /** | |
| 572 | * Removes and returns the element at the specified index. | |
| 573 | * | |
| 574 | * No destructor is called and instead the element is copied to the | |
| 575 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 576 | * | |
| 577 | * @param list the list | |
| 578 | * @param index the index of the element | |
| 579 | * @param targetbuf a buffer where to copy the element | |
| 580 | * @retval zero success | |
| 581 | * @retval non-zero index out of bounds | |
| 582 | */ | |
| 583 | cx_attr_nonnull | |
| 584 | cx_attr_access_w(3) | |
| 585 | static inline int cxListRemoveAndGet( | |
| 586 | CxList *list, | |
| 587 | size_t index, | |
| 588 | void *targetbuf | |
| 589 | ) { | |
| 590 | return list->cl->remove(list, index, 1, targetbuf) == 0; | |
| 591 | } | |
| 592 | ||
| 593 | /** | |
| 594 | * Removes multiple element starting at the specified index. | |
| 595 | * | |
| 596 | * If an element destructor function is specified, it is called for each | |
| 597 | * element. It is guaranteed that the destructor is called before removing | |
| 598 | * the element, however, due to possible optimizations it is neither guaranteed | |
| 599 | * that the destructors are invoked for all elements before starting to remove | |
| 600 | * them, nor that the element is removed immediately after the destructor call | |
| 601 | * before proceeding to the next element. | |
| 602 | * | |
| 603 | * @param list the list | |
| 604 | * @param index the index of the element | |
| 605 | * @param num the number of elements to remove | |
| 606 | * @return the actual number of removed elements | |
| 607 | */ | |
| 608 | cx_attr_nonnull | |
| 609 | static inline size_t cxListRemoveArray( | |
| 610 | CxList *list, | |
| 611 | size_t index, | |
| 612 | size_t num | |
| 613 | ) { | |
| 614 | return list->cl->remove(list, index, num, NULL); | |
| 615 | } | |
| 616 | ||
| 617 | /** | |
| 618 | * Removes and returns multiple element starting at the specified index. | |
| 619 | * | |
| 620 | * No destructor is called and instead the elements are copied to the | |
| 621 | * @p targetbuf which MUST be large enough to hold all removed elements. | |
| 622 | * | |
| 623 | * @param list the list | |
| 624 | * @param index the index of the element | |
| 625 | * @param num the number of elements to remove | |
| 626 | * @param targetbuf a buffer where to copy the elements | |
| 627 | * @return the actual number of removed elements | |
| 628 | */ | |
| 629 | cx_attr_nonnull | |
| 630 | cx_attr_access_w(4) | |
| 631 | static inline size_t cxListRemoveArrayAndGet( | |
| 632 | CxList *list, | |
| 633 | size_t index, | |
| 634 | size_t num, | |
| 635 | void *targetbuf | |
| 636 | ) { | |
| 637 | return list->cl->remove(list, index, num, targetbuf); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
638 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
639 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
640 | /** |
| 490 | 641 | * Removes all elements from this list. |
| 642 | * | |
| 579 | 643 | * If element destructor functions are specified, they are called for each |
| 490 | 644 | * element before removing them. |
| 645 | * | |
| 646 | * @param list the list | |
| 647 | */ | |
| 579 | 648 | cx_attr_nonnull |
| 490 | 649 | static inline void cxListClear(CxList *list) { |
| 579 | 650 | list->collection.sorted = true; // empty lists are always sorted |
| 490 | 651 | list->cl->clear(list); |
| 652 | } | |
| 653 | ||
| 654 | /** | |
| 655 | * Swaps two items in the list. | |
| 656 | * | |
| 657 | * Implementations should only allocate temporary memory for the swap, if | |
| 658 | * it is necessary. | |
| 659 | * | |
| 660 | * @param list the list | |
| 661 | * @param i the index of the first element | |
| 662 | * @param j the index of the second element | |
| 579 | 663 | * @retval zero success |
| 664 | * @retval non-zero one of the indices is out of bounds | |
| 665 | * or the swap needed extra memory but allocation failed | |
| 490 | 666 | */ |
| 579 | 667 | cx_attr_nonnull |
| 490 | 668 | static inline int cxListSwap( |
| 669 | CxList *list, | |
| 670 | size_t i, | |
| 671 | size_t j | |
| 672 | ) { | |
| 579 | 673 | list->collection.sorted = false; |
| 490 | 674 | return list->cl->swap(list, i, j); |
| 675 | } | |
| 676 | ||
| 677 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
678 | * Returns a pointer to the element at the specified index. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
680 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681 | * @param index the index of the element |
| 579 | 682 | * @return a pointer to the element or @c NULL if the index is out of bounds |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
683 | */ |
| 579 | 684 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685 | static inline void *cxListAt( |
| 579 | 686 | const CxList *list, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | size_t index |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688 | ) { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689 | return list->cl->at(list, index); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | * Returns an iterator pointing to the item at the specified index. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | * The returned iterator is position-aware. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
696 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697 | * If the index is out of range, a past-the-end iterator will be returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | * @param index the index where the iterator shall point at |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701 | * @return a new iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
702 | */ |
| 579 | 703 | cx_attr_nonnull |
| 704 | cx_attr_nodiscard | |
| 490 | 705 | static inline CxIterator cxListIteratorAt( |
| 579 | 706 | const CxList *list, |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
707 | size_t index |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
708 | ) { |
| 490 | 709 | return list->cl->iterator(list, index, false); |
| 710 | } | |
| 711 | ||
| 712 | /** | |
| 713 | * Returns a backwards iterator pointing to the item at the specified index. | |
| 714 | * | |
| 715 | * The returned iterator is position-aware. | |
| 716 | * | |
| 717 | * If the index is out of range, a past-the-end iterator will be returned. | |
| 718 | * | |
| 719 | * @param list the list | |
| 720 | * @param index the index where the iterator shall point at | |
| 721 | * @return a new iterator | |
| 722 | */ | |
| 579 | 723 | cx_attr_nonnull |
| 724 | cx_attr_nodiscard | |
| 490 | 725 | static inline CxIterator cxListBackwardsIteratorAt( |
| 579 | 726 | const CxList *list, |
| 490 | 727 | size_t index |
| 728 | ) { | |
| 729 | return list->cl->iterator(list, index, true); | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
730 | } |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
731 | |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
732 | /** |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
733 | * Returns a mutating iterator pointing to the item at the specified index. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
734 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
735 | * The returned iterator is position-aware. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
736 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
737 | * If the index is out of range, a past-the-end iterator will be returned. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
738 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
739 | * @param list the list |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
740 | * @param index the index where the iterator shall point at |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
741 | * @return a new iterator |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
742 | */ |
| 579 | 743 | cx_attr_nonnull |
| 744 | cx_attr_nodiscard | |
| 745 | cx_attr_export | |
| 746 | CxIterator cxListMutIteratorAt( | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747 | CxList *list, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
748 | size_t index |
| 490 | 749 | ); |
| 750 | ||
| 751 | /** | |
| 752 | * Returns a mutating backwards iterator pointing to the item at the | |
| 753 | * specified index. | |
| 754 | * | |
| 755 | * The returned iterator is position-aware. | |
| 756 | * | |
| 757 | * If the index is out of range, a past-the-end iterator will be returned. | |
| 758 | * | |
| 759 | * @param list the list | |
| 760 | * @param index the index where the iterator shall point at | |
| 761 | * @return a new iterator | |
| 762 | */ | |
| 579 | 763 | cx_attr_nonnull |
| 764 | cx_attr_nodiscard | |
| 765 | cx_attr_export | |
| 766 | CxIterator cxListMutBackwardsIteratorAt( | |
| 490 | 767 | CxList *list, |
| 768 | size_t index | |
| 769 | ); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772 | * Returns an iterator pointing to the first item of the list. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | * The returned iterator is position-aware. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | * If the list is empty, a past-the-end iterator will be returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779 | * @return a new iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780 | */ |
| 579 | 781 | cx_attr_nonnull |
| 782 | cx_attr_nodiscard | |
| 783 | static inline CxIterator cxListIterator(const CxList *list) { | |
| 490 | 784 | return list->cl->iterator(list, 0, false); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
785 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
786 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
787 | /** |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
788 | * Returns a mutating iterator pointing to the first item of the list. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
789 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
790 | * The returned iterator is position-aware. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
791 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
792 | * If the list is empty, a past-the-end iterator will be returned. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
793 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
794 | * @param list the list |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
795 | * @return a new iterator |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
796 | */ |
| 579 | 797 | cx_attr_nonnull |
| 798 | cx_attr_nodiscard | |
| 799 | static inline CxIterator cxListMutIterator(CxList *list) { | |
| 490 | 800 | return cxListMutIteratorAt(list, 0); |
| 801 | } | |
| 802 | ||
| 803 | ||
| 804 | /** | |
| 805 | * Returns a backwards iterator pointing to the last item of the list. | |
| 806 | * | |
| 807 | * The returned iterator is position-aware. | |
| 808 | * | |
| 809 | * If the list is empty, a past-the-end iterator will be returned. | |
| 810 | * | |
| 811 | * @param list the list | |
| 812 | * @return a new iterator | |
| 813 | */ | |
| 579 | 814 | cx_attr_nonnull |
| 815 | cx_attr_nodiscard | |
| 816 | static inline CxIterator cxListBackwardsIterator(const CxList *list) { | |
| 817 | return list->cl->iterator(list, list->collection.size - 1, true); | |
| 490 | 818 | } |
| 819 | ||
| 820 | /** | |
| 821 | * Returns a mutating backwards iterator pointing to the last item of the list. | |
| 822 | * | |
| 823 | * The returned iterator is position-aware. | |
| 824 | * | |
| 825 | * If the list is empty, a past-the-end iterator will be returned. | |
| 826 | * | |
| 827 | * @param list the list | |
| 828 | * @return a new iterator | |
| 829 | */ | |
| 579 | 830 | cx_attr_nonnull |
| 831 | cx_attr_nodiscard | |
| 832 | static inline CxIterator cxListMutBackwardsIterator(CxList *list) { | |
| 833 | return cxListMutBackwardsIteratorAt(list, list->collection.size - 1); | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
834 | } |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
835 | |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
836 | /** |
| 579 | 837 | * Returns the index of the first element that equals @p elem. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
838 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
839 | * Determining equality is performed by the list's comparator function. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842 | * @param elem the element to find |
| 579 | 843 | * @return the index of the element or the size of the list when the element is not found |
| 844 | * @see cxListIndexValid() | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845 | */ |
| 579 | 846 | cx_attr_nonnull |
| 847 | cx_attr_nodiscard | |
| 848 | static inline size_t cxListFind( | |
| 849 | const CxList *list, | |
| 850 | const void *elem | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
851 | ) { |
| 579 | 852 | return list->cl->find_remove((CxList*)list, elem, false); |
| 853 | } | |
| 854 | ||
| 855 | /** | |
| 856 | * Checks if the specified index is within bounds. | |
| 857 | * | |
| 858 | * @param list the list | |
| 859 | * @param index the index | |
| 860 | * @retval true if the index is within bounds | |
| 861 | * @retval false if the index is out of bounds | |
| 862 | */ | |
| 863 | cx_attr_nonnull | |
| 864 | cx_attr_nodiscard | |
| 865 | static inline bool cxListIndexValid(const CxList *list, size_t index) { | |
| 866 | return index < list->collection.size; | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
867 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
868 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
869 | /** |
| 579 | 870 | * Removes and returns the index of the first element that equals @p elem. |
| 871 | * | |
| 872 | * Determining equality is performed by the list's comparator function. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
873 | * |
| 579 | 874 | * @param list the list |
| 875 | * @param elem the element to find and remove | |
| 876 | * @return the index of the now removed element or the list size | |
| 877 | * when the element is not found or could not be removed | |
| 878 | * @see cxListIndexValid() | |
| 879 | */ | |
| 880 | cx_attr_nonnull | |
| 881 | static inline size_t cxListFindRemove( | |
| 882 | CxList *list, | |
| 883 | const void *elem | |
| 884 | ) { | |
| 885 | return list->cl->find_remove(list, elem, true); | |
| 886 | } | |
| 887 | ||
| 888 | /** | |
| 889 | * Sorts the list. | |
| 890 | * | |
| 891 | * @remark The underlying sort algorithm is implementation defined. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
892 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
893 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
894 | */ |
| 579 | 895 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
896 | static inline void cxListSort(CxList *list) { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
897 | list->cl->sort(list); |
| 579 | 898 | list->collection.sorted = true; |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
899 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
900 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
901 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
902 | * Reverses the order of the items. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
903 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
904 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
905 | */ |
| 579 | 906 | cx_attr_nonnull |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
907 | static inline void cxListReverse(CxList *list) { |
| 579 | 908 | // still sorted, but not according to the cmp_func |
| 909 | list->collection.sorted = false; | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
910 | list->cl->reverse(list); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911 | } |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
912 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
913 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
914 | * Compares a list to another list of the same type. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915 | * |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
916 | * First, the list sizes are compared. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
917 | * If they match, the lists are compared element-wise. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
918 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
919 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
920 | * @param other the list to compare to |
| 579 | 921 | * @retval zero both lists are equal element wise |
| 922 | * @retval negative the first list is smaller | |
| 923 | * or the first non-equal element in the first list is smaller | |
| 924 | * @retval positive the first list is larger | |
| 925 | * or the first non-equal element in the first list is larger | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
926 | */ |
| 579 | 927 | cx_attr_nonnull |
| 928 | cx_attr_nodiscard | |
| 929 | cx_attr_export | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
930 | int cxListCompare( |
| 579 | 931 | const CxList *list, |
| 932 | const CxList *other | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
933 | ); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
934 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
935 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
936 | * Deallocates the memory of the specified list structure. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
937 | * |
| 579 | 938 | * Also calls the content destructor functions for each element, if specified. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
939 | * |
| 579 | 940 | * @param list the list which shall be freed |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
941 | */ |
| 579 | 942 | cx_attr_export |
| 943 | void cxListFree(CxList *list); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
944 | |
| 504 | 945 | /** |
| 946 | * A shared instance of an empty list. | |
| 947 | * | |
| 579 | 948 | * Writing to that list is not allowed. |
| 949 | * | |
| 950 | * You can use this is a placeholder for initializing CxList pointers | |
| 951 | * for which you do not want to reserve memory right from the beginning. | |
| 504 | 952 | */ |
| 579 | 953 | cx_attr_export |
| 954 | extern CxList *const cxEmptyList; | |
| 504 | 955 | |
| 956 | ||
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
957 | #ifdef __cplusplus |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
958 | } // extern "C" |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959 | #endif |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
960 | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
961 | #endif // UCX_LIST_H |