src/cx/map.h

changeset 985
68754c7de906
parent 984
e8f354a25ac8
equal deleted inserted replaced
984:e8f354a25ac8 985:68754c7de906
87 */ 87 */
88 struct cx_map_class_s { 88 struct cx_map_class_s {
89 /** 89 /**
90 * Deallocates the entire memory. 90 * Deallocates the entire memory.
91 */ 91 */
92 __attribute__((__nonnull__)) 92 cx_attr_nonnull
93 void (*destructor)(struct cx_map_s *map); 93 void (*destructor)(struct cx_map_s *map);
94 94
95 /** 95 /**
96 * Removes all elements. 96 * Removes all elements.
97 */ 97 */
98 __attribute__((__nonnull__)) 98 cx_attr_nonnull
99 void (*clear)(struct cx_map_s *map); 99 void (*clear)(struct cx_map_s *map);
100 100
101 /** 101 /**
102 * Add or overwrite an element. 102 * Add or overwrite an element.
103 */ 103 */
104 __attribute__((__nonnull__)) 104 cx_attr_nonnull
105 int (*put)( 105 int (*put)(
106 CxMap *map, 106 CxMap *map,
107 CxHashKey key, 107 CxHashKey key,
108 void *value 108 void *value
109 ); 109 );
110 110
111 /** 111 /**
112 * Returns an element. 112 * Returns an element.
113 */ 113 */
114 __attribute__((__nonnull__, __warn_unused_result__)) 114 cx_attr_nonnull
115 cx_attr_nodiscard
115 void *(*get)( 116 void *(*get)(
116 const CxMap *map, 117 const CxMap *map,
117 CxHashKey key 118 CxHashKey key
118 ); 119 );
119 120
120 /** 121 /**
121 * Removes an element. 122 * Removes an element.
122 */ 123 */
123 __attribute__((__nonnull__)) 124 cx_attr_nonnull
124 void *(*remove)( 125 void *(*remove)(
125 CxMap *map, 126 CxMap *map,
126 CxHashKey key, 127 CxHashKey key,
127 bool destroy 128 bool destroy
128 ); 129 );
129 130
130 /** 131 /**
131 * Creates an iterator for this map. 132 * Creates an iterator for this map.
132 */ 133 */
133 __attribute__((__nonnull__, __warn_unused_result__)) 134 cx_attr_nonnull
135 cx_attr_nodiscard
134 CxIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type); 136 CxIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type);
135 }; 137 };
136 138
137 /** 139 /**
138 * A map entry. 140 * A map entry.
149 }; 151 };
150 152
151 /** 153 /**
152 * A shared instance of an empty map. 154 * A shared instance of an empty map.
153 * 155 *
154 * Writing to that map is undefined. 156 * Writing to that map is not allowed.
155 */ 157 */
156 extern CxMap *const cxEmptyMap; 158 extern CxMap *const cxEmptyMap;
157 159
158 /** 160 /**
159 * Advises the map to store copies of the objects (default mode of operation). 161 * Advises the map to store copies of the objects (default mode of operation).
162 * within this list. 164 * within this list.
163 * 165 *
164 * @param map the map 166 * @param map the map
165 * @see cxMapStorePointers() 167 * @see cxMapStorePointers()
166 */ 168 */
167 __attribute__((__nonnull__)) 169 cx_attr_nonnull
168 static inline void cxMapStoreObjects(CxMap *map) { 170 static inline void cxMapStoreObjects(CxMap *map) {
169 map->collection.store_pointer = false; 171 map->collection.store_pointer = false;
170 } 172 }
171 173
172 /** 174 /**
179 * objects is undefined. 181 * objects is undefined.
180 * 182 *
181 * @param map the map 183 * @param map the map
182 * @see cxMapStoreObjects() 184 * @see cxMapStoreObjects()
183 */ 185 */
184 __attribute__((__nonnull__)) 186 cx_attr_nonnull
185 static inline void cxMapStorePointers(CxMap *map) { 187 static inline void cxMapStorePointers(CxMap *map) {
186 map->collection.store_pointer = true; 188 map->collection.store_pointer = true;
187 map->collection.elem_size = sizeof(void *); 189 map->collection.elem_size = sizeof(void *);
188 } 190 }
189 191
192 * 194 *
193 * @param map 195 * @param map
194 * @return true, if this map is storing pointers 196 * @return true, if this map is storing pointers
195 * @see cxMapStorePointers() 197 * @see cxMapStorePointers()
196 */ 198 */
197 __attribute__((__nonnull__)) 199 cx_attr_nonnull
198 static inline bool cxMapIsStoringPointers(const CxMap *map) { 200 static inline bool cxMapIsStoringPointers(const CxMap *map) {
199 return map->collection.store_pointer; 201 return map->collection.store_pointer;
200 } 202 }
201 203
202 /** 204 /**
213 /** 215 /**
214 * Clears a map by removing all elements. 216 * Clears a map by removing all elements.
215 * 217 *
216 * @param map the map to be cleared 218 * @param map the map to be cleared
217 */ 219 */
218 __attribute__((__nonnull__)) 220 cx_attr_nonnull
219 static inline void cxMapClear(CxMap *map) { 221 static inline void cxMapClear(CxMap *map) {
220 map->cl->clear(map); 222 map->cl->clear(map);
221 } 223 }
222 224
223 /** 225 /**
224 * Returns the number of elements in this map. 226 * Returns the number of elements in this map.
225 * 227 *
226 * @param map the map 228 * @param map the map
227 * @return the number of stored elements 229 * @return the number of stored elements
228 */ 230 */
229 __attribute__((__nonnull__)) 231 cx_attr_nonnull
230 static inline size_t cxMapSize(const CxMap *map) { 232 static inline size_t cxMapSize(const CxMap *map) {
231 return map->collection.size; 233 return map->collection.size;
232 } 234 }
233 235
234 236
241 * highly depends on the map implementation and may change arbitrarily when the contents change. 243 * highly depends on the map implementation and may change arbitrarily when the contents change.
242 * 244 *
243 * @param map the map to create the iterator for 245 * @param map the map to create the iterator for
244 * @return an iterator for the currently stored values 246 * @return an iterator for the currently stored values
245 */ 247 */
246 __attribute__((__nonnull__, __warn_unused_result__)) 248 cx_attr_nonnull
249 cx_attr_nodiscard
247 static inline CxIterator cxMapIteratorValues(const CxMap *map) { 250 static inline CxIterator cxMapIteratorValues(const CxMap *map) {
248 return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); 251 return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
249 } 252 }
250 253
251 /** 254 /**
257 * highly depends on the map implementation and may change arbitrarily when the contents change. 260 * highly depends on the map implementation and may change arbitrarily when the contents change.
258 * 261 *
259 * @param map the map to create the iterator for 262 * @param map the map to create the iterator for
260 * @return an iterator for the currently stored keys 263 * @return an iterator for the currently stored keys
261 */ 264 */
262 __attribute__((__nonnull__, __warn_unused_result__)) 265 cx_attr_nonnull
266 cx_attr_nodiscard
263 static inline CxIterator cxMapIteratorKeys(const CxMap *map) { 267 static inline CxIterator cxMapIteratorKeys(const CxMap *map) {
264 return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); 268 return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
265 } 269 }
266 270
267 /** 271 /**
275 * @param map the map to create the iterator for 279 * @param map the map to create the iterator for
276 * @return an iterator for the currently stored entries 280 * @return an iterator for the currently stored entries
277 * @see cxMapIteratorKeys() 281 * @see cxMapIteratorKeys()
278 * @see cxMapIteratorValues() 282 * @see cxMapIteratorValues()
279 */ 283 */
280 __attribute__((__nonnull__, __warn_unused_result__)) 284 cx_attr_nonnull
285 cx_attr_nodiscard
281 static inline CxIterator cxMapIterator(const CxMap *map) { 286 static inline CxIterator cxMapIterator(const CxMap *map) {
282 return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); 287 return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
283 } 288 }
284 289
285 290
290 * highly depends on the map implementation and may change arbitrarily when the contents change. 295 * highly depends on the map implementation and may change arbitrarily when the contents change.
291 * 296 *
292 * @param map the map to create the iterator for 297 * @param map the map to create the iterator for
293 * @return an iterator for the currently stored values 298 * @return an iterator for the currently stored values
294 */ 299 */
295 __attribute__((__nonnull__, __warn_unused_result__)) 300 cx_attr_nonnull
301 cx_attr_nodiscard
296 CxIterator cxMapMutIteratorValues(CxMap *map); 302 CxIterator cxMapMutIteratorValues(CxMap *map);
297 303
298 /** 304 /**
299 * Creates a mutating iterator over the keys of a map. 305 * Creates a mutating iterator over the keys of a map.
300 * 306 *
304 * highly depends on the map implementation and may change arbitrarily when the contents change. 310 * highly depends on the map implementation and may change arbitrarily when the contents change.
305 * 311 *
306 * @param map the map to create the iterator for 312 * @param map the map to create the iterator for
307 * @return an iterator for the currently stored keys 313 * @return an iterator for the currently stored keys
308 */ 314 */
309 __attribute__((__nonnull__, __warn_unused_result__)) 315 cx_attr_nonnull
316 cx_attr_nodiscard
310 CxIterator cxMapMutIteratorKeys(CxMap *map); 317 CxIterator cxMapMutIteratorKeys(CxMap *map);
311 318
312 /** 319 /**
313 * Creates a mutating iterator for a map. 320 * Creates a mutating iterator for a map.
314 * 321 *
320 * @param map the map to create the iterator for 327 * @param map the map to create the iterator for
321 * @return an iterator for the currently stored entries 328 * @return an iterator for the currently stored entries
322 * @see cxMapMutIteratorKeys() 329 * @see cxMapMutIteratorKeys()
323 * @see cxMapMutIteratorValues() 330 * @see cxMapMutIteratorValues()
324 */ 331 */
325 __attribute__((__nonnull__, __warn_unused_result__)) 332 cx_attr_nonnull
333 cx_attr_nodiscard
326 CxIterator cxMapMutIterator(CxMap *map); 334 CxIterator cxMapMutIterator(CxMap *map);
327 335
328 #ifdef __cplusplus 336 #ifdef __cplusplus
329 } // end the extern "C" block here, because we want to start overloading 337 } // end the extern "C" block here, because we want to start overloading
330 338
334 * @param map the map 342 * @param map the map
335 * @param key the key 343 * @param key the key
336 * @param value the value 344 * @param value the value
337 * @return 0 on success, non-zero value on failure 345 * @return 0 on success, non-zero value on failure
338 */ 346 */
339 __attribute__((__nonnull__)) 347 cx_attr_nonnull
340 static inline int cxMapPut( 348 static inline int cxMapPut(
341 CxMap *map, 349 CxMap *map,
342 CxHashKey const &key, 350 CxHashKey const &key,
343 void *value 351 void *value
344 ) { 352 ) {
352 * @param map the map 360 * @param map the map
353 * @param key the key 361 * @param key the key
354 * @param value the value 362 * @param value the value
355 * @return 0 on success, non-zero value on failure 363 * @return 0 on success, non-zero value on failure
356 */ 364 */
357 __attribute__((__nonnull__)) 365 cx_attr_nonnull
358 static inline int cxMapPut( 366 static inline int cxMapPut(
359 CxMap *map, 367 CxMap *map,
360 cxstring const &key, 368 cxstring const &key,
361 void *value 369 void *value
362 ) { 370 ) {
369 * @param map the map 377 * @param map the map
370 * @param key the key 378 * @param key the key
371 * @param value the value 379 * @param value the value
372 * @return 0 on success, non-zero value on failure 380 * @return 0 on success, non-zero value on failure
373 */ 381 */
374 __attribute__((__nonnull__)) 382 cx_attr_nonnull
375 static inline int cxMapPut( 383 static inline int cxMapPut(
376 CxMap *map, 384 CxMap *map,
377 cxmutstr const &key, 385 cxmutstr const &key,
378 void *value 386 void *value
379 ) { 387 ) {
386 * @param map the map 394 * @param map the map
387 * @param key the key 395 * @param key the key
388 * @param value the value 396 * @param value the value
389 * @return 0 on success, non-zero value on failure 397 * @return 0 on success, non-zero value on failure
390 */ 398 */
391 __attribute__((__nonnull__)) 399 cx_attr_nonnull
400 cx_attr_cstr_arg(2)
392 static inline int cxMapPut( 401 static inline int cxMapPut(
393 CxMap *map, 402 CxMap *map,
394 const char *key, 403 const char *key,
395 void *value 404 void *value
396 ) { 405 ) {
402 * 411 *
403 * @param map the map 412 * @param map the map
404 * @param key the key 413 * @param key the key
405 * @return the value 414 * @return the value
406 */ 415 */
407 __attribute__((__nonnull__, __warn_unused_result__)) 416 cx_attr_nonnull
417 cx_attr_nodiscard
408 static inline void *cxMapGet( 418 static inline void *cxMapGet(
409 const CxMap *map, 419 const CxMap *map,
410 CxHashKey const &key 420 CxHashKey const &key
411 ) { 421 ) {
412 return map->cl->get(map, key); 422 return map->cl->get(map, key);
417 * 427 *
418 * @param map the map 428 * @param map the map
419 * @param key the key 429 * @param key the key
420 * @return the value 430 * @return the value
421 */ 431 */
422 __attribute__((__nonnull__, __warn_unused_result__)) 432 cx_attr_nonnull
433 cx_attr_nodiscard
423 static inline void *cxMapGet( 434 static inline void *cxMapGet(
424 const CxMap *map, 435 const CxMap *map,
425 cxstring const &key 436 cxstring const &key
426 ) { 437 ) {
427 return map->cl->get(map, cx_hash_key_cxstr(key)); 438 return map->cl->get(map, cx_hash_key_cxstr(key));
432 * 443 *
433 * @param map the map 444 * @param map the map
434 * @param key the key 445 * @param key the key
435 * @return the value 446 * @return the value
436 */ 447 */
437 __attribute__((__nonnull__, __warn_unused_result__)) 448 cx_attr_nonnull
449 cx_attr_nodiscard
438 static inline void *cxMapGet( 450 static inline void *cxMapGet(
439 const CxMap *map, 451 const CxMap *map,
440 cxmutstr const &key 452 cxmutstr const &key
441 ) { 453 ) {
442 return map->cl->get(map, cx_hash_key_cxstr(key)); 454 return map->cl->get(map, cx_hash_key_cxstr(key));
447 * 459 *
448 * @param map the map 460 * @param map the map
449 * @param key the key 461 * @param key the key
450 * @return the value 462 * @return the value
451 */ 463 */
452 __attribute__((__nonnull__, __warn_unused_result__)) 464 cx_attr_nonnull
465 cx_attr_nodiscard
466 cx_attr_cstr_arg(2)
453 static inline void *cxMapGet( 467 static inline void *cxMapGet(
454 const CxMap *map, 468 const CxMap *map,
455 const char *key 469 const char *key
456 ) { 470 ) {
457 return map->cl->get(map, cx_hash_key_str(key)); 471 return map->cl->get(map, cx_hash_key_str(key));
469 * @param map the map 483 * @param map the map
470 * @param key the key 484 * @param key the key
471 * @see cxMapRemoveAndGet() 485 * @see cxMapRemoveAndGet()
472 * @see cxMapDetach() 486 * @see cxMapDetach()
473 */ 487 */
474 __attribute__((__nonnull__)) 488 cx_attr_nonnull
475 static inline void cxMapRemove( 489 static inline void cxMapRemove(
476 CxMap *map, 490 CxMap *map,
477 CxHashKey const &key 491 CxHashKey const &key
478 ) { 492 ) {
479 (void) map->cl->remove(map, key, true); 493 (void) map->cl->remove(map, key, true);
491 * @param map the map 505 * @param map the map
492 * @param key the key 506 * @param key the key
493 * @see cxMapRemoveAndGet() 507 * @see cxMapRemoveAndGet()
494 * @see cxMapDetach() 508 * @see cxMapDetach()
495 */ 509 */
496 __attribute__((__nonnull__)) 510 cx_attr_nonnull
497 static inline void cxMapRemove( 511 static inline void cxMapRemove(
498 CxMap *map, 512 CxMap *map,
499 cxstring const &key 513 cxstring const &key
500 ) { 514 ) {
501 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true); 515 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true);
513 * @param map the map 527 * @param map the map
514 * @param key the key 528 * @param key the key
515 * @see cxMapRemoveAndGet() 529 * @see cxMapRemoveAndGet()
516 * @see cxMapDetach() 530 * @see cxMapDetach()
517 */ 531 */
518 __attribute__((__nonnull__)) 532 cx_attr_nonnull
519 static inline void cxMapRemove( 533 static inline void cxMapRemove(
520 CxMap *map, 534 CxMap *map,
521 cxmutstr const &key 535 cxmutstr const &key
522 ) { 536 ) {
523 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true); 537 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true);
535 * @param map the map 549 * @param map the map
536 * @param key the key 550 * @param key the key
537 * @see cxMapRemoveAndGet() 551 * @see cxMapRemoveAndGet()
538 * @see cxMapDetach() 552 * @see cxMapDetach()
539 */ 553 */
540 __attribute__((__nonnull__)) 554 cx_attr_nonnull
555 cx_attr_cstr_arg(2)
541 static inline void cxMapRemove( 556 static inline void cxMapRemove(
542 CxMap *map, 557 CxMap *map,
543 const char *key 558 const char *key
544 ) { 559 ) {
545 (void) map->cl->remove(map, cx_hash_key_str(key), true); 560 (void) map->cl->remove(map, cx_hash_key_str(key), true);
557 * @param map the map 572 * @param map the map
558 * @param key the key 573 * @param key the key
559 * @see cxMapRemove() 574 * @see cxMapRemove()
560 * @see cxMapRemoveAndGet() 575 * @see cxMapRemoveAndGet()
561 */ 576 */
562 __attribute__((__nonnull__)) 577 cx_attr_nonnull
563 static inline void cxMapDetach( 578 static inline void cxMapDetach(
564 CxMap *map, 579 CxMap *map,
565 CxHashKey const &key 580 CxHashKey const &key
566 ) { 581 ) {
567 (void) map->cl->remove(map, key, false); 582 (void) map->cl->remove(map, key, false);
579 * @param map the map 594 * @param map the map
580 * @param key the key 595 * @param key the key
581 * @see cxMapRemove() 596 * @see cxMapRemove()
582 * @see cxMapRemoveAndGet() 597 * @see cxMapRemoveAndGet()
583 */ 598 */
584 __attribute__((__nonnull__)) 599 cx_attr_nonnull
585 static inline void cxMapDetach( 600 static inline void cxMapDetach(
586 CxMap *map, 601 CxMap *map,
587 cxstring const &key 602 cxstring const &key
588 ) { 603 ) {
589 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false); 604 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false);
601 * @param map the map 616 * @param map the map
602 * @param key the key 617 * @param key the key
603 * @see cxMapRemove() 618 * @see cxMapRemove()
604 * @see cxMapRemoveAndGet() 619 * @see cxMapRemoveAndGet()
605 */ 620 */
606 __attribute__((__nonnull__)) 621 cx_attr_nonnull
607 static inline void cxMapDetach( 622 static inline void cxMapDetach(
608 CxMap *map, 623 CxMap *map,
609 cxmutstr const &key 624 cxmutstr const &key
610 ) { 625 ) {
611 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false); 626 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false);
623 * @param map the map 638 * @param map the map
624 * @param key the key 639 * @param key the key
625 * @see cxMapRemove() 640 * @see cxMapRemove()
626 * @see cxMapRemoveAndGet() 641 * @see cxMapRemoveAndGet()
627 */ 642 */
628 __attribute__((__nonnull__)) 643 cx_attr_nonnull
644 cx_attr_cstr_arg(2)
629 static inline void cxMapDetach( 645 static inline void cxMapDetach(
630 CxMap *map, 646 CxMap *map,
631 const char *key 647 const char *key
632 ) { 648 ) {
633 (void) map->cl->remove(map, cx_hash_key_str(key), false); 649 (void) map->cl->remove(map, cx_hash_key_str(key), false);
650 * @return the stored pointer or \c NULL if either the key is not present 666 * @return the stored pointer or \c NULL if either the key is not present
651 * in the map or the map is not storing pointers 667 * in the map or the map is not storing pointers
652 * @see cxMapStorePointers() 668 * @see cxMapStorePointers()
653 * @see cxMapDetach() 669 * @see cxMapDetach()
654 */ 670 */
655 __attribute__((__nonnull__, __warn_unused_result__)) 671 cx_attr_nonnull
672 cx_attr_nodiscard
656 static inline void *cxMapRemoveAndGet( 673 static inline void *cxMapRemoveAndGet(
657 CxMap *map, 674 CxMap *map,
658 CxHashKey key 675 CxHashKey key
659 ) { 676 ) {
660 return map->cl->remove(map, key, !map->collection.store_pointer); 677 return map->cl->remove(map, key, !map->collection.store_pointer);
677 * @return the stored pointer or \c NULL if either the key is not present 694 * @return the stored pointer or \c NULL if either the key is not present
678 * in the map or the map is not storing pointers 695 * in the map or the map is not storing pointers
679 * @see cxMapStorePointers() 696 * @see cxMapStorePointers()
680 * @see cxMapDetach() 697 * @see cxMapDetach()
681 */ 698 */
682 __attribute__((__nonnull__, __warn_unused_result__)) 699 cx_attr_nonnull
700 cx_attr_nodiscard
683 static inline void *cxMapRemoveAndGet( 701 static inline void *cxMapRemoveAndGet(
684 CxMap *map, 702 CxMap *map,
685 cxstring key 703 cxstring key
686 ) { 704 ) {
687 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer); 705 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer);
704 * @return the stored pointer or \c NULL if either the key is not present 722 * @return the stored pointer or \c NULL if either the key is not present
705 * in the map or the map is not storing pointers 723 * in the map or the map is not storing pointers
706 * @see cxMapStorePointers() 724 * @see cxMapStorePointers()
707 * @see cxMapDetach() 725 * @see cxMapDetach()
708 */ 726 */
709 __attribute__((__nonnull__, __warn_unused_result__)) 727 cx_attr_nonnull
728 cx_attr_nodiscard
710 static inline void *cxMapRemoveAndGet( 729 static inline void *cxMapRemoveAndGet(
711 CxMap *map, 730 CxMap *map,
712 cxmutstr key 731 cxmutstr key
713 ) { 732 ) {
714 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer); 733 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer);
731 * @return the stored pointer or \c NULL if either the key is not present 750 * @return the stored pointer or \c NULL if either the key is not present
732 * in the map or the map is not storing pointers 751 * in the map or the map is not storing pointers
733 * @see cxMapStorePointers() 752 * @see cxMapStorePointers()
734 * @see cxMapDetach() 753 * @see cxMapDetach()
735 */ 754 */
736 __attribute__((__nonnull__, __warn_unused_result__)) 755 cx_attr_nonnull
756 cx_attr_nodiscard
757 cx_attr_cstr_arg(2)
737 static inline void *cxMapRemoveAndGet( 758 static inline void *cxMapRemoveAndGet(
738 CxMap *map, 759 CxMap *map,
739 const char *key 760 const char *key
740 ) { 761 ) {
741 return map->cl->remove(map, cx_hash_key_str(key), !map->collection.store_pointer); 762 return map->cl->remove(map, cx_hash_key_str(key), !map->collection.store_pointer);
749 * @param map the map 770 * @param map the map
750 * @param key the key 771 * @param key the key
751 * @param value the value 772 * @param value the value
752 * @return 0 on success, non-zero value on failure 773 * @return 0 on success, non-zero value on failure
753 */ 774 */
754 __attribute__((__nonnull__)) 775 cx_attr_nonnull
755 static inline int cx_map_put( 776 static inline int cx_map_put(
756 CxMap *map, 777 CxMap *map,
757 CxHashKey key, 778 CxHashKey key,
758 void *value 779 void *value
759 ) { 780 ) {
766 * @param map the map 787 * @param map the map
767 * @param key the key 788 * @param key the key
768 * @param value the value 789 * @param value the value
769 * @return 0 on success, non-zero value on failure 790 * @return 0 on success, non-zero value on failure
770 */ 791 */
771 __attribute__((__nonnull__)) 792 cx_attr_nonnull
772 static inline int cx_map_put_cxstr( 793 static inline int cx_map_put_cxstr(
773 CxMap *map, 794 CxMap *map,
774 cxstring key, 795 cxstring key,
775 void *value 796 void *value
776 ) { 797 ) {
783 * @param map the map 804 * @param map the map
784 * @param key the key 805 * @param key the key
785 * @param value the value 806 * @param value the value
786 * @return 0 on success, non-zero value on failure 807 * @return 0 on success, non-zero value on failure
787 */ 808 */
788 __attribute__((__nonnull__)) 809 cx_attr_nonnull
789 static inline int cx_map_put_mustr( 810 static inline int cx_map_put_mustr(
790 CxMap *map, 811 CxMap *map,
791 cxmutstr key, 812 cxmutstr key,
792 void *value 813 void *value
793 ) { 814 ) {
800 * @param map the map 821 * @param map the map
801 * @param key the key 822 * @param key the key
802 * @param value the value 823 * @param value the value
803 * @return 0 on success, non-zero value on failure 824 * @return 0 on success, non-zero value on failure
804 */ 825 */
805 __attribute__((__nonnull__)) 826 cx_attr_nonnull
827 cx_attr_cstr_arg(2)
806 static inline int cx_map_put_str( 828 static inline int cx_map_put_str(
807 CxMap *map, 829 CxMap *map,
808 const char *key, 830 const char *key,
809 void *value 831 void *value
810 ) { 832 ) {
832 * 854 *
833 * @param map the map 855 * @param map the map
834 * @param key the key 856 * @param key the key
835 * @return the value 857 * @return the value
836 */ 858 */
837 __attribute__((__nonnull__, __warn_unused_result__)) 859 cx_attr_nonnull
860 cx_attr_nodiscard
838 static inline void *cx_map_get( 861 static inline void *cx_map_get(
839 const CxMap *map, 862 const CxMap *map,
840 CxHashKey key 863 CxHashKey key
841 ) { 864 ) {
842 return map->cl->get(map, key); 865 return map->cl->get(map, key);
847 * 870 *
848 * @param map the map 871 * @param map the map
849 * @param key the key 872 * @param key the key
850 * @return the value 873 * @return the value
851 */ 874 */
852 __attribute__((__nonnull__, __warn_unused_result__)) 875 cx_attr_nonnull
876 cx_attr_nodiscard
853 static inline void *cx_map_get_cxstr( 877 static inline void *cx_map_get_cxstr(
854 const CxMap *map, 878 const CxMap *map,
855 cxstring key 879 cxstring key
856 ) { 880 ) {
857 return map->cl->get(map, cx_hash_key_cxstr(key)); 881 return map->cl->get(map, cx_hash_key_cxstr(key));
862 * 886 *
863 * @param map the map 887 * @param map the map
864 * @param key the key 888 * @param key the key
865 * @return the value 889 * @return the value
866 */ 890 */
867 __attribute__((__nonnull__, __warn_unused_result__)) 891 cx_attr_nonnull
892 cx_attr_nodiscard
868 static inline void *cx_map_get_mustr( 893 static inline void *cx_map_get_mustr(
869 const CxMap *map, 894 const CxMap *map,
870 cxmutstr key 895 cxmutstr key
871 ) { 896 ) {
872 return map->cl->get(map, cx_hash_key_cxstr(key)); 897 return map->cl->get(map, cx_hash_key_cxstr(key));
877 * 902 *
878 * @param map the map 903 * @param map the map
879 * @param key the key 904 * @param key the key
880 * @return the value 905 * @return the value
881 */ 906 */
882 __attribute__((__nonnull__, __warn_unused_result__)) 907 cx_attr_nonnull
908 cx_attr_nodiscard
909 cx_attr_cstr_arg(2)
883 static inline void *cx_map_get_str( 910 static inline void *cx_map_get_str(
884 const CxMap *map, 911 const CxMap *map,
885 const char *key 912 const char *key
886 ) { 913 ) {
887 return map->cl->get(map, cx_hash_key_str(key)); 914 return map->cl->get(map, cx_hash_key_str(key));
906 * Removes a key/value-pair from the map by using the key. 933 * Removes a key/value-pair from the map by using the key.
907 * 934 *
908 * @param map the map 935 * @param map the map
909 * @param key the key 936 * @param key the key
910 */ 937 */
911 __attribute__((__nonnull__)) 938 cx_attr_nonnull
912 static inline void cx_map_remove( 939 static inline void cx_map_remove(
913 CxMap *map, 940 CxMap *map,
914 CxHashKey key 941 CxHashKey key
915 ) { 942 ) {
916 (void) map->cl->remove(map, key, true); 943 (void) map->cl->remove(map, key, true);
920 * Removes a key/value-pair from the map by using the key. 947 * Removes a key/value-pair from the map by using the key.
921 * 948 *
922 * @param map the map 949 * @param map the map
923 * @param key the key 950 * @param key the key
924 */ 951 */
925 __attribute__((__nonnull__)) 952 cx_attr_nonnull
926 static inline void cx_map_remove_cxstr( 953 static inline void cx_map_remove_cxstr(
927 CxMap *map, 954 CxMap *map,
928 cxstring key 955 cxstring key
929 ) { 956 ) {
930 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true); 957 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true);
934 * Removes a key/value-pair from the map by using the key. 961 * Removes a key/value-pair from the map by using the key.
935 * 962 *
936 * @param map the map 963 * @param map the map
937 * @param key the key 964 * @param key the key
938 */ 965 */
939 __attribute__((__nonnull__)) 966 cx_attr_nonnull
940 static inline void cx_map_remove_mustr( 967 static inline void cx_map_remove_mustr(
941 CxMap *map, 968 CxMap *map,
942 cxmutstr key 969 cxmutstr key
943 ) { 970 ) {
944 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true); 971 (void) map->cl->remove(map, cx_hash_key_cxstr(key), true);
948 * Removes a key/value-pair from the map by using the key. 975 * Removes a key/value-pair from the map by using the key.
949 * 976 *
950 * @param map the map 977 * @param map the map
951 * @param key the key 978 * @param key the key
952 */ 979 */
953 __attribute__((__nonnull__)) 980 cx_attr_nonnull
981 cx_attr_cstr_arg(2)
954 static inline void cx_map_remove_str( 982 static inline void cx_map_remove_str(
955 CxMap *map, 983 CxMap *map,
956 const char *key 984 const char *key
957 ) { 985 ) {
958 (void) map->cl->remove(map, cx_hash_key_str(key), true); 986 (void) map->cl->remove(map, cx_hash_key_str(key), true);
985 * without invoking the destructor. 1013 * without invoking the destructor.
986 * 1014 *
987 * @param map the map 1015 * @param map the map
988 * @param key the key 1016 * @param key the key
989 */ 1017 */
990 __attribute__((__nonnull__)) 1018 cx_attr_nonnull
991 static inline void cx_map_detach( 1019 static inline void cx_map_detach(
992 CxMap *map, 1020 CxMap *map,
993 CxHashKey key 1021 CxHashKey key
994 ) { 1022 ) {
995 (void) map->cl->remove(map, key, false); 1023 (void) map->cl->remove(map, key, false);
1000 * without invoking the destructor. 1028 * without invoking the destructor.
1001 * 1029 *
1002 * @param map the map 1030 * @param map the map
1003 * @param key the key 1031 * @param key the key
1004 */ 1032 */
1005 __attribute__((__nonnull__)) 1033 cx_attr_nonnull
1006 static inline void cx_map_detach_cxstr( 1034 static inline void cx_map_detach_cxstr(
1007 CxMap *map, 1035 CxMap *map,
1008 cxstring key 1036 cxstring key
1009 ) { 1037 ) {
1010 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false); 1038 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false);
1015 * without invoking the destructor. 1043 * without invoking the destructor.
1016 * 1044 *
1017 * @param map the map 1045 * @param map the map
1018 * @param key the key 1046 * @param key the key
1019 */ 1047 */
1020 __attribute__((__nonnull__)) 1048 cx_attr_nonnull
1021 static inline void cx_map_detach_mustr( 1049 static inline void cx_map_detach_mustr(
1022 CxMap *map, 1050 CxMap *map,
1023 cxmutstr key 1051 cxmutstr key
1024 ) { 1052 ) {
1025 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false); 1053 (void) map->cl->remove(map, cx_hash_key_cxstr(key), false);
1030 * without invoking the destructor. 1058 * without invoking the destructor.
1031 * 1059 *
1032 * @param map the map 1060 * @param map the map
1033 * @param key the key 1061 * @param key the key
1034 */ 1062 */
1035 __attribute__((__nonnull__)) 1063 cx_attr_nonnull
1064 cx_attr_cstr_arg(2)
1036 static inline void cx_map_detach_str( 1065 static inline void cx_map_detach_str(
1037 CxMap *map, 1066 CxMap *map,
1038 const char *key 1067 const char *key
1039 ) { 1068 ) {
1040 (void) map->cl->remove(map, cx_hash_key_str(key), false); 1069 (void) map->cl->remove(map, cx_hash_key_str(key), false);
1068 * @param map the map 1097 * @param map the map
1069 * @param key the key 1098 * @param key the key
1070 * @return the stored pointer or \c NULL if either the key is not present 1099 * @return the stored pointer or \c NULL if either the key is not present
1071 * in the map or the map is not storing pointers 1100 * in the map or the map is not storing pointers
1072 */ 1101 */
1073 __attribute__((__nonnull__, __warn_unused_result__)) 1102 cx_attr_nonnull
1103 cx_attr_nodiscard
1074 static inline void *cx_map_remove_and_get( 1104 static inline void *cx_map_remove_and_get(
1075 CxMap *map, 1105 CxMap *map,
1076 CxHashKey key 1106 CxHashKey key
1077 ) { 1107 ) {
1078 return map->cl->remove(map, key, !map->collection.store_pointer); 1108 return map->cl->remove(map, key, !map->collection.store_pointer);
1084 * @param map the map 1114 * @param map the map
1085 * @param key the key 1115 * @param key the key
1086 * @return the stored pointer or \c NULL if either the key is not present 1116 * @return the stored pointer or \c NULL if either the key is not present
1087 * in the map or the map is not storing pointers 1117 * in the map or the map is not storing pointers
1088 */ 1118 */
1089 __attribute__((__nonnull__, __warn_unused_result__)) 1119 cx_attr_nonnull
1120 cx_attr_nodiscard
1090 static inline void *cx_map_remove_and_get_cxstr( 1121 static inline void *cx_map_remove_and_get_cxstr(
1091 CxMap *map, 1122 CxMap *map,
1092 cxstring key 1123 cxstring key
1093 ) { 1124 ) {
1094 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer); 1125 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer);
1100 * @param map the map 1131 * @param map the map
1101 * @param key the key 1132 * @param key the key
1102 * @return the stored pointer or \c NULL if either the key is not present 1133 * @return the stored pointer or \c NULL if either the key is not present
1103 * in the map or the map is not storing pointers 1134 * in the map or the map is not storing pointers
1104 */ 1135 */
1105 __attribute__((__nonnull__, __warn_unused_result__)) 1136 cx_attr_nonnull
1137 cx_attr_nodiscard
1106 static inline void *cx_map_remove_and_get_mustr( 1138 static inline void *cx_map_remove_and_get_mustr(
1107 CxMap *map, 1139 CxMap *map,
1108 cxmutstr key 1140 cxmutstr key
1109 ) { 1141 ) {
1110 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer); 1142 return map->cl->remove(map, cx_hash_key_cxstr(key), !map->collection.store_pointer);
1116 * @param map the map 1148 * @param map the map
1117 * @param key the key 1149 * @param key the key
1118 * @return the stored pointer or \c NULL if either the key is not present 1150 * @return the stored pointer or \c NULL if either the key is not present
1119 * in the map or the map is not storing pointers 1151 * in the map or the map is not storing pointers
1120 */ 1152 */
1121 __attribute__((__nonnull__, __warn_unused_result__)) 1153 cx_attr_nonnull
1154 cx_attr_nodiscard
1155 cx_attr_cstr_arg(2)
1122 static inline void *cx_map_remove_and_get_str( 1156 static inline void *cx_map_remove_and_get_str(
1123 CxMap *map, 1157 CxMap *map,
1124 const char *key 1158 const char *key
1125 ) { 1159 ) {
1126 return map->cl->remove(map, cx_hash_key_str(key), !map->collection.store_pointer); 1160 return map->cl->remove(map, cx_hash_key_str(key), !map->collection.store_pointer);

mercurial