aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-03-30 19:46:17 +0000
committerChristian Grothoff <christian@grothoff.org>2015-03-30 19:46:17 +0000
commitbf7619be0f8e5fca7a16c28720ab908134d139bc (patch)
tree3433dea1f210b3da2329edc13183d0d8c14e0d81 /src
parentb47c2f2d5175300a531778727c29787ab78749b8 (diff)
downloadgnunet-bf7619be0f8e5fca7a16c28720ab908134d139bc.tar.gz
gnunet-bf7619be0f8e5fca7a16c28720ab908134d139bc.zip
add multihashmap_clear to API
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_container_lib.h18
-rw-r--r--src/include/gnunet_datastore_service.h35
-rw-r--r--src/util/container_multihashmap.c51
3 files changed, 82 insertions, 22 deletions
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
@@ -699,6 +699,18 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *
699 699
700/** 700/**
701 * @ingroup hashmap 701 * @ingroup hashmap
702 * Remove all entries from the map.
703 * Note that the values would not be "freed".
704 *
705 * @param map the map
706 * @return number of values removed
707 */
708unsigned int
709GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map);
710
711
712/**
713 * @ingroup hashmap
702 * Check if the map contains any value under the given 714 * Check if the map contains any value under the given
703 * key (including values that are NULL). 715 * key (including values that are NULL).
704 * 716 *
@@ -757,8 +769,7 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
757 * @return the number of key value pairs 769 * @return the number of key value pairs
758 */ 770 */
759unsigned int 771unsigned int
760GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap 772GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map);
761 *map);
762 773
763 774
764/** 775/**
@@ -772,8 +783,7 @@ GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap
772 * #GNUNET_SYSERR if it aborted iteration 783 * #GNUNET_SYSERR if it aborted iteration
773 */ 784 */
774int 785int
775GNUNET_CONTAINER_multihashmap_iterate (const struct 786GNUNET_CONTAINER_multihashmap_iterate (const struct GNUNET_CONTAINER_MultiHashMap *map,
776 GNUNET_CONTAINER_MultiHashMap *map,
777 GNUNET_CONTAINER_HashMapIterator it, 787 GNUNET_CONTAINER_HashMapIterator it,
778 void *it_cls); 788 void *it_cls);
779 789
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,
207 * (or rather, will already have been invoked) 207 * (or rather, will already have been invoked)
208 */ 208 */
209struct GNUNET_DATASTORE_QueueEntry * 209struct GNUNET_DATASTORE_QueueEntry *
210GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid, 210GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
211 uint64_t uid,
211 uint32_t priority, 212 uint32_t priority,
212 struct GNUNET_TIME_Absolute expiration, 213 struct GNUNET_TIME_Absolute expiration,
213 unsigned int queue_priority, 214 unsigned int queue_priority,
@@ -239,8 +240,10 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid,
239 */ 240 */
240struct GNUNET_DATASTORE_QueueEntry * 241struct GNUNET_DATASTORE_QueueEntry *
241GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, 242GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
242 const struct GNUNET_HashCode * key, size_t size, 243 const struct GNUNET_HashCode *key,
243 const void *data, unsigned int queue_priority, 244 size_t size,
245 const void *data,
246 unsigned int queue_priority,
244 unsigned int max_queue_size, 247 unsigned int max_queue_size,
245 struct GNUNET_TIME_Relative timeout, 248 struct GNUNET_TIME_Relative timeout,
246 GNUNET_DATASTORE_ContinuationWithStatus cont, 249 GNUNET_DATASTORE_ContinuationWithStatus cont,
@@ -261,14 +264,16 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
261 * @param uid unique identifier for the datum; 264 * @param uid unique identifier for the datum;
262 * maybe 0 if no unique identifier is available 265 * maybe 0 if no unique identifier is available
263 */ 266 */
264typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls, 267typedef void
265 const struct GNUNET_HashCode *key, 268(*GNUNET_DATASTORE_DatumProcessor) (void *cls,
266 size_t size, const void *data, 269 const struct GNUNET_HashCode *key,
267 enum GNUNET_BLOCK_Type type, 270 size_t size,
268 uint32_t priority, 271 const void *data,
269 uint32_t anonymity, 272 enum GNUNET_BLOCK_Type type,
270 struct GNUNET_TIME_Absolute expiration, 273 uint32_t priority,
271 uint64_t uid); 274 uint32_t anonymity,
275 struct GNUNET_TIME_Absolute expiration,
276 uint64_t uid);
272 277
273 278
274/** 279/**
@@ -293,13 +298,15 @@ typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
293 * cancel 298 * cancel
294 */ 299 */
295struct GNUNET_DATASTORE_QueueEntry * 300struct GNUNET_DATASTORE_QueueEntry *
296GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t offset, 301GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
302 uint64_t offset,
297 const struct GNUNET_HashCode *key, 303 const struct GNUNET_HashCode *key,
298 enum GNUNET_BLOCK_Type type, 304 enum GNUNET_BLOCK_Type type,
299 unsigned int queue_priority, 305 unsigned int queue_priority,
300 unsigned int max_queue_size, 306 unsigned int max_queue_size,
301 struct GNUNET_TIME_Relative timeout, 307 struct GNUNET_TIME_Relative timeout,
302 GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls); 308 GNUNET_DATASTORE_DatumProcessor proc,
309 void *proc_cls);
303 310
304 311
305/** 312/**
@@ -352,7 +359,7 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
352 * @param proc function to call on a random value; it 359 * @param proc function to call on a random value; it
353 * will be called once with a value (if available) 360 * will be called once with a value (if available)
354 * and always once with a value of NULL. 361 * and always once with a value of NULL.
355 * @param proc_cls closure for proc 362 * @param proc_cls closure for @a proc
356 * @return NULL if the entry was not queued, otherwise a handle that can be used to 363 * @return NULL if the entry was not queued, otherwise a handle that can be used to
357 * cancel 364 * cancel
358 */ 365 */
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 */
277void * 277void *
278GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap 278GNUNET_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 */
448int 448int
449GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap 449GNUNET_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 */
533static int
534remove_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 */
555unsigned int
556GNUNET_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 *