Sun, 14 Dec 2025 17:30:17 +0100
refactor the list and map construction functions and remove the simple macros
relates to #780
relates to #622
|
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
|
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
4 | * Copyright 2025 Mike Becker, Olaf Wintermann All rights reserved. |
|
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
|
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
438
diff
changeset
|
28 | /** |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
29 | * @file kv_list.h |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
30 | * @brief Linked list implementation with key/value-lookup. |
|
1100
2ca6fa71e55e
refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
31 | * @author Mike Becker |
|
2ca6fa71e55e
refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
32 | * @author Olaf Wintermann |
|
2ca6fa71e55e
refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
33 | * @copyright 2-Clause BSD License |
|
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
438
diff
changeset
|
34 | */ |
|
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
36 | #ifndef UCX_KV_LIST_H |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
37 | #define UCX_KV_LIST_H |
|
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | |
|
484
9e6900b1cf9d
add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents:
481
diff
changeset
|
39 | #include "common.h" |
|
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | #include "list.h" |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
41 | #include "map.h" |
|
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | |
| 416 | 43 | #ifdef __cplusplus |
| 44 | extern "C" { | |
| 45 | #endif | |
| 46 | ||
|
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
47 | /** |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
48 | * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. |
|
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
49 | * |
|
1111
78eeeb950883
remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents:
1100
diff
changeset
|
50 | * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
51 | * copies of the added elements, and the compare function will be automatically set |
|
1605
55b13f583356
refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
52 | * to cx_cmp_ptr(). |
|
669
dce9b8450656
add docs for CX_STORE_POINTERS and remove cxHashMapCreateForPointers()
Mike Becker <universe@uap-core.de>
parents:
662
diff
changeset
|
53 | * |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
54 | * After creating the list, it can also be used as a map after converting the pointer |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
55 | * to a CxMap pointer with cxKvListAsMap(). |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
56 | * When you want to use the list interface again, you can also convert the map pointer back |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
57 | * with cxKvListAsList(). |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
58 | * |
|
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
59 | * @param allocator the allocator for allocating the list nodes |
|
1318
12fa1d37fe48
allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents:
1241
diff
changeset
|
60 | * (if @c NULL, the cxDefaultAllocator will be used) |
|
855
35bcb3216c0d
fix inconsistent use of item_size and elem_size
Mike Becker <universe@uap-core.de>
parents:
807
diff
changeset
|
61 | * @param elem_size the size of each element in bytes |
|
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
62 | * @return the created list |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
63 | * @see cxKvListAsMap() |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
64 | * @see cxKvListAsList() |
|
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
65 | */ |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
66 | cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1) |
|
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
67 | CX_EXPORT CxList *cxKvListCreate(const CxAllocator *allocator, |
|
1605
55b13f583356
refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
68 | size_t elem_size); |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
69 | |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
70 | /** |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
71 | * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
72 | * |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
73 | * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
74 | * copies of the added elements, and the compare function will be automatically set |
|
1605
55b13f583356
refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
75 | * to cx_cmp_ptr(). |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
76 | * |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
77 | * This function creates the list with cxKvListCreate() and immediately applies |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
78 | * cxKvListAsMap(). If you want to use the returned object as a list, you can call |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
79 | * cxKvListAsList() later. |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
80 | * |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
81 | * @param allocator the allocator for allocating the list nodes |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
82 | * (if @c NULL, the cxDefaultAllocator will be used) |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
83 | * @param elem_size the size of each element in bytes |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
84 | * @return the created list wrapped into the CxMap interface |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
85 | * @see cxKvListAsMap() |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
86 | * @see cxKvListAsList() |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
87 | */ |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
88 | cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxMapFree, 1) |
|
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
89 | CX_EXPORT CxMap *cxKvListCreateAsMap(const CxAllocator *allocator, |
|
1605
55b13f583356
refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
90 | size_t elem_size); |
|
764
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
91 | |
|
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
92 | /** |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
93 | * Converts a map pointer belonging to a key-value-List back to the original list pointer. |
|
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
473
diff
changeset
|
94 | * |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
95 | * @param map a map pointer that was returned by a call to cxKvListAsMap() |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
96 | * @return the original list pointer |
|
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
473
diff
changeset
|
97 | */ |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
98 | cx_attr_nodiscard cx_attr_nonnull cx_attr_returns_nonnull |
|
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
99 | CX_EXPORT CxList *cxKvListAsList(CxMap *map); |
|
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
100 | |
|
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
101 | /** |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
102 | * Converts a map pointer belonging to a key-value-List back to the original list pointer. |
|
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
103 | * |
|
1605
55b13f583356
refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
104 | * @param list a list created by cxKvListCreate() |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
105 | * @return a map pointer that lets you use the list as if it was a map |
|
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
106 | */ |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
107 | cx_attr_nodiscard cx_attr_nonnull cx_attr_returns_nonnull |
|
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
108 | CX_EXPORT CxMap *cxKvListAsMap(CxList *list); |
|
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
109 | |
| 1407 | 110 | /** |
| 111 | * Sets or updates the key of a list item. | |
| 112 | * | |
| 113 | * This is, for example, useful when you have inserted an element using the CxList interface, | |
| 114 | * and now you want to associate this element with a key. | |
| 115 | * | |
| 116 | * @param list the list | |
| 117 | * @param index the index of the element in the list | |
| 118 | * @param key the key | |
| 119 | * @retval zero success | |
| 120 | * @retval non-zero memory allocation failure or the index is out of bounds | |
| 121 | * @see cxKvListSetKey() | |
| 122 | */ | |
|
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
123 | cx_attr_nonnull |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
124 | CX_EXPORT int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key); |
|
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
125 | |
| 1407 | 126 | /** |
| 127 | * Inserts an item into the list at the specified index and associates it with the specified key. | |
| 128 | * | |
| 129 | * @param list the list | |
| 130 | * @param index the index the inserted element shall have | |
| 131 | * @param key the key | |
| 132 | * @param value the value | |
| 133 | * @retval zero success | |
| 134 | * @retval non-zero memory allocation failure or the index is out of bounds | |
| 135 | * @see cxKvListInsert() | |
| 136 | */ | |
|
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
137 | cx_attr_nonnull |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
138 | CX_EXPORT int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); |
|
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
139 | |
|
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
140 | /** |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
141 | * Sets or updates the key of a list item. |
|
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
142 | * |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
143 | * This is, for example, useful when you have inserted an element using the CxList interface, |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
144 | * and now you want to associate this element with a key. |
|
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
145 | * |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
146 | * @param list (@c CxList*) the list |
|
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
147 | * @param index (@c size_t) the index of the element in the list |
|
1406
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
Mike Becker <universe@uap-core.de>
parents:
1404
diff
changeset
|
148 | * @param key (any supported key type) the key |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
149 | * @retval zero success |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
150 | * @retval non-zero memory allocation failure or the index is out of bounds |
|
1406
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
Mike Becker <universe@uap-core.de>
parents:
1404
diff
changeset
|
151 | * @see CX_HASH_KEY() |
|
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
152 | */ |
|
1406
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
Mike Becker <universe@uap-core.de>
parents:
1404
diff
changeset
|
153 | #define cxKvListSetKey(list, index, key) cx_kv_list_set_key(list, index, CX_HASH_KEY(key)) |
|
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
473
diff
changeset
|
154 | |
|
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
473
diff
changeset
|
155 | /** |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
156 | * Inserts an item into the list at the specified index and associates it with the specified key. |
|
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
157 | * |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
158 | * @param list (@c CxList*) the list |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
159 | * @param index (@c size_t) the index the inserted element shall have |
|
1406
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
Mike Becker <universe@uap-core.de>
parents:
1404
diff
changeset
|
160 | * @param key (any supported key type) the key |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
161 | * @param value (@c void*) the value |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
162 | * @retval zero success |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
163 | * @retval non-zero memory allocation failure or the index is out of bounds |
|
1406
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
Mike Becker <universe@uap-core.de>
parents:
1404
diff
changeset
|
164 | * @see CX_HASH_KEY() |
|
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
165 | */ |
|
1406
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
Mike Becker <universe@uap-core.de>
parents:
1404
diff
changeset
|
166 | #define cxKvListInsert(list, index, key, value) cx_kv_list_insert(list, index, CX_HASH_KEY(key), value) |
|
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
167 | |
|
469
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
467
diff
changeset
|
168 | |
|
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
467
diff
changeset
|
169 | /** |
|
1404
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
170 | * Removes the key of a list item. |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
171 | * |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
172 | * This can be useful if you want to explicitly remove an item from the lookup map. |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
173 | * |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
174 | * If no key is associated with the item, nothing happens, and this function returns zero. |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
175 | * |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
176 | * @param list the list |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
177 | * @param index the index of the element in the list |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
178 | * @retval zero success |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
179 | * @retval non-zero the index is out of bounds |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
180 | */ |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
181 | cx_attr_nonnull |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
182 | CX_EXPORT int cxKvListRemoveKey(CxList *list, size_t index); |
|
1404
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
183 | |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
184 | /** |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
185 | * Returns the key of a list item. |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
186 | * |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
187 | * @param list the list |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
188 | * @param index the index of the element in the list |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
189 | * @return a pointer to the key or @c NULL when the index is out of bounds or the item does not have a key |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
190 | */ |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
191 | cx_attr_nonnull |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
192 | CX_EXPORT const CxHashKey *cxKvListGetKey(CxList *list, size_t index); |
|
1404
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
193 | |
|
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
Mike Becker <universe@uap-core.de>
parents:
1394
diff
changeset
|
194 | /** |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
195 | * Adds an item into the list and associates it with the specified key. |
|
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
485
diff
changeset
|
196 | * |
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
197 | * @param list (@c CxList*) the list |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
198 | * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
199 | * @param value (@c void*) the value |
|
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
200 | * @retval zero success |
|
1378
1b4fa55f7caa
implement cx_kv_list_insert()
Mike Becker <universe@uap-core.de>
parents:
1377
diff
changeset
|
201 | * @retval non-zero memory allocation failure |
|
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
485
diff
changeset
|
202 | */ |
|
1378
1b4fa55f7caa
implement cx_kv_list_insert()
Mike Becker <universe@uap-core.de>
parents:
1377
diff
changeset
|
203 | #define cxKvListAdd(list, key, value) cxKvListInsert(list, (list)->collection.size, key, value) |
|
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
204 | |
| 416 | 205 | #ifdef __cplusplus |
|
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
552
diff
changeset
|
206 | } // extern "C" |
| 416 | 207 | #endif |
| 208 | ||
|
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
209 | #endif // UCX_KV_LIST_H |