Mon, 25 Aug 2025 21:47:45 +0200
roll out the function stubs for the kv-list
relates to #461
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 | |
415 | 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 |
1111
78eeeb950883
remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents:
1100
diff
changeset
|
52 | * to cx_cmp_ptr(), if none is given. |
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) |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
61 | * @param comparator the comparator for the elements |
1100
2ca6fa71e55e
refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
62 | * (if @c NULL, and the list is not storing pointers, sort and find |
763
741a2040fa33
make cx_cmp_ptr default comparator for pointer lists - relates to #340
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
63 | * functions will not work) |
855
35bcb3216c0d
fix inconsistent use of item_size and elem_size
Mike Becker <universe@uap-core.de>
parents:
807
diff
changeset
|
64 | * @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
|
65 | * @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
|
66 | * @see cxKvListAsMap() |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
67 | * @see cxKvListAsList() |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
68 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
69 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
70 | cx_attr_malloc |
993
b642eca4b956
make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents:
989
diff
changeset
|
71 | cx_attr_dealloc(cxListFree, 1) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1162
diff
changeset
|
72 | cx_attr_export |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
73 | CxList *cxKvListCreate( |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
74 | const CxAllocator *allocator, |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
75 | cx_compare_func comparator, |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
76 | size_t elem_size |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
77 | ); |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
78 | |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
79 | /** |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
80 | * 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
|
81 | * |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
82 | * 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
|
83 | * copies of the added elements, and the compare function will be automatically set |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
84 | * to cx_cmp_ptr(), if none is given. |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
85 | * |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
86 | * 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
|
87 | * 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
|
88 | * cxKvListAsList() later. |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
89 | * |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
90 | * @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
|
91 | * (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
|
92 | * @param comparator the comparator for the elements |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
93 | * (if @c NULL, and the list is not storing pointers, sort and find |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
94 | * functions will not work) |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
95 | * @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
|
96 | * @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
|
97 | * @see cxKvListAsMap() |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
98 | * @see cxKvListAsList() |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
99 | */ |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
100 | cx_attr_nodiscard |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
101 | cx_attr_malloc |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
102 | cx_attr_dealloc(cxMapFree, 1) |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
103 | cx_attr_export |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
104 | CxMap *cxKvListCreateAsMap( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
879
diff
changeset
|
105 | const CxAllocator *allocator, |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
670
diff
changeset
|
106 | cx_compare_func comparator, |
855
35bcb3216c0d
fix inconsistent use of item_size and elem_size
Mike Becker <universe@uap-core.de>
parents:
807
diff
changeset
|
107 | size_t elem_size |
670
4ad8ea3aee49
allow NULL for allocator and comparator
Mike Becker <universe@uap-core.de>
parents:
669
diff
changeset
|
108 | ); |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
438
diff
changeset
|
109 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
110 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
111 | * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. |
662
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
647
diff
changeset
|
112 | * |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
647
diff
changeset
|
113 | * The list will use cxDefaultAllocator and no comparator function. If you want |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
647
diff
changeset
|
114 | * to call functions that need a comparator, you must either set one immediately |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
115 | * after list creation or use cxKvListCreate(). |
662
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
647
diff
changeset
|
116 | * |
1111
78eeeb950883
remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents:
1100
diff
changeset
|
117 | * 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
|
118 | * copies of the added elements, and the compare function will be automatically set |
1239
b4b1f15d1866
complete more than 80% of the list.h documentation
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
119 | * 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
|
120 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
121 | * 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
|
122 | * 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
|
123 | * 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
|
124 | * with cxKvListAsList(). |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
125 | * |
1100
2ca6fa71e55e
refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
126 | * @param elem_size (@c size_t) the size of each element in bytes |
2ca6fa71e55e
refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
127 | * @return (@c CxList*) 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
|
128 | * @see cxKvListAsMap() |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
129 | * @see cxKvListAsList() |
662
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
647
diff
changeset
|
130 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
131 | #define cxKvListCreateSimple(elem_size) cxKvListCreate(NULL, NULL, elem_size) |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
415
diff
changeset
|
132 | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
438
diff
changeset
|
133 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
134 | * 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
|
135 | * |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
136 | * The list will use cxDefaultAllocator and no comparator function. If you want |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
137 | * to call functions that need a comparator, you must either set one immediately |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
138 | * after list creation or use cxKvListCreate(). |
480
e3be53a3354f
add cx_linked_list_find()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
139 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
140 | * 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
|
141 | * copies of the added elements, and the compare function will be automatically set |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
142 | * to cx_cmp_ptr(). |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
143 | * |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
144 | * This macro behaves as if the list was created with cxKvListCreateSimple() and |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
145 | * immediately followed up by cxKvListAsMap(). |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
146 | * If you want to use the returned object as a list, you can call cxKvListAsList() later. |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
147 | * |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
148 | * @param elem_size (@c size_t) 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
|
149 | * @return (@c CxMap*) 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
|
150 | * @see cxKvListAsMap() |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
151 | * @see cxKvListAsList() |
480
e3be53a3354f
add cx_linked_list_find()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
152 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
153 | #define cxKvListCreateAsMapSimple(elem_size) cxKvListCreateAsMap(NULL, NULL, elem_size) |
764
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
154 | |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
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 | * 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
|
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 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
|
159 | * @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
|
160 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
161 | cx_attr_nodiscard |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
162 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
163 | cx_attr_returns_nonnull |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1162
diff
changeset
|
164 | cx_attr_export |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
165 | CxList *cxKvListAsList(CxMap *map); |
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
166 | |
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
167 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
168 | * 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
|
169 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
170 | * @param list a list created by cxKvListCreate() or cxKvListCreateSimple() |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
171 | * @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
|
172 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
173 | cx_attr_nodiscard |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
174 | cx_attr_nonnull |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
175 | cx_attr_returns_nonnull |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1162
diff
changeset
|
176 | cx_attr_export |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
177 | CxMap *cxKvListAsMap(CxList *list); |
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
178 | |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
179 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
180 | cx_attr_export |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
181 | int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
182 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
183 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
184 | cx_attr_export |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
185 | int cx_kv_list_remove_key(CxList *list, size_t index, CxHashKey key); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
186 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
187 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
188 | cx_attr_export |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
189 | int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
190 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
191 | // Generic Functions |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
192 | #ifdef __cplusplus |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
193 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
194 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
195 | static inline int cxKvListSetKey(CxList *list, size_t index, CxHashKey key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
196 | return cx_kv_list_set_key(list, index, key); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
197 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
198 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
199 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
200 | static inline int cxKvListSetKey(CxList *list, size_t index, cxstring key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
201 | return cx_kv_list_set_key(list, index, cx_hash_key_cxstr(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
202 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
203 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
204 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
205 | static inline int cxKvListSetKey(CxList *list, size_t index, cxmutstr key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
206 | return cx_kv_list_set_key(list, index, cx_hash_key_cxstr(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
207 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
208 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
209 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
210 | cx_attr_cstr_arg(2) |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
211 | static inline int cxKvListSetKey(CxList *list, size_t index, const char *key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
212 | return cx_kv_list_set_key(list, index, cx_hash_key_str(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
213 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
214 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
215 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
216 | static inline int cxKvListRemoveKey(CxList *list, size_t index, CxHashKey key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
217 | return cx_kv_list_remove_key(list, index, key); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
218 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
219 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
220 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
221 | static inline int cxKvListRemoveKey(CxList *list, size_t index, cxstring key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
222 | return cx_kv_list_remove_key(list, index, cx_hash_key_cxstr(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
223 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
224 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
225 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
226 | static inline int cxKvListRemoveKey(CxList *list, size_t index, cxmutstr key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
227 | return cx_kv_list_remove_key(list, index, cx_hash_key_cxstr(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
228 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
229 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
230 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
231 | cx_attr_cstr_arg(2) |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
232 | static inline int cxKvListRemoveKey(CxList *list, size_t index, const char *key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
233 | return cx_kv_list_remove_key(list, index, cx_hash_key_str(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
234 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
235 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
236 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
237 | static inline int cxKvListInsert(CxList *list, size_t index, CxHashKey key, void *value) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
238 | return cx_kv_list_insert(list, index, key, value, value); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
239 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
240 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
241 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
242 | static inline int cxKvListInsert(CxList *list, size_t index, cxstring key, void *value) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
243 | return cx_kv_list_insert(list, index, cx_hash_key_cxstr(key), value); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
244 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
245 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
246 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
247 | static inline int cxKvListInsert(CxList *list, size_t index, cxmutstr key, void *value) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
248 | return cx_kv_list_insert(list, index, cx_hash_key_cxstr(key), value); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
249 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
250 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
251 | cx_attr_nonnull |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
252 | cx_attr_cstr_arg(2) |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
253 | static inline int cxKvListInsert(CxList *list, size_t index, const char *key, void *value) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
254 | return cx_kv_list_insert(list, index, cx_hash_key_str(key), value); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
255 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
256 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
257 | #else /* ! __cplusplus */ |
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
258 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
259 | * 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
|
260 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
261 | * 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
|
262 | * 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
|
263 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
264 | * @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
|
265 | * @param index (@c size_t) the index of the element in the list |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
266 | * @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
|
267 | * @retval zero success |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
268 | * @retval non-zero memory allocation failure or the index is out of bounds |
481
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
269 | */ |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
270 | #define cxKvListSetKey(list, index, key) _Generic((key), \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
271 | CxHashKey: cx_kv_list_set_key, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
272 | cxstring: cx_kv_list_set_key_cxstr, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
273 | cxmutstr: cx_kv_list_set_key_mustr, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
274 | char*: cx_kv_list_set_key_str, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
275 | const char*: cx_kv_list_set_key_str) \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
276 | (list, index, key) |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
277 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
278 | static inline int cx_kv_list_set_key_cxstr(CxList *list, size_t index, cxstring key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
279 | return cx_kv_list_set_key(list, index, cx_hash_key_cxstr(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
280 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
281 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
282 | static inline int cx_kv_list_set_key_mustr(CxList *list, size_t index, cxmutstr key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
283 | return cx_kv_list_set_key(list, index, cx_hash_key_cxstr(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
284 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
285 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
286 | static inline int cx_kv_list_set_key_str(CxList *list, size_t index, const char *key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
287 | return cx_kv_list_set_key(list, index, cx_hash_key_str(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
288 | } |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
473
diff
changeset
|
289 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
473
diff
changeset
|
290 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
291 | * Removes the key for a list item. |
879
9c24a4eb5ac9
implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents:
878
diff
changeset
|
292 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
293 | * This can be useful if you want to explicitly remove an item from the lookup map, |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
294 | * for example, when you want to prevent a deletion by cxMapClear(). |
879
9c24a4eb5ac9
implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents:
878
diff
changeset
|
295 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
296 | * @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
|
297 | * @param index (@c size_t) the index of the element in the list |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
298 | * @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
|
299 | * @retval zero success |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
300 | * @retval non-zero the index is out of bounds |
879
9c24a4eb5ac9
implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents:
878
diff
changeset
|
301 | */ |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
302 | #define cxKvListRemoveKey(list, index, key) _Generic((key), \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
303 | CxHashKey: cx_kv_list_remove_key, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
304 | cxstring: cx_kv_list_remove_key_cxstr, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
305 | cxmutstr: cx_kv_list_remove_key_mustr, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
306 | char*: cx_kv_list_remove_key_str, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
307 | const char*: cx_kv_list_remove_key_str) \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
308 | (list, index, key) |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
309 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
310 | static inline int cx_kv_list_remove_key_cxstr(CxList *list, size_t index, cxstring key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
311 | return cx_kv_list_remove_key(list, index, cx_hash_key_cxstr(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
312 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
313 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
314 | static inline int cx_kv_list_remove_key_mustr(CxList *list, size_t index, cxmutstr key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
315 | return cx_kv_list_remove_key(list, index, cx_hash_key_cxstr(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
316 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
317 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
318 | static inline int cx_kv_list_remove_key_str(CxList *list, size_t index, const char *key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
319 | return cx_kv_list_remove_key(list, index, cx_hash_key_str(key)); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
320 | } |
919
75da57d4634e
add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents:
891
diff
changeset
|
321 | |
75da57d4634e
add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents:
891
diff
changeset
|
322 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
323 | * 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:
468
diff
changeset
|
324 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
325 | * @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
|
326 | * @param index (@c size_t) the index the inserted element shall have |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
327 | * @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
|
328 | * @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
|
329 | * @retval zero success |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
330 | * @retval non-zero memory allocation failure or the index is out of bounds |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
331 | */ |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
332 | #define cxKvListInsert(list, index, key, value) _Generic((key), \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
333 | CxHashKey: cx_kv_list_insert, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
334 | cxstring: cx_kv_list_insert_cxstr, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
335 | cxmutstr: cx_kv_list_insert_mustr, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
336 | char*: cx_kv_list_insert_str, \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
337 | const char*: cx_kv_list_insert_str) \ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
338 | (list, index, key, value) |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
339 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
340 | static inline int cx_kv_list_insert_cxstr(CxList *list, size_t index, cxstring key, void *value) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
341 | return cx_kv_list_insert(list, index, cx_hash_key_cxstr(key), value); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
342 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
343 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
344 | static inline int cx_kv_list_insert_mustr(CxList *list, size_t index, cxmutstr key, void *value) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
345 | return cx_kv_list_insert(list, index, cx_hash_key_cxstr(key), value); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
346 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
347 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
348 | static inline int cx_kv_list_insert_str(CxList *list, size_t index, const char *key, void *value) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
349 | return cx_kv_list_insert(list, index, cx_hash_key_str(key), value); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
350 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
351 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
1347
diff
changeset
|
352 | #endif |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
467
diff
changeset
|
353 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
467
diff
changeset
|
354 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
355 | * 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
|
356 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
357 | * @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
|
358 | * @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
|
359 | * @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
|
360 | * @retval zero success |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
361 | * @retval non-zero memory allocation failure or the index is out of bounds |
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
485
diff
changeset
|
362 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
363 | #define cxKvListAdd(list, index, 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:
468
diff
changeset
|
364 | |
415 | 365 | #ifdef __cplusplus |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
552
diff
changeset
|
366 | } // extern "C" |
415 | 367 | #endif |
368 | ||
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
369 | #endif // UCX_KV_LIST_H |