diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-03-30 19:46:17 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-03-30 19:46:17 +0000 |
commit | bf7619be0f8e5fca7a16c28720ab908134d139bc (patch) | |
tree | 3433dea1f210b3da2329edc13183d0d8c14e0d81 /src/util | |
parent | b47c2f2d5175300a531778727c29787ab78749b8 (diff) | |
download | gnunet-bf7619be0f8e5fca7a16c28720ab908134d139bc.tar.gz gnunet-bf7619be0f8e5fca7a16c28720ab908134d139bc.zip |
add multihashmap_clear to API
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/container_multihashmap.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c index e6c908d76..789e8f370 100644 --- a/src/util/container_multihashmap.c +++ b/src/util/container_multihashmap.c | |||
@@ -275,8 +275,8 @@ GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap | |||
275 | * key-value pairs with value NULL | 275 | * key-value pairs with value NULL |
276 | */ | 276 | */ |
277 | void * | 277 | void * |
278 | GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap | 278 | GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map, |
279 | *map, const struct GNUNET_HashCode *key) | 279 | const struct GNUNET_HashCode *key) |
280 | { | 280 | { |
281 | union MapEntry me; | 281 | union MapEntry me; |
282 | 282 | ||
@@ -446,8 +446,8 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
446 | * @return number of values removed | 446 | * @return number of values removed |
447 | */ | 447 | */ |
448 | int | 448 | int |
449 | GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap | 449 | GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map, |
450 | *map, const struct GNUNET_HashCode *key) | 450 | const struct GNUNET_HashCode *key) |
451 | { | 451 | { |
452 | union MapEntry me; | 452 | union MapEntry me; |
453 | unsigned int i; | 453 | unsigned int i; |
@@ -523,6 +523,49 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap | |||
523 | 523 | ||
524 | 524 | ||
525 | /** | 525 | /** |
526 | * Callback used to remove all entries from the map. | ||
527 | * | ||
528 | * @param cls the `struct GNUNET_CONTAINER_MultiHashMap` | ||
529 | * @param key the key | ||
530 | * @param value the value | ||
531 | * @return #GNUNET_OK (continue to iterate) | ||
532 | */ | ||
533 | static int | ||
534 | remove_all (void *cls, | ||
535 | const struct GNUNET_HashCode *key, | ||
536 | void *value) | ||
537 | { | ||
538 | struct GNUNET_CONTAINER_MultiHashMap *map = cls; | ||
539 | |||
540 | GNUNET_CONTAINER_multihashmap_remove (map, | ||
541 | key, | ||
542 | value); | ||
543 | return GNUNET_OK; | ||
544 | } | ||
545 | |||
546 | |||
547 | /** | ||
548 | * @ingroup hashmap | ||
549 | * Remove all entries from the map. | ||
550 | * Note that the values would not be "freed". | ||
551 | * | ||
552 | * @param map the map | ||
553 | * @return number of values removed | ||
554 | */ | ||
555 | unsigned int | ||
556 | GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map) | ||
557 | { | ||
558 | unsigned int ret; | ||
559 | |||
560 | ret = map->size; | ||
561 | GNUNET_CONTAINER_multihashmap_iterate (map, | ||
562 | &remove_all, | ||
563 | map); | ||
564 | return ret; | ||
565 | } | ||
566 | |||
567 | |||
568 | /** | ||
526 | * Check if the map contains any value under the given | 569 | * Check if the map contains any value under the given |
527 | * key (including values that are NULL). | 570 | * key (including values that are NULL). |
528 | * | 571 | * |