174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4
|
* Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6
|
* Redistribution and use in source and binary forms, with or without
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7
|
* modification, are permitted provided that the following conditions are met:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9
|
* 1. Redistributions of source code must retain the above copyright
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10
|
* notice, this list of conditions and the following disclaimer.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12
|
* 2. Redistributions in binary form must reproduce the above copyright
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13
|
* notice, this list of conditions and the following disclaimer in the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14
|
* documentation and/or other materials provided with the distribution.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
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
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26
|
* POSSIBILITY OF SUCH DAMAGE.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28
|
/**
|
440
|
29
|
* @file map.h
|
|
30
|
* @brief Interface for map implementations.
|
|
31
|
* @author Mike Becker
|
|
32
|
* @author Olaf Wintermann
|
|
33
|
* @copyright 2-Clause BSD License
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36
|
#ifndef UCX_MAP_H
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37
|
#define UCX_MAP_H
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39
|
#include "common.h"
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40
|
#include "collection.h"
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41
|
#include "string.h"
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42
|
#include "hash_key.h"
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44
|
#ifdef __cplusplus
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45
|
extern "C" {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46
|
#endif
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48
|
/** Type for the UCX map. */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49
|
typedef struct cx_map_s CxMap;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51
|
/** Type for a map entry. */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52
|
typedef struct cx_map_entry_s CxMapEntry;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54
|
/** Type for map class definitions. */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55
|
typedef struct cx_map_class_s cx_map_class;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57
|
/** Structure for the UCX map. */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58
|
struct cx_map_s {
|
324
|
59
|
/**
|
|
60
|
* Base attributes.
|
|
61
|
*/
|
|
62
|
CX_COLLECTION_BASE;
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63
|
/** The map class definition. */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64
|
cx_map_class *cl;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65
|
};
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68
|
* The type of iterator for a map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70
|
enum cx_map_iterator_type {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72
|
* Iterates over key/value pairs.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74
|
CX_MAP_ITERATOR_PAIRS,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76
|
* Iterates over keys only.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78
|
CX_MAP_ITERATOR_KEYS,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80
|
* Iterates over values only.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82
|
CX_MAP_ITERATOR_VALUES
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83
|
};
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86
|
* The class definition for arbitrary maps.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88
|
struct cx_map_class_s {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90
|
* Deallocates the entire memory.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91
|
*/
|
440
|
92
|
void (*deallocate)(struct cx_map_s *map);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95
|
* Removes all elements.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97
|
void (*clear)(struct cx_map_s *map);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100
|
* Add or overwrite an element.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102
|
int (*put)(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104
|
CxHashKey key,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106
|
);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109
|
* Returns an element.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111
|
void *(*get)(
|
324
|
112
|
const CxMap *map,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113
|
CxHashKey key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114
|
);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117
|
* Removes an element.
|
440
|
118
|
*
|
|
119
|
* Implementations SHALL check if @p targetbuf is set and copy the elements
|
|
120
|
* to the buffer without invoking any destructor.
|
|
121
|
* When @p targetbuf is not set, the destructors SHALL be invoked.
|
|
122
|
*
|
|
123
|
* The function SHALL return zero when the @p key was found and
|
|
124
|
* non-zero, otherwise.
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125
|
*/
|
440
|
126
|
int (*remove)(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128
|
CxHashKey key,
|
440
|
129
|
void *targetbuf
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130
|
);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133
|
* Creates an iterator for this map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134
|
*/
|
324
|
135
|
CxIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136
|
};
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139
|
* A map entry.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141
|
struct cx_map_entry_s {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143
|
* A pointer to the key.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144
|
*/
|
324
|
145
|
const CxHashKey *key;
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147
|
* A pointer to the value.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149
|
void *value;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150
|
};
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151
|
|
187
|
152
|
/**
|
|
153
|
* A shared instance of an empty map.
|
|
154
|
*
|
440
|
155
|
* Writing to that map is not allowed.
|
|
156
|
*
|
|
157
|
* You can use this is a placeholder for initializing CxMap pointers
|
|
158
|
* for which you do not want to reserve memory right from the beginning.
|
187
|
159
|
*/
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160
|
extern CxMap *const cxEmptyMap;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163
|
* Advises the map to store copies of the objects (default mode of operation).
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165
|
* Retrieving objects from this map will yield pointers to the copies stored
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166
|
* within this list.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168
|
* @param map the map
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169
|
* @see cxMapStorePointers()
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170
|
*/
|
440
|
171
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172
|
static inline void cxMapStoreObjects(CxMap *map) {
|
324
|
173
|
map->collection.store_pointer = false;
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177
|
* Advises the map to only store pointers to the objects.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179
|
* Retrieving objects from this list will yield the original pointers stored.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181
|
* @note This function forcibly sets the element size to the size of a pointer.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182
|
* Invoking this function on a non-empty map that already stores copies of
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183
|
* objects is undefined.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185
|
* @param map the map
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186
|
* @see cxMapStoreObjects()
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187
|
*/
|
440
|
188
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189
|
static inline void cxMapStorePointers(CxMap *map) {
|
324
|
190
|
map->collection.store_pointer = true;
|
|
191
|
map->collection.elem_size = sizeof(void *);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193
|
|
324
|
194
|
/**
|
|
195
|
* Returns true, if this map is storing pointers instead of the actual data.
|
|
196
|
*
|
|
197
|
* @param map
|
|
198
|
* @return true, if this map is storing pointers
|
|
199
|
* @see cxMapStorePointers()
|
|
200
|
*/
|
440
|
201
|
cx_attr_nonnull
|
324
|
202
|
static inline bool cxMapIsStoringPointers(const CxMap *map) {
|
|
203
|
return map->collection.store_pointer;
|
|
204
|
}
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207
|
* Deallocates the memory of the specified map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208
|
*
|
440
|
209
|
* Also calls the content destructor functions for each element, if specified.
|
|
210
|
*
|
|
211
|
* @param map the map to be freed
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212
|
*/
|
440
|
213
|
void cxMapFree(CxMap *map);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217
|
* Clears a map by removing all elements.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218
|
*
|
440
|
219
|
* Also calls the content destructor functions for each element, if specified.
|
|
220
|
*
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221
|
* @param map the map to be cleared
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222
|
*/
|
440
|
223
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224
|
static inline void cxMapClear(CxMap *map) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225
|
map->cl->clear(map);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227
|
|
324
|
228
|
/**
|
|
229
|
* Returns the number of elements in this map.
|
|
230
|
*
|
|
231
|
* @param map the map
|
|
232
|
* @return the number of stored elements
|
|
233
|
*/
|
440
|
234
|
cx_attr_nonnull
|
324
|
235
|
static inline size_t cxMapSize(const CxMap *map) {
|
|
236
|
return map->collection.size;
|
|
237
|
}
|
|
238
|
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240
|
* Creates a value iterator for a map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241
|
*
|
440
|
242
|
* @note An iterator iterates over all elements successively. Therefore, the order
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243
|
* highly depends on the map implementation and may change arbitrarily when the contents change.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245
|
* @param map the map to create the iterator for
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246
|
* @return an iterator for the currently stored values
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247
|
*/
|
440
|
248
|
cx_attr_nonnull
|
|
249
|
cx_attr_nodiscard
|
324
|
250
|
static inline CxIterator cxMapIteratorValues(const CxMap *map) {
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251
|
return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255
|
* Creates a key iterator for a map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257
|
* The elements of the iterator are keys of type CxHashKey.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258
|
*
|
440
|
259
|
* @note An iterator iterates over all elements successively. Therefore, the order
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260
|
* highly depends on the map implementation and may change arbitrarily when the contents change.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262
|
* @param map the map to create the iterator for
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263
|
* @return an iterator for the currently stored keys
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264
|
*/
|
440
|
265
|
cx_attr_nonnull
|
|
266
|
cx_attr_nodiscard
|
324
|
267
|
static inline CxIterator cxMapIteratorKeys(const CxMap *map) {
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268
|
return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272
|
* Creates an iterator for a map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274
|
* The elements of the iterator are key/value pairs of type CxMapEntry.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275
|
*
|
440
|
276
|
* @note An iterator iterates over all elements successively. Therefore, the order
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277
|
* highly depends on the map implementation and may change arbitrarily when the contents change.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279
|
* @param map the map to create the iterator for
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280
|
* @return an iterator for the currently stored entries
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281
|
* @see cxMapIteratorKeys()
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282
|
* @see cxMapIteratorValues()
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283
|
*/
|
440
|
284
|
cx_attr_nonnull
|
|
285
|
cx_attr_nodiscard
|
324
|
286
|
static inline CxIterator cxMapIterator(const CxMap *map) {
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287
|
return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292
|
* Creates a mutating iterator over the values of a map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293
|
*
|
440
|
294
|
* @note An iterator iterates over all elements successively. Therefore, the order
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295
|
* highly depends on the map implementation and may change arbitrarily when the contents change.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297
|
* @param map the map to create the iterator for
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298
|
* @return an iterator for the currently stored values
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299
|
*/
|
440
|
300
|
cx_attr_nonnull
|
|
301
|
cx_attr_nodiscard
|
324
|
302
|
CxIterator cxMapMutIteratorValues(CxMap *map);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305
|
* Creates a mutating iterator over the keys of a map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307
|
* The elements of the iterator are keys of type CxHashKey.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308
|
*
|
440
|
309
|
* @note An iterator iterates over all elements successively. Therefore, the order
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310
|
* highly depends on the map implementation and may change arbitrarily when the contents change.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312
|
* @param map the map to create the iterator for
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313
|
* @return an iterator for the currently stored keys
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314
|
*/
|
440
|
315
|
cx_attr_nonnull
|
|
316
|
cx_attr_nodiscard
|
324
|
317
|
CxIterator cxMapMutIteratorKeys(CxMap *map);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320
|
* Creates a mutating iterator for a map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322
|
* The elements of the iterator are key/value pairs of type CxMapEntry.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323
|
*
|
440
|
324
|
* @note An iterator iterates over all elements successively. Therefore, the order
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325
|
* highly depends on the map implementation and may change arbitrarily when the contents change.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327
|
* @param map the map to create the iterator for
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328
|
* @return an iterator for the currently stored entries
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329
|
* @see cxMapMutIteratorKeys()
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330
|
* @see cxMapMutIteratorValues()
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331
|
*/
|
440
|
332
|
cx_attr_nonnull
|
|
333
|
cx_attr_nodiscard
|
324
|
334
|
CxIterator cxMapMutIterator(CxMap *map);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336
|
#ifdef __cplusplus
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337
|
} // end the extern "C" block here, because we want to start overloading
|
440
|
338
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339
|
static inline int cxMapPut(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341
|
CxHashKey const &key,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344
|
return map->cl->put(map, key, value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346
|
|
440
|
347
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348
|
static inline int cxMapPut(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350
|
cxstring const &key,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353
|
return map->cl->put(map, cx_hash_key_cxstr(key), value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355
|
|
440
|
356
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357
|
static inline int cxMapPut(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359
|
cxmutstr const &key,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362
|
return map->cl->put(map, cx_hash_key_cxstr(key), value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364
|
|
440
|
365
|
cx_attr_nonnull
|
|
366
|
cx_attr_cstr_arg(2)
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367
|
static inline int cxMapPut(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368
|
CxMap *map,
|
324
|
369
|
const char *key,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372
|
return map->cl->put(map, cx_hash_key_str(key), value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374
|
|
440
|
375
|
cx_attr_nonnull
|
|
376
|
cx_attr_nodiscard
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377
|
static inline void *cxMapGet(
|
324
|
378
|
const CxMap *map,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379
|
CxHashKey const &key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381
|
return map->cl->get(map, key);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383
|
|
440
|
384
|
cx_attr_nonnull
|
|
385
|
cx_attr_nodiscard
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386
|
static inline void *cxMapGet(
|
324
|
387
|
const CxMap *map,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388
|
cxstring const &key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390
|
return map->cl->get(map, cx_hash_key_cxstr(key));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392
|
|
440
|
393
|
cx_attr_nonnull
|
|
394
|
cx_attr_nodiscard
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395
|
static inline void *cxMapGet(
|
324
|
396
|
const CxMap *map,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397
|
cxmutstr const &key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399
|
return map->cl->get(map, cx_hash_key_cxstr(key));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401
|
|
440
|
402
|
cx_attr_nonnull
|
|
403
|
cx_attr_nodiscard
|
|
404
|
cx_attr_cstr_arg(2)
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405
|
static inline void *cxMapGet(
|
324
|
406
|
const CxMap *map,
|
|
407
|
const char *key
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409
|
return map->cl->get(map, cx_hash_key_str(key));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411
|
|
440
|
412
|
cx_attr_nonnull
|
|
413
|
static inline int cxMapRemove(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415
|
CxHashKey const &key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416
|
) {
|
440
|
417
|
return map->cl->remove(map, key, nullptr);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419
|
|
440
|
420
|
cx_attr_nonnull
|
|
421
|
static inline int cxMapRemove(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423
|
cxstring const &key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424
|
) {
|
440
|
425
|
return map->cl->remove(map, cx_hash_key_cxstr(key), nullptr);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
427
|
|
440
|
428
|
cx_attr_nonnull
|
|
429
|
static inline int cxMapRemove(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431
|
cxmutstr const &key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432
|
) {
|
440
|
433
|
return map->cl->remove(map, cx_hash_key_cxstr(key), nullptr);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
434
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435
|
|
440
|
436
|
cx_attr_nonnull
|
|
437
|
cx_attr_cstr_arg(2)
|
|
438
|
static inline int cxMapRemove(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439
|
CxMap *map,
|
324
|
440
|
const char *key
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
441
|
) {
|
440
|
442
|
return map->cl->remove(map, cx_hash_key_str(key), nullptr);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
444
|
|
440
|
445
|
cx_attr_nonnull
|
|
446
|
cx_attr_access_w(3)
|
|
447
|
static inline int cxMapRemoveAndGet(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448
|
CxMap *map,
|
440
|
449
|
CxHashKey key,
|
|
450
|
void *targetbuf
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451
|
) {
|
440
|
452
|
return map->cl->remove(map, key, targetbuf);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454
|
|
440
|
455
|
cx_attr_nonnull
|
|
456
|
cx_attr_access_w(3)
|
|
457
|
static inline int cxMapRemoveAndGet(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458
|
CxMap *map,
|
440
|
459
|
cxstring key,
|
|
460
|
void *targetbuf
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461
|
) {
|
440
|
462
|
return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464
|
|
440
|
465
|
cx_attr_nonnull
|
|
466
|
cx_attr_access_w(3)
|
|
467
|
static inline int cxMapRemoveAndGet(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468
|
CxMap *map,
|
440
|
469
|
cxmutstr key,
|
|
470
|
void *targetbuf
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471
|
) {
|
440
|
472
|
return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474
|
|
440
|
475
|
cx_attr_nonnull
|
|
476
|
cx_attr_access_w(3)
|
|
477
|
cx_attr_cstr_arg(2)
|
|
478
|
static inline int cxMapRemoveAndGet(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479
|
CxMap *map,
|
440
|
480
|
const char *key,
|
|
481
|
void *targetbuf
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482
|
) {
|
440
|
483
|
return map->cl->remove(map, cx_hash_key_str(key), targetbuf);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
486
|
#else // __cplusplus
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488
|
/**
|
440
|
489
|
* @copydoc cxMapPut()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
490
|
*/
|
440
|
491
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
492
|
static inline int cx_map_put(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
493
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
494
|
CxHashKey key,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
495
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
496
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
497
|
return map->cl->put(map, key, value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
498
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500
|
/**
|
440
|
501
|
* @copydoc cxMapPut()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
502
|
*/
|
440
|
503
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504
|
static inline int cx_map_put_cxstr(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506
|
cxstring key,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
507
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509
|
return map->cl->put(map, cx_hash_key_cxstr(key), value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512
|
/**
|
440
|
513
|
* @copydoc cxMapPut()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514
|
*/
|
440
|
515
|
cx_attr_nonnull
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516
|
static inline int cx_map_put_mustr(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518
|
cxmutstr key,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
519
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
521
|
return map->cl->put(map, cx_hash_key_cxstr(key), value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
523
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524
|
/**
|
440
|
525
|
* @copydoc cxMapPut()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526
|
*/
|
440
|
527
|
cx_attr_nonnull
|
|
528
|
cx_attr_cstr_arg(2)
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
529
|
static inline int cx_map_put_str(
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530
|
CxMap *map,
|
324
|
531
|
const char *key,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
532
|
void *value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
533
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534
|
return map->cl->put(map, cx_hash_key_str(key), value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
535
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
536
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
537
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
538
|
* Puts a key/value-pair into the map.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
539
|
*
|
440
|
540
|
* A possible existing value will be overwritten.
|
|
541
|
*
|
|
542
|
* If this map is storing pointers, the @p value pointer is written
|
|
543
|
* to the map. Otherwise, the memory is copied from @p value with
|
|
544
|
* memcpy().
|
|
545
|
*
|
|
546
|
* The @p key is always copied.
|
|
547
|
*
|
|
548
|
* @param map (@c CxMap*) the map
|
|
549
|
* @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key
|
|
550
|
* @param value (@c void*) the value
|
|
551
|
* @retval zero success
|
|
552
|
* @retval non-zero value on memory allocation failure
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
553
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
554
|
#define cxMapPut(map, key, value) _Generic((key), \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
555
|
CxHashKey: cx_map_put, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
556
|
cxstring: cx_map_put_cxstr, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
557
|
cxmutstr: cx_map_put_mustr, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
558
|
char*: cx_map_put_str, \
|
324
|
559
|
const char*: cx_map_put_str) \
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
560
|
(map, key, value)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
561
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562
|
/**
|
440
|
563
|
* @copydoc cxMapGet()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564
|
*/
|
440
|
565
|
cx_attr_nonnull
|
|
566
|
cx_attr_nodiscard
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567
|
static inline void *cx_map_get(
|
324
|
568
|
const CxMap *map,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
569
|
CxHashKey key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
570
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
571
|
return map->cl->get(map, key);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
572
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
573
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
574
|
/**
|
440
|
575
|
* @copydoc cxMapGet()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
576
|
*/
|
440
|
577
|
cx_attr_nonnull
|
|
578
|
cx_attr_nodiscard
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579
|
static inline void *cx_map_get_cxstr(
|
324
|
580
|
const CxMap *map,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581
|
cxstring key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
582
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583
|
return map->cl->get(map, cx_hash_key_cxstr(key));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586
|
/**
|
440
|
587
|
* @copydoc cxMapGet()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
588
|
*/
|
440
|
589
|
cx_attr_nonnull
|
|
590
|
cx_attr_nodiscard
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591
|
static inline void *cx_map_get_mustr(
|
324
|
592
|
const CxMap *map,
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593
|
cxmutstr key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
595
|
return map->cl->get(map, cx_hash_key_cxstr(key));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
596
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
597
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598
|
/**
|
440
|
599
|
* @copydoc cxMapGet()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
600
|
*/
|
440
|
601
|
cx_attr_nonnull
|
|
602
|
cx_attr_nodiscard
|
|
603
|
cx_attr_cstr_arg(2)
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604
|
static inline void *cx_map_get_str(
|
324
|
605
|
const CxMap *map,
|
|
606
|
const char *key
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
607
|
) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608
|
return map->cl->get(map, cx_hash_key_str(key));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
611
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612
|
* Retrieves a value by using a key.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
613
|
*
|
440
|
614
|
* If this map is storing pointers, the stored pointer is returned.
|
|
615
|
* Otherwise, a pointer to the element within the map's memory
|
|
616
|
* is returned (which is valid as long as the element stays in the map).
|
|
617
|
*
|
|
618
|
* @param map (@c CxMap*) the map
|
|
619
|
* @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key
|
|
620
|
* @return (@c void*) the value
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622
|
#define cxMapGet(map, key) _Generic((key), \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
623
|
CxHashKey: cx_map_get, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624
|
cxstring: cx_map_get_cxstr, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
625
|
cxmutstr: cx_map_get_mustr, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
626
|
char*: cx_map_get_str, \
|
324
|
627
|
const char*: cx_map_get_str) \
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
628
|
(map, key)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
630
|
/**
|
440
|
631
|
* @copydoc cxMapRemove()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
632
|
*/
|
440
|
633
|
cx_attr_nonnull
|
|
634
|
static inline int cx_map_remove(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
635
|
CxMap *map,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
636
|
CxHashKey key
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
637
|
) {
|
440
|
638
|
return map->cl->remove(map, key, NULL);
|
|
639
|
}
|
|
640
|
|
|
641
|
/**
|
|
642
|
* @copydoc cxMapRemove()
|
|
643
|
*/
|
|
644
|
cx_attr_nonnull
|
|
645
|
static inline int cx_map_remove_cxstr(
|
|
646
|
CxMap *map,
|
|
647
|
cxstring key
|
|
648
|
) {
|
|
649
|
return map->cl->remove(map, cx_hash_key_cxstr(key), NULL);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
650
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
651
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
652
|
/**
|
440
|
653
|
* @copydoc cxMapRemove()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
654
|
*/
|
440
|
655
|
cx_attr_nonnull
|
|
656
|
static inline int cx_map_remove_mustr(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
657
|
CxMap *map,
|
440
|
658
|
cxmutstr key
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
659
|
) {
|
440
|
660
|
return map->cl->remove(map, cx_hash_key_cxstr(key), NULL);
|
|
661
|
}
|
|
662
|
|
|
663
|
/**
|
|
664
|
* @copydoc cxMapRemove()
|
|
665
|
*/
|
|
666
|
cx_attr_nonnull
|
|
667
|
cx_attr_cstr_arg(2)
|
|
668
|
static inline int cx_map_remove_str(
|
|
669
|
CxMap *map,
|
|
670
|
const char *key
|
|
671
|
) {
|
|
672
|
return map->cl->remove(map, cx_hash_key_str(key), NULL);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
673
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
674
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
676
|
* Removes a key/value-pair from the map by using the key.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677
|
*
|
440
|
678
|
* Always invokes the destructors functions, if any, on the removed element.
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679
|
*
|
440
|
680
|
* @param map (@c CxMap*) the map
|
|
681
|
* @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key
|
|
682
|
* @retval zero success
|
|
683
|
* @retval non-zero the key was not found
|
|
684
|
*
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685
|
* @see cxMapRemoveAndGet()
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687
|
#define cxMapRemove(map, key) _Generic((key), \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688
|
CxHashKey: cx_map_remove, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689
|
cxstring: cx_map_remove_cxstr, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690
|
cxmutstr: cx_map_remove_mustr, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691
|
char*: cx_map_remove_str, \
|
324
|
692
|
const char*: cx_map_remove_str) \
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693
|
(map, key)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695
|
/**
|
440
|
696
|
* @copydoc cxMapRemoveAndGet()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697
|
*/
|
440
|
698
|
cx_attr_nonnull
|
|
699
|
cx_attr_access_w(3)
|
|
700
|
static inline int cx_map_remove_and_get(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701
|
CxMap *map,
|
440
|
702
|
CxHashKey key,
|
|
703
|
void *targetbuf
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
704
|
) {
|
440
|
705
|
return map->cl->remove(map, key, targetbuf);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
706
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
707
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
708
|
/**
|
440
|
709
|
* @copydoc cxMapRemoveAndGet()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
710
|
*/
|
440
|
711
|
cx_attr_nonnull
|
|
712
|
cx_attr_access_w(3)
|
|
713
|
static inline int cx_map_remove_and_get_cxstr(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
714
|
CxMap *map,
|
440
|
715
|
cxstring key,
|
|
716
|
void *targetbuf
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717
|
) {
|
440
|
718
|
return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721
|
/**
|
440
|
722
|
* @copydoc cxMapRemoveAndGet()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723
|
*/
|
440
|
724
|
cx_attr_nonnull
|
|
725
|
cx_attr_access_w(3)
|
|
726
|
static inline int cx_map_remove_and_get_mustr(
|
|
727
|
CxMap *map,
|
|
728
|
cxmutstr key,
|
|
729
|
void *targetbuf
|
|
730
|
) {
|
|
731
|
return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf);
|
|
732
|
}
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
733
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734
|
/**
|
440
|
735
|
* @copydoc cxMapRemoveAndGet()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736
|
*/
|
440
|
737
|
cx_attr_nonnull
|
|
738
|
cx_attr_access_w(3)
|
|
739
|
cx_attr_cstr_arg(2)
|
|
740
|
static inline int cx_map_remove_and_get_str(
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741
|
CxMap *map,
|
440
|
742
|
const char *key,
|
|
743
|
void *targetbuf
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744
|
) {
|
440
|
745
|
return map->cl->remove(map, cx_hash_key_str(key), targetbuf);
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
746
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
748
|
/**
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
749
|
* Removes a key/value-pair from the map by using the key.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
750
|
*
|
440
|
751
|
* This function will copy the contents of the removed element
|
|
752
|
* to the target buffer must be guaranteed to be large enough
|
|
753
|
* to hold the element (the map's element size).
|
|
754
|
* The destructor functions, if any, will @em not be called.
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755
|
*
|
440
|
756
|
* If this map is storing pointers, the element is the pointer itself
|
|
757
|
* and not the object it points to.
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
758
|
*
|
440
|
759
|
* @param map (@c CxMap*) the map
|
|
760
|
* @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key
|
|
761
|
* @param targetbuf (@c void*) the buffer where the element shall be copied to
|
|
762
|
* @retval zero success
|
|
763
|
* @retval non-zero the key was not found
|
|
764
|
*
|
|
765
|
* @see cxMapStorePointers()
|
|
766
|
* @see cxMapRemove()
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
767
|
*/
|
440
|
768
|
#define cxMapRemoveAndGet(map, key, targetbuf) _Generic((key), \
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769
|
CxHashKey: cx_map_remove_and_get, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770
|
cxstring: cx_map_remove_and_get_cxstr, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771
|
cxmutstr: cx_map_remove_and_get_mustr, \
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772
|
char*: cx_map_remove_and_get_str, \
|
324
|
773
|
const char*: cx_map_remove_and_get_str) \
|
440
|
774
|
(map, key, targetbuf)
|
174
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776
|
#endif // __cplusplus
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778
|
#endif // UCX_MAP_H
|