src/cx/map.h

Sun, 05 Jan 2025 12:40:43 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 05 Jan 2025 12:40:43 +0100
changeset 1102
db5e355e5349
parent 994
3603bdf4a78b
child 1109
89ec23988b88
permissions
-rw-r--r--

refine docs for map.h - issue #548

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 /**
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
163 * Advises the map to store copies of the objects (default mode of operation).
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
164 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
165 * Retrieving objects from this map will yield pointers to the copies stored
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
166 * within this list.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
167 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
168 * @param map the map
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
169 * @see cxMapStorePointers()
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
170 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
171 cx_attr_nonnull
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
172 static inline void cxMapStoreObjects(CxMap *map) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
173 map->collection.store_pointer = false;
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
174 }
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
175
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
176 /**
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
177 * Advises the map to only store pointers to the objects.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
178 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
179 * Retrieving objects from this list will yield the original pointers stored.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
180 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
181 * @note This function forcibly sets the element size to the size of a pointer.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
182 * Invoking this function on a non-empty map that already stores copies of
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
183 * objects is undefined.
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
184 *
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
185 * @param map the map
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
186 * @see cxMapStoreObjects()
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
187 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
188 cx_attr_nonnull
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
189 static inline void cxMapStorePointers(CxMap *map) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
190 map->collection.store_pointer = true;
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
191 map->collection.elem_size = sizeof(void *);
658
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
192 }
56c62780582e make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
193
857
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
194 /**
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
195 * Returns true, if this map is storing pointers instead of the actual data.
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
196 *
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
197 * @param map
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
198 * @return true, if this map is storing pointers
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
199 * @see cxMapStorePointers()
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
200 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
201 cx_attr_nonnull
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
202 static inline bool cxMapIsStoringPointers(const CxMap *map) {
857
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
203 return map->collection.store_pointer;
4d12e34bb130 add missing convenience functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
204 }
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 * Deallocates the memory of the specified map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
209 * 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
210 *
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 992
diff changeset
211 * @param map the map to be freed
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 */
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 992
diff changeset
213 static inline void cxMapFree(CxMap *map) {
984
e8f354a25ac8 let cxMapDestroy() ignore NULL as any free()-like function should do
Mike Becker <universe@uap-core.de>
parents: 957
diff changeset
214 if (map == NULL) return;
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 992
diff changeset
215 map->cl->deallocate(map);
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 }
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
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 * Clears a map by removing all elements.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
222 * 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
223 *
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 * @param map the map to be cleared
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
226 cx_attr_nonnull
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 static inline void cxMapClear(CxMap *map) {
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 map->cl->clear(map);
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
231 /**
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
232 * 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
233 *
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
234 * @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
235 * @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
236 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
237 cx_attr_nonnull
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
238 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
239 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
240 }
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
241
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 * Creates a value iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
245 * @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
246 * 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
247 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 * @param map the map to create the iterator for
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 * @return an iterator for the currently stored values
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
251 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
252 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
253 static inline CxIterator cxMapIteratorValues(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
254 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
255 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 * Creates a key iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 *
564
5d8ad7a0ff71 fix obsolete documentation
Mike Becker <universe@uap-core.de>
parents: 563
diff changeset
260 * 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
261 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
262 * @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
263 * 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
264 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 * @param map the map to create the iterator for
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 * @return an iterator for the currently stored keys
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
268 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
269 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
270 static inline CxIterator cxMapIteratorKeys(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
271 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
272 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 /**
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 * Creates an iterator for a map.
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 *
555
d79fbd028e26 fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents: 553
diff changeset
277 * 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
278 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
279 * @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
280 * 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
281 *
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 * @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
283 * @return an iterator for the currently stored entries
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 * @see cxMapIteratorKeys()
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 * @see cxMapIteratorValues()
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
287 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
288 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
289 static inline CxIterator cxMapIterator(const CxMap *map) {
709
1e8ba59e7911 simplify map class structure
Mike Becker <universe@uap-core.de>
parents: 706
diff changeset
290 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
291 }
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
293
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
294 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
295 * 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
296 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
297 * @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
298 * 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
299 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
300 * @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
301 * @return an iterator for the currently stored values
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
302 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
303 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
304 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
305 CxIterator cxMapMutIteratorValues(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
306
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
307 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
308 * 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
309 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
310 * 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
311 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
312 * @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
313 * 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
314 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
315 * @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
316 * @return an iterator for the currently stored keys
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
317 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
318 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
319 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
320 CxIterator cxMapMutIteratorKeys(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
321
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
322 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
323 * Creates a mutating iterator for a map.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
324 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
325 * 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
326 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
327 * @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
328 * 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
329 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
330 * @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
331 * @return an iterator for the currently stored entries
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
332 * @see cxMapMutIteratorKeys()
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
333 * @see cxMapMutIteratorValues()
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
334 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
335 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
336 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
337 CxIterator cxMapMutIterator(CxMap *map);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 564
diff changeset
338
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
339 #ifdef __cplusplus
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
340 } // 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
341 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
342 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
343 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
344 CxHashKey const &key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
345 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
346 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
347 return map->cl->put(map, key, value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
348 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
349
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
350 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
351 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
352 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
353 cxstring const &key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
354 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
355 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
356 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
357 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
358
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
359 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
360 static inline int cxMapPut(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
361 CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
362 cxmutstr const &key,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
363 void *value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
364 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
365 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
366 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
367
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
368 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
369 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
370 static inline int cxMapPut(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
371 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
372 const char *key,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
373 void *value
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 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
376 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
377
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
378 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
379 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
380 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
381 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
382 CxHashKey const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
383 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
384 return map->cl->get(map, key);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
385 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
386
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
387 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
388 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
389 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
390 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
391 cxstring const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
392 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
393 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
394 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
395
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
396 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
397 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
398 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
399 const CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
400 cxmutstr const &key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
401 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
402 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
403 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
404
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
405 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
406 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
407 cx_attr_cstr_arg(2)
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
408 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
409 const CxMap *map,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
410 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
411 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
412 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
413 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
414
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
415 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
416 static inline int cxMapRemove(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
417 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
418 CxHashKey const &key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
419 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
420 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
421 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
422
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
423 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
424 static inline int cxMapRemove(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
425 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
426 cxstring const &key
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), nullptr);
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 static inline int cxMapRemove(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
433 CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
434 cxmutstr const &key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
435 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
436 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
437 }
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
438
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
439 cx_attr_nonnull
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
440 cx_attr_cstr_arg(2)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
441 static inline int cxMapRemove(
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
442 CxMap *map,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
443 const char *key
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
444 ) {
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
445 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
446 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
447
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
448 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
449 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
450 static inline int cxMapRemoveAndGet(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
451 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
452 CxHashKey key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
453 void *targetbuf
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
454 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
455 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
456 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
457
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
458 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
459 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
460 static inline int cxMapRemoveAndGet(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
461 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
462 cxstring key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
463 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
464 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
465 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
466 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
467
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
468 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
469 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
470 static inline int cxMapRemoveAndGet(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
471 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
472 cxmutstr key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
473 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
474 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
475 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
476 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
477
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
478 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
479 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
480 cx_attr_cstr_arg(2)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
481 static inline int cxMapRemoveAndGet(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
482 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
483 const char *key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
484 void *targetbuf
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
485 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
486 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
487 }
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
488
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
489 #else // __cplusplus
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
490
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
491 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
492 * @copydoc cxMapPut()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
493 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
494 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
495 static inline int cx_map_put(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
496 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
497 CxHashKey key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
498 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
499 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
500 return map->cl->put(map, key, value);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
501 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
502
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
503 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
504 * @copydoc cxMapPut()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
505 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
506 cx_attr_nonnull
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
507 static inline int cx_map_put_cxstr(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
508 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
509 cxstring key,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
510 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
511 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
512 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
513 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
514
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
515 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
516 * @copydoc cxMapPut()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
517 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
518 cx_attr_nonnull
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
519 static inline int cx_map_put_mustr(
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
520 CxMap *map,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
521 cxmutstr key,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
522 void *value
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
523 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
524 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
525 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
526
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
527 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
528 * @copydoc cxMapPut()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
529 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
530 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
531 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
532 static inline int cx_map_put_str(
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
533 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
534 const char *key,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
535 void *value
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
536 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
537 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
538 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
539
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 * 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
542 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
543 * 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
544 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
545 * 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
546 * 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
547 * memcpy().
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
548 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
549 * The @p key is always copied.
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
550 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
551 * @param map (@c CxMap*) the map
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
552 * @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
553 * @param value (@c void*) the value
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
554 * @retval zero success
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
555 * @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
556 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
557 #define cxMapPut(map, key, value) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
558 CxHashKey: cx_map_put, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
559 cxstring: cx_map_put_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
560 cxmutstr: cx_map_put_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
561 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
562 const char*: cx_map_put_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
563 (map, key, value)
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
564
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
565 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
566 * @copydoc cxMapGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
567 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
568 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
569 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
570 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
571 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
572 CxHashKey key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
573 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
574 return map->cl->get(map, key);
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
575 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
576
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
577 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
578 * @copydoc cxMapGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
579 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
580 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
581 cx_attr_nodiscard
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
582 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
583 const CxMap *map,
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
584 cxstring 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 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
587 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
588
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
589 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
590 * @copydoc cxMapGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
591 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
592 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
593 cx_attr_nodiscard
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
594 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
595 const CxMap *map,
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
596 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
597 ) {
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
598 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
599 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
600
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
601 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
602 * @copydoc cxMapGet()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
603 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
604 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
605 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
606 cx_attr_cstr_arg(2)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
607 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
608 const CxMap *map,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
609 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
610 ) {
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
611 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
612 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
613
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
614 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
615 * Retrieves a value by using a key.
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
616 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
617 * 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
618 * 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
619 * 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
620 *
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
621 * @param map (@c CxMap*) the map
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
622 * @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
623 * @return (@c void*) the value
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
624 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
625 #define cxMapGet(map, key) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
626 CxHashKey: cx_map_get, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
627 cxstring: cx_map_get_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
628 cxmutstr: cx_map_get_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
629 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
630 const char*: cx_map_get_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
631 (map, key)
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
632
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
633 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
634 * @copydoc cxMapRemove()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
635 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
636 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
637 static inline int cx_map_remove(
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
638 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
639 CxHashKey key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
640 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
641 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
642 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
643
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
644 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
645 * @copydoc cxMapRemove()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
646 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
647 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
648 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
649 CxMap *map,
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
650 cxstring key
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
651 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
652 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
653 }
549
d7f0b5a9a985 #189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
654
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
655 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
656 * @copydoc cxMapRemove()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
657 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
658 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
659 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
660 CxMap *map,
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
661 cxmutstr key
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
662 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
663 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
664 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
665
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
666 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
667 * @copydoc cxMapRemove()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
668 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
669 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
670 cx_attr_cstr_arg(2)
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
671 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
672 CxMap *map,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 857
diff changeset
673 const char *key
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
674 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
675 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
676 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
677
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
678 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
679 * 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
680 *
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
681 * 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
682 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
683 * @param map (@c CxMap*) the map
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
684 * @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
685 * @retval zero success
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
686 * @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
687 *
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
688 * @see cxMapRemoveAndGet()
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
689 */
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
690 #define cxMapRemove(map, key) _Generic((key), \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
691 CxHashKey: cx_map_remove, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
692 cxstring: cx_map_remove_cxstr, \
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
693 cxmutstr: cx_map_remove_mustr, \
694
ac827d873c17 fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents: 692
diff changeset
694 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
695 const char*: cx_map_remove_str) \
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
696 (map, key)
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
697
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
698 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
699 * @copydoc cxMapRemoveAndGet()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
700 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
701 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
702 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
703 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
704 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
705 CxHashKey key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
706 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
707 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
708 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
709 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
710
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
711 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
712 * @copydoc cxMapRemoveAndGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
713 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
714 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
715 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
716 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
717 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
718 cxstring key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
719 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
720 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
721 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
722 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
723
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
724 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
725 * @copydoc cxMapRemoveAndGet()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
726 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
727 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
728 cx_attr_access_w(3)
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
729 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
730 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
731 cxmutstr key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
732 void *targetbuf
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
733 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
734 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
735 }
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
736
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
737 /**
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
738 * @copydoc cxMapRemoveAndGet()
692
6ac92936cd44 add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents: 691
diff changeset
739 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
740 cx_attr_nonnull
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
741 cx_attr_access_w(3)
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 984
diff changeset
742 cx_attr_cstr_arg(2)
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
743 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
744 CxMap *map,
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
745 const char *key,
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
746 void *targetbuf
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
747 ) {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
748 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
749 }
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
750
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
751 /**
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
752 * 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
753 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
754 * 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
755 * 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
756 * 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
757 * 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
758 *
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
759 * 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
760 * 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
761 *
1102
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
762 * @param map (@c CxMap*) the map
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
763 * @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
764 * @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
765 * @retval zero success
db5e355e5349 refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 994
diff changeset
766 * @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
767 *
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
768 * @see cxMapStorePointers()
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
769 * @see cxMapRemove()
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
770 */
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
771 #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
772 CxHashKey: cx_map_remove_and_get, \
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
773 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
774 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
775 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
776 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
777 (map, key, targetbuf)
691
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
778
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
779 #endif // __cplusplus
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
780
65baf7f45ac8 bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents: 689
diff changeset
781 #endif // UCX_MAP_H

mercurial