Sun, 24 Aug 2025 17:11:53 +0200
create a header file for the new key-value-lists
kick-off for issue #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 | * |
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
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 | |
eef025d82a34
add several new linked list functions
Mike Becker <universe@uap-core.de>
parents:
480
diff
changeset
|
179 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
180 | * 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
|
181 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
182 | * 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
|
183 | * 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
|
184 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
185 | * @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
|
186 | * @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
|
187 | * @param index (@c size_t) the index of the element in the list |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
188 | * @retval zero success |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
189 | * @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
|
190 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
191 | #define cxKvListSetKey(list, key, index) |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
473
diff
changeset
|
192 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
473
diff
changeset
|
193 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
194 | * 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
|
195 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
196 | * 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
|
197 | * 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
|
198 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
199 | * @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
|
200 | * @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
|
201 | * @param index (@c size_t) the index of the element in the list |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
202 | * @retval zero success |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
203 | * @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
|
204 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
205 | #define cxKvListRemoveKey(list, key, index) |
919
75da57d4634e
add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents:
891
diff
changeset
|
206 | |
75da57d4634e
add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents:
891
diff
changeset
|
207 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
208 | * 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
|
209 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
210 | * @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
|
211 | * @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
|
212 | * @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
|
213 | * @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
|
214 | * @retval zero success |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
215 | * @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
|
216 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
217 | #define cxKvListInsert(list, index, key, value) |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
467
diff
changeset
|
218 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
467
diff
changeset
|
219 | /** |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
220 | * 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
|
221 | * |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
222 | * @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
|
223 | * @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
|
224 | * @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
|
225 | * @retval zero success |
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
226 | * @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
|
227 | */ |
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
228 | #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
|
229 | |
415 | 230 | #ifdef __cplusplus |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
552
diff
changeset
|
231 | } // extern "C" |
415 | 232 | #endif |
233 | ||
1347
d02b1fde73ee
create a header file for the new key-value-lists
Mike Becker <universe@uap-core.de>
parents:
1318
diff
changeset
|
234 | #endif // UCX_KV_LIST_H |