| 64 * @param elem_size the size of each element in bytes |
64 * @param elem_size the size of each element in bytes |
| 65 * @return the created list |
65 * @return the created list |
| 66 * @see cxKvListAsMap() |
66 * @see cxKvListAsMap() |
| 67 * @see cxKvListAsList() |
67 * @see cxKvListAsList() |
| 68 */ |
68 */ |
| 69 cx_attr_nodiscard |
69 cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1) |
| 70 cx_attr_malloc |
70 CX_EXPORT CxList *cxKvListCreate(const CxAllocator *allocator, |
| 71 cx_attr_dealloc(cxListFree, 1) |
71 cx_compare_func comparator, size_t elem_size); |
| 72 cx_attr_export |
|
| 73 CxList *cxKvListCreate( |
|
| 74 const CxAllocator *allocator, |
|
| 75 cx_compare_func comparator, |
|
| 76 size_t elem_size |
|
| 77 ); |
|
| 78 |
72 |
| 79 /** |
73 /** |
| 80 * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. |
74 * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. |
| 81 * |
75 * |
| 82 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
76 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
| 95 * @param elem_size the size of each element in bytes |
89 * @param elem_size the size of each element in bytes |
| 96 * @return the created list wrapped into the CxMap interface |
90 * @return the created list wrapped into the CxMap interface |
| 97 * @see cxKvListAsMap() |
91 * @see cxKvListAsMap() |
| 98 * @see cxKvListAsList() |
92 * @see cxKvListAsList() |
| 99 */ |
93 */ |
| 100 cx_attr_nodiscard |
94 cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxMapFree, 1) |
| 101 cx_attr_malloc |
95 CX_EXPORT CxMap *cxKvListCreateAsMap(const CxAllocator *allocator, |
| 102 cx_attr_dealloc(cxMapFree, 1) |
96 cx_compare_func comparator, size_t elem_size); |
| 103 cx_attr_export |
|
| 104 CxMap *cxKvListCreateAsMap( |
|
| 105 const CxAllocator *allocator, |
|
| 106 cx_compare_func comparator, |
|
| 107 size_t elem_size |
|
| 108 ); |
|
| 109 |
97 |
| 110 /** |
98 /** |
| 111 * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. |
99 * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. |
| 112 * |
100 * |
| 113 * The list will use cxDefaultAllocator and no comparator function. If you want |
101 * The list will use cxDefaultAllocator and no comparator function. If you want |
| 156 * Converts a map pointer belonging to a key-value-List back to the original list pointer. |
144 * Converts a map pointer belonging to a key-value-List back to the original list pointer. |
| 157 * |
145 * |
| 158 * @param map a map pointer that was returned by a call to cxKvListAsMap() |
146 * @param map a map pointer that was returned by a call to cxKvListAsMap() |
| 159 * @return the original list pointer |
147 * @return the original list pointer |
| 160 */ |
148 */ |
| 161 cx_attr_nodiscard |
149 cx_attr_nodiscard cx_attr_nonnull cx_attr_returns_nonnull |
| 162 cx_attr_nonnull |
150 CX_EXPORT CxList *cxKvListAsList(CxMap *map); |
| 163 cx_attr_returns_nonnull |
|
| 164 cx_attr_export |
|
| 165 CxList *cxKvListAsList(CxMap *map); |
|
| 166 |
151 |
| 167 /** |
152 /** |
| 168 * Converts a map pointer belonging to a key-value-List back to the original list pointer. |
153 * Converts a map pointer belonging to a key-value-List back to the original list pointer. |
| 169 * |
154 * |
| 170 * @param list a list created by cxKvListCreate() or cxKvListCreateSimple() |
155 * @param list a list created by cxKvListCreate() or cxKvListCreateSimple() |
| 171 * @return a map pointer that lets you use the list as if it was a map |
156 * @return a map pointer that lets you use the list as if it was a map |
| 172 */ |
157 */ |
| 173 cx_attr_nodiscard |
158 cx_attr_nodiscard cx_attr_nonnull cx_attr_returns_nonnull |
| 174 cx_attr_nonnull |
159 CX_EXPORT CxMap *cxKvListAsMap(CxList *list); |
| 175 cx_attr_returns_nonnull |
|
| 176 cx_attr_export |
|
| 177 CxMap *cxKvListAsMap(CxList *list); |
|
| 178 |
160 |
| 179 /** |
161 /** |
| 180 * Sets or updates the key of a list item. |
162 * Sets or updates the key of a list item. |
| 181 * |
163 * |
| 182 * This is, for example, useful when you have inserted an element using the CxList interface, |
164 * This is, for example, useful when you have inserted an element using the CxList interface, |
| 188 * @retval zero success |
170 * @retval zero success |
| 189 * @retval non-zero memory allocation failure or the index is out of bounds |
171 * @retval non-zero memory allocation failure or the index is out of bounds |
| 190 * @see cxKvListSetKey() |
172 * @see cxKvListSetKey() |
| 191 */ |
173 */ |
| 192 cx_attr_nonnull |
174 cx_attr_nonnull |
| 193 cx_attr_export |
175 CX_EXPORT int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key); |
| 194 int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key); |
|
| 195 |
176 |
| 196 /** |
177 /** |
| 197 * Inserts an item into the list at the specified index and associates it with the specified key. |
178 * Inserts an item into the list at the specified index and associates it with the specified key. |
| 198 * |
179 * |
| 199 * @param list the list |
180 * @param list the list |
| 203 * @retval zero success |
184 * @retval zero success |
| 204 * @retval non-zero memory allocation failure or the index is out of bounds |
185 * @retval non-zero memory allocation failure or the index is out of bounds |
| 205 * @see cxKvListInsert() |
186 * @see cxKvListInsert() |
| 206 */ |
187 */ |
| 207 cx_attr_nonnull |
188 cx_attr_nonnull |
| 208 cx_attr_export |
189 CX_EXPORT int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); |
| 209 int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); |
|
| 210 |
190 |
| 211 /** |
191 /** |
| 212 * Sets or updates the key of a list item. |
192 * Sets or updates the key of a list item. |
| 213 * |
193 * |
| 214 * This is, for example, useful when you have inserted an element using the CxList interface, |
194 * This is, for example, useful when you have inserted an element using the CxList interface, |
| 248 * @param index the index of the element in the list |
228 * @param index the index of the element in the list |
| 249 * @retval zero success |
229 * @retval zero success |
| 250 * @retval non-zero the index is out of bounds |
230 * @retval non-zero the index is out of bounds |
| 251 */ |
231 */ |
| 252 cx_attr_nonnull |
232 cx_attr_nonnull |
| 253 cx_attr_export |
233 CX_EXPORT int cxKvListRemoveKey(CxList *list, size_t index); |
| 254 int cxKvListRemoveKey(CxList *list, size_t index); |
|
| 255 |
234 |
| 256 /** |
235 /** |
| 257 * Returns the key of a list item. |
236 * Returns the key of a list item. |
| 258 * |
237 * |
| 259 * @param list the list |
238 * @param list the list |
| 260 * @param index the index of the element in the list |
239 * @param index the index of the element in the list |
| 261 * @return a pointer to the key or @c NULL when the index is out of bounds or the item does not have a key |
240 * @return a pointer to the key or @c NULL when the index is out of bounds or the item does not have a key |
| 262 */ |
241 */ |
| 263 cx_attr_nonnull |
242 cx_attr_nonnull |
| 264 cx_attr_export |
243 CX_EXPORT const CxHashKey *cxKvListGetKey(CxList *list, size_t index); |
| 265 const CxHashKey *cxKvListGetKey(CxList *list, size_t index); |
|
| 266 |
244 |
| 267 /** |
245 /** |
| 268 * Adds an item into the list and associates it with the specified key. |
246 * Adds an item into the list and associates it with the specified key. |
| 269 * |
247 * |
| 270 * @param list (@c CxList*) the list |
248 * @param list (@c CxList*) the list |