diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-04 11:52:52 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-04 11:52:52 +0200 |
commit | 9ce956ea4c93f038995a21c6c1c0133eee6bff75 (patch) | |
tree | a77d69671a84ab7199bd3d6f8473011f13b87a49 /src/util | |
parent | ce4a47a9937aa30075b8cc8624bdb1332cd69a2d (diff) | |
download | gnunet-9ce956ea4c93f038995a21c6c1c0133eee6bff75.tar.gz gnunet-9ce956ea4c93f038995a21c6c1c0133eee6bff75.zip |
memcmp -> GNUNET_memcmp
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/container_multihashmap.c | 388 | ||||
-rw-r--r-- | src/util/container_multipeermap.c | 378 | ||||
-rw-r--r-- | src/util/container_multishortmap.c | 384 |
3 files changed, 519 insertions, 631 deletions
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c index 7605ea151..165f04149 100644 --- a/src/util/container_multihashmap.c +++ b/src/util/container_multihashmap.c | |||
@@ -26,7 +26,8 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_container_lib.h" | 27 | #include "gnunet_container_lib.h" |
28 | 28 | ||
29 | #define LOG(kind,...) GNUNET_log_from (kind, "util-container-multihashmap", __VA_ARGS__) | 29 | #define LOG(kind, ...) \ |
30 | GNUNET_log_from (kind, "util-container-multihashmap", __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_HashCode key; | 60 | struct GNUNET_HashCode 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_HashCode *key; | 83 | const struct GNUNET_HashCode *key; |
84 | |||
85 | }; | 84 | }; |
86 | 85 | ||
87 | 86 | ||
@@ -194,8 +193,7 @@ struct GNUNET_CONTAINER_MultiHashMapIterator | |||
194 | * @return NULL on error | 193 | * @return NULL on error |
195 | */ | 194 | */ |
196 | struct GNUNET_CONTAINER_MultiHashMap * | 195 | struct GNUNET_CONTAINER_MultiHashMap * |
197 | GNUNET_CONTAINER_multihashmap_create (unsigned int len, | 196 | GNUNET_CONTAINER_multihashmap_create (unsigned int len, int do_not_copy_keys) |
198 | int do_not_copy_keys) | ||
199 | { | 197 | { |
200 | struct GNUNET_CONTAINER_MultiHashMap *hm; | 198 | struct GNUNET_CONTAINER_MultiHashMap *hm; |
201 | 199 | ||
@@ -207,7 +205,7 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len, | |||
207 | /* application *explicitly* requested very large map, hopefully | 205 | /* application *explicitly* requested very large map, hopefully |
208 | it checks the return value... */ | 206 | it checks the return value... */ |
209 | s = len * sizeof (union MapEntry); | 207 | s = len * sizeof (union MapEntry); |
210 | if ( (s / sizeof (union MapEntry)) != len) | 208 | if ((s / sizeof (union MapEntry)) != len) |
211 | return NULL; /* integer overflow on multiplication */ | 209 | return NULL; /* integer overflow on multiplication */ |
212 | if (NULL == (hm->map = GNUNET_malloc_large (s))) | 210 | if (NULL == (hm->map = GNUNET_malloc_large (s))) |
213 | { | 211 | { |
@@ -221,8 +219,7 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len, | |||
221 | } | 219 | } |
222 | else | 220 | else |
223 | { | 221 | { |
224 | hm->map = GNUNET_new_array (len, | 222 | hm->map = GNUNET_new_array (len, union MapEntry); |
225 | union MapEntry); | ||
226 | } | 223 | } |
227 | hm->map_length = len; | 224 | hm->map_length = len; |
228 | hm->use_small_entries = do_not_copy_keys; | 225 | hm->use_small_entries = do_not_copy_keys; |
@@ -237,7 +234,8 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len, | |||
237 | * @param map the map | 234 | * @param map the map |
238 | */ | 235 | */ |
239 | void | 236 | void |
240 | GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map) | 237 | GNUNET_CONTAINER_multihashmap_destroy ( |
238 | struct GNUNET_CONTAINER_MultiHashMap *map) | ||
241 | { | 239 | { |
242 | GNUNET_assert (0 == map->next_cache_off); | 240 | GNUNET_assert (0 == map->next_cache_off); |
243 | for (unsigned int i = 0; i < map->map_length; i++) | 241 | for (unsigned int i = 0; i < map->map_length; i++) |
@@ -253,8 +251,8 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map | |||
253 | nxt = me.sme; | 251 | nxt = me.sme; |
254 | while (NULL != (sme = nxt)) | 252 | while (NULL != (sme = nxt)) |
255 | { | 253 | { |
256 | nxt = sme->next; | 254 | nxt = sme->next; |
257 | GNUNET_free (sme); | 255 | GNUNET_free (sme); |
258 | } | 256 | } |
259 | me.sme = NULL; | 257 | me.sme = NULL; |
260 | } | 258 | } |
@@ -266,8 +264,8 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map | |||
266 | nxt = me.bme; | 264 | nxt = me.bme; |
267 | while (NULL != (bme = nxt)) | 265 | while (NULL != (bme = nxt)) |
268 | { | 266 | { |
269 | nxt = bme->next; | 267 | nxt = bme->next; |
270 | GNUNET_free (bme); | 268 | GNUNET_free (bme); |
271 | } | 269 | } |
272 | me.bme = NULL; | 270 | me.bme = NULL; |
273 | } | 271 | } |
@@ -300,7 +298,8 @@ idx_of (const struct GNUNET_CONTAINER_MultiHashMap *map, | |||
300 | * @return the number of key value pairs | 298 | * @return the number of key value pairs |
301 | */ | 299 | */ |
302 | unsigned int | 300 | unsigned int |
303 | GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map) | 301 | GNUNET_CONTAINER_multihashmap_size ( |
302 | const struct GNUNET_CONTAINER_MultiHashMap *map) | ||
304 | { | 303 | { |
305 | return map->size; | 304 | return map->size; |
306 | } | 305 | } |
@@ -317,8 +316,9 @@ GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap * | |||
317 | * key-value pairs with value NULL | 316 | * key-value pairs with value NULL |
318 | */ | 317 | */ |
319 | void * | 318 | void * |
320 | GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map, | 319 | GNUNET_CONTAINER_multihashmap_get ( |
321 | const struct GNUNET_HashCode *key) | 320 | const struct GNUNET_CONTAINER_MultiHashMap *map, |
321 | const struct GNUNET_HashCode *key) | ||
322 | { | 322 | { |
323 | union MapEntry me; | 323 | union MapEntry me; |
324 | 324 | ||
@@ -328,20 +328,16 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *m | |||
328 | struct SmallMapEntry *sme; | 328 | struct SmallMapEntry *sme; |
329 | 329 | ||
330 | for (sme = me.sme; NULL != sme; sme = sme->next) | 330 | for (sme = me.sme; NULL != sme; sme = sme->next) |
331 | if (0 == memcmp (key, | 331 | if (0 == GNUNET_memcmp (key, sme->key)) |
332 | sme->key, | 332 | return sme->value; |
333 | sizeof (struct GNUNET_HashCode))) | ||
334 | return sme->value; | ||
335 | } | 333 | } |
336 | else | 334 | else |
337 | { | 335 | { |
338 | struct BigMapEntry *bme; | 336 | struct BigMapEntry *bme; |
339 | 337 | ||
340 | for (bme = me.bme; NULL != bme; bme = bme->next) | 338 | for (bme = me.bme; NULL != bme; bme = bme->next) |
341 | if (0 == memcmp (key, | 339 | if (0 == GNUNET_memcmp (key, &bme->key)) |
342 | &bme->key, | 340 | return bme->value; |
343 | sizeof (struct GNUNET_HashCode))) | ||
344 | return bme->value; | ||
345 | } | 341 | } |
346 | return NULL; | 342 | return NULL; |
347 | } | 343 | } |
@@ -357,9 +353,10 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *m | |||
357 | * #GNUNET_SYSERR if it aborted iteration | 353 | * #GNUNET_SYSERR if it aborted iteration |
358 | */ | 354 | */ |
359 | int | 355 | int |
360 | GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map, | 356 | GNUNET_CONTAINER_multihashmap_iterate ( |
361 | GNUNET_CONTAINER_HashMapIterator it, | 357 | struct GNUNET_CONTAINER_MultiHashMap *map, |
362 | void *it_cls) | 358 | GNUNET_CONTAINER_HashMapIterator it, |
359 | void *it_cls) | ||
363 | { | 360 | { |
364 | int count; | 361 | int count; |
365 | union MapEntry me; | 362 | union MapEntry me; |
@@ -380,18 +377,16 @@ GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map | |||
380 | ce->sme = me.sme; | 377 | ce->sme = me.sme; |
381 | while (NULL != (sme = ce->sme)) | 378 | while (NULL != (sme = ce->sme)) |
382 | { | 379 | { |
383 | ce->sme = sme->next; | 380 | ce->sme = sme->next; |
384 | if (NULL != it) | 381 | if (NULL != it) |
385 | { | 382 | { |
386 | if (GNUNET_OK != it (it_cls, | 383 | if (GNUNET_OK != it (it_cls, sme->key, sme->value)) |
387 | sme->key, | 384 | { |
388 | sme->value)) | 385 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
389 | { | 386 | return GNUNET_SYSERR; |
390 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 387 | } |
391 | return GNUNET_SYSERR; | 388 | } |
392 | } | 389 | count++; |
393 | } | ||
394 | count++; | ||
395 | } | 390 | } |
396 | } | 391 | } |
397 | else | 392 | else |
@@ -401,19 +396,17 @@ GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map | |||
401 | ce->bme = me.bme; | 396 | ce->bme = me.bme; |
402 | while (NULL != (bme = ce->bme)) | 397 | while (NULL != (bme = ce->bme)) |
403 | { | 398 | { |
404 | ce->bme = bme->next; | 399 | ce->bme = bme->next; |
405 | if (NULL != it) | 400 | if (NULL != it) |
406 | { | 401 | { |
407 | kc = bme->key; | 402 | kc = bme->key; |
408 | if (GNUNET_OK != it (it_cls, | 403 | if (GNUNET_OK != it (it_cls, &kc, bme->value)) |
409 | &kc, | 404 | { |
410 | bme->value)) | 405 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
411 | { | 406 | return GNUNET_SYSERR; |
412 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 407 | } |
413 | return GNUNET_SYSERR; | 408 | } |
414 | } | 409 | count++; |
415 | } | ||
416 | count++; | ||
417 | } | 410 | } |
418 | } | 411 | } |
419 | } | 412 | } |
@@ -431,9 +424,9 @@ GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map | |||
431 | */ | 424 | */ |
432 | static void | 425 | static void |
433 | update_next_cache_bme (struct GNUNET_CONTAINER_MultiHashMap *map, | 426 | update_next_cache_bme (struct GNUNET_CONTAINER_MultiHashMap *map, |
434 | const struct BigMapEntry *bme) | 427 | const struct BigMapEntry *bme) |
435 | { | 428 | { |
436 | for (unsigned int i=0;i<map->next_cache_off;i++) | 429 | for (unsigned int i = 0; i < map->next_cache_off; i++) |
437 | if (map->next_cache[i].bme == bme) | 430 | if (map->next_cache[i].bme == bme) |
438 | map->next_cache[i].bme = bme->next; | 431 | map->next_cache[i].bme = bme->next; |
439 | } | 432 | } |
@@ -448,9 +441,9 @@ update_next_cache_bme (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
448 | */ | 441 | */ |
449 | static void | 442 | static void |
450 | update_next_cache_sme (struct GNUNET_CONTAINER_MultiHashMap *map, | 443 | update_next_cache_sme (struct GNUNET_CONTAINER_MultiHashMap *map, |
451 | const struct SmallMapEntry *sme) | 444 | const struct SmallMapEntry *sme) |
452 | { | 445 | { |
453 | for (unsigned int i=0;i<map->next_cache_off;i++) | 446 | for (unsigned int i = 0; i < map->next_cache_off; i++) |
454 | if (map->next_cache[i].sme == sme) | 447 | if (map->next_cache[i].sme == sme) |
455 | map->next_cache[i].sme = sme->next; | 448 | map->next_cache[i].sme = sme->next; |
456 | } | 449 | } |
@@ -470,7 +463,7 @@ update_next_cache_sme (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
470 | int | 463 | int |
471 | GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, | 464 | GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, |
472 | const struct GNUNET_HashCode *key, | 465 | const struct GNUNET_HashCode *key, |
473 | const void *value) | 466 | const void *value) |
474 | { | 467 | { |
475 | union MapEntry me; | 468 | union MapEntry me; |
476 | unsigned int i; | 469 | unsigned int i; |
@@ -486,20 +479,16 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
486 | p = NULL; | 479 | p = NULL; |
487 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) | 480 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) |
488 | { | 481 | { |
489 | if ( (0 == memcmp (key, | 482 | if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value)) |
490 | sme->key, | ||
491 | sizeof (struct GNUNET_HashCode))) && | ||
492 | (value == sme->value) ) | ||
493 | { | 483 | { |
494 | if (NULL == p) | 484 | if (NULL == p) |
495 | map->map[i].sme = sme->next; | 485 | map->map[i].sme = sme->next; |
496 | else | 486 | else |
497 | p->next = sme->next; | 487 | p->next = sme->next; |
498 | update_next_cache_sme (map, | 488 | update_next_cache_sme (map, sme); |
499 | sme); | 489 | GNUNET_free (sme); |
500 | GNUNET_free (sme); | 490 | map->size--; |
501 | map->size--; | 491 | return GNUNET_YES; |
502 | return GNUNET_YES; | ||
503 | } | 492 | } |
504 | p = sme; | 493 | p = sme; |
505 | } | 494 | } |
@@ -511,20 +500,16 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
511 | p = NULL; | 500 | p = NULL; |
512 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) | 501 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) |
513 | { | 502 | { |
514 | if ( (0 == memcmp (key, | 503 | if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value)) |
515 | &bme->key, | ||
516 | sizeof (struct GNUNET_HashCode))) && | ||
517 | (value == bme->value) ) | ||
518 | { | 504 | { |
519 | if (NULL == p) | 505 | if (NULL == p) |
520 | map->map[i].bme = bme->next; | 506 | map->map[i].bme = bme->next; |
521 | else | 507 | else |
522 | p->next = bme->next; | 508 | p->next = bme->next; |
523 | update_next_cache_bme (map, | 509 | update_next_cache_bme (map, bme); |
524 | bme); | 510 | GNUNET_free (bme); |
525 | GNUNET_free (bme); | 511 | map->size--; |
526 | map->size--; | 512 | return GNUNET_YES; |
527 | return GNUNET_YES; | ||
528 | } | 513 | } |
529 | p = bme; | 514 | p = bme; |
530 | } | 515 | } |
@@ -542,8 +527,9 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
542 | * @return number of values removed | 527 | * @return number of values removed |
543 | */ | 528 | */ |
544 | int | 529 | int |
545 | GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map, | 530 | GNUNET_CONTAINER_multihashmap_remove_all ( |
546 | const struct GNUNET_HashCode *key) | 531 | struct GNUNET_CONTAINER_MultiHashMap *map, |
532 | const struct GNUNET_HashCode *key) | ||
547 | { | 533 | { |
548 | union MapEntry me; | 534 | union MapEntry me; |
549 | unsigned int i; | 535 | unsigned int i; |
@@ -563,28 +549,25 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap * | |||
563 | sme = me.sme; | 549 | sme = me.sme; |
564 | while (NULL != sme) | 550 | while (NULL != sme) |
565 | { | 551 | { |
566 | if (0 == memcmp (key, | 552 | if (0 == GNUNET_memcmp (key, sme->key)) |
567 | sme->key, | ||
568 | sizeof (struct GNUNET_HashCode))) | ||
569 | { | 553 | { |
570 | if (NULL == p) | 554 | if (NULL == p) |
571 | map->map[i].sme = sme->next; | 555 | map->map[i].sme = sme->next; |
572 | else | 556 | else |
573 | p->next = sme->next; | 557 | p->next = sme->next; |
574 | update_next_cache_sme (map, | 558 | update_next_cache_sme (map, sme); |
575 | sme); | 559 | GNUNET_free (sme); |
576 | GNUNET_free (sme); | 560 | map->size--; |
577 | map->size--; | 561 | if (NULL == p) |
578 | if (NULL == p) | 562 | sme = map->map[i].sme; |
579 | sme = map->map[i].sme; | 563 | else |
580 | else | 564 | sme = p->next; |
581 | sme = p->next; | 565 | ret++; |
582 | ret++; | ||
583 | } | 566 | } |
584 | else | 567 | else |
585 | { | 568 | { |
586 | p = sme; | 569 | p = sme; |
587 | sme = sme->next; | 570 | sme = sme->next; |
588 | } | 571 | } |
589 | } | 572 | } |
590 | } | 573 | } |
@@ -597,28 +580,25 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap * | |||
597 | bme = me.bme; | 580 | bme = me.bme; |
598 | while (NULL != bme) | 581 | while (NULL != bme) |
599 | { | 582 | { |
600 | if (0 == memcmp (key, | 583 | if (0 == GNUNET_memcmp (key, &bme->key)) |
601 | &bme->key, | ||
602 | sizeof (struct GNUNET_HashCode))) | ||
603 | { | 584 | { |
604 | if (NULL == p) | 585 | if (NULL == p) |
605 | map->map[i].bme = bme->next; | 586 | map->map[i].bme = bme->next; |
606 | else | 587 | else |
607 | p->next = bme->next; | 588 | p->next = bme->next; |
608 | update_next_cache_bme (map, | 589 | update_next_cache_bme (map, bme); |
609 | bme); | 590 | GNUNET_free (bme); |
610 | GNUNET_free (bme); | 591 | map->size--; |
611 | map->size--; | 592 | if (NULL == p) |
612 | if (NULL == p) | 593 | bme = map->map[i].bme; |
613 | bme = map->map[i].bme; | 594 | else |
614 | else | 595 | bme = p->next; |
615 | bme = p->next; | 596 | ret++; |
616 | ret++; | ||
617 | } | 597 | } |
618 | else | 598 | else |
619 | { | 599 | { |
620 | p = bme; | 600 | p = bme; |
621 | bme = bme->next; | 601 | bme = bme->next; |
622 | } | 602 | } |
623 | } | 603 | } |
624 | } | 604 | } |
@@ -635,15 +615,12 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap * | |||
635 | * @return #GNUNET_OK (continue to iterate) | 615 | * @return #GNUNET_OK (continue to iterate) |
636 | */ | 616 | */ |
637 | static int | 617 | static int |
638 | remove_all (void *cls, | 618 | remove_all (void *cls, const struct GNUNET_HashCode *key, void *value) |
639 | const struct GNUNET_HashCode *key, | ||
640 | void *value) | ||
641 | { | 619 | { |
642 | struct GNUNET_CONTAINER_MultiHashMap *map = cls; | 620 | struct GNUNET_CONTAINER_MultiHashMap *map = cls; |
643 | 621 | ||
644 | GNUNET_CONTAINER_multihashmap_remove (map, | 622 | GNUNET_assert (GNUNET_YES == |
645 | key, | 623 | GNUNET_CONTAINER_multihashmap_remove (map, key, value)); |
646 | value); | ||
647 | return GNUNET_OK; | 624 | return GNUNET_OK; |
648 | } | 625 | } |
649 | 626 | ||
@@ -662,9 +639,7 @@ GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map) | |||
662 | unsigned int ret; | 639 | unsigned int ret; |
663 | 640 | ||
664 | ret = map->size; | 641 | ret = map->size; |
665 | GNUNET_CONTAINER_multihashmap_iterate (map, | 642 | GNUNET_CONTAINER_multihashmap_iterate (map, &remove_all, map); |
666 | &remove_all, | ||
667 | map); | ||
668 | return ret; | 643 | return ret; |
669 | } | 644 | } |
670 | 645 | ||
@@ -679,9 +654,9 @@ GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map) | |||
679 | * #GNUNET_NO if not | 654 | * #GNUNET_NO if not |
680 | */ | 655 | */ |
681 | int | 656 | int |
682 | GNUNET_CONTAINER_multihashmap_contains (const struct | 657 | GNUNET_CONTAINER_multihashmap_contains ( |
683 | GNUNET_CONTAINER_MultiHashMap *map, | 658 | const struct GNUNET_CONTAINER_MultiHashMap *map, |
684 | const struct GNUNET_HashCode *key) | 659 | const struct GNUNET_HashCode *key) |
685 | { | 660 | { |
686 | union MapEntry me; | 661 | union MapEntry me; |
687 | 662 | ||
@@ -691,16 +666,16 @@ GNUNET_CONTAINER_multihashmap_contains (const struct | |||
691 | struct SmallMapEntry *sme; | 666 | struct SmallMapEntry *sme; |
692 | 667 | ||
693 | for (sme = me.sme; NULL != sme; sme = sme->next) | 668 | for (sme = me.sme; NULL != sme; sme = sme->next) |
694 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_HashCode))) | 669 | if (0 == GNUNET_memcmp (key, sme->key)) |
695 | return GNUNET_YES; | 670 | return GNUNET_YES; |
696 | } | 671 | } |
697 | else | 672 | else |
698 | { | 673 | { |
699 | struct BigMapEntry *bme; | 674 | struct BigMapEntry *bme; |
700 | 675 | ||
701 | for (bme = me.bme; NULL != bme; bme = bme->next) | 676 | for (bme = me.bme; NULL != bme; bme = bme->next) |
702 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_HashCode))) | 677 | if (0 == GNUNET_memcmp (key, &bme->key)) |
703 | return GNUNET_YES; | 678 | return GNUNET_YES; |
704 | } | 679 | } |
705 | return GNUNET_NO; | 680 | return GNUNET_NO; |
706 | } | 681 | } |
@@ -717,9 +692,10 @@ GNUNET_CONTAINER_multihashmap_contains (const struct | |||
717 | * #GNUNET_NO if not | 692 | * #GNUNET_NO if not |
718 | */ | 693 | */ |
719 | int | 694 | int |
720 | GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map, | 695 | GNUNET_CONTAINER_multihashmap_contains_value ( |
721 | const struct GNUNET_HashCode *key, | 696 | const struct GNUNET_CONTAINER_MultiHashMap *map, |
722 | const void *value) | 697 | const struct GNUNET_HashCode *key, |
698 | const void *value) | ||
723 | { | 699 | { |
724 | union MapEntry me; | 700 | union MapEntry me; |
725 | 701 | ||
@@ -729,22 +705,16 @@ GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_Mult | |||
729 | struct SmallMapEntry *sme; | 705 | struct SmallMapEntry *sme; |
730 | 706 | ||
731 | for (sme = me.sme; NULL != sme; sme = sme->next) | 707 | for (sme = me.sme; NULL != sme; sme = sme->next) |
732 | if ( (0 == memcmp (key, | 708 | if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value)) |
733 | sme->key, | 709 | return GNUNET_YES; |
734 | sizeof (struct GNUNET_HashCode))) && | ||
735 | (sme->value == value) ) | ||
736 | return GNUNET_YES; | ||
737 | } | 710 | } |
738 | else | 711 | else |
739 | { | 712 | { |
740 | struct BigMapEntry *bme; | 713 | struct BigMapEntry *bme; |
741 | 714 | ||
742 | for (bme = me.bme; NULL != bme; bme = bme->next) | 715 | for (bme = me.bme; NULL != bme; bme = bme->next) |
743 | if ( (0 == memcmp (key, | 716 | if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value)) |
744 | &bme->key, | 717 | return GNUNET_YES; |
745 | sizeof (struct GNUNET_HashCode))) && | ||
746 | (bme->value == value) ) | ||
747 | return GNUNET_YES; | ||
748 | } | 718 | } |
749 | return GNUNET_NO; | 719 | return GNUNET_NO; |
750 | } | 720 | } |
@@ -772,8 +742,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) | |||
772 | new_len = old_len; /* never use 0 */ | 742 | new_len = old_len; /* never use 0 */ |
773 | if (new_len == old_len) | 743 | if (new_len == old_len) |
774 | return; /* nothing changed */ | 744 | return; /* nothing changed */ |
775 | new_map = GNUNET_malloc_large (new_len * | 745 | new_map = GNUNET_malloc_large (new_len * sizeof (union MapEntry)); |
776 | sizeof (union MapEntry)); | ||
777 | if (NULL == new_map) | 746 | if (NULL == new_map) |
778 | return; /* grow not possible */ | 747 | return; /* grow not possible */ |
779 | map->modification_counter++; | 748 | map->modification_counter++; |
@@ -787,10 +756,10 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) | |||
787 | 756 | ||
788 | while (NULL != (sme = old_map[i].sme)) | 757 | while (NULL != (sme = old_map[i].sme)) |
789 | { | 758 | { |
790 | old_map[i].sme = sme->next; | 759 | old_map[i].sme = sme->next; |
791 | idx = idx_of (map, sme->key); | 760 | idx = idx_of (map, sme->key); |
792 | sme->next = new_map[idx].sme; | 761 | sme->next = new_map[idx].sme; |
793 | new_map[idx].sme = sme; | 762 | new_map[idx].sme = sme; |
794 | } | 763 | } |
795 | } | 764 | } |
796 | else | 765 | else |
@@ -799,10 +768,10 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) | |||
799 | 768 | ||
800 | while (NULL != (bme = old_map[i].bme)) | 769 | while (NULL != (bme = old_map[i].bme)) |
801 | { | 770 | { |
802 | old_map[i].bme = bme->next; | 771 | old_map[i].bme = bme->next; |
803 | idx = idx_of (map, &bme->key); | 772 | idx = idx_of (map, &bme->key); |
804 | bme->next = new_map[idx].bme; | 773 | bme->next = new_map[idx].bme; |
805 | new_map[idx].bme = bme; | 774 | new_map[idx].bme = bme; |
806 | } | 775 | } |
807 | } | 776 | } |
808 | } | 777 | } |
@@ -825,7 +794,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) | |||
825 | int | 794 | int |
826 | GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, | 795 | GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, |
827 | const struct GNUNET_HashCode *key, | 796 | const struct GNUNET_HashCode *key, |
828 | void *value, | 797 | void *value, |
829 | enum GNUNET_CONTAINER_MultiHashMapOption opt) | 798 | enum GNUNET_CONTAINER_MultiHashMapOption opt) |
830 | { | 799 | { |
831 | union MapEntry me; | 800 | union MapEntry me; |
@@ -841,26 +810,26 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
841 | struct SmallMapEntry *sme; | 810 | struct SmallMapEntry *sme; |
842 | 811 | ||
843 | for (sme = me.sme; NULL != sme; sme = sme->next) | 812 | for (sme = me.sme; NULL != sme; sme = sme->next) |
844 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_HashCode))) | 813 | if (0 == GNUNET_memcmp (key, sme->key)) |
845 | { | 814 | { |
846 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 815 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) |
847 | return GNUNET_SYSERR; | 816 | return GNUNET_SYSERR; |
848 | sme->value = value; | 817 | sme->value = value; |
849 | return GNUNET_NO; | 818 | return GNUNET_NO; |
850 | } | 819 | } |
851 | } | 820 | } |
852 | else | 821 | else |
853 | { | 822 | { |
854 | struct BigMapEntry *bme; | 823 | struct BigMapEntry *bme; |
855 | 824 | ||
856 | for (bme = me.bme; NULL != bme; bme = bme->next) | 825 | for (bme = me.bme; NULL != bme; bme = bme->next) |
857 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_HashCode))) | 826 | if (0 == GNUNET_memcmp (key, &bme->key)) |
858 | { | 827 | { |
859 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 828 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) |
860 | return GNUNET_SYSERR; | 829 | return GNUNET_SYSERR; |
861 | bme->value = value; | 830 | bme->value = value; |
862 | return GNUNET_NO; | 831 | return GNUNET_NO; |
863 | } | 832 | } |
864 | } | 833 | } |
865 | } | 834 | } |
866 | if (map->size / 3 >= map->map_length / 4) | 835 | if (map->size / 3 >= map->map_length / 4) |
@@ -904,10 +873,11 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
904 | * #GNUNET_SYSERR if it aborted iteration | 873 | * #GNUNET_SYSERR if it aborted iteration |
905 | */ | 874 | */ |
906 | int | 875 | int |
907 | GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap *map, | 876 | GNUNET_CONTAINER_multihashmap_get_multiple ( |
908 | const struct GNUNET_HashCode *key, | 877 | struct GNUNET_CONTAINER_MultiHashMap *map, |
909 | GNUNET_CONTAINER_HashMapIterator it, | 878 | const struct GNUNET_HashCode *key, |
910 | void *it_cls) | 879 | GNUNET_CONTAINER_HashMapIterator it, |
880 | void *it_cls) | ||
911 | { | 881 | { |
912 | int count; | 882 | int count; |
913 | union MapEntry *me; | 883 | union MapEntry *me; |
@@ -925,17 +895,12 @@ GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap | |||
925 | while (NULL != (sme = ce->sme)) | 895 | while (NULL != (sme = ce->sme)) |
926 | { | 896 | { |
927 | ce->sme = sme->next; | 897 | ce->sme = sme->next; |
928 | if (0 != memcmp (key, | 898 | if (0 != GNUNET_memcmp (key, sme->key)) |
929 | sme->key, | 899 | continue; |
930 | sizeof (struct GNUNET_HashCode))) | 900 | if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value))) |
931 | continue; | ||
932 | if ( (NULL != it) && | ||
933 | (GNUNET_OK != it (it_cls, | ||
934 | key, | ||
935 | sme->value))) | ||
936 | { | 901 | { |
937 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 902 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
938 | return GNUNET_SYSERR; | 903 | return GNUNET_SYSERR; |
939 | } | 904 | } |
940 | count++; | 905 | count++; |
941 | } | 906 | } |
@@ -948,17 +913,12 @@ GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap | |||
948 | while (NULL != (bme = ce->bme)) | 913 | while (NULL != (bme = ce->bme)) |
949 | { | 914 | { |
950 | ce->bme = bme->next; | 915 | ce->bme = bme->next; |
951 | if (0 != memcmp (key, | 916 | if (0 != GNUNET_memcmp (key, &bme->key)) |
952 | &bme->key, | 917 | continue; |
953 | sizeof (struct GNUNET_HashCode))) | 918 | if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value))) |
954 | continue; | ||
955 | if ( (NULL != it) && | ||
956 | (GNUNET_OK != it (it_cls, | ||
957 | key, | ||
958 | bme->value))) | ||
959 | { | 919 | { |
960 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 920 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
961 | return GNUNET_SYSERR; | 921 | return GNUNET_SYSERR; |
962 | } | 922 | } |
963 | count++; | 923 | count++; |
964 | } | 924 | } |
@@ -980,9 +940,10 @@ GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap | |||
980 | * @return the number of key value pairs processed, zero or one. | 940 | * @return the number of key value pairs processed, zero or one. |
981 | */ | 941 | */ |
982 | unsigned int | 942 | unsigned int |
983 | GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHashMap *map, | 943 | GNUNET_CONTAINER_multihashmap_get_random ( |
984 | GNUNET_CONTAINER_HashMapIterator it, | 944 | const struct GNUNET_CONTAINER_MultiHashMap *map, |
985 | void *it_cls) | 945 | GNUNET_CONTAINER_HashMapIterator it, |
946 | void *it_cls) | ||
986 | { | 947 | { |
987 | unsigned int off; | 948 | unsigned int off; |
988 | unsigned int idx; | 949 | unsigned int idx; |
@@ -992,8 +953,7 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHas | |||
992 | return 0; | 953 | return 0; |
993 | if (NULL == it) | 954 | if (NULL == it) |
994 | return 1; | 955 | return 1; |
995 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 956 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, map->size); |
996 | map->size); | ||
997 | for (idx = 0; idx < map->map_length; idx++) | 957 | for (idx = 0; idx < map->map_length; idx++) |
998 | { | 958 | { |
999 | me = map->map[idx]; | 959 | me = map->map[idx]; |
@@ -1008,9 +968,7 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHas | |||
1008 | nxt = sme->next; | 968 | nxt = sme->next; |
1009 | if (0 == off) | 969 | if (0 == off) |
1010 | { | 970 | { |
1011 | if (GNUNET_OK != it (it_cls, | 971 | if (GNUNET_OK != it (it_cls, sme->key, sme->value)) |
1012 | sme->key, | ||
1013 | sme->value)) | ||
1014 | return GNUNET_SYSERR; | 972 | return GNUNET_SYSERR; |
1015 | return 1; | 973 | return 1; |
1016 | } | 974 | } |
@@ -1028,8 +986,7 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHas | |||
1028 | nxt = bme->next; | 986 | nxt = bme->next; |
1029 | if (0 == off) | 987 | if (0 == off) |
1030 | { | 988 | { |
1031 | if (GNUNET_OK != it (it_cls, | 989 | if (GNUNET_OK != it (it_cls, &bme->key, bme->value)) |
1032 | &bme->key, bme->value)) | ||
1033 | return GNUNET_SYSERR; | 990 | return GNUNET_SYSERR; |
1034 | return 1; | 991 | return 1; |
1035 | } | 992 | } |
@@ -1055,7 +1012,8 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHas | |||
1055 | * @return an iterator over the given multihashmap 'map' | 1012 | * @return an iterator over the given multihashmap 'map' |
1056 | */ | 1013 | */ |
1057 | struct GNUNET_CONTAINER_MultiHashMapIterator * | 1014 | struct GNUNET_CONTAINER_MultiHashMapIterator * |
1058 | GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map) | 1015 | GNUNET_CONTAINER_multihashmap_iterator_create ( |
1016 | const struct GNUNET_CONTAINER_MultiHashMap *map) | ||
1059 | { | 1017 | { |
1060 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter; | 1018 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter; |
1061 | 1019 | ||
@@ -1082,9 +1040,10 @@ GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_Mul | |||
1082 | * #GNUNET_NO if we are out of elements | 1040 | * #GNUNET_NO if we are out of elements |
1083 | */ | 1041 | */ |
1084 | int | 1042 | int |
1085 | GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, | 1043 | GNUNET_CONTAINER_multihashmap_iterator_next ( |
1086 | struct GNUNET_HashCode *key, | 1044 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter, |
1087 | const void **value) | 1045 | struct GNUNET_HashCode *key, |
1046 | const void **value) | ||
1088 | { | 1047 | { |
1089 | /* make sure the map has not been modified */ | 1048 | /* make sure the map has not been modified */ |
1090 | GNUNET_assert (iter->modification_counter == iter->map->modification_counter); | 1049 | GNUNET_assert (iter->modification_counter == iter->map->modification_counter); |
@@ -1131,7 +1090,8 @@ GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMa | |||
1131 | * @param iter the iterator to destroy | 1090 | * @param iter the iterator to destroy |
1132 | */ | 1091 | */ |
1133 | void | 1092 | void |
1134 | GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter) | 1093 | GNUNET_CONTAINER_multihashmap_iterator_destroy ( |
1094 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter) | ||
1135 | { | 1095 | { |
1136 | GNUNET_free (iter); | 1096 | GNUNET_free (iter); |
1137 | } | 1097 | } |
diff --git a/src/util/container_multipeermap.c b/src/util/container_multipeermap.c index 613efc0a9..d03221cb5 100644 --- a/src/util/container_multipeermap.c +++ b/src/util/container_multipeermap.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-multipeermap", __VA_ARGS__) | 29 | #define LOG(kind, ...) \ |
30 | GNUNET_log_from (kind, "util-container-multipeermap", __VA_ARGS__) | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * Maximum recursion depth for callbacks of | 33 | * Maximum recursion depth for callbacks of |
@@ -56,7 +57,6 @@ struct BigMapEntry | |||
56 | * Key for the entry. | 57 | * Key for the entry. |
57 | */ | 58 | */ |
58 | struct GNUNET_PeerIdentity key; | 59 | struct GNUNET_PeerIdentity key; |
59 | |||
60 | }; | 60 | }; |
61 | 61 | ||
62 | 62 | ||
@@ -80,7 +80,6 @@ struct SmallMapEntry | |||
80 | * Key for the entry. | 80 | * Key for the entry. |
81 | */ | 81 | */ |
82 | const struct GNUNET_PeerIdentity *key; | 82 | const struct GNUNET_PeerIdentity *key; |
83 | |||
84 | }; | 83 | }; |
85 | 84 | ||
86 | 85 | ||
@@ -193,15 +192,13 @@ struct GNUNET_CONTAINER_MultiPeerMapIterator | |||
193 | * @return NULL on error | 192 | * @return NULL on error |
194 | */ | 193 | */ |
195 | struct GNUNET_CONTAINER_MultiPeerMap * | 194 | struct GNUNET_CONTAINER_MultiPeerMap * |
196 | GNUNET_CONTAINER_multipeermap_create (unsigned int len, | 195 | GNUNET_CONTAINER_multipeermap_create (unsigned int len, int do_not_copy_keys) |
197 | int do_not_copy_keys) | ||
198 | { | 196 | { |
199 | struct GNUNET_CONTAINER_MultiPeerMap *map; | 197 | struct GNUNET_CONTAINER_MultiPeerMap *map; |
200 | 198 | ||
201 | GNUNET_assert (len > 0); | 199 | GNUNET_assert (len > 0); |
202 | map = GNUNET_new (struct GNUNET_CONTAINER_MultiPeerMap); | 200 | map = GNUNET_new (struct GNUNET_CONTAINER_MultiPeerMap); |
203 | map->map = GNUNET_malloc_large (len * | 201 | map->map = GNUNET_malloc_large (len * sizeof (union MapEntry)); |
204 | sizeof (union MapEntry)); | ||
205 | if (NULL == map->map) | 202 | if (NULL == map->map) |
206 | { | 203 | { |
207 | GNUNET_free (map); | 204 | GNUNET_free (map); |
@@ -220,7 +217,8 @@ GNUNET_CONTAINER_multipeermap_create (unsigned int len, | |||
220 | * @param map the map | 217 | * @param map the map |
221 | */ | 218 | */ |
222 | void | 219 | void |
223 | GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map) | 220 | GNUNET_CONTAINER_multipeermap_destroy ( |
221 | struct GNUNET_CONTAINER_MultiPeerMap *map) | ||
224 | { | 222 | { |
225 | GNUNET_assert (0 == map->next_cache_off); | 223 | GNUNET_assert (0 == map->next_cache_off); |
226 | for (unsigned int i = 0; i < map->map_length; i++) | 224 | for (unsigned int i = 0; i < map->map_length; i++) |
@@ -236,8 +234,8 @@ GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map | |||
236 | nxt = me.sme; | 234 | nxt = me.sme; |
237 | while (NULL != (sme = nxt)) | 235 | while (NULL != (sme = nxt)) |
238 | { | 236 | { |
239 | nxt = sme->next; | 237 | nxt = sme->next; |
240 | GNUNET_free (sme); | 238 | GNUNET_free (sme); |
241 | } | 239 | } |
242 | me.sme = NULL; | 240 | me.sme = NULL; |
243 | } | 241 | } |
@@ -249,8 +247,8 @@ GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map | |||
249 | nxt = me.bme; | 247 | nxt = me.bme; |
250 | while (NULL != (bme = nxt)) | 248 | while (NULL != (bme = nxt)) |
251 | { | 249 | { |
252 | nxt = bme->next; | 250 | nxt = bme->next; |
253 | GNUNET_free (bme); | 251 | GNUNET_free (bme); |
254 | } | 252 | } |
255 | me.bme = NULL; | 253 | me.bme = NULL; |
256 | } | 254 | } |
@@ -274,9 +272,7 @@ idx_of (const struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
274 | unsigned int kx; | 272 | unsigned int kx; |
275 | 273 | ||
276 | GNUNET_assert (NULL != map); | 274 | GNUNET_assert (NULL != map); |
277 | GNUNET_memcpy (&kx, | 275 | GNUNET_memcpy (&kx, key, sizeof (kx)); |
278 | key, | ||
279 | sizeof (kx)); | ||
280 | return kx % map->map_length; | 276 | return kx % map->map_length; |
281 | } | 277 | } |
282 | 278 | ||
@@ -288,7 +284,8 @@ idx_of (const struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
288 | * @return the number of key value pairs | 284 | * @return the number of key value pairs |
289 | */ | 285 | */ |
290 | unsigned int | 286 | unsigned int |
291 | GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map) | 287 | GNUNET_CONTAINER_multipeermap_size ( |
288 | const struct GNUNET_CONTAINER_MultiPeerMap *map) | ||
292 | { | 289 | { |
293 | return map->size; | 290 | return map->size; |
294 | } | 291 | } |
@@ -305,8 +302,9 @@ GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap * | |||
305 | * key-value pairs with value NULL | 302 | * key-value pairs with value NULL |
306 | */ | 303 | */ |
307 | void * | 304 | void * |
308 | GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map, | 305 | GNUNET_CONTAINER_multipeermap_get ( |
309 | const struct GNUNET_PeerIdentity *key) | 306 | const struct GNUNET_CONTAINER_MultiPeerMap *map, |
307 | const struct GNUNET_PeerIdentity *key) | ||
310 | { | 308 | { |
311 | union MapEntry me; | 309 | union MapEntry me; |
312 | 310 | ||
@@ -314,18 +312,14 @@ GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *m | |||
314 | if (map->use_small_entries) | 312 | if (map->use_small_entries) |
315 | { | 313 | { |
316 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) | 314 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) |
317 | if (0 == memcmp (key, | 315 | if (0 == GNUNET_memcmp (key, sme->key)) |
318 | sme->key, | 316 | return sme->value; |
319 | sizeof (struct GNUNET_PeerIdentity))) | ||
320 | return sme->value; | ||
321 | } | 317 | } |
322 | else | 318 | else |
323 | { | 319 | { |
324 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) | 320 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) |
325 | if (0 == memcmp (key, | 321 | if (0 == GNUNET_memcmp (key, &bme->key)) |
326 | &bme->key, | 322 | return bme->value; |
327 | sizeof (struct GNUNET_PeerIdentity))) | ||
328 | return bme->value; | ||
329 | } | 323 | } |
330 | return NULL; | 324 | return NULL; |
331 | } | 325 | } |
@@ -341,9 +335,10 @@ GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *m | |||
341 | * #GNUNET_SYSERR if it aborted iteration | 335 | * #GNUNET_SYSERR if it aborted iteration |
342 | */ | 336 | */ |
343 | int | 337 | int |
344 | GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map, | 338 | GNUNET_CONTAINER_multipeermap_iterate ( |
345 | GNUNET_CONTAINER_PeerMapIterator it, | 339 | struct GNUNET_CONTAINER_MultiPeerMap *map, |
346 | void *it_cls) | 340 | GNUNET_CONTAINER_PeerMapIterator it, |
341 | void *it_cls) | ||
347 | { | 342 | { |
348 | int count; | 343 | int count; |
349 | union MapEntry me; | 344 | union MapEntry me; |
@@ -364,18 +359,16 @@ GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map | |||
364 | ce->sme = me.sme; | 359 | ce->sme = me.sme; |
365 | while (NULL != (sme = ce->sme)) | 360 | while (NULL != (sme = ce->sme)) |
366 | { | 361 | { |
367 | ce->sme = sme->next; | 362 | ce->sme = sme->next; |
368 | if (NULL != it) | 363 | if (NULL != it) |
369 | { | 364 | { |
370 | if (GNUNET_OK != it (it_cls, | 365 | if (GNUNET_OK != it (it_cls, sme->key, sme->value)) |
371 | sme->key, | 366 | { |
372 | sme->value)) | 367 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
373 | { | 368 | return GNUNET_SYSERR; |
374 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 369 | } |
375 | return GNUNET_SYSERR; | 370 | } |
376 | } | 371 | count++; |
377 | } | ||
378 | count++; | ||
379 | } | 372 | } |
380 | } | 373 | } |
381 | else | 374 | else |
@@ -385,19 +378,17 @@ GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map | |||
385 | ce->bme = me.bme; | 378 | ce->bme = me.bme; |
386 | while (NULL != (bme = ce->bme)) | 379 | while (NULL != (bme = ce->bme)) |
387 | { | 380 | { |
388 | ce->bme = bme->next; | 381 | ce->bme = bme->next; |
389 | if (NULL != it) | 382 | if (NULL != it) |
390 | { | 383 | { |
391 | kc = bme->key; | 384 | kc = bme->key; |
392 | if (GNUNET_OK != it (it_cls, | 385 | if (GNUNET_OK != it (it_cls, &kc, bme->value)) |
393 | &kc, | 386 | { |
394 | bme->value)) | 387 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
395 | { | 388 | return GNUNET_SYSERR; |
396 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 389 | } |
397 | return GNUNET_SYSERR; | 390 | } |
398 | } | 391 | count++; |
399 | } | ||
400 | count++; | ||
401 | } | 392 | } |
402 | } | 393 | } |
403 | } | 394 | } |
@@ -415,9 +406,9 @@ GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map | |||
415 | */ | 406 | */ |
416 | static void | 407 | static void |
417 | update_next_cache_bme (struct GNUNET_CONTAINER_MultiPeerMap *map, | 408 | update_next_cache_bme (struct GNUNET_CONTAINER_MultiPeerMap *map, |
418 | const struct BigMapEntry *bme) | 409 | const struct BigMapEntry *bme) |
419 | { | 410 | { |
420 | for (unsigned int i=0;i<map->next_cache_off;i++) | 411 | for (unsigned int i = 0; i < map->next_cache_off; i++) |
421 | if (map->next_cache[i].bme == bme) | 412 | if (map->next_cache[i].bme == bme) |
422 | map->next_cache[i].bme = bme->next; | 413 | map->next_cache[i].bme = bme->next; |
423 | } | 414 | } |
@@ -432,9 +423,9 @@ update_next_cache_bme (struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
432 | */ | 423 | */ |
433 | static void | 424 | static void |
434 | update_next_cache_sme (struct GNUNET_CONTAINER_MultiPeerMap *map, | 425 | update_next_cache_sme (struct GNUNET_CONTAINER_MultiPeerMap *map, |
435 | const struct SmallMapEntry *sme) | 426 | const struct SmallMapEntry *sme) |
436 | { | 427 | { |
437 | for (unsigned int i=0;i<map->next_cache_off;i++) | 428 | for (unsigned int i = 0; i < map->next_cache_off; i++) |
438 | if (map->next_cache[i].sme == sme) | 429 | if (map->next_cache[i].sme == sme) |
439 | map->next_cache[i].sme = sme->next; | 430 | map->next_cache[i].sme = sme->next; |
440 | } | 431 | } |
@@ -454,7 +445,7 @@ update_next_cache_sme (struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
454 | int | 445 | int |
455 | GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, | 446 | GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, |
456 | const struct GNUNET_PeerIdentity *key, | 447 | const struct GNUNET_PeerIdentity *key, |
457 | const void *value) | 448 | const void *value) |
458 | { | 449 | { |
459 | union MapEntry me; | 450 | union MapEntry me; |
460 | unsigned int i; | 451 | unsigned int i; |
@@ -468,18 +459,16 @@ GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
468 | 459 | ||
469 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) | 460 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) |
470 | { | 461 | { |
471 | if ((0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) && | 462 | if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value)) |
472 | (value == sme->value)) | ||
473 | { | 463 | { |
474 | if (NULL == p) | 464 | if (NULL == p) |
475 | map->map[i].sme = sme->next; | 465 | map->map[i].sme = sme->next; |
476 | else | 466 | else |
477 | p->next = sme->next; | 467 | p->next = sme->next; |
478 | update_next_cache_sme (map, | 468 | update_next_cache_sme (map, sme); |
479 | sme); | 469 | GNUNET_free (sme); |
480 | GNUNET_free (sme); | 470 | map->size--; |
481 | map->size--; | 471 | return GNUNET_YES; |
482 | return GNUNET_YES; | ||
483 | } | 472 | } |
484 | p = sme; | 473 | p = sme; |
485 | } | 474 | } |
@@ -490,20 +479,16 @@ GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
490 | 479 | ||
491 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) | 480 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) |
492 | { | 481 | { |
493 | if ((0 == memcmp (key, | 482 | if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value)) |
494 | &bme->key, | ||
495 | sizeof (struct GNUNET_PeerIdentity))) && | ||
496 | (value == bme->value)) | ||
497 | { | 483 | { |
498 | if (NULL == p) | 484 | if (NULL == p) |
499 | map->map[i].bme = bme->next; | 485 | map->map[i].bme = bme->next; |
500 | else | 486 | else |
501 | p->next = bme->next; | 487 | p->next = bme->next; |
502 | update_next_cache_bme (map, | 488 | update_next_cache_bme (map, bme); |
503 | bme); | 489 | GNUNET_free (bme); |
504 | GNUNET_free (bme); | 490 | map->size--; |
505 | map->size--; | 491 | return GNUNET_YES; |
506 | return GNUNET_YES; | ||
507 | } | 492 | } |
508 | p = bme; | 493 | p = bme; |
509 | } | 494 | } |
@@ -521,8 +506,9 @@ GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
521 | * @return number of values removed | 506 | * @return number of values removed |
522 | */ | 507 | */ |
523 | int | 508 | int |
524 | GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map, | 509 | GNUNET_CONTAINER_multipeermap_remove_all ( |
525 | const struct GNUNET_PeerIdentity *key) | 510 | struct GNUNET_CONTAINER_MultiPeerMap *map, |
511 | const struct GNUNET_PeerIdentity *key) | ||
526 | { | 512 | { |
527 | union MapEntry me; | 513 | union MapEntry me; |
528 | unsigned int i; | 514 | unsigned int i; |
@@ -542,28 +528,25 @@ GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap * | |||
542 | sme = me.sme; | 528 | sme = me.sme; |
543 | while (NULL != sme) | 529 | while (NULL != sme) |
544 | { | 530 | { |
545 | if (0 == memcmp (key, | 531 | if (0 == GNUNET_memcmp (key, sme->key)) |
546 | sme->key, | ||
547 | sizeof (struct GNUNET_PeerIdentity))) | ||
548 | { | 532 | { |
549 | if (NULL == p) | 533 | if (NULL == p) |
550 | map->map[i].sme = sme->next; | 534 | map->map[i].sme = sme->next; |
551 | else | 535 | else |
552 | p->next = sme->next; | 536 | p->next = sme->next; |
553 | update_next_cache_sme (map, | 537 | update_next_cache_sme (map, sme); |
554 | sme); | 538 | GNUNET_free (sme); |
555 | GNUNET_free (sme); | 539 | map->size--; |
556 | map->size--; | 540 | if (NULL == p) |
557 | if (NULL == p) | 541 | sme = map->map[i].sme; |
558 | sme = map->map[i].sme; | 542 | else |
559 | else | 543 | sme = p->next; |
560 | sme = p->next; | 544 | ret++; |
561 | ret++; | ||
562 | } | 545 | } |
563 | else | 546 | else |
564 | { | 547 | { |
565 | p = sme; | 548 | p = sme; |
566 | sme = sme->next; | 549 | sme = sme->next; |
567 | } | 550 | } |
568 | } | 551 | } |
569 | } | 552 | } |
@@ -576,28 +559,25 @@ GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap * | |||
576 | bme = me.bme; | 559 | bme = me.bme; |
577 | while (NULL != bme) | 560 | while (NULL != bme) |
578 | { | 561 | { |
579 | if (0 == memcmp (key, | 562 | if (0 == GNUNET_memcmp (key, &bme->key)) |
580 | &bme->key, | ||
581 | sizeof (struct GNUNET_PeerIdentity))) | ||
582 | { | 563 | { |
583 | if (NULL == p) | 564 | if (NULL == p) |
584 | map->map[i].bme = bme->next; | 565 | map->map[i].bme = bme->next; |
585 | else | 566 | else |
586 | p->next = bme->next; | 567 | p->next = bme->next; |
587 | update_next_cache_bme (map, | 568 | update_next_cache_bme (map, bme); |
588 | bme); | 569 | GNUNET_free (bme); |
589 | GNUNET_free (bme); | 570 | map->size--; |
590 | map->size--; | 571 | if (NULL == p) |
591 | if (NULL == p) | 572 | bme = map->map[i].bme; |
592 | bme = map->map[i].bme; | 573 | else |
593 | else | 574 | bme = p->next; |
594 | bme = p->next; | 575 | ret++; |
595 | ret++; | ||
596 | } | 576 | } |
597 | else | 577 | else |
598 | { | 578 | { |
599 | p = bme; | 579 | p = bme; |
600 | bme = bme->next; | 580 | bme = bme->next; |
601 | } | 581 | } |
602 | } | 582 | } |
603 | } | 583 | } |
@@ -615,8 +595,9 @@ GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap * | |||
615 | * #GNUNET_NO if not | 595 | * #GNUNET_NO if not |
616 | */ | 596 | */ |
617 | int | 597 | int |
618 | GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map, | 598 | GNUNET_CONTAINER_multipeermap_contains ( |
619 | const struct GNUNET_PeerIdentity *key) | 599 | const struct GNUNET_CONTAINER_MultiPeerMap *map, |
600 | const struct GNUNET_PeerIdentity *key) | ||
620 | { | 601 | { |
621 | union MapEntry me; | 602 | union MapEntry me; |
622 | 603 | ||
@@ -624,14 +605,14 @@ GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerM | |||
624 | if (map->use_small_entries) | 605 | if (map->use_small_entries) |
625 | { | 606 | { |
626 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) | 607 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) |
627 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) | 608 | if (0 == GNUNET_memcmp (key, sme->key)) |
628 | return GNUNET_YES; | 609 | return GNUNET_YES; |
629 | } | 610 | } |
630 | else | 611 | else |
631 | { | 612 | { |
632 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) | 613 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) |
633 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) | 614 | if (0 == GNUNET_memcmp (key, &bme->key)) |
634 | return GNUNET_YES; | 615 | return GNUNET_YES; |
635 | } | 616 | } |
636 | return GNUNET_NO; | 617 | return GNUNET_NO; |
637 | } | 618 | } |
@@ -648,9 +629,10 @@ GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerM | |||
648 | * #GNUNET_NO if not | 629 | * #GNUNET_NO if not |
649 | */ | 630 | */ |
650 | int | 631 | int |
651 | GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map, | 632 | GNUNET_CONTAINER_multipeermap_contains_value ( |
652 | const struct GNUNET_PeerIdentity *key, | 633 | const struct GNUNET_CONTAINER_MultiPeerMap *map, |
653 | const void *value) | 634 | const struct GNUNET_PeerIdentity *key, |
635 | const void *value) | ||
654 | { | 636 | { |
655 | union MapEntry me; | 637 | union MapEntry me; |
656 | 638 | ||
@@ -658,20 +640,14 @@ GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_Mult | |||
658 | if (map->use_small_entries) | 640 | if (map->use_small_entries) |
659 | { | 641 | { |
660 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) | 642 | for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) |
661 | if ( (0 == memcmp (key, | 643 | if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value)) |
662 | sme->key, | 644 | return GNUNET_YES; |
663 | sizeof (struct GNUNET_PeerIdentity))) && | ||
664 | (sme->value == value) ) | ||
665 | return GNUNET_YES; | ||
666 | } | 645 | } |
667 | else | 646 | else |
668 | { | 647 | { |
669 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) | 648 | for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) |
670 | if ( (0 == memcmp (key, | 649 | if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value)) |
671 | &bme->key, | 650 | return GNUNET_YES; |
672 | sizeof (struct GNUNET_PeerIdentity))) && | ||
673 | (bme->value == value) ) | ||
674 | return GNUNET_YES; | ||
675 | } | 651 | } |
676 | return GNUNET_NO; | 652 | return GNUNET_NO; |
677 | } | 653 | } |
@@ -699,8 +675,7 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map) | |||
699 | new_len = old_len; /* never use 0 */ | 675 | new_len = old_len; /* never use 0 */ |
700 | if (new_len == old_len) | 676 | if (new_len == old_len) |
701 | return; /* nothing changed */ | 677 | return; /* nothing changed */ |
702 | new_map = GNUNET_malloc_large (new_len * | 678 | new_map = GNUNET_malloc_large (new_len * sizeof (union MapEntry)); |
703 | sizeof (union MapEntry)); | ||
704 | if (NULL == new_map) | 679 | if (NULL == new_map) |
705 | return; /* grow not possible */ | 680 | return; /* grow not possible */ |
706 | map->modification_counter++; | 681 | map->modification_counter++; |
@@ -714,10 +689,10 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map) | |||
714 | 689 | ||
715 | while (NULL != (sme = old_map[i].sme)) | 690 | while (NULL != (sme = old_map[i].sme)) |
716 | { | 691 | { |
717 | old_map[i].sme = sme->next; | 692 | old_map[i].sme = sme->next; |
718 | idx = idx_of (map, sme->key); | 693 | idx = idx_of (map, sme->key); |
719 | sme->next = new_map[idx].sme; | 694 | sme->next = new_map[idx].sme; |
720 | new_map[idx].sme = sme; | 695 | new_map[idx].sme = sme; |
721 | } | 696 | } |
722 | } | 697 | } |
723 | else | 698 | else |
@@ -726,10 +701,10 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map) | |||
726 | 701 | ||
727 | while (NULL != (bme = old_map[i].bme)) | 702 | while (NULL != (bme = old_map[i].bme)) |
728 | { | 703 | { |
729 | old_map[i].bme = bme->next; | 704 | old_map[i].bme = bme->next; |
730 | idx = idx_of (map, &bme->key); | 705 | idx = idx_of (map, &bme->key); |
731 | bme->next = new_map[idx].bme; | 706 | bme->next = new_map[idx].bme; |
732 | new_map[idx].bme = bme; | 707 | new_map[idx].bme = bme; |
733 | } | 708 | } |
734 | } | 709 | } |
735 | } | 710 | } |
@@ -752,7 +727,7 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map) | |||
752 | int | 727 | int |
753 | GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, | 728 | GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, |
754 | const struct GNUNET_PeerIdentity *key, | 729 | const struct GNUNET_PeerIdentity *key, |
755 | void *value, | 730 | void *value, |
756 | enum GNUNET_CONTAINER_MultiHashMapOption opt) | 731 | enum GNUNET_CONTAINER_MultiHashMapOption opt) |
757 | { | 732 | { |
758 | union MapEntry me; | 733 | union MapEntry me; |
@@ -768,26 +743,26 @@ GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
768 | struct SmallMapEntry *sme; | 743 | struct SmallMapEntry *sme; |
769 | 744 | ||
770 | for (sme = me.sme; NULL != sme; sme = sme->next) | 745 | for (sme = me.sme; NULL != sme; sme = sme->next) |
771 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) | 746 | if (0 == GNUNET_memcmp (key, sme->key)) |
772 | { | 747 | { |
773 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 748 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) |
774 | return GNUNET_SYSERR; | 749 | return GNUNET_SYSERR; |
775 | sme->value = value; | 750 | sme->value = value; |
776 | return GNUNET_NO; | 751 | return GNUNET_NO; |
777 | } | 752 | } |
778 | } | 753 | } |
779 | else | 754 | else |
780 | { | 755 | { |
781 | struct BigMapEntry *bme; | 756 | struct BigMapEntry *bme; |
782 | 757 | ||
783 | for (bme = me.bme; NULL != bme; bme = bme->next) | 758 | for (bme = me.bme; NULL != bme; bme = bme->next) |
784 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) | 759 | if (0 == GNUNET_memcmp (key, &bme->key)) |
785 | { | 760 | { |
786 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 761 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) |
787 | return GNUNET_SYSERR; | 762 | return GNUNET_SYSERR; |
788 | bme->value = value; | 763 | bme->value = value; |
789 | return GNUNET_NO; | 764 | return GNUNET_NO; |
790 | } | 765 | } |
791 | } | 766 | } |
792 | } | 767 | } |
793 | if (map->size / 3 >= map->map_length / 4) | 768 | if (map->size / 3 >= map->map_length / 4) |
@@ -831,10 +806,11 @@ GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
831 | * #GNUNET_SYSERR if it aborted iteration | 806 | * #GNUNET_SYSERR if it aborted iteration |
832 | */ | 807 | */ |
833 | int | 808 | int |
834 | GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap *map, | 809 | GNUNET_CONTAINER_multipeermap_get_multiple ( |
835 | const struct GNUNET_PeerIdentity *key, | 810 | struct GNUNET_CONTAINER_MultiPeerMap *map, |
836 | GNUNET_CONTAINER_PeerMapIterator it, | 811 | const struct GNUNET_PeerIdentity *key, |
837 | void *it_cls) | 812 | GNUNET_CONTAINER_PeerMapIterator it, |
813 | void *it_cls) | ||
838 | { | 814 | { |
839 | int count; | 815 | int count; |
840 | union MapEntry me; | 816 | union MapEntry me; |
@@ -852,17 +828,12 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap | |||
852 | while (NULL != (sme = ce->sme)) | 828 | while (NULL != (sme = ce->sme)) |
853 | { | 829 | { |
854 | ce->sme = sme->next; | 830 | ce->sme = sme->next; |
855 | if (0 != memcmp (key, | 831 | if (0 != GNUNET_memcmp (key, sme->key)) |
856 | sme->key, | 832 | continue; |
857 | sizeof (struct GNUNET_PeerIdentity))) | 833 | if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value))) |
858 | continue; | ||
859 | if ( (NULL != it) && | ||
860 | (GNUNET_OK != it (it_cls, | ||
861 | key, | ||
862 | sme->value))) | ||
863 | { | 834 | { |
864 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 835 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
865 | return GNUNET_SYSERR; | 836 | return GNUNET_SYSERR; |
866 | } | 837 | } |
867 | count++; | 838 | count++; |
868 | } | 839 | } |
@@ -875,17 +846,12 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap | |||
875 | while (NULL != (bme = ce->bme)) | 846 | while (NULL != (bme = ce->bme)) |
876 | { | 847 | { |
877 | ce->bme = bme->next; | 848 | ce->bme = bme->next; |
878 | if (0 != memcmp (key, | 849 | if (0 != GNUNET_memcmp (key, &bme->key)) |
879 | &bme->key, | 850 | continue; |
880 | sizeof (struct GNUNET_PeerIdentity))) | 851 | if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value))) |
881 | continue; | ||
882 | if ( (NULL != it) && | ||
883 | (GNUNET_OK != it (it_cls, | ||
884 | key, | ||
885 | bme->value))) | ||
886 | { | 852 | { |
887 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 853 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
888 | return GNUNET_SYSERR; | 854 | return GNUNET_SYSERR; |
889 | } | 855 | } |
890 | count++; | 856 | count++; |
891 | } | 857 | } |
@@ -907,9 +873,10 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap | |||
907 | * @return the number of key value pairs processed, zero or one. | 873 | * @return the number of key value pairs processed, zero or one. |
908 | */ | 874 | */ |
909 | unsigned int | 875 | unsigned int |
910 | GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPeerMap *map, | 876 | GNUNET_CONTAINER_multipeermap_get_random ( |
911 | GNUNET_CONTAINER_PeerMapIterator it, | 877 | const struct GNUNET_CONTAINER_MultiPeerMap *map, |
912 | void *it_cls) | 878 | GNUNET_CONTAINER_PeerMapIterator it, |
879 | void *it_cls) | ||
913 | { | 880 | { |
914 | unsigned int off; | 881 | unsigned int off; |
915 | union MapEntry me; | 882 | union MapEntry me; |
@@ -918,8 +885,7 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPee | |||
918 | return 0; | 885 | return 0; |
919 | if (NULL == it) | 886 | if (NULL == it) |
920 | return 1; | 887 | return 1; |
921 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 888 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, map->size); |
922 | map->size); | ||
923 | for (unsigned int idx = 0; idx < map->map_length; idx++) | 889 | for (unsigned int idx = 0; idx < map->map_length; idx++) |
924 | { | 890 | { |
925 | me = map->map[idx]; | 891 | me = map->map[idx]; |
@@ -934,9 +900,7 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPee | |||
934 | nxt = sme->next; | 900 | nxt = sme->next; |
935 | if (0 == off) | 901 | if (0 == off) |
936 | { | 902 | { |
937 | if (GNUNET_OK != it (it_cls, | 903 | if (GNUNET_OK != it (it_cls, sme->key, sme->value)) |
938 | sme->key, | ||
939 | sme->value)) | ||
940 | return GNUNET_SYSERR; | 904 | return GNUNET_SYSERR; |
941 | return 1; | 905 | return 1; |
942 | } | 906 | } |
@@ -954,11 +918,9 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPee | |||
954 | nxt = bme->next; | 918 | nxt = bme->next; |
955 | if (0 == off) | 919 | if (0 == off) |
956 | { | 920 | { |
957 | if (GNUNET_OK != it (it_cls, | 921 | if (GNUNET_OK != it (it_cls, &bme->key, bme->value)) |
958 | &bme->key, | 922 | return GNUNET_SYSERR; |
959 | bme->value)) | 923 | return 1; |
960 | return GNUNET_SYSERR; | ||
961 | return 1; | ||
962 | } | 924 | } |
963 | off--; | 925 | off--; |
964 | } | 926 | } |
@@ -982,7 +944,8 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPee | |||
982 | * @return an iterator over the given multipeermap 'map' | 944 | * @return an iterator over the given multipeermap 'map' |
983 | */ | 945 | */ |
984 | struct GNUNET_CONTAINER_MultiPeerMapIterator * | 946 | struct GNUNET_CONTAINER_MultiPeerMapIterator * |
985 | GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map) | 947 | GNUNET_CONTAINER_multipeermap_iterator_create ( |
948 | const struct GNUNET_CONTAINER_MultiPeerMap *map) | ||
986 | { | 949 | { |
987 | struct GNUNET_CONTAINER_MultiPeerMapIterator *iter; | 950 | struct GNUNET_CONTAINER_MultiPeerMapIterator *iter; |
988 | 951 | ||
@@ -1009,8 +972,10 @@ GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_Mul | |||
1009 | * #GNUNET_NO if we are out of elements | 972 | * #GNUNET_NO if we are out of elements |
1010 | */ | 973 | */ |
1011 | int | 974 | int |
1012 | GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, | 975 | GNUNET_CONTAINER_multipeermap_iterator_next ( |
1013 | struct GNUNET_PeerIdentity *key, const void **value) | 976 | struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, |
977 | struct GNUNET_PeerIdentity *key, | ||
978 | const void **value) | ||
1014 | { | 979 | { |
1015 | /* make sure the map has not been modified */ | 980 | /* make sure the map has not been modified */ |
1016 | GNUNET_assert (iter->modification_counter == iter->map->modification_counter); | 981 | GNUNET_assert (iter->modification_counter == iter->map->modification_counter); |
@@ -1057,7 +1022,8 @@ GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMa | |||
1057 | * @param iter the iterator to destroy | 1022 | * @param iter the iterator to destroy |
1058 | */ | 1023 | */ |
1059 | void | 1024 | void |
1060 | GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter) | 1025 | GNUNET_CONTAINER_multipeermap_iterator_destroy ( |
1026 | struct GNUNET_CONTAINER_MultiPeerMapIterator *iter) | ||
1061 | { | 1027 | { |
1062 | GNUNET_free (iter); | 1028 | GNUNET_free (iter); |
1063 | } | 1029 | } |
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 | */ |
197 | struct GNUNET_CONTAINER_MultiShortmap * | 195 | struct GNUNET_CONTAINER_MultiShortmap * |
198 | GNUNET_CONTAINER_multishortmap_create (unsigned int len, | 196 | GNUNET_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 | */ |
224 | void | 220 | void |
225 | GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *map) | 221 | GNUNET_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 | */ |
290 | unsigned int | 287 | unsigned int |
291 | GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap *map) | 288 | GNUNET_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 | */ |
307 | void * | 305 | void * |
308 | GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map, | 306 | GNUNET_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 | */ |
343 | int | 338 | int |
344 | GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *map, | 339 | GNUNET_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 | */ |
414 | static void | 405 | static void |
415 | update_next_cache_bme (struct GNUNET_CONTAINER_MultiShortmap *map, | 406 | update_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 | */ |
431 | static void | 422 | static void |
432 | update_next_cache_sme (struct GNUNET_CONTAINER_MultiShortmap *map, | 423 | update_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 | */ |
452 | int | 443 | int |
453 | GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map, | 444 | GNUNET_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 | */ |
523 | int | 507 | int |
524 | GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map, | 508 | GNUNET_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 | */ |
613 | int | 596 | int |
614 | GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map, | 597 | GNUNET_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 | */ |
650 | int | 630 | int |
651 | GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map, | 631 | GNUNET_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 | */ |
751 | int | 725 | int |
752 | GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, | 726 | GNUNET_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 | */ |
832 | int | 803 | int |
833 | GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortmap *map, | 804 | GNUNET_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 | */ |
908 | unsigned int | 870 | unsigned int |
909 | GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiShortmap *map, | 871 | GNUNET_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 | */ |
972 | struct GNUNET_CONTAINER_MultiShortmapIterator * | 931 | struct GNUNET_CONTAINER_MultiShortmapIterator * |
973 | GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_MultiShortmap *map) | 932 | GNUNET_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 | */ |
999 | int | 959 | int |
1000 | GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter, | 960 | GNUNET_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 | */ |
1048 | void | 1009 | void |
1049 | GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiShortmapIterator *iter) | 1010 | GNUNET_CONTAINER_multishortmap_iterator_destroy ( |
1011 | struct GNUNET_CONTAINER_MultiShortmapIterator *iter) | ||
1050 | { | 1012 | { |
1051 | GNUNET_free (iter); | 1013 | GNUNET_free (iter); |
1052 | } | 1014 | } |