Thu, 30 Oct 2025 19:27:18 +0100
fix typo bug in cxListDifference() - resolves #745
| 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: 
1347diff
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: 
438diff
changeset | 28 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 29 | * @file kv_list.h | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
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: 
993diff
changeset | 31 | * @author Mike Becker | 
| 
2ca6fa71e55e
refine docs for linked_list.h - issue #548
 Mike Becker <universe@uap-core.de> parents: 
993diff
changeset | 32 | * @author Olaf Wintermann | 
| 
2ca6fa71e55e
refine docs for linked_list.h - issue #548
 Mike Becker <universe@uap-core.de> parents: 
993diff
changeset | 33 | * @copyright 2-Clause BSD License | 
| 453 
bb144d08cd44
add some documentation and changes some signatures
 Mike Becker <universe@uap-core.de> parents: 
438diff
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: 
1318diff
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: 
1318diff
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: 
481diff
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: 
1318diff
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: 
456diff
changeset | 47 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
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: 
456diff
changeset | 49 | * | 
| 1111 
78eeeb950883
remove API for changing the store_pointer property after list creation
 Mike Becker <universe@uap-core.de> parents: 
1100diff
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: 
1318diff
changeset | 51 | * copies of the added elements, and the compare function will be automatically set | 
| 1424 
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
 Mike Becker <universe@uap-core.de> parents: 
1407diff
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: 
662diff
changeset | 53 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
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: 
1318diff
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: 
1318diff
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: 
1318diff
changeset | 57 | * with cxKvListAsList(). | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 58 | * | 
| 466 
28bc3e10ac28
add special linked list implementation for storing pointers
 Mike Becker <universe@uap-core.de> parents: 
456diff
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: 
1241diff
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: 
456diff
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: 
993diff
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: 
759diff
changeset | 63 | * functions will not work) | 
| 855 
35bcb3216c0d
fix inconsistent use of item_size and elem_size
 Mike Becker <universe@uap-core.de> parents: 
807diff
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: 
456diff
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: 
1318diff
changeset | 66 | * @see cxKvListAsMap() | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 67 | * @see cxKvListAsList() | 
| 466 
28bc3e10ac28
add special linked list implementation for storing pointers
 Mike Becker <universe@uap-core.de> parents: 
456diff
changeset | 68 | */ | 
| 1426 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 69 | cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1) | 
| 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 70 | CX_EXPORT CxList *cxKvListCreate(const CxAllocator *allocator, | 
| 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 71 | cx_compare_func comparator, size_t elem_size); | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 72 | |
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 73 | /** | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 74 | * 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: 
1318diff
changeset | 75 | * | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 76 | * 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: 
1318diff
changeset | 77 | * copies of the added elements, and the compare function will be automatically set | 
| 1424 
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
 Mike Becker <universe@uap-core.de> parents: 
1407diff
changeset | 78 | * to cx_cmp_ptr() if none is given. | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 79 | * | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 80 | * 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: 
1318diff
changeset | 81 | * 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: 
1318diff
changeset | 82 | * cxKvListAsList() later. | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 83 | * | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 84 | * @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: 
1318diff
changeset | 85 | * (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: 
1318diff
changeset | 86 | * @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: 
1318diff
changeset | 87 | * (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: 
1318diff
changeset | 88 | * functions will not work) | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 89 | * @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: 
1318diff
changeset | 90 | * @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: 
1318diff
changeset | 91 | * @see cxKvListAsMap() | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 92 | * @see cxKvListAsList() | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 93 | */ | 
| 1426 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 94 | cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxMapFree, 1) | 
| 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 95 | CX_EXPORT CxMap *cxKvListCreateAsMap(const CxAllocator *allocator, | 
| 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 96 | cx_compare_func comparator, size_t elem_size); | 
| 453 
bb144d08cd44
add some documentation and changes some signatures
 Mike Becker <universe@uap-core.de> parents: 
438diff
changeset | 97 | |
| 466 
28bc3e10ac28
add special linked list implementation for storing pointers
 Mike Becker <universe@uap-core.de> parents: 
456diff
changeset | 98 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 99 | * 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: 
647diff
changeset | 100 | * | 
| 
d0d95740071b
add simple functions for creating lists
 Mike Becker <universe@uap-core.de> parents: 
647diff
changeset | 101 | * 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: 
647diff
changeset | 102 | * 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: 
1318diff
changeset | 103 | * after list creation or use cxKvListCreate(). | 
| 662 
d0d95740071b
add simple functions for creating lists
 Mike Becker <universe@uap-core.de> parents: 
647diff
changeset | 104 | * | 
| 1111 
78eeeb950883
remove API for changing the store_pointer property after list creation
 Mike Becker <universe@uap-core.de> parents: 
1100diff
changeset | 105 | * 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: 
1318diff
changeset | 106 | * 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: 
1180diff
changeset | 107 | * to cx_cmp_ptr(). | 
| 669 
dce9b8450656
add docs for CX_STORE_POINTERS and remove cxHashMapCreateForPointers()
 Mike Becker <universe@uap-core.de> parents: 
662diff
changeset | 108 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 109 | * 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: 
1318diff
changeset | 110 | * to a CxMap pointer with cxKvListAsMap(). | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 111 | * 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: 
1318diff
changeset | 112 | * with cxKvListAsList(). | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 113 | * | 
| 1100 
2ca6fa71e55e
refine docs for linked_list.h - issue #548
 Mike Becker <universe@uap-core.de> parents: 
993diff
changeset | 114 | * @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: 
993diff
changeset | 115 | * @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: 
1318diff
changeset | 116 | * @see cxKvListAsMap() | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 117 | * @see cxKvListAsList() | 
| 662 
d0d95740071b
add simple functions for creating lists
 Mike Becker <universe@uap-core.de> parents: 
647diff
changeset | 118 | */ | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 119 | #define cxKvListCreateSimple(elem_size) cxKvListCreate(NULL, NULL, elem_size) | 
| 438 
cd3069757010
add function cx_linked_list_at()
 Mike Becker <universe@uap-core.de> parents: 
415diff
changeset | 120 | |
| 453 
bb144d08cd44
add some documentation and changes some signatures
 Mike Becker <universe@uap-core.de> parents: 
438diff
changeset | 121 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 122 | * 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: 
1318diff
changeset | 123 | * | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 124 | * 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: 
1318diff
changeset | 125 | * 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: 
1318diff
changeset | 126 | * after list creation or use cxKvListCreate(). | 
| 480 
e3be53a3354f
add cx_linked_list_find()
 Mike Becker <universe@uap-core.de> parents: 
478diff
changeset | 127 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 128 | * 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: 
1318diff
changeset | 129 | * 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: 
1318diff
changeset | 130 | * to cx_cmp_ptr(). | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 131 | * | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 132 | * 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: 
1318diff
changeset | 133 | * immediately followed up by cxKvListAsMap(). | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 134 | * 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: 
1318diff
changeset | 135 | * | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 136 | * @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: 
1318diff
changeset | 137 | * @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: 
1318diff
changeset | 138 | * @see cxKvListAsMap() | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 139 | * @see cxKvListAsList() | 
| 480 
e3be53a3354f
add cx_linked_list_find()
 Mike Becker <universe@uap-core.de> parents: 
478diff
changeset | 140 | */ | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 141 | #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: 
763diff
changeset | 142 | |
| 
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
 Mike Becker <universe@uap-core.de> parents: 
763diff
changeset | 143 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 144 | * 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: 
473diff
changeset | 145 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 146 | * @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: 
1318diff
changeset | 147 | * @return the original list pointer | 
| 475 
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
 Mike Becker <universe@uap-core.de> parents: 
473diff
changeset | 148 | */ | 
| 1426 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 149 | cx_attr_nodiscard cx_attr_nonnull cx_attr_returns_nonnull | 
| 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 150 | CX_EXPORT CxList *cxKvListAsList(CxMap *map); | 
| 481 
eef025d82a34
add several new linked list functions
 Mike Becker <universe@uap-core.de> parents: 
480diff
changeset | 151 | |
| 
eef025d82a34
add several new linked list functions
 Mike Becker <universe@uap-core.de> parents: 
480diff
changeset | 152 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 153 | * 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: 
480diff
changeset | 154 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 155 | * @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: 
1318diff
changeset | 156 | * @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: 
480diff
changeset | 157 | */ | 
| 1426 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 158 | cx_attr_nodiscard cx_attr_nonnull cx_attr_returns_nonnull | 
| 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 159 | CX_EXPORT CxMap *cxKvListAsMap(CxList *list); | 
| 481 
eef025d82a34
add several new linked list functions
 Mike Becker <universe@uap-core.de> parents: 
480diff
changeset | 160 | |
| 1407 | 161 | /** | 
| 162 | * Sets or updates the key of a list item. | |
| 163 | * | |
| 164 | * This is, for example, useful when you have inserted an element using the CxList interface, | |
| 165 | * and now you want to associate this element with a key. | |
| 166 | * | |
| 167 | * @param list the list | |
| 168 | * @param index the index of the element in the list | |
| 169 | * @param key the key | |
| 170 | * @retval zero success | |
| 171 | * @retval non-zero memory allocation failure or the index is out of bounds | |
| 172 | * @see cxKvListSetKey() | |
| 173 | */ | |
| 1348 
a1da355ed3b8
roll out the function stubs for the kv-list
 Mike Becker <universe@uap-core.de> parents: 
1347diff
changeset | 174 | cx_attr_nonnull | 
| 1426 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 175 | CX_EXPORT int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key); | 
| 1348 
a1da355ed3b8
roll out the function stubs for the kv-list
 Mike Becker <universe@uap-core.de> parents: 
1347diff
changeset | 176 | |
| 1407 | 177 | /** | 
| 178 | * Inserts an item into the list at the specified index and associates it with the specified key. | |
| 179 | * | |
| 180 | * @param list the list | |
| 181 | * @param index the index the inserted element shall have | |
| 182 | * @param key the key | |
| 183 | * @param value the value | |
| 184 | * @retval zero success | |
| 185 | * @retval non-zero memory allocation failure or the index is out of bounds | |
| 186 | * @see cxKvListInsert() | |
| 187 | */ | |
| 1348 
a1da355ed3b8
roll out the function stubs for the kv-list
 Mike Becker <universe@uap-core.de> parents: 
1347diff
changeset | 188 | cx_attr_nonnull | 
| 1426 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 189 | CX_EXPORT int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); | 
| 1348 
a1da355ed3b8
roll out the function stubs for the kv-list
 Mike Becker <universe@uap-core.de> parents: 
1347diff
changeset | 190 | |
| 481 
eef025d82a34
add several new linked list functions
 Mike Becker <universe@uap-core.de> parents: 
480diff
changeset | 191 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 192 | * Sets or updates the key of a list item. | 
| 481 
eef025d82a34
add several new linked list functions
 Mike Becker <universe@uap-core.de> parents: 
480diff
changeset | 193 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 194 | * 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: 
1318diff
changeset | 195 | * 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: 
480diff
changeset | 196 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 197 | * @param list (@c CxList*) the list | 
| 1348 
a1da355ed3b8
roll out the function stubs for the kv-list
 Mike Becker <universe@uap-core.de> parents: 
1347diff
changeset | 198 | * @param index (@c size_t) the index of the element in the list | 
| 1406 
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
 Mike Becker <universe@uap-core.de> parents: 
1404diff
changeset | 199 | * @param key (any supported key type) the key | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 200 | * @retval zero success | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 201 | * @retval non-zero memory allocation failure or the index is out of bounds | 
| 1406 
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
 Mike Becker <universe@uap-core.de> parents: 
1404diff
changeset | 202 | * @see CX_HASH_KEY() | 
| 481 
eef025d82a34
add several new linked list functions
 Mike Becker <universe@uap-core.de> parents: 
480diff
changeset | 203 | */ | 
| 1406 
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
 Mike Becker <universe@uap-core.de> parents: 
1404diff
changeset | 204 | #define cxKvListSetKey(list, index, key) cx_kv_list_set_key(list, index, CX_HASH_KEY(key)) | 
| 475 
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
 Mike Becker <universe@uap-core.de> parents: 
473diff
changeset | 205 | |
| 
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
 Mike Becker <universe@uap-core.de> parents: 
473diff
changeset | 206 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 207 | * 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: 
468diff
changeset | 208 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 209 | * @param list (@c CxList*) the list | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 210 | * @param index (@c size_t) the index the inserted element shall have | 
| 1406 
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
 Mike Becker <universe@uap-core.de> parents: 
1404diff
changeset | 211 | * @param key (any supported key type) the key | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 212 | * @param value (@c void*) the value | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 213 | * @retval zero success | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 214 | * @retval non-zero memory allocation failure or the index is out of bounds | 
| 1406 
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
 Mike Becker <universe@uap-core.de> parents: 
1404diff
changeset | 215 | * @see CX_HASH_KEY() | 
| 473 
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
 Mike Becker <universe@uap-core.de> parents: 
468diff
changeset | 216 | */ | 
| 1406 
85dc816f3442
change kv-list to use new CX_HASH_KEY macro
 Mike Becker <universe@uap-core.de> parents: 
1404diff
changeset | 217 | #define cxKvListInsert(list, index, key, value) cx_kv_list_insert(list, index, CX_HASH_KEY(key), value) | 
| 1348 
a1da355ed3b8
roll out the function stubs for the kv-list
 Mike Becker <universe@uap-core.de> parents: 
1347diff
changeset | 218 | |
| 468 
75ae1dccd101
add cx_linked_list_sort()
 Mike Becker <universe@uap-core.de> parents: 
467diff
changeset | 219 | |
| 
75ae1dccd101
add cx_linked_list_sort()
 Mike Becker <universe@uap-core.de> parents: 
467diff
changeset | 220 | /** | 
| 1404 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 221 | * Removes the key of a list item. | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 222 | * | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 223 | * This can be useful if you want to explicitly remove an item from the lookup map. | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 224 | * | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 225 | * If no key is associated with the item, nothing happens, and this function returns zero. | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 226 | * | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 227 | * @param list the list | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 228 | * @param index the index of the element in the list | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 229 | * @retval zero success | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 230 | * @retval non-zero the index is out of bounds | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 231 | */ | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 232 | cx_attr_nonnull | 
| 1426 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 233 | CX_EXPORT int cxKvListRemoveKey(CxList *list, size_t index); | 
| 1404 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 234 | |
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 235 | /** | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 236 | * Returns the key of a list item. | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 237 | * | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 238 | * @param list the list | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 239 | * @param index the index of the element in the list | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 240 | * @return a pointer to the key or @c NULL when the index is out of bounds or the item does not have a key | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 241 | */ | 
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 242 | cx_attr_nonnull | 
| 1426 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 Mike Becker <universe@uap-core.de> parents: 
1424diff
changeset | 243 | CX_EXPORT const CxHashKey *cxKvListGetKey(CxList *list, size_t index); | 
| 1404 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 244 | |
| 
ae80e36c05c7
fix cxKvListSetKey() and cxKvListRemoveKey() accidentally not declared for C++
 Mike Becker <universe@uap-core.de> parents: 
1394diff
changeset | 245 | /** | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 246 | * 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: 
485diff
changeset | 247 | * | 
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 248 | * @param list (@c CxList*) the list | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 249 | * @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: 
1318diff
changeset | 250 | * @param value (@c void*) the value | 
| 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 251 | * @retval zero success | 
| 1378 
1b4fa55f7caa
implement cx_kv_list_insert()
 Mike Becker <universe@uap-core.de> parents: 
1377diff
changeset | 252 | * @retval non-zero memory allocation failure | 
| 486 
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
 Mike Becker <universe@uap-core.de> parents: 
485diff
changeset | 253 | */ | 
| 1378 
1b4fa55f7caa
implement cx_kv_list_insert()
 Mike Becker <universe@uap-core.de> parents: 
1377diff
changeset | 254 | #define cxKvListAdd(list, key, value) cxKvListInsert(list, (list)->collection.size, key, value) | 
| 473 
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
 Mike Becker <universe@uap-core.de> parents: 
468diff
changeset | 255 | |
| 415 | 256 | #ifdef __cplusplus | 
| 628 
1e2be40f0cb5
use //-style single line comments everywhere
 Mike Becker <universe@uap-core.de> parents: 
552diff
changeset | 257 | } // extern "C" | 
| 415 | 258 | #endif | 
| 259 | ||
| 1347 
d02b1fde73ee
create a header file for the new key-value-lists
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 260 | #endif // UCX_KV_LIST_H |