diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-17 16:54:38 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-17 16:54:38 +0100 |
commit | 100e16ba31dac7138413bda3389d30b3575a8b8e (patch) | |
tree | 620d38424df719e98dcfd834dca3465705a1c385 /src/util/container_multishortmap.c | |
parent | 5d52f126f510a223d371459f17d5aaa46e9dfe49 (diff) | |
download | gnunet-100e16ba31dac7138413bda3389d30b3575a8b8e.tar.gz gnunet-100e16ba31dac7138413bda3389d30b3575a8b8e.zip |
make shortmap actually over shorts
Diffstat (limited to 'src/util/container_multishortmap.c')
-rw-r--r-- | src/util/container_multishortmap.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/src/util/container_multishortmap.c b/src/util/container_multishortmap.c index 71d1073b0..5e8a47b09 100644 --- a/src/util/container_multishortmap.c +++ b/src/util/container_multishortmap.c | |||
@@ -47,7 +47,7 @@ struct BigMapEntry | |||
47 | /** | 47 | /** |
48 | * Key for the entry. | 48 | * Key for the entry. |
49 | */ | 49 | */ |
50 | struct GNUNET_PeerIdentity key; | 50 | struct GNUNET_ShortHashCode key; |
51 | 51 | ||
52 | }; | 52 | }; |
53 | 53 | ||
@@ -71,7 +71,7 @@ struct SmallMapEntry | |||
71 | /** | 71 | /** |
72 | * Key for the entry. | 72 | * Key for the entry. |
73 | */ | 73 | */ |
74 | const struct GNUNET_PeerIdentity *key; | 74 | const struct GNUNET_ShortHashCode *key; |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
@@ -243,7 +243,7 @@ GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap | |||
243 | */ | 243 | */ |
244 | static unsigned int | 244 | static unsigned int |
245 | idx_of (const struct GNUNET_CONTAINER_MultiShortmap *map, | 245 | idx_of (const struct GNUNET_CONTAINER_MultiShortmap *map, |
246 | const struct GNUNET_PeerIdentity *key) | 246 | const struct GNUNET_ShortHashCode *key) |
247 | { | 247 | { |
248 | unsigned int kx; | 248 | unsigned int kx; |
249 | 249 | ||
@@ -278,7 +278,7 @@ GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap | |||
278 | */ | 278 | */ |
279 | void * | 279 | void * |
280 | GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map, | 280 | GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map, |
281 | const struct GNUNET_PeerIdentity *key) | 281 | const struct GNUNET_ShortHashCode *key) |
282 | { | 282 | { |
283 | union MapEntry me; | 283 | union MapEntry me; |
284 | 284 | ||
@@ -288,7 +288,7 @@ GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap | |||
288 | struct SmallMapEntry *sme; | 288 | struct SmallMapEntry *sme; |
289 | 289 | ||
290 | for (sme = me.sme; NULL != sme; sme = sme->next) | 290 | for (sme = me.sme; NULL != sme; sme = sme->next) |
291 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) | 291 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode))) |
292 | return sme->value; | 292 | return sme->value; |
293 | } | 293 | } |
294 | else | 294 | else |
@@ -296,7 +296,7 @@ GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap | |||
296 | struct BigMapEntry *bme; | 296 | struct BigMapEntry *bme; |
297 | 297 | ||
298 | for (bme = me.bme; NULL != bme; bme = bme->next) | 298 | for (bme = me.bme; NULL != bme; bme = bme->next) |
299 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) | 299 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode))) |
300 | return bme->value; | 300 | return bme->value; |
301 | } | 301 | } |
302 | return NULL; | 302 | return NULL; |
@@ -320,7 +320,7 @@ GNUNET_CONTAINER_multishortmap_iterate (const struct GNUNET_CONTAINER_MultiShort | |||
320 | int count; | 320 | int count; |
321 | unsigned int i; | 321 | unsigned int i; |
322 | union MapEntry me; | 322 | union MapEntry me; |
323 | struct GNUNET_PeerIdentity kc; | 323 | struct GNUNET_ShortHashCode kc; |
324 | 324 | ||
325 | count = 0; | 325 | count = 0; |
326 | GNUNET_assert (NULL != map); | 326 | GNUNET_assert (NULL != map); |
@@ -380,7 +380,7 @@ GNUNET_CONTAINER_multishortmap_iterate (const struct GNUNET_CONTAINER_MultiShort | |||
380 | */ | 380 | */ |
381 | int | 381 | int |
382 | GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map, | 382 | GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map, |
383 | const struct GNUNET_PeerIdentity *key, | 383 | const struct GNUNET_ShortHashCode *key, |
384 | const void *value) | 384 | const void *value) |
385 | { | 385 | { |
386 | union MapEntry me; | 386 | union MapEntry me; |
@@ -398,7 +398,7 @@ GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *ma | |||
398 | p = NULL; | 398 | p = NULL; |
399 | for (sme = me.sme; NULL != sme; sme = sme->next) | 399 | for (sme = me.sme; NULL != sme; sme = sme->next) |
400 | { | 400 | { |
401 | if ((0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) && | 401 | if ((0 == memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode))) && |
402 | (value == sme->value)) | 402 | (value == sme->value)) |
403 | { | 403 | { |
404 | if (NULL == p) | 404 | if (NULL == p) |
@@ -420,7 +420,7 @@ GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *ma | |||
420 | p = NULL; | 420 | p = NULL; |
421 | for (bme = me.bme; NULL != bme; bme = bme->next) | 421 | for (bme = me.bme; NULL != bme; bme = bme->next) |
422 | { | 422 | { |
423 | if ((0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) && | 423 | if ((0 == memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode))) && |
424 | (value == bme->value)) | 424 | (value == bme->value)) |
425 | { | 425 | { |
426 | if (NULL == p) | 426 | if (NULL == p) |
@@ -448,7 +448,7 @@ GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *ma | |||
448 | */ | 448 | */ |
449 | int | 449 | int |
450 | GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map, | 450 | GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map, |
451 | const struct GNUNET_PeerIdentity *key) | 451 | const struct GNUNET_ShortHashCode *key) |
452 | { | 452 | { |
453 | union MapEntry me; | 453 | union MapEntry me; |
454 | unsigned int i; | 454 | unsigned int i; |
@@ -468,7 +468,7 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap | |||
468 | sme = me.sme; | 468 | sme = me.sme; |
469 | while (NULL != sme) | 469 | while (NULL != sme) |
470 | { | 470 | { |
471 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) | 471 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode))) |
472 | { | 472 | { |
473 | if (NULL == p) | 473 | if (NULL == p) |
474 | map->map[i].sme = sme->next; | 474 | map->map[i].sme = sme->next; |
@@ -498,7 +498,7 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap | |||
498 | bme = me.bme; | 498 | bme = me.bme; |
499 | while (NULL != bme) | 499 | while (NULL != bme) |
500 | { | 500 | { |
501 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) | 501 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode))) |
502 | { | 502 | { |
503 | if (NULL == p) | 503 | if (NULL == p) |
504 | map->map[i].bme = bme->next; | 504 | map->map[i].bme = bme->next; |
@@ -534,7 +534,7 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap | |||
534 | */ | 534 | */ |
535 | int | 535 | int |
536 | GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map, | 536 | GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map, |
537 | const struct GNUNET_PeerIdentity *key) | 537 | const struct GNUNET_ShortHashCode *key) |
538 | { | 538 | { |
539 | union MapEntry me; | 539 | union MapEntry me; |
540 | 540 | ||
@@ -544,7 +544,7 @@ GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShor | |||
544 | struct SmallMapEntry *sme; | 544 | struct SmallMapEntry *sme; |
545 | 545 | ||
546 | for (sme = me.sme; NULL != sme; sme = sme->next) | 546 | for (sme = me.sme; NULL != sme; sme = sme->next) |
547 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) | 547 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode))) |
548 | return GNUNET_YES; | 548 | return GNUNET_YES; |
549 | } | 549 | } |
550 | else | 550 | else |
@@ -552,7 +552,7 @@ GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShor | |||
552 | struct BigMapEntry *bme; | 552 | struct BigMapEntry *bme; |
553 | 553 | ||
554 | for (bme = me.bme; NULL != bme; bme = bme->next) | 554 | for (bme = me.bme; NULL != bme; bme = bme->next) |
555 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) | 555 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode))) |
556 | return GNUNET_YES; | 556 | return GNUNET_YES; |
557 | } | 557 | } |
558 | return GNUNET_NO; | 558 | return GNUNET_NO; |
@@ -571,7 +571,7 @@ GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShor | |||
571 | */ | 571 | */ |
572 | int | 572 | int |
573 | GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map, | 573 | GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map, |
574 | const struct GNUNET_PeerIdentity *key, | 574 | const struct GNUNET_ShortHashCode *key, |
575 | const void *value) | 575 | const void *value) |
576 | { | 576 | { |
577 | union MapEntry me; | 577 | union MapEntry me; |
@@ -582,7 +582,7 @@ GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_Mul | |||
582 | struct SmallMapEntry *sme; | 582 | struct SmallMapEntry *sme; |
583 | 583 | ||
584 | for (sme = me.sme; NULL != sme; sme = sme->next) | 584 | for (sme = me.sme; NULL != sme; sme = sme->next) |
585 | if ( (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) && | 585 | if ( (0 == memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode))) && |
586 | (sme->value == value) ) | 586 | (sme->value == value) ) |
587 | return GNUNET_YES; | 587 | return GNUNET_YES; |
588 | } | 588 | } |
@@ -591,7 +591,7 @@ GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_Mul | |||
591 | struct BigMapEntry *bme; | 591 | struct BigMapEntry *bme; |
592 | 592 | ||
593 | for (bme = me.bme; NULL != bme; bme = bme->next) | 593 | for (bme = me.bme; NULL != bme; bme = bme->next) |
594 | if ( (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) && | 594 | if ( (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode))) && |
595 | (bme->value == value) ) | 595 | (bme->value == value) ) |
596 | return GNUNET_YES; | 596 | return GNUNET_YES; |
597 | } | 597 | } |
@@ -667,7 +667,7 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map) | |||
667 | */ | 667 | */ |
668 | int | 668 | int |
669 | GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, | 669 | GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, |
670 | const struct GNUNET_PeerIdentity *key, | 670 | const struct GNUNET_ShortHashCode *key, |
671 | void *value, | 671 | void *value, |
672 | enum GNUNET_CONTAINER_MultiHashMapOption opt) | 672 | enum GNUNET_CONTAINER_MultiHashMapOption opt) |
673 | { | 673 | { |
@@ -684,7 +684,7 @@ GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, | |||
684 | struct SmallMapEntry *sme; | 684 | struct SmallMapEntry *sme; |
685 | 685 | ||
686 | for (sme = me.sme; NULL != sme; sme = sme->next) | 686 | for (sme = me.sme; NULL != sme; sme = sme->next) |
687 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) | 687 | if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode))) |
688 | { | 688 | { |
689 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 689 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) |
690 | return GNUNET_SYSERR; | 690 | return GNUNET_SYSERR; |
@@ -697,7 +697,7 @@ GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, | |||
697 | struct BigMapEntry *bme; | 697 | struct BigMapEntry *bme; |
698 | 698 | ||
699 | for (bme = me.bme; NULL != bme; bme = bme->next) | 699 | for (bme = me.bme; NULL != bme; bme = bme->next) |
700 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) | 700 | if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode))) |
701 | { | 701 | { |
702 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 702 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) |
703 | return GNUNET_SYSERR; | 703 | return GNUNET_SYSERR; |
@@ -748,7 +748,7 @@ GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, | |||
748 | */ | 748 | */ |
749 | int | 749 | int |
750 | GNUNET_CONTAINER_multishortmap_get_multiple (const struct GNUNET_CONTAINER_MultiShortmap *map, | 750 | GNUNET_CONTAINER_multishortmap_get_multiple (const struct GNUNET_CONTAINER_MultiShortmap *map, |
751 | const struct GNUNET_PeerIdentity *key, | 751 | const struct GNUNET_ShortHashCode *key, |
752 | GNUNET_CONTAINER_ShortmapIterator it, | 752 | GNUNET_CONTAINER_ShortmapIterator it, |
753 | void *it_cls) | 753 | void *it_cls) |
754 | { | 754 | { |
@@ -766,7 +766,7 @@ GNUNET_CONTAINER_multishortmap_get_multiple (const struct GNUNET_CONTAINER_Multi | |||
766 | while (NULL != (sme = nxt)) | 766 | while (NULL != (sme = nxt)) |
767 | { | 767 | { |
768 | nxt = sme->next; | 768 | nxt = sme->next; |
769 | if (0 != memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) | 769 | if (0 != memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode))) |
770 | continue; | 770 | continue; |
771 | if ((it != NULL) && (GNUNET_OK != it (it_cls, key, sme->value))) | 771 | if ((it != NULL) && (GNUNET_OK != it (it_cls, key, sme->value))) |
772 | return GNUNET_SYSERR; | 772 | return GNUNET_SYSERR; |
@@ -782,7 +782,7 @@ GNUNET_CONTAINER_multishortmap_get_multiple (const struct GNUNET_CONTAINER_Multi | |||
782 | while (NULL != (bme = nxt)) | 782 | while (NULL != (bme = nxt)) |
783 | { | 783 | { |
784 | nxt = bme->next; | 784 | nxt = bme->next; |
785 | if (0 != memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity))) | 785 | if (0 != memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode))) |
786 | continue; | 786 | continue; |
787 | if ((it != NULL) && (GNUNET_OK != it (it_cls, key, bme->value))) | 787 | if ((it != NULL) && (GNUNET_OK != it (it_cls, key, bme->value))) |
788 | return GNUNET_SYSERR; | 788 | return GNUNET_SYSERR; |
@@ -908,7 +908,8 @@ GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_Mu | |||
908 | */ | 908 | */ |
909 | int | 909 | int |
910 | GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter, | 910 | GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter, |
911 | struct GNUNET_PeerIdentity *key, const void **value) | 911 | struct GNUNET_ShortHashCode *key, |
912 | const void **value) | ||
912 | { | 913 | { |
913 | /* make sure the map has not been modified */ | 914 | /* make sure the map has not been modified */ |
914 | GNUNET_assert (iter->modification_counter == iter->map->modification_counter); | 915 | GNUNET_assert (iter->modification_counter == iter->map->modification_counter); |