Sat, 08 Nov 2025 23:06:11 +0100
update ucx
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 852 | 29 | * @file map.h |
| 30 | * @brief Interface for map implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #ifndef UCX_MAP_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #define UCX_MAP_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "common.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "collection.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include "string.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include "hash_key.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
| 888 | 44 | #ifndef UCX_LIST_H |
| 45 | // forward-declare CxList | |
| 46 | typedef struct cx_list_s CxList; | |
| 47 | #endif | |
| 48 | ||
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | extern "C" { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | /** Type for the UCX map. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | typedef struct cx_map_s CxMap; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | /** Type for a map entry. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | typedef struct cx_map_entry_s CxMapEntry; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
59 | /** Type for a map iterator. */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
60 | typedef struct cx_map_iterator_s CxMapIterator; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
61 | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | /** Type for map class definitions. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | typedef struct cx_map_class_s cx_map_class; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | /** Structure for the UCX map. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | struct cx_map_s { |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
67 | /** |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
68 | * Base attributes. |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
69 | */ |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
70 | CX_COLLECTION_BASE; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | /** The map class definition. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | cx_map_class *cl; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | }; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | /** |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
76 | * A map entry. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
77 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
78 | struct cx_map_entry_s { |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
79 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
80 | * A pointer to the key. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
81 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
82 | const CxHashKey *key; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
83 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
84 | * A pointer to the value. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
85 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
86 | void *value; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
87 | }; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
88 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
89 | /** |
| 750 | 90 | * The type of iterator for a map. |
| 91 | */ | |
| 92 | enum cx_map_iterator_type { | |
| 93 | /** | |
| 94 | * Iterates over key/value pairs. | |
| 95 | */ | |
| 96 | CX_MAP_ITERATOR_PAIRS, | |
| 97 | /** | |
| 98 | * Iterates over keys only. | |
| 99 | */ | |
| 100 | CX_MAP_ITERATOR_KEYS, | |
| 101 | /** | |
| 102 | * Iterates over values only. | |
| 103 | */ | |
| 104 | CX_MAP_ITERATOR_VALUES | |
| 105 | }; | |
| 106 | ||
| 107 | /** | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
108 | * Internal iterator struct - use CxMapIterator. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
109 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
110 | struct cx_map_iterator_s { |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
111 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
112 | * Inherited common data for all iterators. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
113 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
114 | CX_ITERATOR_BASE; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
115 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
116 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
117 | * Handle for the source map. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
118 | */ |
| 888 | 119 | CxMap *map; |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
120 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
121 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
122 | * Handle for the current element. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
123 | * |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
124 | * @attention Depends on the map implementation, do not assume a type (better: do not use!). |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
125 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
126 | void *elem; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
127 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
128 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
129 | * Reserved memory for a map entry. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
130 | * |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
131 | * If a map implementation uses an incompatible layout, the iterator needs something |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
132 | * to point to during iteration which @em is compatible. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
133 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
134 | CxMapEntry entry; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
135 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
136 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
137 | * Field for storing the current slot number. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
138 | * |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
139 | * (Used internally) |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
140 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
141 | size_t slot; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
142 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
143 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
144 | * Counts the elements successfully. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
145 | * It usually does not denote a stable index within the map as it would be for arrays. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
146 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
147 | size_t index; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
148 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
149 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
150 | * The size of a value stored in this map. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
151 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
152 | size_t elem_size; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
153 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
154 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
155 | * May contain the total number of elements, if known. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
156 | * Set to @c SIZE_MAX when the total number is unknown during iteration. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
157 | * |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
158 | * @remark The UCX implementations of #CxMap always know the number of elements they store. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
159 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
160 | size_t elem_count; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
161 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
162 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
163 | * The type of this iterator. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
164 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
165 | enum cx_map_iterator_type type; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
166 | }; |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
167 | |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
168 | /** |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | * The class definition for arbitrary maps. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | struct cx_map_class_s { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | * Deallocates the entire memory. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | */ |
| 852 | 175 | void (*deallocate)(struct cx_map_s *map); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | * Removes all elements. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | void (*clear)(struct cx_map_s *map); |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | * Add or overwrite an element. |
| 888 | 184 | * If the @p value is @c NULL, the implementation |
| 185 | * shall only allocate memory instead of adding an existing value to the map. | |
| 186 | * Returns a pointer to the allocated memory or @c NULL if allocation fails. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | */ |
| 888 | 188 | void *(*put)(CxMap *map, CxHashKey key, void *value); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | * Returns an element. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | */ |
| 888 | 193 | void *(*get)(const CxMap *map, CxHashKey key); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | * Removes an element. |
| 852 | 197 | * |
| 198 | * Implementations SHALL check if @p targetbuf is set and copy the elements | |
| 199 | * to the buffer without invoking any destructor. | |
| 200 | * When @p targetbuf is not set, the destructors SHALL be invoked. | |
| 201 | * | |
| 202 | * The function SHALL return zero when the @p key was found and | |
| 203 | * non-zero, otherwise. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | */ |
| 888 | 205 | int (*remove)(CxMap *map, CxHashKey key, void *targetbuf); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | /** |
| 750 | 208 | * Creates an iterator for this map. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | */ |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
210 | CxMapIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | }; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | |
| 775 | 213 | /** |
| 214 | * A shared instance of an empty map. | |
| 215 | * | |
| 852 | 216 | * Writing to that map is not allowed. |
| 217 | * | |
| 888 | 218 | * You can use this as a placeholder for initializing CxMap pointers |
| 852 | 219 | * for which you do not want to reserve memory right from the beginning. |
| 775 | 220 | */ |
| 888 | 221 | CX_EXPORT extern CxMap *const cxEmptyMap; |
| 750 | 222 | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | * Deallocates the memory of the specified map. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | * |
| 852 | 226 | * Also calls the content destructor functions for each element, if specified. |
| 227 | * | |
| 228 | * @param map the map to be freed | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | */ |
| 888 | 230 | CX_EXPORT void cxMapFree(CxMap *map); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | * Clears a map by removing all elements. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | * |
| 852 | 236 | * Also calls the content destructor functions for each element, if specified. |
| 237 | * | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | * @param map the map to be cleared |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | */ |
| 852 | 240 | cx_attr_nonnull |
| 888 | 241 | CX_EXPORT void cxMapClear(CxMap *map); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
243 | /** |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
244 | * Returns the number of elements in this map. |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
245 | * |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
246 | * @param map the map |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
247 | * @return the number of stored elements |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
248 | */ |
| 852 | 249 | cx_attr_nonnull |
| 888 | 250 | CX_EXPORT size_t cxMapSize(const CxMap *map); |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
775
diff
changeset
|
251 | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | * Creates a value iterator for a map. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | * |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
255 | * When the map is storing pointers, those pointers are returned. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
256 | * Otherwise, the iterator iterates over pointers to the memory within the map where the |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
257 | * respective elements are stored. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
258 | * |
| 852 | 259 | * @note An iterator iterates over all elements successively. Therefore, the order |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | * |
| 888 | 262 | * @param map the map to create the iterator for (can be @c NULL) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | * @return an iterator for the currently stored values |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | */ |
| 852 | 265 | cx_attr_nodiscard |
| 888 | 266 | CX_EXPORT CxMapIterator cxMapIteratorValues(const CxMap *map); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | * Creates a key iterator for a map. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | * |
| 888 | 271 | * The elements of the iterator are keys of type CxHashKey, and the pointer returned |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
272 | * during iterator shall be treated as @c const @c CxHashKey* . |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | * |
| 852 | 274 | * @note An iterator iterates over all elements successively. Therefore, the order |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | * |
| 888 | 277 | * @param map the map to create the iterator for (can be @c NULL) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | * @return an iterator for the currently stored keys |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | */ |
| 852 | 280 | cx_attr_nodiscard |
| 888 | 281 | CX_EXPORT CxMapIterator cxMapIteratorKeys(const CxMap *map); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | * Creates an iterator for a map. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | * |
| 888 | 286 | * The elements of the iterator are key/value pairs of type CxMapEntry, and the pointer returned |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
287 | * during iterator shall be treated as @c const @c CxMapEntry* . |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | * |
| 852 | 289 | * @note An iterator iterates over all elements successively. Therefore, the order |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | * |
| 888 | 292 | * @param map the map to create the iterator for (can be @c NULL) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | * @return an iterator for the currently stored entries |
| 888 | 294 | * @see cxMapIteratorKeys() |
| 295 | * @see cxMapIteratorValues() | |
| 296 | */ | |
| 297 | cx_attr_nodiscard | |
| 298 | CX_EXPORT CxMapIterator cxMapIterator(const CxMap *map); | |
| 299 | ||
| 300 | /** | |
| 301 | * Puts a key/value-pair into the map. | |
| 302 | * | |
| 303 | * A possible existing value will be overwritten. | |
| 304 | * If destructor functions are specified, they are called for | |
| 305 | * the overwritten element. | |
| 306 | * | |
| 307 | * If this map is storing pointers, the @p value pointer is written | |
| 308 | * to the map. Otherwise, the memory is copied from @p value with | |
| 309 | * memcpy(). | |
| 310 | * | |
| 311 | * The @p key is always copied. | |
| 312 | * | |
| 313 | * @param map the map | |
| 314 | * @param key the key | |
| 315 | * @param value the value | |
| 316 | * @retval zero success | |
| 317 | * @retval non-zero value on memory allocation failure | |
| 318 | * @see cxMapPut() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | */ |
| 852 | 320 | cx_attr_nonnull |
| 888 | 321 | CX_EXPORT int cx_map_put(CxMap *map, CxHashKey key, void *value); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | * Puts a key/value-pair into the map. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | * |
| 852 | 326 | * A possible existing value will be overwritten. |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
327 | * If destructor functions are specified, they are called for |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
328 | * the overwritten element. |
| 852 | 329 | * |
| 330 | * If this map is storing pointers, the @p value pointer is written | |
| 331 | * to the map. Otherwise, the memory is copied from @p value with | |
| 332 | * memcpy(). | |
| 333 | * | |
| 334 | * The @p key is always copied. | |
| 335 | * | |
| 336 | * @param map (@c CxMap*) the map | |
| 888 | 337 | * @param key (any supported key type) the key |
| 852 | 338 | * @param value (@c void*) the value |
| 339 | * @retval zero success | |
| 340 | * @retval non-zero value on memory allocation failure | |
| 888 | 341 | * @see CX_HASH_KEY() |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | */ |
| 888 | 343 | #define cxMapPut(map, key, value) cx_map_put(map, CX_HASH_KEY(key), value) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | /** |
| 888 | 346 | * Allocates memory for a value in the map associated with the specified key. |
| 347 | * | |
| 348 | * A possible existing value will be overwritten. | |
| 349 | * If destructor functions are specified, they are called for | |
| 350 | * the overwritten element. | |
| 351 | * | |
| 352 | * If the map is storing pointers, this function returns a @c void** pointer, | |
| 353 | * meaning a pointer to that pointer. | |
| 354 | * | |
| 355 | * The @p key is always copied. | |
| 356 | * | |
| 357 | * @param map the map | |
| 358 | * @param key the key | |
| 359 | * @return the pointer to the allocated memory or @c NULL if allocation fails | |
| 360 | * @retval zero success | |
| 361 | * @retval non-zero value on memory allocation failure | |
| 362 | * @see cxMapEmplace() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | */ |
| 852 | 364 | cx_attr_nonnull |
| 888 | 365 | CX_EXPORT void *cx_map_emplace(CxMap *map, CxHashKey key); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | /** |
| 888 | 368 | * Allocates memory for a value in the map associated with the specified key. |
| 369 | * | |
| 370 | * A possible existing value will be overwritten. | |
| 371 | * If destructor functions are specified, they are called for | |
| 372 | * the overwritten element. | |
| 373 | * | |
| 374 | * If the map is storing pointers, this function returns a @c void** pointer, | |
| 375 | * meaning a pointer to that pointer. | |
| 376 | * | |
| 377 | * The @p key is always copied. | |
| 378 | * | |
| 379 | * @param map (@c CxMap*) the map | |
| 380 | * @param key (any supported key type) the key | |
| 381 | * @return the pointer to the allocated memory or @c NULL if allocation fails | |
| 382 | * @retval zero success | |
| 383 | * @retval non-zero value on memory allocation failure | |
| 384 | * @see CX_HASH_KEY() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | */ |
| 888 | 386 | #define cxMapEmplace(map, key) cx_map_emplace(map, CX_HASH_KEY(key)) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | /** |
| 888 | 389 | * Retrieves a value by using a key. |
| 390 | * | |
| 391 | * If this map is storing pointers, the stored pointer is returned. | |
| 392 | * Otherwise, a pointer to the element within the map's memory | |
| 393 | * is returned (which is valid as long as the element stays in the map). | |
| 394 | * | |
| 395 | * @param map the map | |
| 396 | * @param key the key | |
| 397 | * @return the value | |
| 398 | * @see cxMapGet() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | */ |
| 888 | 400 | cx_attr_nonnull cx_attr_nodiscard |
| 401 | CX_EXPORT void *cx_map_get(const CxMap *map, CxHashKey key); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | * Retrieves a value by using a key. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | * |
| 852 | 406 | * If this map is storing pointers, the stored pointer is returned. |
| 407 | * Otherwise, a pointer to the element within the map's memory | |
| 408 | * is returned (which is valid as long as the element stays in the map). | |
| 409 | * | |
| 410 | * @param map (@c CxMap*) the map | |
| 888 | 411 | * @param key (any supported key type) the key |
| 412 | * @return (@c void*) the value or @c NULL when no value with that @p key exists | |
| 413 | * @see CX_HASH_KEY() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | */ |
| 888 | 415 | #define cxMapGet(map, key) cx_map_get(map, CX_HASH_KEY(key)) |
| 852 | 416 | |
| 417 | /** | |
| 888 | 418 | * Checks if a map contains a specific key. |
| 419 | * | |
| 420 | * @param map (@c CxMap*) the map | |
| 421 | * @param key (any supported key type) the key | |
| 422 | * @retval true if the key exists in the map | |
| 423 | * @retval false if the key does not exist in the map | |
| 424 | * @see CX_HASH_KEY() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | */ |
| 888 | 426 | #define cxMapContains(map, key) (cxMapGet(map, key) != NULL) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
427 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
428 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | * Removes a key/value-pair from the map by using the key. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | * |
| 888 | 431 | * Invokes the destructor functions, if any, on the removed element if and only if the |
| 432 | * @p targetbuf is @c NULL. | |
| 433 | * | |
| 434 | * @param map the map | |
| 435 | * @param key the key | |
| 436 | * @param targetbuf the optional buffer where the removed element shall be copied to | |
| 437 | * @retval zero success | |
| 438 | * @retval non-zero the key was not found | |
| 439 | * | |
| 440 | * @see cxMapRemove() | |
| 441 | * @see cxMapRemoveAndGet() | |
| 442 | */ | |
| 443 | cx_attr_nonnull_arg(1) | |
| 444 | CX_EXPORT int cx_map_remove(CxMap *map, CxHashKey key, void *targetbuf); | |
| 445 | ||
| 446 | /** | |
| 447 | * Removes a key/value-pair from the map by using the key. | |
| 448 | * | |
| 449 | * Always invokes the destructor functions, if any, on the removed element. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | * |
| 852 | 451 | * @param map (@c CxMap*) the map |
| 888 | 452 | * @param key (any supported key type) the key |
| 852 | 453 | * @retval zero success |
| 454 | * @retval non-zero the key was not found | |
| 455 | * | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | * @see cxMapRemoveAndGet() |
| 888 | 457 | * @see CX_HASH_KEY() |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | */ |
| 888 | 459 | #define cxMapRemove(map, key) cx_map_remove(map, CX_HASH_KEY(key), NULL) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | * Removes a key/value-pair from the map by using the key. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | * |
| 852 | 464 | * This function will copy the contents of the removed element |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
465 | * to the target buffer, which must be guaranteed to be large enough |
| 852 | 466 | * to hold the element (the map's element size). |
| 467 | * The destructor functions, if any, will @em not be called. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | * |
| 852 | 469 | * If this map is storing pointers, the element is the pointer itself |
| 470 | * and not the object it points to. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | * |
| 852 | 472 | * @param map (@c CxMap*) the map |
| 888 | 473 | * @param key (any supported key type) the key |
| 852 | 474 | * @param targetbuf (@c void*) the buffer where the element shall be copied to |
| 475 | * @retval zero success | |
| 476 | * @retval non-zero the key was not found | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
477 | * |
| 852 | 478 | * @see cxMapRemove() |
| 888 | 479 | * @see CX_HASH_KEY() |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | */ |
| 888 | 481 | #define cxMapRemoveAndGet(map, key, targetbuf) cx_map_remove(map, CX_HASH_KEY(key), targetbuf) |
| 482 | ||
| 483 | ||
| 484 | /** | |
| 485 | * Performs a deep clone of one map into another. | |
| 486 | * | |
| 487 | * If the destination map already contains entries, the cloned entries | |
| 488 | * are added to that map, possibly overwriting existing elements when | |
| 489 | * the keys already exist. | |
| 490 | * | |
| 491 | * When elements in the destination map need to be replaced, any destructor | |
| 492 | * function is called on the replaced elements before replacing them. | |
| 493 | * | |
| 494 | * @attention If the cloned elements need to be destroyed by a destructor | |
| 495 | * function, you must make sure that the destination map also uses this | |
| 496 | * destructor function. | |
| 497 | * | |
| 498 | * @param dst the destination map | |
| 499 | * @param src the source map | |
| 500 | * @param clone_func the clone function for the values | |
| 501 | * @param clone_allocator the allocator that is passed to the clone function | |
| 502 | * @param data optional additional data that is passed to the clone function | |
| 503 | * @retval zero when all elements were successfully cloned | |
| 504 | * @retval non-zero when an allocation error occurred | |
| 505 | */ | |
| 506 | cx_attr_nonnull_arg(1, 2, 3) | |
| 507 | CX_EXPORT int cxMapClone(CxMap *dst, const CxMap *src, | |
| 508 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 509 | ||
| 510 | ||
| 511 | /** | |
| 512 | * Clones entries of a map if their key is not present in another map. | |
| 513 | * | |
| 514 | * @param dst the destination map | |
| 515 | * @param minuend the map to subtract the entries from | |
| 516 | * @param subtrahend the map containing the elements to be subtracted | |
| 517 | * @param clone_func the clone function for the values | |
| 518 | * @param clone_allocator the allocator that is passed to the clone function | |
| 519 | * @param data optional additional data that is passed to the clone function | |
| 520 | * @retval zero when the elements were successfully cloned | |
| 521 | * @retval non-zero when an allocation error occurred | |
| 522 | */ | |
| 523 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 524 | CX_EXPORT int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend, | |
| 525 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526 | |
| 888 | 527 | /** |
| 528 | * Clones entries of a map if their key is not present in a list. | |
| 529 | * | |
| 530 | * Note that the list must contain keys of type @c CxKey | |
| 531 | * (or pointers to such keys) and must use @c cx_hash_key_cmp | |
| 532 | * as the compare function. | |
| 533 | * Generic key types cannot be processed in this case. | |
| 534 | * | |
| 535 | * @param dst the destination map | |
| 536 | * @param src the source map | |
| 537 | * @param keys the list of @c CxKey items | |
| 538 | * @param clone_func the clone function for the values | |
| 539 | * @param clone_allocator the allocator that is passed to the clone function | |
| 540 | * @param data optional additional data that is passed to the clone function | |
| 541 | * @retval zero when the elements were successfully cloned | |
| 542 | * @retval non-zero when an allocation error occurred | |
| 543 | */ | |
| 544 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 545 | CX_EXPORT int cxMapListDifference(CxMap *dst, const CxMap *src, const CxList *keys, | |
| 546 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 547 | ||
| 548 | ||
| 549 | /** | |
| 550 | * Clones entries of a map only if their key is present in another map. | |
| 551 | * | |
| 552 | * @param dst the destination map | |
| 553 | * @param src the map to clone the entries from | |
| 554 | * @param other the map to check for existence of the keys | |
| 555 | * @param clone_func the clone function for the values | |
| 556 | * @param clone_allocator the allocator that is passed to the clone function | |
| 557 | * @param data optional additional data that is passed to the clone function | |
| 558 | * @retval zero when the elements were successfully cloned | |
| 559 | * @retval non-zero when an allocation error occurred | |
| 560 | */ | |
| 561 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 562 | CX_EXPORT int cxMapIntersection(CxMap *dst, const CxMap *src, const CxMap *other, | |
| 563 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 564 | ||
| 565 | /** | |
| 566 | * Clones entries of a map only if their key is present in a list. | |
| 567 | * | |
| 568 | * Note that the list must contain keys of type @c CxKey | |
| 569 | * (or pointers to such keys) and must use @c cx_hash_key_cmp | |
| 570 | * as the compare function. | |
| 571 | * Generic key types cannot be processed in this case. | |
| 572 | * | |
| 573 | * @param dst the destination map | |
| 574 | * @param src the source map | |
| 575 | * @param keys the list of @c CxKey items | |
| 576 | * @param clone_func the clone function for the values | |
| 577 | * @param clone_allocator the allocator that is passed to the clone function | |
| 578 | * @param data optional additional data that is passed to the clone function | |
| 579 | * @retval zero when the elements were successfully cloned | |
| 580 | * @retval non-zero when an allocation error occurred | |
| 581 | */ | |
| 582 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 583 | CX_EXPORT int cxMapListIntersection(CxMap *dst, const CxMap *src, const CxList *keys, | |
| 584 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 585 | ||
| 586 | /** | |
| 587 | * Clones entries into a map if their key does not exist yet. | |
| 588 | * | |
| 589 | * If you want to calculate the union of two maps into a fresh new map, | |
| 590 | * you can proceed as follows: | |
| 591 | * 1. Clone the first map into a fresh, empty map. | |
| 592 | * 2. Use this function to clone the second map into the result from step 1. | |
| 593 | * | |
| 594 | * @param dst the destination map | |
| 595 | * @param src the map to clone the entries from | |
| 596 | * @param clone_func the clone function for the values | |
| 597 | * @param clone_allocator the allocator that is passed to the clone function | |
| 598 | * @param data optional additional data that is passed to the clone function | |
| 599 | * @retval zero when the elements were successfully cloned | |
| 600 | * @retval non-zero when an allocation error occurred | |
| 601 | */ | |
| 602 | cx_attr_nonnull_arg(1, 2, 3) | |
| 603 | CX_EXPORT int cxMapUnion(CxMap *dst, const CxMap *src, | |
| 604 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 605 | ||
| 606 | #ifdef __cplusplus | |
| 607 | } // extern "C" | |
| 608 | #endif | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | #endif // UCX_MAP_H |