src/cx/map.h

Sat, 23 Nov 2024 15:15:09 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 23 Nov 2024 15:15:09 +0100
changeset 990
f708863e7ec6
parent 985
68754c7de906
child 992
14ca894190fd
permissions
-rw-r--r--

automatically disable szmul builtin when testing with coverage

549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 * \file map.h
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 * \brief Interface for map implementations.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 * \author Mike Becker
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 * \author Olaf Wintermann
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 * \copyright 2-Clause BSD License
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 #ifndef UCX_MAP_H
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 #define UCX_MAP_H
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38
681
502105523db7 fix common.h include problems - fixes #255
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
39 #include "common.h"
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 669
diff changeset
40 #include "collection.h"
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
41 #include "string.h"
563
69a83fad8a35 improve hash key handling
Mike Becker <universe@uap-core.de>
parents: 558
diff changeset
42 #include "hash_key.h"
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 #ifdef __cplusplus
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 extern "C" {
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 #endif
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 /** Type for the UCX map. */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 typedef struct cx_map_s CxMap;
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 /** Type for a map entry. */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 typedef struct cx_map_entry_s CxMapEntry;
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 /** Type for map class definitions. */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 typedef struct cx_map_class_s cx_map_class;
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 /** Structure for the UCX map. */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 struct cx_map_s {
854
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
59 /**
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
60 * Base attributes.
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
61 */
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
62 CX_COLLECTION_BASE;
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 /** The map class definition. */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 cx_map_class *cl;
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 };
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 /**
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
68 * The type of iterator for a map.
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
69 */
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
70 enum cx_map_iterator_type {
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
71 /**
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
72 * Iterates over key/value pairs.
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
73 */
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
74 CX_MAP_ITERATOR_PAIRS,
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
75 /**
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
76 * Iterates over keys only.
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
77 */
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
78 CX_MAP_ITERATOR_KEYS,
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
79 /**
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
80 * Iterates over values only.
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
81 */
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
82 CX_MAP_ITERATOR_VALUES
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
83 };
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
84
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
85 /**
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 * The class definition for arbitrary maps.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 struct cx_map_class_s {
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 * Deallocates the entire memory.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
92 cx_attr_nonnull
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 void (*destructor)(struct cx_map_s *map);
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 * Removes all elements.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
98 cx_attr_nonnull
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 void (*clear)(struct cx_map_s *map);
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 * Add or overwrite an element.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
104 cx_attr_nonnull
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 int (*put)(
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 CxMap *map,
563
69a83fad8a35 improve hash key handling
Mike Becker <universe@uap-core.de>
parents: 558
diff changeset
107 CxHashKey key,
550
89b2a83728b1 #189 basic map implementation
Mike Becker <universe@uap-core.de>
parents: 549
diff changeset
108 void *value
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 );
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 * Returns an element.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
114 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
115 cx_attr_nodiscard
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 void *(*get)(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
117 const CxMap *map,
563
69a83fad8a35 improve hash key handling
Mike Becker <universe@uap-core.de>
parents: 558
diff changeset
118 CxHashKey key
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 );
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 * Removes an element.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
124 cx_attr_nonnull
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 void *(*remove)(
550
89b2a83728b1 #189 basic map implementation
Mike Becker <universe@uap-core.de>
parents: 549
diff changeset
126 CxMap *map,
686
64919f63f059 add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents: 685
diff changeset
127 CxHashKey key,
64919f63f059 add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents: 685
diff changeset
128 bool destroy
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 );
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 /**
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
132 * Creates an iterator for this map.
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
134 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
135 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
136 CxIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 };
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 * A map entry.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 struct cx_map_entry_s {
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 /**
551
2946e13c89a4 #189 implement map iterators
Mike Becker <universe@uap-core.de>
parents: 550
diff changeset
144 * A pointer to the key.
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 */
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
146 const CxHashKey *key;
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 /**
551
2946e13c89a4 #189 implement map iterators
Mike Becker <universe@uap-core.de>
parents: 550
diff changeset
148 * A pointer to the value.
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 */
551
2946e13c89a4 #189 implement map iterators
Mike Becker <universe@uap-core.de>
parents: 550
diff changeset
150 void *value;
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 };
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152
714
34565d898f1f add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents: 710
diff changeset
153 /**
34565d898f1f add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents: 710
diff changeset
154 * A shared instance of an empty map.
34565d898f1f add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents: 710
diff changeset
155 *
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
156 * Writing to that map is not allowed.
714
34565d898f1f add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents: 710
diff changeset
157 */
706
8c6edaccaef1 add empty map implementation - fixes #259
Mike Becker <universe@uap-core.de>
parents: 694
diff changeset
158 extern CxMap *const cxEmptyMap;
8c6edaccaef1 add empty map implementation - fixes #259
Mike Becker <universe@uap-core.de>
parents: 694
diff changeset
159
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
160 /**
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
161 * Advises the map to store copies of the objects (default mode of operation).
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
162 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
163 * Retrieving objects from this map will yield pointers to the copies stored
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
164 * within this list.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
165 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
166 * @param map the map
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
167 * @see cxMapStorePointers()
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
168 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
169 cx_attr_nonnull
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
170 static inline void cxMapStoreObjects(CxMap *map) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
171 map->collection.store_pointer = false;
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
172 }
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
173
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
174 /**
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
175 * Advises the map to only store pointers to the objects.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
176 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
177 * Retrieving objects from this list will yield the original pointers stored.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
178 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
179 * @note This function forcibly sets the element size to the size of a pointer.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
180 * Invoking this function on a non-empty map that already stores copies of
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
181 * objects is undefined.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
182 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
183 * @param map the map
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
184 * @see cxMapStoreObjects()
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
185 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
186 cx_attr_nonnull
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
187 static inline void cxMapStorePointers(CxMap *map) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
188 map->collection.store_pointer = true;
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
189 map->collection.elem_size = sizeof(void *);
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
190 }
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
191
857
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
192 /**
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
193 * Returns true, if this map is storing pointers instead of the actual data.
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
194 *
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
195 * @param map
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
196 * @return true, if this map is storing pointers
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
197 * @see cxMapStorePointers()
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
198 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
199 cx_attr_nonnull
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
200 static inline bool cxMapIsStoringPointers(const CxMap *map) {
857
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
201 return map->collection.store_pointer;
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
202 }
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205 * Deallocates the memory of the specified map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 * @param map the map to be destroyed
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209 static inline void cxMapDestroy(CxMap *map) {
984
e8f354a25ac8 let cxMapDestroy() ignore NULL as any free()-like function should do
Mike Becker <universe@uap-core.de>
parents: 957
diff changeset
210 if (map == NULL) return;
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 map->cl->destructor(map);
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 * Clears a map by removing all elements.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 * @param map the map to be cleared
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
220 cx_attr_nonnull
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 static inline void cxMapClear(CxMap *map) {
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 map->cl->clear(map);
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
225 /**
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
226 * Returns the number of elements in this map.
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
227 *
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
228 * @param map the map
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
229 * @return the number of stored elements
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
230 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
231 cx_attr_nonnull
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
232 static inline size_t cxMapSize(const CxMap *map) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
233 return map->collection.size;
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
234 }
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
235
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237 // TODO: set-like map operations (union, intersect, difference)
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240 * Creates a value iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 * \note An iterator iterates over all elements successively. Therefore the order
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 * highly depends on the map implementation and may change arbitrarily when the contents change.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245 * @param map the map to create the iterator for
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 * @return an iterator for the currently stored values
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
248 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
249 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
250 static inline CxIterator cxMapIteratorValues(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
251 return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 * Creates a key iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 *
564
5d8ad7a0ff71 fix obsolete documentation
Mike Becker <universe@uap-core.de>
parents: 563
diff changeset
257 * The elements of the iterator are keys of type CxHashKey.
555
d79fbd028e26 fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents: 553
diff changeset
258 *
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 * \note An iterator iterates over all elements successively. Therefore the order
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 * highly depends on the map implementation and may change arbitrarily when the contents change.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
262 * @param map the map to create the iterator for
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 * @return an iterator for the currently stored keys
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
265 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
266 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
267 static inline CxIterator cxMapIteratorKeys(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
268 return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
271 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 * Creates an iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 *
555
d79fbd028e26 fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents: 553
diff changeset
274 * The elements of the iterator are key/value pairs of type CxMapEntry.
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 * \note An iterator iterates over all elements successively. Therefore the order
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 * highly depends on the map implementation and may change arbitrarily when the contents change.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 * @param map the map to create the iterator for
555
d79fbd028e26 fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents: 553
diff changeset
280 * @return an iterator for the currently stored entries
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 * @see cxMapIteratorKeys()
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 * @see cxMapIteratorValues()
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
284 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
285 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
286 static inline CxIterator cxMapIterator(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
287 return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
290
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
291 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
292 * Creates a mutating iterator over the values of a map.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
293 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
294 * \note An iterator iterates over all elements successively. Therefore the order
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
295 * highly depends on the map implementation and may change arbitrarily when the contents change.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
296 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
297 * @param map the map to create the iterator for
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
298 * @return an iterator for the currently stored values
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
299 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
300 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
301 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
302 CxIterator cxMapMutIteratorValues(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
303
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
304 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
305 * Creates a mutating iterator over the keys of a map.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
306 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
307 * The elements of the iterator are keys of type CxHashKey.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
308 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
309 * \note An iterator iterates over all elements successively. Therefore the order
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
310 * highly depends on the map implementation and may change arbitrarily when the contents change.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
311 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
312 * @param map the map to create the iterator for
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
313 * @return an iterator for the currently stored keys
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
314 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
315 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
316 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
317 CxIterator cxMapMutIteratorKeys(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
318
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
319 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
320 * Creates a mutating iterator for a map.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
321 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
322 * The elements of the iterator are key/value pairs of type CxMapEntry.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
323 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
324 * \note An iterator iterates over all elements successively. Therefore the order
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
325 * highly depends on the map implementation and may change arbitrarily when the contents change.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
326 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
327 * @param map the map to create the iterator for
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
328 * @return an iterator for the currently stored entries
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
329 * @see cxMapMutIteratorKeys()
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
330 * @see cxMapMutIteratorValues()
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
331 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
332 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
333 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
334 CxIterator cxMapMutIterator(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
335
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
336 #ifdef __cplusplus
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
337 } // end the extern "C" block here, because we want to start overloading
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
338
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
339 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
340 * Puts a key/value-pair into the map.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
341 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
342 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
343 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
344 * @param value the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
345 * @return 0 on success, non-zero value on failure
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
346 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
347 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
348 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
349 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
350 CxHashKey const &key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
351 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
352 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
353 return map->cl->put(map, key, value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
354 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
355
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
356
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
357 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
358 * Puts a key/value-pair into the map.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
359 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
360 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
361 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
362 * @param value the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
363 * @return 0 on success, non-zero value on failure
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
364 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
365 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
366 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
367 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
368 cxstring const &key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
369 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
370 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
371 return map->cl->put(map, cx_hash_key_cxstr(key), value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
372 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
373
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
374 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
375 * Puts a key/value-pair into the map.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
376 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
377 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
378 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
379 * @param value the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
380 * @return 0 on success, non-zero value on failure
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
381 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
382 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
383 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
384 CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
385 cxmutstr const &key,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
386 void *value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
387 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
388 return map->cl->put(map, cx_hash_key_cxstr(key), value);
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
389 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
390
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
391 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
392 * Puts a key/value-pair into the map.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
393 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
394 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
395 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
396 * @param value the value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
397 * @return 0 on success, non-zero value on failure
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
398 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
399 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
400 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
401 static inline int cxMapPut(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
402 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
403 const char *key,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
404 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
405 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
406 return map->cl->put(map, cx_hash_key_str(key), value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
407 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
408
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
409 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
410 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
411 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
412 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
413 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
414 * @return the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
415 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
416 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
417 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
418 static inline void *cxMapGet(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
419 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
420 CxHashKey const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
421 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
422 return map->cl->get(map, key);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
423 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
424
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
425 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
426 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
427 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
428 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
429 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
430 * @return the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
431 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
432 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
433 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
434 static inline void *cxMapGet(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
435 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
436 cxstring const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
437 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
438 return map->cl->get(map, cx_hash_key_cxstr(key));
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
439 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
440
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
441 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
442 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
443 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
444 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
445 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
446 * @return the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
447 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
448 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
449 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
450 static inline void *cxMapGet(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
451 const CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
452 cxmutstr const &key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
453 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
454 return map->cl->get(map, cx_hash_key_cxstr(key));
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
455 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
456
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
457 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
458 * Retrieves a value by using a key.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
459 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
460 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
461 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
462 * @return the value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
463 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
464 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
465 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
466 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
467 static inline void *cxMapGet(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
468 const CxMap *map,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
469 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
470 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
471 return map->cl->get(map, cx_hash_key_str(key));
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
472 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
473
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
474 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
475 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
476 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
477 * Always invokes the destructor function, if any, on the removed element.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
478 * If this map is storing pointers and you just want to retrieve the pointer
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
479 * without invoking the destructor, use cxMapRemoveAndGet().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
480 * If you just want to detach the element from the map without invoking the
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
481 * destructor or returning the element, use cxMapDetach().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
482 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
483 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
484 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
485 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
486 * @see cxMapDetach()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
487 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
488 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
489 static inline void cxMapRemove(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
490 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
491 CxHashKey const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
492 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
493 (void) map->cl->remove(map, key, true);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
494 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
495
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
496 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
497 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
498 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
499 * Always invokes the destructor function, if any, on the removed element.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
500 * If this map is storing pointers and you just want to retrieve the pointer
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
501 * without invoking the destructor, use cxMapRemoveAndGet().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
502 * If you just want to detach the element from the map without invoking the
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
503 * destructor or returning the element, use cxMapDetach().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
504 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
505 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
506 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
507 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
508 * @see cxMapDetach()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
509 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
510 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
511 static inline void cxMapRemove(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
512 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
513 cxstring const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
514 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
515 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
516 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
517
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
518 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
519 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
520 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
521 * Always invokes the destructor function, if any, on the removed element.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
522 * If this map is storing pointers and you just want to retrieve the pointer
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
523 * without invoking the destructor, use cxMapRemoveAndGet().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
524 * If you just want to detach the element from the map without invoking the
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
525 * destructor or returning the element, use cxMapDetach().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
526 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
527 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
528 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
529 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
530 * @see cxMapDetach()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
531 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
532 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
533 static inline void cxMapRemove(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
534 CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
535 cxmutstr const &key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
536 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
537 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true);
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
538 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
539
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
540 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
541 * Removes a key/value-pair from the map by using the key.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
542 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
543 * Always invokes the destructor function, if any, on the removed element.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
544 * If this map is storing pointers and you just want to retrieve the pointer
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
545 * without invoking the destructor, use cxMapRemoveAndGet().
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
546 * If you just want to detach the element from the map without invoking the
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
547 * destructor or returning the element, use cxMapDetach().
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
548 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
549 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
550 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
551 * @see cxMapRemoveAndGet()
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
552 * @see cxMapDetach()
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
553 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
554 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
555 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
556 static inline void cxMapRemove(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
557 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
558 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
559 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
560 (void) map->cl->remove(map, cx_hash_key_str(key), true);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
561 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
562
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
563 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
564 * Detaches a key/value-pair from the map by using the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
565 * without invoking the destructor.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
566 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
567 * In general, you should only use this function if the map does not own
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
568 * the data and there is a valid reference to the data somewhere else
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
569 * in the program. In all other cases it is preferable to use
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
570 * cxMapRemove() or cxMapRemoveAndGet().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
571 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
572 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
573 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
574 * @see cxMapRemove()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
575 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
576 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
577 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
578 static inline void cxMapDetach(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
579 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
580 CxHashKey const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
581 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
582 (void) map->cl->remove(map, key, false);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
583 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
584
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
585 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
586 * Detaches a key/value-pair from the map by using the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
587 * without invoking the destructor.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
588 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
589 * In general, you should only use this function if the map does not own
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
590 * the data and there is a valid reference to the data somewhere else
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
591 * in the program. In all other cases it is preferable to use
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
592 * cxMapRemove() or cxMapRemoveAndGet().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
593 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
594 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
595 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
596 * @see cxMapRemove()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
597 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
598 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
599 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
600 static inline void cxMapDetach(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
601 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
602 cxstring const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
603 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
604 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
605 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
606
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
607 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
608 * Detaches a key/value-pair from the map by using the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
609 * without invoking the destructor.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
610 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
611 * In general, you should only use this function if the map does not own
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
612 * the data and there is a valid reference to the data somewhere else
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
613 * in the program. In all other cases it is preferable to use
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
614 * cxMapRemove() or cxMapRemoveAndGet().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
615 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
616 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
617 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
618 * @see cxMapRemove()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
619 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
620 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
621 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
622 static inline void cxMapDetach(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
623 CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
624 cxmutstr const &key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
625 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
626 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false);
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
627 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
628
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
629 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
630 * Detaches a key/value-pair from the map by using the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
631 * without invoking the destructor.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
632 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
633 * In general, you should only use this function if the map does not own
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
634 * the data and there is a valid reference to the data somewhere else
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
635 * in the program. In all other cases it is preferable to use
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
636 * cxMapRemove() or cxMapRemoveAndGet().
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
637 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
638 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
639 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
640 * @see cxMapRemove()
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
641 * @see cxMapRemoveAndGet()
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
642 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
643 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
644 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
645 static inline void cxMapDetach(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
646 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
647 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
648 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
649 (void) map->cl->remove(map, cx_hash_key_str(key), false);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
650 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
651
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
652 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
653 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
654 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
655 * This function can be used when the map is storing pointers,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
656 * in order to retrieve the pointer from the map without invoking
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
657 * any destructor function. Sometimes you do not want the pointer
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
658 * to be returned - in that case (instead of suppressing the "unused
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
659 * result" warning) you can use cxMapDetach().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
660 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
661 * If this map is not storing pointers, this function behaves like
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
662 * cxMapRemove() and returns \c NULL.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
663 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
664 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
665 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
666 * @return the stored pointer or \c NULL if either the key is not present
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
667 * in the map or the map is not storing pointers
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
668 * @see cxMapStorePointers()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
669 * @see cxMapDetach()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
670 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
671 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
672 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
673 static inline void *cxMapRemoveAndGet(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
674 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
675 CxHashKey key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
676 ) {
957
26e47a874f19 fix map.h C++ inline functions not ported to new collection base class
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 890
diff changeset
677 return map->cl->remove(map, key, !map->collection.store_pointer);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
678 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
679
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
680 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
681 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
682 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
683 * This function can be used when the map is storing pointers,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
684 * in order to retrieve the pointer from the map without invoking
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
685 * any destructor function. Sometimes you do not want the pointer
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
686 * to be returned - in that case (instead of suppressing the "unused
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
687 * result" warning) you can use cxMapDetach().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
688 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
689 * If this map is not storing pointers, this function behaves like
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
690 * cxMapRemove() and returns \c NULL.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
691 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
692 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
693 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
694 * @return the stored pointer or \c NULL if either the key is not present
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
695 * in the map or the map is not storing pointers
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
696 * @see cxMapStorePointers()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
697 * @see cxMapDetach()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
698 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
699 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
700 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
701 static inline void *cxMapRemoveAndGet(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
702 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
703 cxstring key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
704 ) {
957
26e47a874f19 fix map.h C++ inline functions not ported to new collection base class
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 890
diff changeset
705 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
706 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
707
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
708 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
709 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
710 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
711 * This function can be used when the map is storing pointers,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
712 * in order to retrieve the pointer from the map without invoking
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
713 * any destructor function. Sometimes you do not want the pointer
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
714 * to be returned - in that case (instead of suppressing the "unused
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
715 * result" warning) you can use cxMapDetach().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
716 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
717 * If this map is not storing pointers, this function behaves like
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
718 * cxMapRemove() and returns \c NULL.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
719 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
720 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
721 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
722 * @return the stored pointer or \c NULL if either the key is not present
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
723 * in the map or the map is not storing pointers
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
724 * @see cxMapStorePointers()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
725 * @see cxMapDetach()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
726 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
727 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
728 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
729 static inline void *cxMapRemoveAndGet(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
730 CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
731 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
732 ) {
957
26e47a874f19 fix map.h C++ inline functions not ported to new collection base class
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 890
diff changeset
733 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer);
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
734 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
735
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
736 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
737 * Removes a key/value-pair from the map by using the key.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
738 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
739 * This function can be used when the map is storing pointers,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
740 * in order to retrieve the pointer from the map without invoking
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
741 * any destructor function. Sometimes you do not want the pointer
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
742 * to be returned - in that case (instead of suppressing the "unused
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
743 * result" warning) you can use cxMapDetach().
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
744 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
745 * If this map is not storing pointers, this function behaves like
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
746 * cxMapRemove() and returns \c NULL.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
747 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
748 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
749 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
750 * @return the stored pointer or \c NULL if either the key is not present
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
751 * in the map or the map is not storing pointers
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
752 * @see cxMapStorePointers()
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
753 * @see cxMapDetach()
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
754 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
755 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
756 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
757 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
758 static inline void *cxMapRemoveAndGet(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
759 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
760 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
761 ) {
957
26e47a874f19 fix map.h C++ inline functions not ported to new collection base class
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 890
diff changeset
762 return map->cl->remove(map, cx_hash_key_str(key), !map->collection.store_pointer);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
763 }
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
764
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
765 #else // __cplusplus
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
766
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
767 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
768 * Puts a key/value-pair into the map.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
769 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
770 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
771 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
772 * @param value the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
773 * @return 0 on success, non-zero value on failure
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
774 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
775 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
776 static inline int cx_map_put(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
777 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
778 CxHashKey key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
779 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
780 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
781 return map->cl->put(map, key, value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
782 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
783
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
784 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
785 * Puts a key/value-pair into the map.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
786 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
787 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
788 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
789 * @param value the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
790 * @return 0 on success, non-zero value on failure
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
791 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
792 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
793 static inline int cx_map_put_cxstr(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
794 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
795 cxstring key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
796 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
797 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
798 return map->cl->put(map, cx_hash_key_cxstr(key), value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
799 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
800
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
801 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
802 * Puts a key/value-pair into the map.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
803 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
804 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
805 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
806 * @param value the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
807 * @return 0 on success, non-zero value on failure
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
808 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
809 cx_attr_nonnull
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
810 static inline int cx_map_put_mustr(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
811 CxMap *map,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
812 cxmutstr key,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
813 void *value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
814 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
815 return map->cl->put(map, cx_hash_key_cxstr(key), value);
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
816 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
817
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
818 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
819 * Puts a key/value-pair into the map.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
820 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
821 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
822 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
823 * @param value the value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
824 * @return 0 on success, non-zero value on failure
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
825 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
826 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
827 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
828 static inline int cx_map_put_str(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
829 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
830 const char *key,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
831 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
832 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
833 return map->cl->put(map, cx_hash_key_str(key), value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
834 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
835
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
836 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
837 * Puts a key/value-pair into the map.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
838 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
839 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
840 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
841 * @param value the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
842 * @return 0 on success, non-zero value on failure
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
843 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
844 #define cxMapPut(map, key, value) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
845 CxHashKey: cx_map_put, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
846 cxstring: cx_map_put_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
847 cxmutstr: cx_map_put_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
848 char*: cx_map_put_str, \
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
849 const char*: cx_map_put_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
850 (map, key, value)
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
851
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
852 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
853 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
854 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
855 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
856 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
857 * @return the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
858 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
859 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
860 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
861 static inline void *cx_map_get(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
862 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
863 CxHashKey key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
864 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
865 return map->cl->get(map, key);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
866 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
867
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
868 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
869 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
870 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
871 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
872 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
873 * @return the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
874 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
875 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
876 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
877 static inline void *cx_map_get_cxstr(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
878 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
879 cxstring key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
880 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
881 return map->cl->get(map, cx_hash_key_cxstr(key));
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
882 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
883
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
884 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
885 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
886 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
887 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
888 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
889 * @return the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
890 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
891 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
892 cx_attr_nodiscard
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
893 static inline void *cx_map_get_mustr(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
894 const CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
895 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
896 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
897 return map->cl->get(map, cx_hash_key_cxstr(key));
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
898 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
899
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
900 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
901 * Retrieves a value by using a key.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
902 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
903 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
904 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
905 * @return the value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
906 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
907 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
908 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
909 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
910 static inline void *cx_map_get_str(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
911 const CxMap *map,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
912 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
913 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
914 return map->cl->get(map, cx_hash_key_str(key));
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
915 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
916
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
917 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
918 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
919 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
920 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
921 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
922 * @return the value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
923 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
924 #define cxMapGet(map, key) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
925 CxHashKey: cx_map_get, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
926 cxstring: cx_map_get_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
927 cxmutstr: cx_map_get_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
928 char*: cx_map_get_str, \
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
929 const char*: cx_map_get_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
930 (map, key)
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
931
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
932 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
933 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
934 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
935 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
936 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
937 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
938 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
939 static inline void cx_map_remove(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
940 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
941 CxHashKey key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
942 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
943 (void) map->cl->remove(map, key, true);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
944 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
945
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
946 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
947 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
948 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
949 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
950 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
951 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
952 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
953 static inline void cx_map_remove_cxstr(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
954 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
955 cxstring key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
956 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
957 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
958 }
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
959
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
960 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
961 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
962 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
963 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
964 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
965 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
966 cx_attr_nonnull
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
967 static inline void cx_map_remove_mustr(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
968 CxMap *map,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
969 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
970 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
971 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true);
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
972 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
973
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
974 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
975 * Removes a key/value-pair from the map by using the key.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
976 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
977 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
978 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
979 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
980 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
981 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
982 static inline void cx_map_remove_str(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
983 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
984 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
985 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
986 (void) map->cl->remove(map, cx_hash_key_str(key), true);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
987 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
988
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
989 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
990 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
991 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
992 * Always invokes the destructor function, if any, on the removed element.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
993 * If this map is storing pointers and you just want to retrieve the pointer
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
994 * without invoking the destructor, use cxMapRemoveAndGet().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
995 * If you just want to detach the element from the map without invoking the
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
996 * destructor or returning the element, use cxMapDetach().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
997 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
998 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
999 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1000 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1001 * @see cxMapDetach()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1002 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1003 #define cxMapRemove(map, key) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1004 CxHashKey: cx_map_remove, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1005 cxstring: cx_map_remove_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1006 cxmutstr: cx_map_remove_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
1007 char*: cx_map_remove_str, \
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
1008 const char*: cx_map_remove_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1009 (map, key)
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1010
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1011 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1012 * Detaches a key/value-pair from the map by using the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1013 * without invoking the destructor.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1014 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1015 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1016 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1017 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1018 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1019 static inline void cx_map_detach(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1020 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1021 CxHashKey key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1022 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1023 (void) map->cl->remove(map, key, false);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1024 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1025
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1026 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1027 * Detaches a key/value-pair from the map by using the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1028 * without invoking the destructor.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1029 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1030 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1031 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1032 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1033 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1034 static inline void cx_map_detach_cxstr(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1035 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1036 cxstring key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1037 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1038 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1039 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1040
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1041 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1042 * Detaches a key/value-pair from the map by using the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1043 * without invoking the destructor.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1044 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1045 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1046 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1047 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1048 cx_attr_nonnull
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1049 static inline void cx_map_detach_mustr(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1050 CxMap *map,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1051 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1052 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1053 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false);
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1054 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1055
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1056 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1057 * Detaches a key/value-pair from the map by using the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1058 * without invoking the destructor.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1059 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1060 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1061 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1062 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1063 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1064 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1065 static inline void cx_map_detach_str(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1066 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
1067 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1068 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1069 (void) map->cl->remove(map, cx_hash_key_str(key), false);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1070 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1071
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1072 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1073 * Detaches a key/value-pair from the map by using the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1074 * without invoking the destructor.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1075 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1076 * In general, you should only use this function if the map does not own
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1077 * the data and there is a valid reference to the data somewhere else
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1078 * in the program. In all other cases it is preferable to use
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1079 * cxMapRemove() or cxMapRemoveAndGet().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1080 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1081 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1082 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1083 * @see cxMapRemove()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1084 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1085 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1086 #define cxMapDetach(map, key) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1087 CxHashKey: cx_map_detach, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1088 cxstring: cx_map_detach_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1089 cxmutstr: cx_map_detach_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
1090 char*: cx_map_detach_str, \
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
1091 const char*: cx_map_detach_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1092 (map, key)
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1093
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1094 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1095 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1096 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1097 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1098 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1099 * @return the stored pointer or \c NULL if either the key is not present
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1100 * in the map or the map is not storing pointers
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1101 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1102 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1103 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1104 static inline void *cx_map_remove_and_get(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1105 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1106 CxHashKey key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1107 ) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
1108 return map->cl->remove(map, key, !map->collection.store_pointer);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1109 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1110
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1111 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1112 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1113 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1114 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1115 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1116 * @return the stored pointer or \c NULL if either the key is not present
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1117 * in the map or the map is not storing pointers
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1118 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1119 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1120 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1121 static inline void *cx_map_remove_and_get_cxstr(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1122 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1123 cxstring key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1124 ) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
1125 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1126 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1127
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1128 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1129 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1130 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1131 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1132 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1133 * @return the stored pointer or \c NULL if either the key is not present
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1134 * in the map or the map is not storing pointers
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1135 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1136 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1137 cx_attr_nodiscard
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1138 static inline void *cx_map_remove_and_get_mustr(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1139 CxMap *map,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1140 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1141 ) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
1142 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer);
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1143 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1144
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1145 /**
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1146 * Removes a key/value-pair from the map by using the key.
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1147 *
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1148 * @param map the map
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1149 * @param key the key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1150 * @return the stored pointer or \c NULL if either the key is not present
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1151 * in the map or the map is not storing pointers
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1152 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1153 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1154 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
1155 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1156 static inline void *cx_map_remove_and_get_str(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1157 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
1158 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1159 ) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
1160 return map->cl->remove(map, cx_hash_key_str(key), !map->collection.store_pointer);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1161 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1162
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1163 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1164 * Removes a key/value-pair from the map by using the key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1165 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1166 * This function can be used when the map is storing pointers,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1167 * in order to retrieve the pointer from the map without invoking
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1168 * any destructor function. Sometimes you do not want the pointer
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1169 * to be returned - in that case (instead of suppressing the "unused
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1170 * result" warning) you can use cxMapDetach().
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1171 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1172 * If this map is not storing pointers, this function behaves like
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1173 * cxMapRemove() and returns \c NULL.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1174 *
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1175 * @param map the map
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1176 * @param key the key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1177 * @return the stored pointer or \c NULL if either the key is not present
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1178 * in the map or the map is not storing pointers
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1179 * @see cxMapStorePointers()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1180 * @see cxMapDetach()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1181 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1182 #define cxMapRemoveAndGet(map, key) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1183 CxHashKey: cx_map_remove_and_get, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1184 cxstring: cx_map_remove_and_get_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
1185 cxmutstr: cx_map_remove_and_get_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
1186 char*: cx_map_remove_and_get_str, \
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
1187 const char*: cx_map_remove_and_get_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1188 (map, key)
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1189
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1190 #endif // __cplusplus
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1191
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
1192 #endif // UCX_MAP_H

mercurial