src/cx/map.h

Mon, 06 Jan 2025 23:29:41 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 06 Jan 2025 23:29:41 +0100
changeset 1111
78eeeb950883
parent 1109
89ec23988b88
child 1114
ad5eeb256242
permissions
-rw-r--r--

remove API for changing the store_pointer property after list creation

fixes #553

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 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
29 * @file map.h
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
30 * @brief Interface for map implementations.
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
31 * @author Mike Becker
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
32 * @author Olaf Wintermann
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
33 * @copyright 2-Clause BSD License
549
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 */
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 992
diff changeset
92 void (*deallocate)(struct cx_map_s *map);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93
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 * Removes all elements.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 void (*clear)(struct cx_map_s *map);
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 * Add or overwrite an element.
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 int (*put)(
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 CxMap *map,
563
69a83fad8a35 improve hash key handling
Mike Becker <universe@uap-core.de>
parents: 558
diff changeset
104 CxHashKey key,
550
89b2a83728b1 #189 basic map implementation
Mike Becker <universe@uap-core.de>
parents: 549
diff changeset
105 void *value
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 );
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 * Returns an element.
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 void *(*get)(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
112 const CxMap *map,
563
69a83fad8a35 improve hash key handling
Mike Becker <universe@uap-core.de>
parents: 558
diff changeset
113 CxHashKey key
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 );
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 * Removes an element.
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
118 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
119 * Implementations SHALL check if @p targetbuf is set and copy the elements
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
120 * to the buffer without invoking any destructor.
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
121 * When @p targetbuf is not set, the destructors SHALL be invoked.
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
122 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
123 * The function SHALL return zero when the @p key was found and
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
124 * non-zero, otherwise.
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 */
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
126 int (*remove)(
550
89b2a83728b1 #189 basic map implementation
Mike Becker <universe@uap-core.de>
parents: 549
diff changeset
127 CxMap *map,
686
64919f63f059 add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents: 685
diff changeset
128 CxHashKey key,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
129 void *targetbuf
549
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
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 /**
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
133 * Creates an iterator for this map.
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 */
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
135 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
136 };
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 * A map entry.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 */
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 struct cx_map_entry_s {
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 /**
551
2946e13c89a4 #189 implement map iterators
Mike Becker <universe@uap-core.de>
parents: 550
diff changeset
143 * A pointer to the key.
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 */
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
145 const CxHashKey *key;
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 /**
551
2946e13c89a4 #189 implement map iterators
Mike Becker <universe@uap-core.de>
parents: 550
diff changeset
147 * A pointer to the value.
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 */
551
2946e13c89a4 #189 implement map iterators
Mike Becker <universe@uap-core.de>
parents: 550
diff changeset
149 void *value;
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 };
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151
714
34565d898f1f add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents: 710
diff changeset
152 /**
34565d898f1f add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents: 710
diff changeset
153 * A shared instance of an empty map.
34565d898f1f add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents: 710
diff changeset
154 *
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
155 * Writing to that map is not allowed.
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
156 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
157 * You can use this is a placeholder for initializing CxMap pointers
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
158 * for which you do not want to reserve memory right from the beginning.
714
34565d898f1f add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents: 710
diff changeset
159 */
706
8c6edaccaef1 add empty map implementation - fixes #259
Mike Becker <universe@uap-core.de>
parents: 694
diff changeset
160 extern CxMap *const cxEmptyMap;
8c6edaccaef1 add empty map implementation - fixes #259
Mike Becker <universe@uap-core.de>
parents: 694
diff changeset
161
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
162 /**
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 * Deallocates the memory of the specified map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
165 * Also calls the content destructor functions for each element, if specified.
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
166 *
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 992
diff changeset
167 * @param map the map to be freed
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 */
1109
89ec23988b88 free functions should not be inline in release mode - relates to #541
Mike Becker <universe@uap-core.de>
parents: 1102
diff changeset
169 void cxMapFree(CxMap *map);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 * Clears a map by removing all elements.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
175 * Also calls the content destructor functions for each element, if specified.
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
176 *
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 * @param map the map to be cleared
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
179 cx_attr_nonnull
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 static inline void cxMapClear(CxMap *map) {
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 map->cl->clear(map);
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
184 /**
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
185 * 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
186 *
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
187 * @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
188 * @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
189 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
190 cx_attr_nonnull
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
191 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
192 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
193 }
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
194
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 * Creates a value iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
198 * @note An iterator iterates over all elements successively. Therefore, the order
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 * 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
200 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 * @param map the map to create the iterator for
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 * @return an iterator for the currently stored values
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
204 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
205 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
206 static inline CxIterator cxMapIteratorValues(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
207 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
208 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 * Creates a key iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 *
564
5d8ad7a0ff71 fix obsolete documentation
Mike Becker <universe@uap-core.de>
parents: 563
diff changeset
213 * 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
214 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
215 * @note An iterator iterates over all elements successively. Therefore, the order
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 * 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
217 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 * @param map the map to create the iterator for
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 * @return an iterator for the currently stored keys
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
221 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
222 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
223 static inline CxIterator cxMapIteratorKeys(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
224 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
225 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 * Creates an iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 *
555
d79fbd028e26 fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents: 553
diff changeset
230 * 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
231 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
232 * @note An iterator iterates over all elements successively. Therefore, the order
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 * 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
234 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235 * @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
236 * @return an iterator for the currently stored entries
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237 * @see cxMapIteratorKeys()
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 * @see cxMapIteratorValues()
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
240 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
241 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
242 static inline CxIterator cxMapIterator(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
243 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
244 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
246
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
247 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
248 * 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
249 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
250 * @note An iterator iterates over all elements successively. Therefore, the order
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
251 * 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
252 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
253 * @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
254 * @return an iterator for the currently stored values
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
255 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
256 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
257 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
258 CxIterator cxMapMutIteratorValues(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
259
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
260 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
261 * 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
262 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
263 * 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
264 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
265 * @note An iterator iterates over all elements successively. Therefore, the order
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
266 * 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
267 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
268 * @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
269 * @return an iterator for the currently stored keys
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
270 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
271 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
272 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
273 CxIterator cxMapMutIteratorKeys(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
274
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
275 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
276 * Creates a mutating iterator for a map.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
277 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
278 * 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
279 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
280 * @note An iterator iterates over all elements successively. Therefore, the order
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
281 * 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
282 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
283 * @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
284 * @return an iterator for the currently stored entries
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
285 * @see cxMapMutIteratorKeys()
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
286 * @see cxMapMutIteratorValues()
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
287 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
288 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
289 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
290 CxIterator cxMapMutIterator(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
291
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
292 #ifdef __cplusplus
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
293 } // end the extern "C" block here, because we want to start overloading
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
294 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
295 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
296 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
297 CxHashKey const &key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
298 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
299 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
300 return map->cl->put(map, key, value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
301 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
302
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
303 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
304 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
305 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
306 cxstring const &key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
307 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
308 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
309 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
310 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
311
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
312 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
313 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
314 CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
315 cxmutstr const &key,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
316 void *value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
317 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
318 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
319 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
320
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
321 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
322 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
323 static inline int cxMapPut(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
324 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
325 const char *key,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
326 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
327 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
328 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
329 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
330
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
331 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
332 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
333 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
334 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
335 CxHashKey const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
336 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
337 return map->cl->get(map, key);
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
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
340 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
341 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
342 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
343 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
344 cxstring const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
345 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
346 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
347 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
348
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
349 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
350 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
351 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
352 const CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
353 cxmutstr const &key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
354 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
355 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
356 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
357
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
358 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
359 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
360 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
361 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
362 const CxMap *map,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
363 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
364 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
365 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
366 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
367
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
368 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
369 static inline int cxMapRemove(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
370 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
371 CxHashKey const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
372 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
373 return map->cl->remove(map, key, nullptr);
691
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
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
376 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
377 static inline int cxMapRemove(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
378 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
379 cxstring const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
380 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
381 return map->cl->remove(map, cx_hash_key_cxstr(key), nullptr);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
382 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
383
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
384 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
385 static inline int cxMapRemove(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
386 CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
387 cxmutstr const &key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
388 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
389 return map->cl->remove(map, cx_hash_key_cxstr(key), nullptr);
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
390 }
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
391
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
392 cx_attr_nonnull
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
393 cx_attr_cstr_arg(2)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
394 static inline int cxMapRemove(
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
395 CxMap *map,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
396 const char *key
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
397 ) {
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
398 return map->cl->remove(map, cx_hash_key_str(key), nullptr);
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
399 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
400
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
401 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
402 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
403 static inline int cxMapRemoveAndGet(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
404 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
405 CxHashKey key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
406 void *targetbuf
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
407 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
408 return map->cl->remove(map, key, targetbuf);
691
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
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
411 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
412 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
413 static inline int cxMapRemoveAndGet(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
414 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
415 cxstring key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
416 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
417 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
418 return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
419 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
420
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
421 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
422 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
423 static inline int cxMapRemoveAndGet(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
424 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
425 cxmutstr key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
426 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
427 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
428 return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
429 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
430
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
431 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
432 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
433 cx_attr_cstr_arg(2)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
434 static inline int cxMapRemoveAndGet(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
435 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
436 const char *key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
437 void *targetbuf
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
438 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
439 return map->cl->remove(map, cx_hash_key_str(key), targetbuf);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
440 }
691
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 #else // __cplusplus
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 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
445 * @copydoc cxMapPut()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
446 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
447 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
448 static inline int cx_map_put(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
449 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
450 CxHashKey key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
451 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
452 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
453 return map->cl->put(map, key, value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
454 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
455
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
456 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
457 * @copydoc cxMapPut()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
458 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
459 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
460 static inline int cx_map_put_cxstr(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
461 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
462 cxstring key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
463 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
464 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
465 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
466 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
467
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
468 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
469 * @copydoc cxMapPut()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
470 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
471 cx_attr_nonnull
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
472 static inline int cx_map_put_mustr(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
473 CxMap *map,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
474 cxmutstr key,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
475 void *value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
476 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
477 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
478 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
479
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
480 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
481 * @copydoc cxMapPut()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
482 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
483 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
484 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
485 static inline int cx_map_put_str(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
486 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
487 const char *key,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
488 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
489 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
490 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
491 }
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 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
494 * 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
495 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
496 * A possible existing value will be overwritten.
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
497 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
498 * If this map is storing pointers, the @p value pointer is written
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
499 * to the map. Otherwise, the memory is copied from @p value with
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
500 * memcpy().
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
501 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
502 * The @p key is always copied.
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
503 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
504 * @param map (@c CxMap*) the map
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
505 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
506 * @param value (@c void*) the value
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
507 * @retval zero success
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
508 * @retval non-zero value on memory allocation failure
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
509 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
510 #define cxMapPut(map, key, value) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
511 CxHashKey: cx_map_put, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
512 cxstring: cx_map_put_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
513 cxmutstr: cx_map_put_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
514 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
515 const char*: cx_map_put_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
516 (map, key, value)
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 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
519 * @copydoc cxMapGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
520 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
521 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
522 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
523 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
524 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
525 CxHashKey key
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 return map->cl->get(map, key);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
528 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
529
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
530 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
531 * @copydoc cxMapGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
532 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
533 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
534 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
535 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
536 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
537 cxstring key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
538 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
539 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
540 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
541
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
542 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
543 * @copydoc cxMapGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
544 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
545 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
546 cx_attr_nodiscard
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
547 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
548 const CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
549 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
550 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
551 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
552 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
553
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
554 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
555 * @copydoc cxMapGet()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
556 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
557 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
558 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
559 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
560 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
561 const CxMap *map,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
562 const char *key
691
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 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
565 }
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 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
568 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
569 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
570 * If this map is storing pointers, the stored pointer is returned.
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
571 * Otherwise, a pointer to the element within the map's memory
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
572 * is returned (which is valid as long as the element stays in the map).
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
573 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
574 * @param map (@c CxMap*) the map
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
575 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
576 * @return (@c void*) the value
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
577 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
578 #define cxMapGet(map, key) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
579 CxHashKey: cx_map_get, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
580 cxstring: cx_map_get_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
581 cxmutstr: cx_map_get_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
582 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
583 const char*: cx_map_get_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
584 (map, key)
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 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
587 * @copydoc cxMapRemove()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
588 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
589 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
590 static inline int cx_map_remove(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
591 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
592 CxHashKey key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
593 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
594 return map->cl->remove(map, key, NULL);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
595 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
596
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
597 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
598 * @copydoc cxMapRemove()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
599 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
600 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
601 static inline int cx_map_remove_cxstr(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
602 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
603 cxstring key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
604 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
605 return map->cl->remove(map, cx_hash_key_cxstr(key), NULL);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
606 }
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
607
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
608 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
609 * @copydoc cxMapRemove()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
610 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
611 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
612 static inline int cx_map_remove_mustr(
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
613 CxMap *map,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
614 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
615 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
616 return map->cl->remove(map, cx_hash_key_cxstr(key), NULL);
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
617 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
618
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
619 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
620 * @copydoc cxMapRemove()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
621 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
622 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
623 cx_attr_cstr_arg(2)
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
624 static inline int cx_map_remove_str(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
625 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
626 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
627 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
628 return map->cl->remove(map, cx_hash_key_str(key), NULL);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
629 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
630
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
631 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
632 * 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
633 *
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
634 * Always invokes the destructors functions, if any, on the removed element.
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
635 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
636 * @param map (@c CxMap*) the map
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
637 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
638 * @retval zero success
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
639 * @retval non-zero the key was not found
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
640 *
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
641 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
642 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
643 #define cxMapRemove(map, key) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
644 CxHashKey: cx_map_remove, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
645 cxstring: cx_map_remove_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
646 cxmutstr: cx_map_remove_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
647 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
648 const char*: cx_map_remove_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
649 (map, key)
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 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
652 * @copydoc cxMapRemoveAndGet()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
653 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
654 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
655 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
656 static inline int cx_map_remove_and_get(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
657 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
658 CxHashKey key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
659 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
660 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
661 return map->cl->remove(map, key, targetbuf);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
662 }
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 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
665 * @copydoc cxMapRemoveAndGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
666 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
667 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
668 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
669 static inline int cx_map_remove_and_get_cxstr(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
670 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
671 cxstring key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
672 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
673 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
674 return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
675 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
676
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
677 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
678 * @copydoc cxMapRemoveAndGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
679 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
680 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
681 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
682 static inline int cx_map_remove_and_get_mustr(
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
683 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
684 cxmutstr key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
685 void *targetbuf
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
686 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
687 return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf);
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
688 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
689
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
690 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
691 * @copydoc cxMapRemoveAndGet()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
692 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
693 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
694 cx_attr_access_w(3)
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
695 cx_attr_cstr_arg(2)
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
696 static inline int cx_map_remove_and_get_str(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
697 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
698 const char *key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
699 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
700 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
701 return map->cl->remove(map, cx_hash_key_str(key), targetbuf);
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
702 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
703
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
704 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
705 * 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
706 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
707 * This function will copy the contents of the removed element
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
708 * to the target buffer must be guaranteed to be large enough
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
709 * to hold the element (the map's element size).
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
710 * The destructor functions, if any, will @em not be called.
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
711 *
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
712 * If this map is storing pointers, the element is the pointer itself
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
713 * and not the object it points to.
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
714 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
715 * @param map (@c CxMap*) the map
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
716 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
717 * @param targetbuf (@c void*) the buffer where the element shall be copied to
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
718 * @retval zero success
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
719 * @retval non-zero the key was not found
1111
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
720 *
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
721 * @see cxMapRemove()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
722 */
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
723 #define cxMapRemoveAndGet(map, key, targetbuf) _Generic((key), \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
724 CxHashKey: cx_map_remove_and_get, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
725 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
726 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
727 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
728 const char*: cx_map_remove_and_get_str) \
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
729 (map, key, targetbuf)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
730
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
731 #endif // __cplusplus
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
732
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
733 #endif // UCX_MAP_H

mercurial