1.1 --- a/src/cx/map.h Fri Apr 21 18:38:18 2023 +0200 1.2 +++ b/src/cx/map.h Fri Apr 21 19:50:43 2023 +0200 1.3 @@ -39,6 +39,7 @@ 1.4 1.5 #include "common.h" 1.6 #include "collection.h" 1.7 +#include "string.h" 1.8 #include "hash_key.h" 1.9 1.10 #ifdef __cplusplus 1.11 @@ -211,108 +212,6 @@ 1.12 map->cl->clear(map); 1.13 } 1.14 1.15 -/** 1.16 - * Puts a key/value-pair into the map. 1.17 - * 1.18 - * @param map the map 1.19 - * @param key the key 1.20 - * @param value the value 1.21 - * @return 0 on success, non-zero value on failure 1.22 - */ 1.23 -__attribute__((__nonnull__)) 1.24 -static inline int cxMapPut( 1.25 - CxMap *map, 1.26 - CxHashKey key, 1.27 - void *value 1.28 -) { 1.29 - return map->cl->put(map, key, value); 1.30 -} 1.31 - 1.32 -/** 1.33 - * Retrieves a value by using a key. 1.34 - * 1.35 - * @param map the map 1.36 - * @param key the key 1.37 - * @return the value 1.38 - */ 1.39 -__attribute__((__nonnull__, __warn_unused_result__)) 1.40 -static inline void *cxMapGet( 1.41 - CxMap const *map, 1.42 - CxHashKey key 1.43 -) { 1.44 - return map->cl->get(map, key); 1.45 -} 1.46 - 1.47 -/** 1.48 - * Removes a key/value-pair from the map by using the key. 1.49 - * 1.50 - * Always invokes the destructor function, if any, on the removed element. 1.51 - * If this map is storing pointers and you just want to retrieve the pointer 1.52 - * without invoking the destructor, use cxMapRemoveAndGet(). 1.53 - * If you just want to detach the element from the map without invoking the 1.54 - * destructor or returning the element, use cxMapDetach(). 1.55 - * 1.56 - * @param map the map 1.57 - * @param key the key 1.58 - * @see cxMapRemoveAndGet() 1.59 - * @see cxMapDetach() 1.60 - */ 1.61 -__attribute__((__nonnull__)) 1.62 -static inline void cxMapRemove( 1.63 - CxMap *map, 1.64 - CxHashKey key 1.65 -) { 1.66 - (void) map->cl->remove(map, key, true); 1.67 -} 1.68 - 1.69 -/** 1.70 - * Detaches a key/value-pair from the map by using the key 1.71 - * without invoking the destructor. 1.72 - * 1.73 - * In general, you should only use this function if the map does not own 1.74 - * the data and there is a valid reference to the data somewhere else 1.75 - * in the program. In all other cases it is preferable to use 1.76 - * cxMapRemove() or cxMapRemoveAndGet(). 1.77 - * 1.78 - * @param map the map 1.79 - * @param key the key 1.80 - * @see cxMapRemove() 1.81 - * @see cxMapRemoveAndGet() 1.82 - */ 1.83 -__attribute__((__nonnull__)) 1.84 -static inline void cxMapDetach( 1.85 - CxMap *map, 1.86 - CxHashKey key 1.87 -) { 1.88 - (void) map->cl->remove(map, key, false); 1.89 -} 1.90 - 1.91 -/** 1.92 - * Removes a key/value-pair from the map by using the key. 1.93 - * 1.94 - * This function can be used when the map is storing pointers, 1.95 - * in order to retrieve the pointer from the map without invoking 1.96 - * any destructor function. Sometimes you do not want the pointer 1.97 - * to be returned - in that case (instead of suppressing the "unused 1.98 - * result" warning) you can use cxMapDetach(). 1.99 - * 1.100 - * If this map is not storing pointers, this function behaves like 1.101 - * cxMapRemove() and returns \c NULL. 1.102 - * 1.103 - * @param map the map 1.104 - * @param key the key 1.105 - * @return the stored pointer or \c NULL if either the key is not present 1.106 - * in the map or the map is not storing pointers 1.107 - * @see cxMapStorePointers() 1.108 - * @see cxMapDetach() 1.109 - */ 1.110 -__attribute__((__nonnull__, __warn_unused_result__)) 1.111 -static inline void *cxMapRemoveAndGet( 1.112 - CxMap *map, 1.113 - CxHashKey key 1.114 -) { 1.115 - return map->cl->remove(map, key, !map->store_pointer); 1.116 -} 1.117 1.118 // TODO: set-like map operations (union, intersect, difference) 1.119 1.120 @@ -413,8 +312,644 @@ 1.121 return map->cl->mut_iterator(map); 1.122 } 1.123 1.124 -#ifdef __cplusplus 1.125 +#ifdef __cplusplus 1.126 +} // end the extern "C" block here, because we want to start overloading 1.127 + 1.128 +/** 1.129 + * Puts a key/value-pair into the map. 1.130 + * 1.131 + * @param map the map 1.132 + * @param key the key 1.133 + * @param value the value 1.134 + * @return 0 on success, non-zero value on failure 1.135 + */ 1.136 +__attribute__((__nonnull__)) 1.137 +static inline int cxMapPut( 1.138 + CxMap *map, 1.139 + CxHashKey const &key, 1.140 + void *value 1.141 +) { 1.142 + return map->cl->put(map, key, value); 1.143 } 1.144 -#endif 1.145 1.146 -#endif // UCX_MAP_H 1.147 \ No newline at end of file 1.148 + 1.149 +/** 1.150 + * Puts a key/value-pair into the map. 1.151 + * 1.152 + * @param map the map 1.153 + * @param key the key 1.154 + * @param value the value 1.155 + * @return 0 on success, non-zero value on failure 1.156 + */ 1.157 +__attribute__((__nonnull__)) 1.158 +static inline int cxMapPut( 1.159 + CxMap *map, 1.160 + cxstring const &key, 1.161 + void *value 1.162 +) { 1.163 + return map->cl->put(map, cx_hash_key_cxstr(key), value); 1.164 +} 1.165 + 1.166 +/** 1.167 + * Puts a key/value-pair into the map. 1.168 + * 1.169 + * @param map the map 1.170 + * @param key the key 1.171 + * @param value the value 1.172 + * @return 0 on success, non-zero value on failure 1.173 + */ 1.174 +__attribute__((__nonnull__)) 1.175 +static inline int cxMapPut( 1.176 + CxMap *map, 1.177 + char const *key, 1.178 + void *value 1.179 +) { 1.180 + return map->cl->put(map, cx_hash_key_str(key), value); 1.181 +} 1.182 + 1.183 +/** 1.184 + * Retrieves a value by using a key. 1.185 + * 1.186 + * @param map the map 1.187 + * @param key the key 1.188 + * @return the value 1.189 + */ 1.190 +__attribute__((__nonnull__, __warn_unused_result__)) 1.191 +static inline void *cxMapGet( 1.192 + CxMap const *map, 1.193 + CxHashKey const &key 1.194 +) { 1.195 + return map->cl->get(map, key); 1.196 +} 1.197 + 1.198 +/** 1.199 + * Retrieves a value by using a key. 1.200 + * 1.201 + * @param map the map 1.202 + * @param key the key 1.203 + * @return the value 1.204 + */ 1.205 +__attribute__((__nonnull__, __warn_unused_result__)) 1.206 +static inline void *cxMapGet( 1.207 + CxMap const *map, 1.208 + cxstring const &key 1.209 +) { 1.210 + return map->cl->get(map, cx_hash_key_cxstr(key)); 1.211 +} 1.212 + 1.213 +/** 1.214 + * Retrieves a value by using a key. 1.215 + * 1.216 + * @param map the map 1.217 + * @param key the key 1.218 + * @return the value 1.219 + */ 1.220 +__attribute__((__nonnull__, __warn_unused_result__)) 1.221 +static inline void *cxMapGet( 1.222 + CxMap const *map, 1.223 + char const *key 1.224 +) { 1.225 + return map->cl->get(map, cx_hash_key_str(key)); 1.226 +} 1.227 + 1.228 +/** 1.229 + * Removes a key/value-pair from the map by using the key. 1.230 + * 1.231 + * Always invokes the destructor function, if any, on the removed element. 1.232 + * If this map is storing pointers and you just want to retrieve the pointer 1.233 + * without invoking the destructor, use cxMapRemoveAndGet(). 1.234 + * If you just want to detach the element from the map without invoking the 1.235 + * destructor or returning the element, use cxMapDetach(). 1.236 + * 1.237 + * @param map the map 1.238 + * @param key the key 1.239 + * @see cxMapRemoveAndGet() 1.240 + * @see cxMapDetach() 1.241 + */ 1.242 +__attribute__((__nonnull__)) 1.243 +static inline void cxMapRemove( 1.244 + CxMap *map, 1.245 + CxHashKey const &key 1.246 +) { 1.247 + (void) map->cl->remove(map, key, true); 1.248 +} 1.249 + 1.250 +/** 1.251 + * Removes a key/value-pair from the map by using the key. 1.252 + * 1.253 + * Always invokes the destructor function, if any, on the removed element. 1.254 + * If this map is storing pointers and you just want to retrieve the pointer 1.255 + * without invoking the destructor, use cxMapRemoveAndGet(). 1.256 + * If you just want to detach the element from the map without invoking the 1.257 + * destructor or returning the element, use cxMapDetach(). 1.258 + * 1.259 + * @param map the map 1.260 + * @param key the key 1.261 + * @see cxMapRemoveAndGet() 1.262 + * @see cxMapDetach() 1.263 + */ 1.264 +__attribute__((__nonnull__)) 1.265 +static inline void cxMapRemove( 1.266 + CxMap *map, 1.267 + cxstring const &key 1.268 +) { 1.269 + (void) map->cl->remove(map, cx_hash_key_cxstr(key), true); 1.270 +} 1.271 + 1.272 +/** 1.273 + * Removes a key/value-pair from the map by using the key. 1.274 + * 1.275 + * Always invokes the destructor function, if any, on the removed element. 1.276 + * If this map is storing pointers and you just want to retrieve the pointer 1.277 + * without invoking the destructor, use cxMapRemoveAndGet(). 1.278 + * If you just want to detach the element from the map without invoking the 1.279 + * destructor or returning the element, use cxMapDetach(). 1.280 + * 1.281 + * @param map the map 1.282 + * @param key the key 1.283 + * @see cxMapRemoveAndGet() 1.284 + * @see cxMapDetach() 1.285 + */ 1.286 +__attribute__((__nonnull__)) 1.287 +static inline void cxMapRemove( 1.288 + CxMap *map, 1.289 + char const *key 1.290 +) { 1.291 + (void) map->cl->remove(map, cx_hash_key_str(key), true); 1.292 +} 1.293 + 1.294 +/** 1.295 + * Detaches a key/value-pair from the map by using the key 1.296 + * without invoking the destructor. 1.297 + * 1.298 + * In general, you should only use this function if the map does not own 1.299 + * the data and there is a valid reference to the data somewhere else 1.300 + * in the program. In all other cases it is preferable to use 1.301 + * cxMapRemove() or cxMapRemoveAndGet(). 1.302 + * 1.303 + * @param map the map 1.304 + * @param key the key 1.305 + * @see cxMapRemove() 1.306 + * @see cxMapRemoveAndGet() 1.307 + */ 1.308 +__attribute__((__nonnull__)) 1.309 +static inline void cxMapDetach( 1.310 + CxMap *map, 1.311 + CxHashKey const &key 1.312 +) { 1.313 + (void) map->cl->remove(map, key, false); 1.314 +} 1.315 + 1.316 +/** 1.317 + * Detaches a key/value-pair from the map by using the key 1.318 + * without invoking the destructor. 1.319 + * 1.320 + * In general, you should only use this function if the map does not own 1.321 + * the data and there is a valid reference to the data somewhere else 1.322 + * in the program. In all other cases it is preferable to use 1.323 + * cxMapRemove() or cxMapRemoveAndGet(). 1.324 + * 1.325 + * @param map the map 1.326 + * @param key the key 1.327 + * @see cxMapRemove() 1.328 + * @see cxMapRemoveAndGet() 1.329 + */ 1.330 +__attribute__((__nonnull__)) 1.331 +static inline void cxMapDetach( 1.332 + CxMap *map, 1.333 + cxstring const &key 1.334 +) { 1.335 + (void) map->cl->remove(map, cx_hash_key_cxstr(key), false); 1.336 +} 1.337 + 1.338 +/** 1.339 + * Detaches a key/value-pair from the map by using the key 1.340 + * without invoking the destructor. 1.341 + * 1.342 + * In general, you should only use this function if the map does not own 1.343 + * the data and there is a valid reference to the data somewhere else 1.344 + * in the program. In all other cases it is preferable to use 1.345 + * cxMapRemove() or cxMapRemoveAndGet(). 1.346 + * 1.347 + * @param map the map 1.348 + * @param key the key 1.349 + * @see cxMapRemove() 1.350 + * @see cxMapRemoveAndGet() 1.351 + */ 1.352 +__attribute__((__nonnull__)) 1.353 +static inline void cxMapDetach( 1.354 + CxMap *map, 1.355 + char const *key 1.356 +) { 1.357 + (void) map->cl->remove(map, cx_hash_key_str(key), false); 1.358 +} 1.359 + 1.360 +/** 1.361 + * Removes a key/value-pair from the map by using the key. 1.362 + * 1.363 + * This function can be used when the map is storing pointers, 1.364 + * in order to retrieve the pointer from the map without invoking 1.365 + * any destructor function. Sometimes you do not want the pointer 1.366 + * to be returned - in that case (instead of suppressing the "unused 1.367 + * result" warning) you can use cxMapDetach(). 1.368 + * 1.369 + * If this map is not storing pointers, this function behaves like 1.370 + * cxMapRemove() and returns \c NULL. 1.371 + * 1.372 + * @param map the map 1.373 + * @param key the key 1.374 + * @return the stored pointer or \c NULL if either the key is not present 1.375 + * in the map or the map is not storing pointers 1.376 + * @see cxMapStorePointers() 1.377 + * @see cxMapDetach() 1.378 + */ 1.379 +__attribute__((__nonnull__, __warn_unused_result__)) 1.380 +static inline void *cxMapRemoveAndGet( 1.381 + CxMap *map, 1.382 + CxHashKey key 1.383 +) { 1.384 + return map->cl->remove(map, key, !map->store_pointer); 1.385 +} 1.386 + 1.387 +/** 1.388 + * Removes a key/value-pair from the map by using the key. 1.389 + * 1.390 + * This function can be used when the map is storing pointers, 1.391 + * in order to retrieve the pointer from the map without invoking 1.392 + * any destructor function. Sometimes you do not want the pointer 1.393 + * to be returned - in that case (instead of suppressing the "unused 1.394 + * result" warning) you can use cxMapDetach(). 1.395 + * 1.396 + * If this map is not storing pointers, this function behaves like 1.397 + * cxMapRemove() and returns \c NULL. 1.398 + * 1.399 + * @param map the map 1.400 + * @param key the key 1.401 + * @return the stored pointer or \c NULL if either the key is not present 1.402 + * in the map or the map is not storing pointers 1.403 + * @see cxMapStorePointers() 1.404 + * @see cxMapDetach() 1.405 + */ 1.406 +__attribute__((__nonnull__, __warn_unused_result__)) 1.407 +static inline void *cxMapRemoveAndGet( 1.408 + CxMap *map, 1.409 + cxstring key 1.410 +) { 1.411 + return map->cl->remove(map, cx_hash_key_cxstr(key), !map->store_pointer); 1.412 +} 1.413 + 1.414 +/** 1.415 + * Removes a key/value-pair from the map by using the key. 1.416 + * 1.417 + * This function can be used when the map is storing pointers, 1.418 + * in order to retrieve the pointer from the map without invoking 1.419 + * any destructor function. Sometimes you do not want the pointer 1.420 + * to be returned - in that case (instead of suppressing the "unused 1.421 + * result" warning) you can use cxMapDetach(). 1.422 + * 1.423 + * If this map is not storing pointers, this function behaves like 1.424 + * cxMapRemove() and returns \c NULL. 1.425 + * 1.426 + * @param map the map 1.427 + * @param key the key 1.428 + * @return the stored pointer or \c NULL if either the key is not present 1.429 + * in the map or the map is not storing pointers 1.430 + * @see cxMapStorePointers() 1.431 + * @see cxMapDetach() 1.432 + */ 1.433 +__attribute__((__nonnull__, __warn_unused_result__)) 1.434 +static inline void *cxMapRemoveAndGet( 1.435 + CxMap *map, 1.436 + char const *key 1.437 +) { 1.438 + return map->cl->remove(map, cx_hash_key_str(key), !map->store_pointer); 1.439 +} 1.440 + 1.441 +#else // __cplusplus 1.442 + 1.443 +/** 1.444 + * Puts a key/value-pair into the map. 1.445 + * 1.446 + * @param map the map 1.447 + * @param key the key 1.448 + * @param value the value 1.449 + * @return 0 on success, non-zero value on failure 1.450 + */ 1.451 +__attribute__((__nonnull__)) 1.452 +static inline int cx_map_put( 1.453 + CxMap *map, 1.454 + CxHashKey key, 1.455 + void *value 1.456 +) { 1.457 + return map->cl->put(map, key, value); 1.458 +} 1.459 + 1.460 +/** 1.461 + * Puts a key/value-pair into the map. 1.462 + * 1.463 + * @param map the map 1.464 + * @param key the key 1.465 + * @param value the value 1.466 + * @return 0 on success, non-zero value on failure 1.467 + */ 1.468 +__attribute__((__nonnull__)) 1.469 +static inline int cx_map_put_cxstr( 1.470 + CxMap *map, 1.471 + cxstring key, 1.472 + void *value 1.473 +) { 1.474 + return map->cl->put(map, cx_hash_key_cxstr(key), value); 1.475 +} 1.476 + 1.477 +/** 1.478 + * Puts a key/value-pair into the map. 1.479 + * 1.480 + * @param map the map 1.481 + * @param key the key 1.482 + * @param value the value 1.483 + * @return 0 on success, non-zero value on failure 1.484 + */ 1.485 +__attribute__((__nonnull__)) 1.486 +static inline int cx_map_put_str( 1.487 + CxMap *map, 1.488 + char const *key, 1.489 + void *value 1.490 +) { 1.491 + return map->cl->put(map, cx_hash_key_str(key), value); 1.492 +} 1.493 + 1.494 +/** 1.495 + * Puts a key/value-pair into the map. 1.496 + * 1.497 + * @param map the map 1.498 + * @param key the key 1.499 + * @param value the value 1.500 + * @return 0 on success, non-zero value on failure 1.501 + */ 1.502 +#define cxMapPut(map, key, value) _Generic((key), \ 1.503 + CxHashKey: cx_map_put, \ 1.504 + cxstring: cx_map_put_cxstr, \ 1.505 + char*: cx_map_put_str) \ 1.506 + (map, key, value) 1.507 + 1.508 +/** 1.509 + * Retrieves a value by using a key. 1.510 + * 1.511 + * @param map the map 1.512 + * @param key the key 1.513 + * @return the value 1.514 + */ 1.515 +__attribute__((__nonnull__, __warn_unused_result__)) 1.516 +static inline void *cx_map_get( 1.517 + CxMap const *map, 1.518 + CxHashKey key 1.519 +) { 1.520 + return map->cl->get(map, key); 1.521 +} 1.522 + 1.523 +/** 1.524 + * Retrieves a value by using a key. 1.525 + * 1.526 + * @param map the map 1.527 + * @param key the key 1.528 + * @return the value 1.529 + */ 1.530 +__attribute__((__nonnull__, __warn_unused_result__)) 1.531 +static inline void *cx_map_get_cxstr( 1.532 + CxMap const *map, 1.533 + cxstring key 1.534 +) { 1.535 + return map->cl->get(map, cx_hash_key_cxstr(key)); 1.536 +} 1.537 + 1.538 +/** 1.539 + * Retrieves a value by using a key. 1.540 + * 1.541 + * @param map the map 1.542 + * @param key the key 1.543 + * @return the value 1.544 + */ 1.545 +__attribute__((__nonnull__, __warn_unused_result__)) 1.546 +static inline void *cx_map_get_str( 1.547 + CxMap const *map, 1.548 + char const *key 1.549 +) { 1.550 + return map->cl->get(map, cx_hash_key_str(key)); 1.551 +} 1.552 + 1.553 +/** 1.554 + * Retrieves a value by using a key. 1.555 + * 1.556 + * @param map the map 1.557 + * @param key the key 1.558 + * @return the value 1.559 + */ 1.560 +#define cxMapGet(map, key) _Generic((key), \ 1.561 + CxHashKey: cx_map_get, \ 1.562 + cxstring: cx_map_get_cxstr, \ 1.563 + char*: cx_map_get_str) \ 1.564 + (map, key) 1.565 + 1.566 +/** 1.567 + * Removes a key/value-pair from the map by using the key. 1.568 + * 1.569 + * @param map the map 1.570 + * @param key the key 1.571 + */ 1.572 +__attribute__((__nonnull__)) 1.573 +static inline void cx_map_remove( 1.574 + CxMap *map, 1.575 + CxHashKey key 1.576 +) { 1.577 + (void) map->cl->remove(map, key, true); 1.578 +} 1.579 + 1.580 +/** 1.581 + * Removes a key/value-pair from the map by using the key. 1.582 + * 1.583 + * @param map the map 1.584 + * @param key the key 1.585 + */ 1.586 +__attribute__((__nonnull__)) 1.587 +static inline void cx_map_remove_cxstr( 1.588 + CxMap *map, 1.589 + cxstring key 1.590 +) { 1.591 + (void) map->cl->remove(map, cx_hash_key_cxstr(key), true); 1.592 +} 1.593 + 1.594 +/** 1.595 + * Removes a key/value-pair from the map by using the key. 1.596 + * 1.597 + * @param map the map 1.598 + * @param key the key 1.599 + */ 1.600 +__attribute__((__nonnull__)) 1.601 +static inline void cx_map_remove_str( 1.602 + CxMap *map, 1.603 + char const *key 1.604 +) { 1.605 + (void) map->cl->remove(map, cx_hash_key_str(key), true); 1.606 +} 1.607 + 1.608 +/** 1.609 + * Removes a key/value-pair from the map by using the key. 1.610 + * 1.611 + * Always invokes the destructor function, if any, on the removed element. 1.612 + * If this map is storing pointers and you just want to retrieve the pointer 1.613 + * without invoking the destructor, use cxMapRemoveAndGet(). 1.614 + * If you just want to detach the element from the map without invoking the 1.615 + * destructor or returning the element, use cxMapDetach(). 1.616 + * 1.617 + * @param map the map 1.618 + * @param key the key 1.619 + * @see cxMapRemoveAndGet() 1.620 + * @see cxMapDetach() 1.621 + */ 1.622 +#define cxMapRemove(map, key) _Generic((key), \ 1.623 + CxHashKey: cx_map_remove, \ 1.624 + cxstring: cx_map_remove_cxstr, \ 1.625 + char*: cx_map_remove_str) \ 1.626 + (map, key) 1.627 + 1.628 +/** 1.629 + * Detaches a key/value-pair from the map by using the key 1.630 + * without invoking the destructor. 1.631 + * 1.632 + * @param map the map 1.633 + * @param key the key 1.634 + */ 1.635 +__attribute__((__nonnull__)) 1.636 +static inline void cx_map_detach( 1.637 + CxMap *map, 1.638 + CxHashKey key 1.639 +) { 1.640 + (void) map->cl->remove(map, key, false); 1.641 +} 1.642 + 1.643 +/** 1.644 + * Detaches a key/value-pair from the map by using the key 1.645 + * without invoking the destructor. 1.646 + * 1.647 + * @param map the map 1.648 + * @param key the key 1.649 + */ 1.650 +__attribute__((__nonnull__)) 1.651 +static inline void cx_map_detach_cxstr( 1.652 + CxMap *map, 1.653 + cxstring key 1.654 +) { 1.655 + (void) map->cl->remove(map, cx_hash_key_cxstr(key), false); 1.656 +} 1.657 + 1.658 +/** 1.659 + * Detaches a key/value-pair from the map by using the key 1.660 + * without invoking the destructor. 1.661 + * 1.662 + * @param map the map 1.663 + * @param key the key 1.664 + */ 1.665 +__attribute__((__nonnull__)) 1.666 +static inline void cx_map_detach_str( 1.667 + CxMap *map, 1.668 + char const *key 1.669 +) { 1.670 + (void) map->cl->remove(map, cx_hash_key_str(key), false); 1.671 +} 1.672 + 1.673 +/** 1.674 + * Detaches a key/value-pair from the map by using the key 1.675 + * without invoking the destructor. 1.676 + * 1.677 + * In general, you should only use this function if the map does not own 1.678 + * the data and there is a valid reference to the data somewhere else 1.679 + * in the program. In all other cases it is preferable to use 1.680 + * cxMapRemove() or cxMapRemoveAndGet(). 1.681 + * 1.682 + * @param map the map 1.683 + * @param key the key 1.684 + * @see cxMapRemove() 1.685 + * @see cxMapRemoveAndGet() 1.686 + */ 1.687 +#define cxMapDetach(map, key) _Generic((key), \ 1.688 + CxHashKey: cx_map_detach, \ 1.689 + cxstring: cx_map_detach_cxstr, \ 1.690 + char*: cx_map_detach_str) \ 1.691 + (map, key) 1.692 + 1.693 +/** 1.694 + * Removes a key/value-pair from the map by using the key. 1.695 + * 1.696 + * @param map the map 1.697 + * @param key the key 1.698 + * @return the stored pointer or \c NULL if either the key is not present 1.699 + * in the map or the map is not storing pointers 1.700 + */ 1.701 +__attribute__((__nonnull__, __warn_unused_result__)) 1.702 +static inline void *cx_map_remove_and_get( 1.703 + CxMap *map, 1.704 + CxHashKey key 1.705 +) { 1.706 + return map->cl->remove(map, key, !map->store_pointer); 1.707 +} 1.708 + 1.709 +/** 1.710 + * Removes a key/value-pair from the map by using the key. 1.711 + * 1.712 + * @param map the map 1.713 + * @param key the key 1.714 + * @return the stored pointer or \c NULL if either the key is not present 1.715 + * in the map or the map is not storing pointers 1.716 + */ 1.717 +__attribute__((__nonnull__, __warn_unused_result__)) 1.718 +static inline void *cx_map_remove_and_get_cxstr( 1.719 + CxMap *map, 1.720 + cxstring key 1.721 +) { 1.722 + return map->cl->remove(map, cx_hash_key_cxstr(key), !map->store_pointer); 1.723 +} 1.724 + 1.725 +/** 1.726 + * Removes a key/value-pair from the map by using the key. 1.727 + * 1.728 + * @param map the map 1.729 + * @param key the key 1.730 + * @return the stored pointer or \c NULL if either the key is not present 1.731 + * in the map or the map is not storing pointers 1.732 + */ 1.733 +__attribute__((__nonnull__, __warn_unused_result__)) 1.734 +static inline void *cx_map_remove_and_get_str( 1.735 + CxMap *map, 1.736 + char const *key 1.737 +) { 1.738 + return map->cl->remove(map, cx_hash_key_str(key), !map->store_pointer); 1.739 +} 1.740 + 1.741 +/** 1.742 + * Removes a key/value-pair from the map by using the key. 1.743 + * 1.744 + * This function can be used when the map is storing pointers, 1.745 + * in order to retrieve the pointer from the map without invoking 1.746 + * any destructor function. Sometimes you do not want the pointer 1.747 + * to be returned - in that case (instead of suppressing the "unused 1.748 + * result" warning) you can use cxMapDetach(). 1.749 + * 1.750 + * If this map is not storing pointers, this function behaves like 1.751 + * cxMapRemove() and returns \c NULL. 1.752 + * 1.753 + * @param map the map 1.754 + * @param key the key 1.755 + * @return the stored pointer or \c NULL if either the key is not present 1.756 + * in the map or the map is not storing pointers 1.757 + * @see cxMapStorePointers() 1.758 + * @see cxMapDetach() 1.759 + */ 1.760 +#define cxMapRemoveAndGet(map, key) _Generic((key), \ 1.761 + CxHashKey: cx_map_remove_and_get, \ 1.762 + cxstring: cx_map_remove_and_get_cxstr, \ 1.763 + char*: cx_map_remove_and_get_str) \ 1.764 + (map, key) 1.765 + 1.766 +#endif // __cplusplus 1.767 + 1.768 +#endif // UCX_MAP_H