summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-07-21 11:08:40 +0200
committerChristian Grothoff <christian@grothoff.org>2019-07-21 11:08:51 +0200
commitdfeef02bf7882cdfb952430cfbdb9793ecd780e2 (patch)
tree9ed8a31e4774f36d79ab0d606af2769107b7c250 /src/util
parent4a85347dcea576d8f297efba24c1aaa77ded92d0 (diff)
downloadgnunet-dfeef02bf7882cdfb952430cfbdb9793ecd780e2.tar.gz
gnunet-dfeef02bf7882cdfb952430cfbdb9793ecd780e2.zip
fix #5793
Diffstat (limited to 'src/util')
-rw-r--r--src/util/container_multihashmap.c6
-rw-r--r--src/util/container_multihashmap32.c123
-rw-r--r--src/util/container_multiuuidmap.c6
3 files changed, 69 insertions, 66 deletions
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c
index 165f04149..bcf6dccf0 100644
--- a/src/util/container_multihashmap.c
+++ b/src/util/container_multihashmap.c
@@ -355,7 +355,7 @@ GNUNET_CONTAINER_multihashmap_get (
355int 355int
356GNUNET_CONTAINER_multihashmap_iterate ( 356GNUNET_CONTAINER_multihashmap_iterate (
357 struct GNUNET_CONTAINER_MultiHashMap *map, 357 struct GNUNET_CONTAINER_MultiHashMap *map,
358 GNUNET_CONTAINER_HashMapIterator it, 358 GNUNET_CONTAINER_MulitHashMapIteratorCallback it,
359 void *it_cls) 359 void *it_cls)
360{ 360{
361 int count; 361 int count;
@@ -876,7 +876,7 @@ int
876GNUNET_CONTAINER_multihashmap_get_multiple ( 876GNUNET_CONTAINER_multihashmap_get_multiple (
877 struct GNUNET_CONTAINER_MultiHashMap *map, 877 struct GNUNET_CONTAINER_MultiHashMap *map,
878 const struct GNUNET_HashCode *key, 878 const struct GNUNET_HashCode *key,
879 GNUNET_CONTAINER_HashMapIterator it, 879 GNUNET_CONTAINER_MulitHashMapIteratorCallback it,
880 void *it_cls) 880 void *it_cls)
881{ 881{
882 int count; 882 int count;
@@ -942,7 +942,7 @@ GNUNET_CONTAINER_multihashmap_get_multiple (
942unsigned int 942unsigned int
943GNUNET_CONTAINER_multihashmap_get_random ( 943GNUNET_CONTAINER_multihashmap_get_random (
944 const struct GNUNET_CONTAINER_MultiHashMap *map, 944 const struct GNUNET_CONTAINER_MultiHashMap *map,
945 GNUNET_CONTAINER_HashMapIterator it, 945 GNUNET_CONTAINER_MulitHashMapIteratorCallback it,
946 void *it_cls) 946 void *it_cls)
947{ 947{
948 unsigned int off; 948 unsigned int off;
diff --git a/src/util/container_multihashmap32.c b/src/util/container_multihashmap32.c
index a614c04ae..0956ada67 100644
--- a/src/util/container_multihashmap32.c
+++ b/src/util/container_multihashmap32.c
@@ -28,7 +28,8 @@
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_container_lib.h" 29#include "gnunet_container_lib.h"
30 30
31#define LOG(kind,...) GNUNET_log_from (kind, "util-container-multihashmap32", __VA_ARGS__) 31#define LOG(kind, ...) \
32 GNUNET_log_from (kind, "util-container-multihashmap32", __VA_ARGS__)
32 33
33 34
34/** 35/**
@@ -59,7 +60,6 @@ struct MapEntry
59 * If there is a hash collision, we create a linked list. 60 * If there is a hash collision, we create a linked list.
60 */ 61 */
61 struct MapEntry *next; 62 struct MapEntry *next;
62
63}; 63};
64 64
65/** 65/**
@@ -146,8 +146,7 @@ GNUNET_CONTAINER_multihashmap32_create (unsigned int len)
146 146
147 GNUNET_assert (len > 0); 147 GNUNET_assert (len > 0);
148 ret = GNUNET_new (struct GNUNET_CONTAINER_MultiHashMap32); 148 ret = GNUNET_new (struct GNUNET_CONTAINER_MultiHashMap32);
149 ret->map = GNUNET_malloc_large (len * 149 ret->map = GNUNET_malloc_large (len * sizeof (struct MapEntry *));
150 sizeof (struct MapEntry *));
151 if (NULL == ret->map) 150 if (NULL == ret->map)
152 { 151 {
153 GNUNET_free (ret); 152 GNUNET_free (ret);
@@ -165,7 +164,8 @@ GNUNET_CONTAINER_multihashmap32_create (unsigned int len)
165 * @param map the map 164 * @param map the map
166 */ 165 */
167void 166void
168GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32 *map) 167GNUNET_CONTAINER_multihashmap32_destroy (
168 struct GNUNET_CONTAINER_MultiHashMap32 *map)
169{ 169{
170 struct MapEntry *e; 170 struct MapEntry *e;
171 171
@@ -190,8 +190,7 @@ GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32
190 * @return offset into the "map" array of "m" 190 * @return offset into the "map" array of "m"
191 */ 191 */
192static unsigned int 192static unsigned int
193idx_of (const struct GNUNET_CONTAINER_MultiHashMap32 *m, 193idx_of (const struct GNUNET_CONTAINER_MultiHashMap32 *m, const uint32_t key)
194 const uint32_t key)
195{ 194{
196 GNUNET_assert (NULL != m); 195 GNUNET_assert (NULL != m);
197 return ((unsigned int) key) % m->map_length; 196 return ((unsigned int) key) % m->map_length;
@@ -205,7 +204,8 @@ idx_of (const struct GNUNET_CONTAINER_MultiHashMap32 *m,
205 * @return the number of key value pairs 204 * @return the number of key value pairs
206 */ 205 */
207unsigned int 206unsigned int
208GNUNET_CONTAINER_multihashmap32_size (const struct GNUNET_CONTAINER_MultiHashMap32 *map) 207GNUNET_CONTAINER_multihashmap32_size (
208 const struct GNUNET_CONTAINER_MultiHashMap32 *map)
209{ 209{
210 return map->size; 210 return map->size;
211} 211}
@@ -222,8 +222,9 @@ GNUNET_CONTAINER_multihashmap32_size (const struct GNUNET_CONTAINER_MultiHashMap
222 * key-value pairs with value NULL 222 * key-value pairs with value NULL
223 */ 223 */
224void * 224void *
225GNUNET_CONTAINER_multihashmap32_get (const struct GNUNET_CONTAINER_MultiHashMap32 *map, 225GNUNET_CONTAINER_multihashmap32_get (
226 uint32_t key) 226 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
227 uint32_t key)
227{ 228{
228 struct MapEntry *e; 229 struct MapEntry *e;
229 230
@@ -248,9 +249,10 @@ GNUNET_CONTAINER_multihashmap32_get (const struct GNUNET_CONTAINER_MultiHashMap3
248 * #GNUNET_SYSERR if it aborted iteration 249 * #GNUNET_SYSERR if it aborted iteration
249 */ 250 */
250int 251int
251GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32 *map, 252GNUNET_CONTAINER_multihashmap32_iterate (
252 GNUNET_CONTAINER_HashMapIterator32 it, 253 struct GNUNET_CONTAINER_MultiHashMap32 *map,
253 void *it_cls) 254 GNUNET_CONTAINER_MulitHashMapIterator32Callback it,
255 void *it_cls)
254{ 256{
255 int count; 257 int count;
256 struct MapEntry **ce; 258 struct MapEntry **ce;
@@ -269,13 +271,11 @@ GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32
269 *ce = e->next; 271 *ce = e->next;
270 if (NULL != it) 272 if (NULL != it)
271 { 273 {
272 if (GNUNET_OK != it (it_cls, 274 if (GNUNET_OK != it (it_cls, e->key, e->value))
273 e->key, 275 {
274 e->value)) 276 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
275 {
276 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
277 return GNUNET_SYSERR; 277 return GNUNET_SYSERR;
278 } 278 }
279 } 279 }
280 count++; 280 count++;
281 } 281 }
@@ -294,9 +294,9 @@ GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32
294 */ 294 */
295static void 295static void
296update_next_cache (struct GNUNET_CONTAINER_MultiHashMap32 *map, 296update_next_cache (struct GNUNET_CONTAINER_MultiHashMap32 *map,
297 const struct MapEntry *me) 297 const struct MapEntry *me)
298{ 298{
299 for (unsigned int i=0;i<map->next_cache_off;i++) 299 for (unsigned int i = 0; i < map->next_cache_off; i++)
300 if (map->next_cache[i] == me) 300 if (map->next_cache[i] == me)
301 map->next_cache[i] = me->next; 301 map->next_cache[i] = me->next;
302} 302}
@@ -314,9 +314,10 @@ update_next_cache (struct GNUNET_CONTAINER_MultiHashMap32 *map,
314 * is not in the map 314 * is not in the map
315 */ 315 */
316int 316int
317GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map, 317GNUNET_CONTAINER_multihashmap32_remove (
318 uint32_t key, 318 struct GNUNET_CONTAINER_MultiHashMap32 *map,
319 const void *value) 319 uint32_t key,
320 const void *value)
320{ 321{
321 struct MapEntry *e; 322 struct MapEntry *e;
322 struct MapEntry *p; 323 struct MapEntry *p;
@@ -329,14 +330,13 @@ GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *
329 e = map->map[i]; 330 e = map->map[i];
330 while (e != NULL) 331 while (e != NULL)
331 { 332 {
332 if ( (key == e->key) && (value == e->value) ) 333 if ((key == e->key) && (value == e->value))
333 { 334 {
334 if (p == NULL) 335 if (p == NULL)
335 map->map[i] = e->next; 336 map->map[i] = e->next;
336 else 337 else
337 p->next = e->next; 338 p->next = e->next;
338 update_next_cache (map, 339 update_next_cache (map, e);
339 e);
340 GNUNET_free (e); 340 GNUNET_free (e);
341 map->size--; 341 map->size--;
342 return GNUNET_YES; 342 return GNUNET_YES;
@@ -357,8 +357,9 @@ GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *
357 * @return number of values removed 357 * @return number of values removed
358 */ 358 */
359int 359int
360GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map, 360GNUNET_CONTAINER_multihashmap32_remove_all (
361 uint32_t key) 361 struct GNUNET_CONTAINER_MultiHashMap32 *map,
362 uint32_t key)
362{ 363{
363 struct MapEntry *e; 364 struct MapEntry *e;
364 struct MapEntry *p; 365 struct MapEntry *p;
@@ -379,8 +380,7 @@ GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap
379 map->map[i] = e->next; 380 map->map[i] = e->next;
380 else 381 else
381 p->next = e->next; 382 p->next = e->next;
382 update_next_cache (map, 383 update_next_cache (map, e);
383 e);
384 GNUNET_free (e); 384 GNUNET_free (e);
385 map->size--; 385 map->size--;
386 if (p == NULL) 386 if (p == NULL)
@@ -409,8 +409,9 @@ GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap
409 * #GNUNET_NO if not 409 * #GNUNET_NO if not
410 */ 410 */
411int 411int
412GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map, 412GNUNET_CONTAINER_multihashmap32_contains (
413 uint32_t key) 413 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
414 uint32_t key)
414{ 415{
415 struct MapEntry *e; 416 struct MapEntry *e;
416 417
@@ -436,16 +437,17 @@ GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHas
436 * #GNUNET_NO if not 437 * #GNUNET_NO if not
437 */ 438 */
438int 439int
439GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map, 440GNUNET_CONTAINER_multihashmap32_contains_value (
440 uint32_t key, 441 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
441 const void *value) 442 uint32_t key,
443 const void *value)
442{ 444{
443 struct MapEntry *e; 445 struct MapEntry *e;
444 446
445 e = map->map[idx_of (map, key)]; 447 e = map->map[idx_of (map, key)];
446 while (e != NULL) 448 while (e != NULL)
447 { 449 {
448 if ( (key == e->key) && (e->value == value) ) 450 if ((key == e->key) && (e->value == value))
449 return GNUNET_YES; 451 return GNUNET_YES;
450 e = e->next; 452 e = e->next;
451 } 453 }
@@ -475,8 +477,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap32 *map)
475 new_len = old_len; /* never use 0 */ 477 new_len = old_len; /* never use 0 */
476 if (new_len == old_len) 478 if (new_len == old_len)
477 return; /* nothing changed */ 479 return; /* nothing changed */
478 new_map = GNUNET_malloc_large (new_len * 480 new_map = GNUNET_malloc_large (new_len * sizeof (struct MapEntry *));
479 sizeof (struct MapEntry *));
480 if (NULL == new_map) 481 if (NULL == new_map)
481 return; /* grow not possible */ 482 return; /* grow not possible */
482 map->modification_counter++; 483 map->modification_counter++;
@@ -509,10 +510,11 @@ grow (struct GNUNET_CONTAINER_MultiHashMap32 *map)
509 * value already exists 510 * value already exists
510 */ 511 */
511int 512int
512GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 513GNUNET_CONTAINER_multihashmap32_put (
513 *map, uint32_t key, void *value, 514 struct GNUNET_CONTAINER_MultiHashMap32 *map,
514 enum GNUNET_CONTAINER_MultiHashMapOption 515 uint32_t key,
515 opt) 516 void *value,
517 enum GNUNET_CONTAINER_MultiHashMapOption opt)
516{ 518{
517 struct MapEntry *e; 519 struct MapEntry *e;
518 unsigned int i; 520 unsigned int i;
@@ -560,10 +562,11 @@ GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32
560 * GNUNET_SYSERR if it aborted iteration 562 * GNUNET_SYSERR if it aborted iteration
561 */ 563 */
562int 564int
563GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashMap32 *map, 565GNUNET_CONTAINER_multihashmap32_get_multiple (
564 uint32_t key, 566 struct GNUNET_CONTAINER_MultiHashMap32 *map,
565 GNUNET_CONTAINER_HashMapIterator32 it, 567 uint32_t key,
566 void *it_cls) 568 GNUNET_CONTAINER_MulitHashMapIterator32Callback it,
569 void *it_cls)
567{ 570{
568 int count; 571 int count;
569 struct MapEntry *e; 572 struct MapEntry *e;
@@ -579,14 +582,11 @@ GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashM
579 *ce = e->next; 582 *ce = e->next;
580 if (key != e->key) 583 if (key != e->key)
581 continue; 584 continue;
582 if ( (NULL != it) && 585 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, e->value)))
583 (GNUNET_OK != it (it_cls, 586 {
584 key, 587 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
585 e->value)) ) 588 return GNUNET_SYSERR;
586 { 589 }
587 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
588 return GNUNET_SYSERR;
589 }
590 count++; 590 count++;
591 } 591 }
592 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); 592 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
@@ -607,7 +607,8 @@ GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashM
607 * @return an iterator over the given multihashmap @a map 607 * @return an iterator over the given multihashmap @a map
608 */ 608 */
609struct GNUNET_CONTAINER_MultiHashMap32Iterator * 609struct GNUNET_CONTAINER_MultiHashMap32Iterator *
610GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap32 *map) 610GNUNET_CONTAINER_multihashmap32_iterator_create (
611 const struct GNUNET_CONTAINER_MultiHashMap32 *map)
611{ 612{
612 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter; 613 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter;
613 614
@@ -634,9 +635,10 @@ GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_M
634 * #GNUNET_NO if we are out of elements 635 * #GNUNET_NO if we are out of elements
635 */ 636 */
636int 637int
637GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter, 638GNUNET_CONTAINER_multihashmap32_iterator_next (
638 uint32_t *key, 639 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
639 const void **value) 640 uint32_t *key,
641 const void **value)
640{ 642{
641 /* make sure the map has not been modified */ 643 /* make sure the map has not been modified */
642 GNUNET_assert (iter->modification_counter == iter->map->modification_counter); 644 GNUNET_assert (iter->modification_counter == iter->map->modification_counter);
@@ -668,7 +670,8 @@ GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHash
668 * @param iter the iterator to destroy 670 * @param iter the iterator to destroy
669 */ 671 */
670void 672void
671GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter) 673GNUNET_CONTAINER_multihashmap32_iterator_destroy (
674 struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
672{ 675{
673 GNUNET_free (iter); 676 GNUNET_free (iter);
674} 677}
diff --git a/src/util/container_multiuuidmap.c b/src/util/container_multiuuidmap.c
index 49eb64cfe..dd21fd128 100644
--- a/src/util/container_multiuuidmap.c
+++ b/src/util/container_multiuuidmap.c
@@ -338,7 +338,7 @@ GNUNET_CONTAINER_multiuuidmap_get (
338int 338int
339GNUNET_CONTAINER_multiuuidmap_iterate ( 339GNUNET_CONTAINER_multiuuidmap_iterate (
340 struct GNUNET_CONTAINER_MultiUuidmap *map, 340 struct GNUNET_CONTAINER_MultiUuidmap *map,
341 GNUNET_CONTAINER_MultiUuidmapIterator it, 341 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it,
342 void *it_cls) 342 void *it_cls)
343{ 343{
344 int count; 344 int count;
@@ -802,7 +802,7 @@ int
802GNUNET_CONTAINER_multiuuidmap_get_multiple ( 802GNUNET_CONTAINER_multiuuidmap_get_multiple (
803 struct GNUNET_CONTAINER_MultiUuidmap *map, 803 struct GNUNET_CONTAINER_MultiUuidmap *map,
804 const struct GNUNET_Uuid *key, 804 const struct GNUNET_Uuid *key,
805 GNUNET_CONTAINER_MultiUuidmapIterator it, 805 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it,
806 void *it_cls) 806 void *it_cls)
807{ 807{
808 int count; 808 int count;
@@ -868,7 +868,7 @@ GNUNET_CONTAINER_multiuuidmap_get_multiple (
868unsigned int 868unsigned int
869GNUNET_CONTAINER_multiuuidmap_get_random ( 869GNUNET_CONTAINER_multiuuidmap_get_random (
870 const struct GNUNET_CONTAINER_MultiUuidmap *map, 870 const struct GNUNET_CONTAINER_MultiUuidmap *map,
871 GNUNET_CONTAINER_MultiUuidmapIterator it, 871 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it,
872 void *it_cls) 872 void *it_cls)
873{ 873{
874 unsigned int off; 874 unsigned int off;