162 * @param map the map |
164 * @param map the map |
163 * @see cxMapStorePointers() |
165 * @see cxMapStorePointers() |
164 */ |
166 */ |
165 __attribute__((__nonnull__)) |
167 __attribute__((__nonnull__)) |
166 static inline void cxMapStoreObjects(CxMap *map) { |
168 static inline void cxMapStoreObjects(CxMap *map) { |
167 map->store_pointer = false; |
169 map->collection.store_pointer = false; |
168 } |
170 } |
169 |
171 |
170 /** |
172 /** |
171 * Advises the map to only store pointers to the objects. |
173 * Advises the map to only store pointers to the objects. |
172 * |
174 * |
179 * @param map the map |
181 * @param map the map |
180 * @see cxMapStoreObjects() |
182 * @see cxMapStoreObjects() |
181 */ |
183 */ |
182 __attribute__((__nonnull__)) |
184 __attribute__((__nonnull__)) |
183 static inline void cxMapStorePointers(CxMap *map) { |
185 static inline void cxMapStorePointers(CxMap *map) { |
184 map->store_pointer = true; |
186 map->collection.store_pointer = true; |
185 map->item_size = sizeof(void *); |
187 map->collection.elem_size = sizeof(void *); |
186 } |
188 } |
187 |
189 |
|
190 /** |
|
191 * Returns true, if this map is storing pointers instead of the actual data. |
|
192 * |
|
193 * @param map |
|
194 * @return true, if this map is storing pointers |
|
195 * @see cxMapStorePointers() |
|
196 */ |
|
197 __attribute__((__nonnull__)) |
|
198 static inline bool cxMapIsStoringPointers(CxMap const *map) { |
|
199 return map->collection.store_pointer; |
|
200 } |
188 |
201 |
189 /** |
202 /** |
190 * Deallocates the memory of the specified map. |
203 * Deallocates the memory of the specified map. |
191 * |
204 * |
192 * @param map the map to be destroyed |
205 * @param map the map to be destroyed |
203 * @param map the map to be cleared |
216 * @param map the map to be cleared |
204 */ |
217 */ |
205 __attribute__((__nonnull__)) |
218 __attribute__((__nonnull__)) |
206 static inline void cxMapClear(CxMap *map) { |
219 static inline void cxMapClear(CxMap *map) { |
207 map->cl->clear(map); |
220 map->cl->clear(map); |
|
221 } |
|
222 |
|
223 /** |
|
224 * Returns the number of elements in this map. |
|
225 * |
|
226 * @param map the map |
|
227 * @return the number of stored elements |
|
228 */ |
|
229 __attribute__((__nonnull__)) |
|
230 static inline size_t cxMapSize(CxMap const *map) { |
|
231 return map->collection.size; |
208 } |
232 } |
209 |
233 |
210 |
234 |
211 // TODO: set-like map operations (union, intersect, difference) |
235 // TODO: set-like map operations (union, intersect, difference) |
212 |
236 |
267 * |
291 * |
268 * @param map the map to create the iterator for |
292 * @param map the map to create the iterator for |
269 * @return an iterator for the currently stored values |
293 * @return an iterator for the currently stored values |
270 */ |
294 */ |
271 __attribute__((__nonnull__, __warn_unused_result__)) |
295 __attribute__((__nonnull__, __warn_unused_result__)) |
272 CxMutIterator cxMapMutIteratorValues(CxMap *map); |
296 CxIterator cxMapMutIteratorValues(CxMap *map); |
273 |
297 |
274 /** |
298 /** |
275 * Creates a mutating iterator over the keys of a map. |
299 * Creates a mutating iterator over the keys of a map. |
276 * |
300 * |
277 * The elements of the iterator are keys of type CxHashKey. |
301 * The elements of the iterator are keys of type CxHashKey. |
281 * |
305 * |
282 * @param map the map to create the iterator for |
306 * @param map the map to create the iterator for |
283 * @return an iterator for the currently stored keys |
307 * @return an iterator for the currently stored keys |
284 */ |
308 */ |
285 __attribute__((__nonnull__, __warn_unused_result__)) |
309 __attribute__((__nonnull__, __warn_unused_result__)) |
286 CxMutIterator cxMapMutIteratorKeys(CxMap *map); |
310 CxIterator cxMapMutIteratorKeys(CxMap *map); |
287 |
311 |
288 /** |
312 /** |
289 * Creates a mutating iterator for a map. |
313 * Creates a mutating iterator for a map. |
290 * |
314 * |
291 * The elements of the iterator are key/value pairs of type CxMapEntry. |
315 * The elements of the iterator are key/value pairs of type CxMapEntry. |
297 * @return an iterator for the currently stored entries |
321 * @return an iterator for the currently stored entries |
298 * @see cxMapMutIteratorKeys() |
322 * @see cxMapMutIteratorKeys() |
299 * @see cxMapMutIteratorValues() |
323 * @see cxMapMutIteratorValues() |
300 */ |
324 */ |
301 __attribute__((__nonnull__, __warn_unused_result__)) |
325 __attribute__((__nonnull__, __warn_unused_result__)) |
302 CxMutIterator cxMapMutIterator(CxMap *map); |
326 CxIterator cxMapMutIterator(CxMap *map); |
303 |
327 |
304 #ifdef __cplusplus |
328 #ifdef __cplusplus |
305 } // end the extern "C" block here, because we want to start overloading |
329 } // end the extern "C" block here, because we want to start overloading |
306 |
330 |
307 /** |
331 /** |
1049 __attribute__((__nonnull__, __warn_unused_result__)) |
1073 __attribute__((__nonnull__, __warn_unused_result__)) |
1050 static inline void *cx_map_remove_and_get( |
1074 static inline void *cx_map_remove_and_get( |
1051 CxMap *map, |
1075 CxMap *map, |
1052 CxHashKey key |
1076 CxHashKey key |
1053 ) { |
1077 ) { |
1054 return map->cl->remove(map, key, !map->store_pointer); |
1078 return map->cl->remove(map, key, !map->collection.store_pointer); |
1055 } |
1079 } |
1056 |
1080 |
1057 /** |
1081 /** |
1058 * Removes a key/value-pair from the map by using the key. |
1082 * Removes a key/value-pair from the map by using the key. |
1059 * |
1083 * |
1065 __attribute__((__nonnull__, __warn_unused_result__)) |
1089 __attribute__((__nonnull__, __warn_unused_result__)) |
1066 static inline void *cx_map_remove_and_get_cxstr( |
1090 static inline void *cx_map_remove_and_get_cxstr( |
1067 CxMap *map, |
1091 CxMap *map, |
1068 cxstring key |
1092 cxstring key |
1069 ) { |
1093 ) { |
1070 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->store_pointer); |
1094 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer); |
1071 } |
1095 } |
1072 |
1096 |
1073 /** |
1097 /** |
1074 * Removes a key/value-pair from the map by using the key. |
1098 * Removes a key/value-pair from the map by using the key. |
1075 * |
1099 * |
1081 __attribute__((__nonnull__, __warn_unused_result__)) |
1105 __attribute__((__nonnull__, __warn_unused_result__)) |
1082 static inline void *cx_map_remove_and_get_mustr( |
1106 static inline void *cx_map_remove_and_get_mustr( |
1083 CxMap *map, |
1107 CxMap *map, |
1084 cxmutstr key |
1108 cxmutstr key |
1085 ) { |
1109 ) { |
1086 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->store_pointer); |
1110 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer); |
1087 } |
1111 } |
1088 |
1112 |
1089 /** |
1113 /** |
1090 * Removes a key/value-pair from the map by using the key. |
1114 * Removes a key/value-pair from the map by using the key. |
1091 * |
1115 * |
1097 __attribute__((__nonnull__, __warn_unused_result__)) |
1121 __attribute__((__nonnull__, __warn_unused_result__)) |
1098 static inline void *cx_map_remove_and_get_str( |
1122 static inline void *cx_map_remove_and_get_str( |
1099 CxMap *map, |
1123 CxMap *map, |
1100 char const *key |
1124 char const *key |
1101 ) { |
1125 ) { |
1102 return map->cl->remove(map, cx_hash_key_str(key), !map->store_pointer); |
1126 return map->cl->remove(map, cx_hash_key_str(key), !map->collection.store_pointer); |
1103 } |
1127 } |
1104 |
1128 |
1105 /** |
1129 /** |
1106 * Removes a key/value-pair from the map by using the key. |
1130 * Removes a key/value-pair from the map by using the key. |
1107 * |
1131 * |