From: Christian Grothoff Date: Mon, 30 Mar 2015 19:46:17 +0000 (+0000) Subject: add multihashmap_clear to API X-Git-Tag: initial-import-from-subversion-38251~2106 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bf7619be0f8e5fca7a16c28720ab908134d139bc;p=oweals%2Fgnunet.git add multihashmap_clear to API --- diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index b83130307..125bc81b2 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -697,6 +697,18 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap * const struct GNUNET_HashCode *key); +/** + * @ingroup hashmap + * Remove all entries from the map. + * Note that the values would not be "freed". + * + * @param map the map + * @return number of values removed + */ +unsigned int +GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map); + + /** * @ingroup hashmap * Check if the map contains any value under the given @@ -757,8 +769,7 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, * @return the number of key value pairs */ unsigned int -GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap - *map); +GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map); /** @@ -772,8 +783,7 @@ GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multihashmap_iterate (const struct - GNUNET_CONTAINER_MultiHashMap *map, +GNUNET_CONTAINER_multihashmap_iterate (const struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_HashMapIterator it, void *it_cls); diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h index 39605807a..38a027200 100644 --- a/src/include/gnunet_datastore_service.h +++ b/src/include/gnunet_datastore_service.h @@ -207,7 +207,8 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, * (or rather, will already have been invoked) */ struct GNUNET_DATASTORE_QueueEntry * -GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid, +GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, + uint64_t uid, uint32_t priority, struct GNUNET_TIME_Absolute expiration, unsigned int queue_priority, @@ -239,8 +240,10 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid, */ struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, - const struct GNUNET_HashCode * key, size_t size, - const void *data, unsigned int queue_priority, + const struct GNUNET_HashCode *key, + size_t size, + const void *data, + unsigned int queue_priority, unsigned int max_queue_size, struct GNUNET_TIME_Relative timeout, GNUNET_DATASTORE_ContinuationWithStatus cont, @@ -261,14 +264,16 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, * @param uid unique identifier for the datum; * maybe 0 if no unique identifier is available */ -typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls, - const struct GNUNET_HashCode *key, - size_t size, const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid); +typedef void +(*GNUNET_DATASTORE_DatumProcessor) (void *cls, + const struct GNUNET_HashCode *key, + size_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid); /** @@ -293,13 +298,15 @@ typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls, * cancel */ struct GNUNET_DATASTORE_QueueEntry * -GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t offset, +GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, + uint64_t offset, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, unsigned int queue_priority, unsigned int max_queue_size, struct GNUNET_TIME_Relative timeout, - GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls); + GNUNET_DATASTORE_DatumProcessor proc, + void *proc_cls); /** @@ -352,7 +359,7 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, * @param proc function to call on a random value; it * will be called once with a value (if available) * and always once with a value of NULL. - * @param proc_cls closure for proc + * @param proc_cls closure for @a proc * @return NULL if the entry was not queued, otherwise a handle that can be used to * cancel */ 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 * key-value pairs with value NULL */ void * -GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap - *map, const struct GNUNET_HashCode *key) +GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map, + const struct GNUNET_HashCode *key) { union MapEntry me; @@ -446,8 +446,8 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, * @return number of values removed */ int -GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap - *map, const struct GNUNET_HashCode *key) +GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map, + const struct GNUNET_HashCode *key) { union MapEntry me; unsigned int i; @@ -522,6 +522,49 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap } +/** + * Callback used to remove all entries from the map. + * + * @param cls the `struct GNUNET_CONTAINER_MultiHashMap` + * @param key the key + * @param value the value + * @return #GNUNET_OK (continue to iterate) + */ +static int +remove_all (void *cls, + const struct GNUNET_HashCode *key, + void *value) +{ + struct GNUNET_CONTAINER_MultiHashMap *map = cls; + + GNUNET_CONTAINER_multihashmap_remove (map, + key, + value); + return GNUNET_OK; +} + + +/** + * @ingroup hashmap + * Remove all entries from the map. + * Note that the values would not be "freed". + * + * @param map the map + * @return number of values removed + */ +unsigned int +GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map) +{ + unsigned int ret; + + ret = map->size; + GNUNET_CONTAINER_multihashmap_iterate (map, + &remove_all, + map); + return ret; +} + + /** * Check if the map contains any value under the given * key (including values that are NULL).