aboutsummaryrefslogtreecommitdiff
path: root/src/util/container_multishortmap.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-04 11:52:52 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-04 11:52:52 +0200
commit9ce956ea4c93f038995a21c6c1c0133eee6bff75 (patch)
treea77d69671a84ab7199bd3d6f8473011f13b87a49 /src/util/container_multishortmap.c
parentce4a47a9937aa30075b8cc8624bdb1332cd69a2d (diff)
downloadgnunet-9ce956ea4c93f038995a21c6c1c0133eee6bff75.tar.gz
gnunet-9ce956ea4c93f038995a21c6c1c0133eee6bff75.zip
memcmp -> GNUNET_memcmp
Diffstat (limited to 'src/util/container_multishortmap.c')
-rw-r--r--src/util/container_multishortmap.c384
1 files changed, 173 insertions, 211 deletions
diff --git a/src/util/container_multishortmap.c b/src/util/container_multishortmap.c
index 966e23d35..0371b0a48 100644
--- a/src/util/container_multishortmap.c
+++ b/src/util/container_multishortmap.c
@@ -26,7 +26,8 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28 28
29#define LOG(kind,...) GNUNET_log_from (kind, "util-container-multishortmap", __VA_ARGS__) 29#define LOG(kind, ...) \
30 GNUNET_log_from (kind, "util-container-multishortmap", __VA_ARGS__)
30 31
31/** 32/**
32 * Maximum recursion depth for callbacks of 33 * Maximum recursion depth for callbacks of
@@ -57,7 +58,6 @@ struct BigMapEntry
57 * Key for the entry. 58 * Key for the entry.
58 */ 59 */
59 struct GNUNET_ShortHashCode key; 60 struct GNUNET_ShortHashCode key;
60
61}; 61};
62 62
63 63
@@ -81,7 +81,6 @@ struct SmallMapEntry
81 * Key for the entry. 81 * Key for the entry.
82 */ 82 */
83 const struct GNUNET_ShortHashCode *key; 83 const struct GNUNET_ShortHashCode *key;
84
85}; 84};
86 85
87 86
@@ -146,7 +145,6 @@ struct GNUNET_CONTAINER_MultiShortmap
146 * than #NEXT_CACHE_SIZE. 145 * than #NEXT_CACHE_SIZE.
147 */ 146 */
148 unsigned int next_cache_off; 147 unsigned int next_cache_off;
149
150}; 148};
151 149
152 150
@@ -195,15 +193,13 @@ struct GNUNET_CONTAINER_MultiShortmapIterator
195 * @return NULL on error 193 * @return NULL on error
196 */ 194 */
197struct GNUNET_CONTAINER_MultiShortmap * 195struct GNUNET_CONTAINER_MultiShortmap *
198GNUNET_CONTAINER_multishortmap_create (unsigned int len, 196GNUNET_CONTAINER_multishortmap_create (unsigned int len, int do_not_copy_keys)
199 int do_not_copy_keys)
200{ 197{
201 struct GNUNET_CONTAINER_MultiShortmap *map; 198 struct GNUNET_CONTAINER_MultiShortmap *map;
202 199
203 GNUNET_assert (len > 0); 200 GNUNET_assert (len > 0);
204 map = GNUNET_new (struct GNUNET_CONTAINER_MultiShortmap); 201 map = GNUNET_new (struct GNUNET_CONTAINER_MultiShortmap);
205 map->map = GNUNET_malloc_large (len * 202 map->map = GNUNET_malloc_large (len * sizeof (union MapEntry));
206 sizeof (union MapEntry));
207 if (NULL == map->map) 203 if (NULL == map->map)
208 { 204 {
209 GNUNET_free (map); 205 GNUNET_free (map);
@@ -222,7 +218,8 @@ GNUNET_CONTAINER_multishortmap_create (unsigned int len,
222 * @param map the map 218 * @param map the map
223 */ 219 */
224void 220void
225GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *map) 221GNUNET_CONTAINER_multishortmap_destroy (
222 struct GNUNET_CONTAINER_MultiShortmap *map)
226{ 223{
227 GNUNET_assert (0 == map->next_cache_off); 224 GNUNET_assert (0 == map->next_cache_off);
228 for (unsigned int i = 0; i < map->map_length; i++) 225 for (unsigned int i = 0; i < map->map_length; i++)
@@ -238,8 +235,8 @@ GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *m
238 nxt = me.sme; 235 nxt = me.sme;
239 while (NULL != (sme = nxt)) 236 while (NULL != (sme = nxt))
240 { 237 {
241 nxt = sme->next; 238 nxt = sme->next;
242 GNUNET_free (sme); 239 GNUNET_free (sme);
243 } 240 }
244 me.sme = NULL; 241 me.sme = NULL;
245 } 242 }
@@ -251,8 +248,8 @@ GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *m
251 nxt = me.bme; 248 nxt = me.bme;
252 while (NULL != (bme = nxt)) 249 while (NULL != (bme = nxt))
253 { 250 {
254 nxt = bme->next; 251 nxt = bme->next;
255 GNUNET_free (bme); 252 GNUNET_free (bme);
256 } 253 }
257 me.bme = NULL; 254 me.bme = NULL;
258 } 255 }
@@ -288,7 +285,8 @@ idx_of (const struct GNUNET_CONTAINER_MultiShortmap *map,
288 * @return the number of key value pairs 285 * @return the number of key value pairs
289 */ 286 */
290unsigned int 287unsigned int
291GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap *map) 288GNUNET_CONTAINER_multishortmap_size (
289 const struct GNUNET_CONTAINER_MultiShortmap *map)
292{ 290{
293 return map->size; 291 return map->size;
294} 292}
@@ -305,8 +303,9 @@ GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap
305 * key-value pairs with value NULL 303 * key-value pairs with value NULL
306 */ 304 */
307void * 305void *
308GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map, 306GNUNET_CONTAINER_multishortmap_get (
309 const struct GNUNET_ShortHashCode *key) 307 const struct GNUNET_CONTAINER_MultiShortmap *map,
308 const struct GNUNET_ShortHashCode *key)
310{ 309{
311 union MapEntry me; 310 union MapEntry me;
312 311
@@ -314,18 +313,14 @@ GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap
314 if (map->use_small_entries) 313 if (map->use_small_entries)
315 { 314 {
316 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) 315 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
317 if (0 == memcmp (key, 316 if (0 == GNUNET_memcmp (key, sme->key))
318 sme->key, 317 return sme->value;
319 sizeof (struct GNUNET_ShortHashCode)))
320 return sme->value;
321 } 318 }
322 else 319 else
323 { 320 {
324 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) 321 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
325 if (0 == memcmp (key, 322 if (0 == GNUNET_memcmp (key, &bme->key))
326 &bme->key, 323 return bme->value;
327 sizeof (struct GNUNET_ShortHashCode)))
328 return bme->value;
329 } 324 }
330 return NULL; 325 return NULL;
331} 326}
@@ -341,9 +336,10 @@ GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap
341 * #GNUNET_SYSERR if it aborted iteration 336 * #GNUNET_SYSERR if it aborted iteration
342 */ 337 */
343int 338int
344GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *map, 339GNUNET_CONTAINER_multishortmap_iterate (
345 GNUNET_CONTAINER_ShortmapIterator it, 340 struct GNUNET_CONTAINER_MultiShortmap *map,
346 void *it_cls) 341 GNUNET_CONTAINER_ShortmapIterator it,
342 void *it_cls)
347{ 343{
348 int count; 344 int count;
349 union MapEntry me; 345 union MapEntry me;
@@ -364,16 +360,13 @@ GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *m
364 ce->sme = me.sme; 360 ce->sme = me.sme;
365 while (NULL != (sme = ce->sme)) 361 while (NULL != (sme = ce->sme))
366 { 362 {
367 ce->sme = sme->next; 363 ce->sme = sme->next;
368 if ( (NULL != it) && 364 if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
369 (GNUNET_OK != it (it_cls, 365 {
370 sme->key, 366 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
371 sme->value)) ) 367 return GNUNET_SYSERR;
372 { 368 }
373 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); 369 count++;
374 return GNUNET_SYSERR;
375 }
376 count++;
377 } 370 }
378 } 371 }
379 else 372 else
@@ -383,19 +376,17 @@ GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *m
383 ce->bme = me.bme; 376 ce->bme = me.bme;
384 while (NULL != (bme = ce->bme)) 377 while (NULL != (bme = ce->bme))
385 { 378 {
386 ce->bme = bme->next; 379 ce->bme = bme->next;
387 if (NULL != it) 380 if (NULL != it)
388 { 381 {
389 kc = bme->key; 382 kc = bme->key;
390 if (GNUNET_OK != it (it_cls, 383 if (GNUNET_OK != it (it_cls, &kc, bme->value))
391 &kc, 384 {
392 bme->value)) 385 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
393 { 386 return GNUNET_SYSERR;
394 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); 387 }
395 return GNUNET_SYSERR; 388 }
396 } 389 count++;
397 }
398 count++;
399 } 390 }
400 } 391 }
401 } 392 }
@@ -413,9 +404,9 @@ GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *m
413 */ 404 */
414static void 405static void
415update_next_cache_bme (struct GNUNET_CONTAINER_MultiShortmap *map, 406update_next_cache_bme (struct GNUNET_CONTAINER_MultiShortmap *map,
416 const struct BigMapEntry *bme) 407 const struct BigMapEntry *bme)
417{ 408{
418 for (unsigned int i=0;i<map->next_cache_off;i++) 409 for (unsigned int i = 0; i < map->next_cache_off; i++)
419 if (map->next_cache[i].bme == bme) 410 if (map->next_cache[i].bme == bme)
420 map->next_cache[i].bme = bme->next; 411 map->next_cache[i].bme = bme->next;
421} 412}
@@ -430,9 +421,9 @@ update_next_cache_bme (struct GNUNET_CONTAINER_MultiShortmap *map,
430 */ 421 */
431static void 422static void
432update_next_cache_sme (struct GNUNET_CONTAINER_MultiShortmap *map, 423update_next_cache_sme (struct GNUNET_CONTAINER_MultiShortmap *map,
433 const struct SmallMapEntry *sme) 424 const struct SmallMapEntry *sme)
434{ 425{
435 for (unsigned int i=0;i<map->next_cache_off;i++) 426 for (unsigned int i = 0; i < map->next_cache_off; i++)
436 if (map->next_cache[i].sme == sme) 427 if (map->next_cache[i].sme == sme)
437 map->next_cache[i].sme = sme->next; 428 map->next_cache[i].sme = sme->next;
438} 429}
@@ -450,9 +441,10 @@ update_next_cache_sme (struct GNUNET_CONTAINER_MultiShortmap *map,
450 * is not in the map 441 * is not in the map
451 */ 442 */
452int 443int
453GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map, 444GNUNET_CONTAINER_multishortmap_remove (
454 const struct GNUNET_ShortHashCode *key, 445 struct GNUNET_CONTAINER_MultiShortmap *map,
455 const void *value) 446 const struct GNUNET_ShortHashCode *key,
447 const void *value)
456{ 448{
457 union MapEntry me; 449 union MapEntry me;
458 unsigned int i; 450 unsigned int i;
@@ -466,20 +458,16 @@ GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *ma
466 458
467 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) 459 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
468 { 460 {
469 if ((0 == memcmp (key, 461 if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
470 sme->key,
471 sizeof (struct GNUNET_ShortHashCode))) &&
472 (value == sme->value))
473 { 462 {
474 if (NULL == p) 463 if (NULL == p)
475 map->map[i].sme = sme->next; 464 map->map[i].sme = sme->next;
476 else 465 else
477 p->next = sme->next; 466 p->next = sme->next;
478 update_next_cache_sme (map, 467 update_next_cache_sme (map, sme);
479 sme); 468 GNUNET_free (sme);
480 GNUNET_free (sme); 469 map->size--;
481 map->size--; 470 return GNUNET_YES;
482 return GNUNET_YES;
483 } 471 }
484 p = sme; 472 p = sme;
485 } 473 }
@@ -490,20 +478,16 @@ GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *ma
490 478
491 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) 479 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
492 { 480 {
493 if ((0 == memcmp (key, 481 if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
494 &bme->key,
495 sizeof (struct GNUNET_ShortHashCode))) &&
496 (value == bme->value))
497 { 482 {
498 if (NULL == p) 483 if (NULL == p)
499 map->map[i].bme = bme->next; 484 map->map[i].bme = bme->next;
500 else 485 else
501 p->next = bme->next; 486 p->next = bme->next;
502 update_next_cache_bme (map, 487 update_next_cache_bme (map, bme);
503 bme); 488 GNUNET_free (bme);
504 GNUNET_free (bme); 489 map->size--;
505 map->size--; 490 return GNUNET_YES;
506 return GNUNET_YES;
507 } 491 }
508 p = bme; 492 p = bme;
509 } 493 }
@@ -521,8 +505,9 @@ GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *ma
521 * @return number of values removed 505 * @return number of values removed
522 */ 506 */
523int 507int
524GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map, 508GNUNET_CONTAINER_multishortmap_remove_all (
525 const struct GNUNET_ShortHashCode *key) 509 struct GNUNET_CONTAINER_MultiShortmap *map,
510 const struct GNUNET_ShortHashCode *key)
526{ 511{
527 union MapEntry me; 512 union MapEntry me;
528 unsigned int i; 513 unsigned int i;
@@ -542,26 +527,25 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap
542 sme = me.sme; 527 sme = me.sme;
543 while (NULL != sme) 528 while (NULL != sme)
544 { 529 {
545 if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode))) 530 if (0 == GNUNET_memcmp (key, sme->key))
546 { 531 {
547 if (NULL == p) 532 if (NULL == p)
548 map->map[i].sme = sme->next; 533 map->map[i].sme = sme->next;
549 else 534 else
550 p->next = sme->next; 535 p->next = sme->next;
551 update_next_cache_sme (map, 536 update_next_cache_sme (map, sme);
552 sme); 537 GNUNET_free (sme);
553 GNUNET_free (sme); 538 map->size--;
554 map->size--; 539 if (NULL == p)
555 if (NULL == p) 540 sme = map->map[i].sme;
556 sme = map->map[i].sme; 541 else
557 else 542 sme = p->next;
558 sme = p->next; 543 ret++;
559 ret++;
560 } 544 }
561 else 545 else
562 { 546 {
563 p = sme; 547 p = sme;
564 sme = sme->next; 548 sme = sme->next;
565 } 549 }
566 } 550 }
567 } 551 }
@@ -574,26 +558,25 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap
574 bme = me.bme; 558 bme = me.bme;
575 while (NULL != bme) 559 while (NULL != bme)
576 { 560 {
577 if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode))) 561 if (0 == GNUNET_memcmp (key, &bme->key))
578 { 562 {
579 if (NULL == p) 563 if (NULL == p)
580 map->map[i].bme = bme->next; 564 map->map[i].bme = bme->next;
581 else 565 else
582 p->next = bme->next; 566 p->next = bme->next;
583 update_next_cache_bme (map, 567 update_next_cache_bme (map, bme);
584 bme); 568 GNUNET_free (bme);
585 GNUNET_free (bme); 569 map->size--;
586 map->size--; 570 if (NULL == p)
587 if (NULL == p) 571 bme = map->map[i].bme;
588 bme = map->map[i].bme; 572 else
589 else 573 bme = p->next;
590 bme = p->next; 574 ret++;
591 ret++;
592 } 575 }
593 else 576 else
594 { 577 {
595 p = bme; 578 p = bme;
596 bme = bme->next; 579 bme = bme->next;
597 } 580 }
598 } 581 }
599 } 582 }
@@ -611,8 +594,9 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap
611 * #GNUNET_NO if not 594 * #GNUNET_NO if not
612 */ 595 */
613int 596int
614GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map, 597GNUNET_CONTAINER_multishortmap_contains (
615 const struct GNUNET_ShortHashCode *key) 598 const struct GNUNET_CONTAINER_MultiShortmap *map,
599 const struct GNUNET_ShortHashCode *key)
616{ 600{
617 union MapEntry me; 601 union MapEntry me;
618 602
@@ -620,18 +604,14 @@ GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShor
620 if (map->use_small_entries) 604 if (map->use_small_entries)
621 { 605 {
622 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) 606 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
623 if (0 == memcmp (key, 607 if (0 == GNUNET_memcmp (key, sme->key))
624 sme->key, 608 return GNUNET_YES;
625 sizeof (struct GNUNET_ShortHashCode)))
626 return GNUNET_YES;
627 } 609 }
628 else 610 else
629 { 611 {
630 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) 612 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
631 if (0 == memcmp (key, 613 if (0 == GNUNET_memcmp (key, &bme->key))
632 &bme->key, 614 return GNUNET_YES;
633 sizeof (struct GNUNET_ShortHashCode)))
634 return GNUNET_YES;
635 } 615 }
636 return GNUNET_NO; 616 return GNUNET_NO;
637} 617}
@@ -648,9 +628,10 @@ GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShor
648 * #GNUNET_NO if not 628 * #GNUNET_NO if not
649 */ 629 */
650int 630int
651GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map, 631GNUNET_CONTAINER_multishortmap_contains_value (
652 const struct GNUNET_ShortHashCode *key, 632 const struct GNUNET_CONTAINER_MultiShortmap *map,
653 const void *value) 633 const struct GNUNET_ShortHashCode *key,
634 const void *value)
654{ 635{
655 union MapEntry me; 636 union MapEntry me;
656 637
@@ -658,20 +639,14 @@ GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_Mul
658 if (map->use_small_entries) 639 if (map->use_small_entries)
659 { 640 {
660 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) 641 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
661 if ( (0 == memcmp (key, 642 if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
662 sme->key, 643 return GNUNET_YES;
663 sizeof (struct GNUNET_ShortHashCode))) &&
664 (sme->value == value) )
665 return GNUNET_YES;
666 } 644 }
667 else 645 else
668 { 646 {
669 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) 647 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
670 if ( (0 == memcmp (key, 648 if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
671 &bme->key, 649 return GNUNET_YES;
672 sizeof (struct GNUNET_ShortHashCode))) &&
673 (bme->value == value) )
674 return GNUNET_YES;
675 } 650 }
676 return GNUNET_NO; 651 return GNUNET_NO;
677} 652}
@@ -698,8 +673,7 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map)
698 new_len = old_len; /* never use 0 */ 673 new_len = old_len; /* never use 0 */
699 if (new_len == old_len) 674 if (new_len == old_len)
700 return; /* nothing changed */ 675 return; /* nothing changed */
701 new_map = GNUNET_malloc_large (new_len * 676 new_map = GNUNET_malloc_large (new_len * sizeof (union MapEntry));
702 sizeof (union MapEntry));
703 if (NULL == new_map) 677 if (NULL == new_map)
704 return; /* grow not possible */ 678 return; /* grow not possible */
705 map->modification_counter++; 679 map->modification_counter++;
@@ -713,10 +687,10 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map)
713 687
714 while (NULL != (sme = old_map[i].sme)) 688 while (NULL != (sme = old_map[i].sme))
715 { 689 {
716 old_map[i].sme = sme->next; 690 old_map[i].sme = sme->next;
717 idx = idx_of (map, sme->key); 691 idx = idx_of (map, sme->key);
718 sme->next = new_map[idx].sme; 692 sme->next = new_map[idx].sme;
719 new_map[idx].sme = sme; 693 new_map[idx].sme = sme;
720 } 694 }
721 } 695 }
722 else 696 else
@@ -725,10 +699,10 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map)
725 699
726 while (NULL != (bme = old_map[i].bme)) 700 while (NULL != (bme = old_map[i].bme))
727 { 701 {
728 old_map[i].bme = bme->next; 702 old_map[i].bme = bme->next;
729 idx = idx_of (map, &bme->key); 703 idx = idx_of (map, &bme->key);
730 bme->next = new_map[idx].bme; 704 bme->next = new_map[idx].bme;
731 new_map[idx].bme = bme; 705 new_map[idx].bme = bme;
732 } 706 }
733 } 707 }
734 } 708 }
@@ -749,10 +723,11 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map)
749 * value already exists 723 * value already exists
750 */ 724 */
751int 725int
752GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, 726GNUNET_CONTAINER_multishortmap_put (
753 const struct GNUNET_ShortHashCode *key, 727 struct GNUNET_CONTAINER_MultiShortmap *map,
754 void *value, 728 const struct GNUNET_ShortHashCode *key,
755 enum GNUNET_CONTAINER_MultiHashMapOption opt) 729 void *value,
730 enum GNUNET_CONTAINER_MultiHashMapOption opt)
756{ 731{
757 union MapEntry me; 732 union MapEntry me;
758 unsigned int i; 733 unsigned int i;
@@ -765,28 +740,24 @@ GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map,
765 if (map->use_small_entries) 740 if (map->use_small_entries)
766 { 741 {
767 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) 742 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
768 if (0 == memcmp (key, 743 if (0 == GNUNET_memcmp (key, sme->key))
769 sme->key, 744 {
770 sizeof (struct GNUNET_ShortHashCode))) 745 if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
771 { 746 return GNUNET_SYSERR;
772 if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) 747 sme->value = value;
773 return GNUNET_SYSERR; 748 return GNUNET_NO;
774 sme->value = value; 749 }
775 return GNUNET_NO;
776 }
777 } 750 }
778 else 751 else
779 { 752 {
780 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) 753 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
781 if (0 == memcmp (key, 754 if (0 == GNUNET_memcmp (key, &bme->key))
782 &bme->key, 755 {
783 sizeof (struct GNUNET_ShortHashCode))) 756 if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
784 { 757 return GNUNET_SYSERR;
785 if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) 758 bme->value = value;
786 return GNUNET_SYSERR; 759 return GNUNET_NO;
787 bme->value = value; 760 }
788 return GNUNET_NO;
789 }
790 } 761 }
791 } 762 }
792 if (map->size / 3 >= map->map_length / 4) 763 if (map->size / 3 >= map->map_length / 4)
@@ -830,10 +801,11 @@ GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map,
830 * #GNUNET_SYSERR if it aborted iteration 801 * #GNUNET_SYSERR if it aborted iteration
831 */ 802 */
832int 803int
833GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortmap *map, 804GNUNET_CONTAINER_multishortmap_get_multiple (
834 const struct GNUNET_ShortHashCode *key, 805 struct GNUNET_CONTAINER_MultiShortmap *map,
835 GNUNET_CONTAINER_ShortmapIterator it, 806 const struct GNUNET_ShortHashCode *key,
836 void *it_cls) 807 GNUNET_CONTAINER_ShortmapIterator it,
808 void *it_cls)
837{ 809{
838 int count; 810 int count;
839 union MapEntry me; 811 union MapEntry me;
@@ -851,17 +823,12 @@ GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortm
851 while (NULL != (sme = ce->sme)) 823 while (NULL != (sme = ce->sme))
852 { 824 {
853 ce->sme = sme->next; 825 ce->sme = sme->next;
854 if (0 != memcmp (key, 826 if (0 != GNUNET_memcmp (key, sme->key))
855 sme->key, 827 continue;
856 sizeof (struct GNUNET_ShortHashCode))) 828 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
857 continue;
858 if ( (NULL != it) &&
859 (GNUNET_OK != it (it_cls,
860 key,
861 sme->value)) )
862 { 829 {
863 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); 830 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
864 return GNUNET_SYSERR; 831 return GNUNET_SYSERR;
865 } 832 }
866 count++; 833 count++;
867 } 834 }
@@ -874,17 +841,12 @@ GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortm
874 while (NULL != (bme = ce->bme)) 841 while (NULL != (bme = ce->bme))
875 { 842 {
876 ce->bme = bme->next; 843 ce->bme = bme->next;
877 if (0 != memcmp (key, 844 if (0 != GNUNET_memcmp (key, &bme->key))
878 &bme->key, 845 continue;
879 sizeof (struct GNUNET_ShortHashCode))) 846 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
880 continue;
881 if ( (NULL != it) &&
882 (GNUNET_OK != it (it_cls,
883 key,
884 bme->value)) )
885 { 847 {
886 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); 848 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
887 return GNUNET_SYSERR; 849 return GNUNET_SYSERR;
888 } 850 }
889 count++; 851 count++;
890 } 852 }
@@ -906,9 +868,10 @@ GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortm
906 * @return the number of key value pairs processed, zero or one. 868 * @return the number of key value pairs processed, zero or one.
907 */ 869 */
908unsigned int 870unsigned int
909GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiShortmap *map, 871GNUNET_CONTAINER_multishortmap_get_random (
910 GNUNET_CONTAINER_ShortmapIterator it, 872 const struct GNUNET_CONTAINER_MultiShortmap *map,
911 void *it_cls) 873 GNUNET_CONTAINER_ShortmapIterator it,
874 void *it_cls)
912{ 875{
913 unsigned int off; 876 unsigned int off;
914 union MapEntry me; 877 union MapEntry me;
@@ -917,8 +880,7 @@ GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiSh
917 return 0; 880 return 0;
918 if (NULL == it) 881 if (NULL == it)
919 return 1; 882 return 1;
920 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 883 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, map->size);
921 map->size);
922 for (unsigned int idx = 0; idx < map->map_length; idx++) 884 for (unsigned int idx = 0; idx < map->map_length; idx++)
923 { 885 {
924 me = map->map[idx]; 886 me = map->map[idx];
@@ -928,9 +890,7 @@ GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiSh
928 { 890 {
929 if (0 == off) 891 if (0 == off)
930 { 892 {
931 if (GNUNET_OK != it (it_cls, 893 if (GNUNET_OK != it (it_cls, sme->key, sme->value))
932 sme->key,
933 sme->value))
934 return GNUNET_SYSERR; 894 return GNUNET_SYSERR;
935 return 1; 895 return 1;
936 } 896 }
@@ -943,8 +903,7 @@ GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiSh
943 { 903 {
944 if (0 == off) 904 if (0 == off)
945 { 905 {
946 if (GNUNET_OK != it (it_cls, 906 if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
947 &bme->key, bme->value))
948 return GNUNET_SYSERR; 907 return GNUNET_SYSERR;
949 return 1; 908 return 1;
950 } 909 }
@@ -970,7 +929,8 @@ GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiSh
970 * @return an iterator over the given multishortmap 'map' 929 * @return an iterator over the given multishortmap 'map'
971 */ 930 */
972struct GNUNET_CONTAINER_MultiShortmapIterator * 931struct GNUNET_CONTAINER_MultiShortmapIterator *
973GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_MultiShortmap *map) 932GNUNET_CONTAINER_multishortmap_iterator_create (
933 const struct GNUNET_CONTAINER_MultiShortmap *map)
974{ 934{
975 struct GNUNET_CONTAINER_MultiShortmapIterator *iter; 935 struct GNUNET_CONTAINER_MultiShortmapIterator *iter;
976 936
@@ -997,9 +957,10 @@ GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_Mu
997 * #GNUNET_NO if we are out of elements 957 * #GNUNET_NO if we are out of elements
998 */ 958 */
999int 959int
1000GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter, 960GNUNET_CONTAINER_multishortmap_iterator_next (
1001 struct GNUNET_ShortHashCode *key, 961 struct GNUNET_CONTAINER_MultiShortmapIterator *iter,
1002 const void **value) 962 struct GNUNET_ShortHashCode *key,
963 const void **value)
1003{ 964{
1004 /* make sure the map has not been modified */ 965 /* make sure the map has not been modified */
1005 GNUNET_assert (iter->modification_counter == iter->map->modification_counter); 966 GNUNET_assert (iter->modification_counter == iter->map->modification_counter);
@@ -1046,7 +1007,8 @@ GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShort
1046 * @param iter the iterator to destroy 1007 * @param iter the iterator to destroy
1047 */ 1008 */
1048void 1009void
1049GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiShortmapIterator *iter) 1010GNUNET_CONTAINER_multishortmap_iterator_destroy (
1011 struct GNUNET_CONTAINER_MultiShortmapIterator *iter)
1050{ 1012{
1051 GNUNET_free (iter); 1013 GNUNET_free (iter);
1052} 1014}