src/cx/map.h

Sun, 21 May 2023 14:56:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 21 May 2023 14:56:10 +0200
changeset 708
1caed6c9ba68
parent 706
8c6edaccaef1
child 709
1e8ba59e7911
permissions
-rw-r--r--

fix inconsistent destructor requirements for list and map classes

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

mercurial