diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-30 13:55:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-30 13:55:43 +0000 |
commit | c886c53017f31d76c22f5ed55df61719b71ef87a (patch) | |
tree | f7379a2ef9fa764d36c1f778e47cd9a87d8c51f3 /src/include/gnunet_container_lib.h | |
parent | 81337e9011e6f8a9e14330946d504812f732755e (diff) | |
download | gnunet-c886c53017f31d76c22f5ed55df61719b71ef87a.tar.gz gnunet-c886c53017f31d76c22f5ed55df61719b71ef87a.zip |
-adding specialized hash table for peer identities
Diffstat (limited to 'src/include/gnunet_container_lib.h')
-rw-r--r-- | src/include/gnunet_container_lib.h | 303 |
1 files changed, 269 insertions, 34 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index ad7bb8cc0..39176e93b 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h | |||
@@ -634,8 +634,7 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len, | |||
634 | * @param map the map | 634 | * @param map the map |
635 | */ | 635 | */ |
636 | void | 636 | void |
637 | GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap | 637 | GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map); |
638 | *map); | ||
639 | 638 | ||
640 | 639 | ||
641 | /** | 640 | /** |
@@ -650,8 +649,8 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap | |||
650 | * key-value pairs with value NULL | 649 | * key-value pairs with value NULL |
651 | */ | 650 | */ |
652 | void * | 651 | void * |
653 | GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap | 652 | GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map, |
654 | *map, const struct GNUNET_HashCode * key); | 653 | const struct GNUNET_HashCode *key); |
655 | 654 | ||
656 | 655 | ||
657 | /** | 656 | /** |
@@ -668,7 +667,7 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap | |||
668 | */ | 667 | */ |
669 | int | 668 | int |
670 | GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, | 669 | GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, |
671 | const struct GNUNET_HashCode * key, | 670 | const struct GNUNET_HashCode *key, |
672 | const void *value); | 671 | const void *value); |
673 | 672 | ||
674 | /** | 673 | /** |
@@ -681,8 +680,8 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
681 | * @return number of values removed | 680 | * @return number of values removed |
682 | */ | 681 | */ |
683 | int | 682 | int |
684 | GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap | 683 | GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map, |
685 | *map, const struct GNUNET_HashCode * key); | 684 | const struct GNUNET_HashCode *key); |
686 | 685 | ||
687 | 686 | ||
688 | /** | 687 | /** |
@@ -696,8 +695,7 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap | |||
696 | * #GNUNET_NO if not | 695 | * #GNUNET_NO if not |
697 | */ | 696 | */ |
698 | int | 697 | int |
699 | GNUNET_CONTAINER_multihashmap_contains (const struct | 698 | GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map, |
700 | GNUNET_CONTAINER_MultiHashMap *map, | ||
701 | const struct GNUNET_HashCode * key); | 699 | const struct GNUNET_HashCode * key); |
702 | 700 | ||
703 | 701 | ||
@@ -713,9 +711,8 @@ GNUNET_CONTAINER_multihashmap_contains (const struct | |||
713 | * #GNUNET_NO if not | 711 | * #GNUNET_NO if not |
714 | */ | 712 | */ |
715 | int | 713 | int |
716 | GNUNET_CONTAINER_multihashmap_contains_value (const struct | 714 | GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map, |
717 | GNUNET_CONTAINER_MultiHashMap | 715 | const struct GNUNET_HashCode *key, |
718 | *map, const struct GNUNET_HashCode * key, | ||
719 | const void *value); | 716 | const void *value); |
720 | 717 | ||
721 | 718 | ||
@@ -729,7 +726,7 @@ GNUNET_CONTAINER_multihashmap_contains_value (const struct | |||
729 | * @param opt options for put | 726 | * @param opt options for put |
730 | * @return #GNUNET_OK on success, | 727 | * @return #GNUNET_OK on success, |
731 | * #GNUNET_NO if a value was replaced (with REPLACE) | 728 | * #GNUNET_NO if a value was replaced (with REPLACE) |
732 | * #GNUNET_SYSERR if UNIQUE_ONLY was the option and the | 729 | * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the |
733 | * value already exists | 730 | * value already exists |
734 | */ | 731 | */ |
735 | int | 732 | int |
@@ -772,7 +769,7 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct | |||
772 | * Create an iterator for a multihashmap. | 769 | * Create an iterator for a multihashmap. |
773 | * The iterator can be used to retrieve all the elements in the multihashmap | 770 | * The iterator can be used to retrieve all the elements in the multihashmap |
774 | * one by one, without having to handle all elements at once (in contrast to | 771 | * one by one, without having to handle all elements at once (in contrast to |
775 | * 'GNUNET_CONTAINER_multihashmap_iterate'). Note that the iterator can not be | 772 | * #GNUNET_CONTAINER_multihashmap_iterate). Note that the iterator can not be |
776 | * used anymore if elements have been removed from 'map' after the creation of | 773 | * used anymore if elements have been removed from 'map' after the creation of |
777 | * the iterator, or 'map' has been destroyed. Adding elements to 'map' may | 774 | * the iterator, or 'map' has been destroyed. Adding elements to 'map' may |
778 | * result in skipped or repeated elements. | 775 | * result in skipped or repeated elements. |
@@ -801,7 +798,8 @@ GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_Mul | |||
801 | */ | 798 | */ |
802 | int | 799 | int |
803 | GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, | 800 | GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, |
804 | struct GNUNET_HashCode *key, const void **value); | 801 | struct GNUNET_HashCode *key, |
802 | const void **value); | ||
805 | 803 | ||
806 | 804 | ||
807 | /** | 805 | /** |
@@ -832,6 +830,250 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct | |||
832 | GNUNET_CONTAINER_HashMapIterator it, | 830 | GNUNET_CONTAINER_HashMapIterator it, |
833 | void *it_cls); | 831 | void *it_cls); |
834 | 832 | ||
833 | |||
834 | /* ***************** Version of Multihashmap for peer identities ****************** */ | ||
835 | |||
836 | /** | ||
837 | * @ingroup hashmap | ||
838 | * Iterator over hash map entries. | ||
839 | * | ||
840 | * @param cls closure | ||
841 | * @param key current public key | ||
842 | * @param value value in the hash map | ||
843 | * @return #GNUNET_YES if we should continue to | ||
844 | * iterate, | ||
845 | * #GNUNET_NO if not. | ||
846 | */ | ||
847 | typedef int (*GNUNET_CONTAINER_PeerMapIterator) (void *cls, | ||
848 | const struct GNUNET_PeerIdentity *key, | ||
849 | void *value); | ||
850 | |||
851 | |||
852 | /** | ||
853 | * @ingroup hashmap | ||
854 | * Create a multi peer map (hash map for public keys of peers). | ||
855 | * | ||
856 | * @param len initial size (map will grow as needed) | ||
857 | * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default; | ||
858 | * #GNUNET_YES means that on 'put', the 'key' does not have | ||
859 | * to be copied as the destination of the pointer is | ||
860 | * guaranteed to be life as long as the value is stored in | ||
861 | * the hashmap. This can significantly reduce memory | ||
862 | * consumption, but of course is also a recipie for | ||
863 | * heap corruption if the assumption is not true. Only | ||
864 | * use this if (1) memory use is important in this case and | ||
865 | * (2) you have triple-checked that the invariant holds | ||
866 | * @return NULL on error | ||
867 | */ | ||
868 | struct GNUNET_CONTAINER_MultiPeerMap * | ||
869 | GNUNET_CONTAINER_multipeermap_create (unsigned int len, | ||
870 | int do_not_copy_keys); | ||
871 | |||
872 | |||
873 | /** | ||
874 | * @ingroup hashmap | ||
875 | * Destroy a hash map. Will not free any values | ||
876 | * stored in the hash map! | ||
877 | * | ||
878 | * @param map the map | ||
879 | */ | ||
880 | void | ||
881 | GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map); | ||
882 | |||
883 | |||
884 | /** | ||
885 | * @ingroup hashmap | ||
886 | * Given a key find a value in the map matching the key. | ||
887 | * | ||
888 | * @param map the map | ||
889 | * @param key what to look for | ||
890 | * @return NULL if no value was found; note that | ||
891 | * this is indistinguishable from values that just | ||
892 | * happen to be NULL; use "contains" to test for | ||
893 | * key-value pairs with value NULL | ||
894 | */ | ||
895 | void * | ||
896 | GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
897 | const struct GNUNET_PeerIdentity *key); | ||
898 | |||
899 | |||
900 | /** | ||
901 | * @ingroup hashmap | ||
902 | * Remove the given key-value pair from the map. Note that if the | ||
903 | * key-value pair is in the map multiple times, only one of the pairs | ||
904 | * will be removed. | ||
905 | * | ||
906 | * @param map the map | ||
907 | * @param key key of the key-value pair | ||
908 | * @param value value of the key-value pair | ||
909 | * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair | ||
910 | * is not in the map | ||
911 | */ | ||
912 | int | ||
913 | GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
914 | const struct GNUNET_PeerIdentity * key, | ||
915 | const void *value); | ||
916 | |||
917 | /** | ||
918 | * @ingroup hashmap | ||
919 | * Remove all entries for the given key from the map. | ||
920 | * Note that the values would not be "freed". | ||
921 | * | ||
922 | * @param map the map | ||
923 | * @param key identifies values to be removed | ||
924 | * @return number of values removed | ||
925 | */ | ||
926 | int | ||
927 | GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
928 | const struct GNUNET_PeerIdentity *key); | ||
929 | |||
930 | |||
931 | /** | ||
932 | * @ingroup hashmap | ||
933 | * Check if the map contains any value under the given | ||
934 | * key (including values that are NULL). | ||
935 | * | ||
936 | * @param map the map | ||
937 | * @param key the key to test if a value exists for it | ||
938 | * @return #GNUNET_YES if such a value exists, | ||
939 | * #GNUNET_NO if not | ||
940 | */ | ||
941 | int | ||
942 | GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
943 | const struct GNUNET_PeerIdentity *key); | ||
944 | |||
945 | |||
946 | /** | ||
947 | * @ingroup hashmap | ||
948 | * Check if the map contains the given value under the given | ||
949 | * key. | ||
950 | * | ||
951 | * @param map the map | ||
952 | * @param key the key to test if a value exists for it | ||
953 | * @param value value to test for | ||
954 | * @return #GNUNET_YES if such a value exists, | ||
955 | * #GNUNET_NO if not | ||
956 | */ | ||
957 | int | ||
958 | GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
959 | const struct GNUNET_PeerIdentity * key, | ||
960 | const void *value); | ||
961 | |||
962 | |||
963 | /** | ||
964 | * @ingroup hashmap | ||
965 | * Store a key-value pair in the map. | ||
966 | * | ||
967 | * @param map the map | ||
968 | * @param key key to use | ||
969 | * @param value value to use | ||
970 | * @param opt options for put | ||
971 | * @return #GNUNET_OK on success, | ||
972 | * #GNUNET_NO if a value was replaced (with REPLACE) | ||
973 | * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the | ||
974 | * value already exists | ||
975 | */ | ||
976 | int | ||
977 | GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
978 | const struct GNUNET_PeerIdentity *key, | ||
979 | void *value, | ||
980 | enum GNUNET_CONTAINER_MultiHashMapOption opt); | ||
981 | |||
982 | |||
983 | /** | ||
984 | * @ingroup hashmap | ||
985 | * Get the number of key-value pairs in the map. | ||
986 | * | ||
987 | * @param map the map | ||
988 | * @return the number of key value pairs | ||
989 | */ | ||
990 | unsigned int | ||
991 | GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map); | ||
992 | |||
993 | |||
994 | /** | ||
995 | * @ingroup hashmap | ||
996 | * Iterate over all entries in the map. | ||
997 | * | ||
998 | * @param map the map | ||
999 | * @param it function to call on each entry | ||
1000 | * @param it_cls extra argument to @a it | ||
1001 | * @return the number of key value pairs processed, | ||
1002 | * #GNUNET_SYSERR if it aborted iteration | ||
1003 | */ | ||
1004 | int | ||
1005 | GNUNET_CONTAINER_multipeermap_iterate (const struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
1006 | GNUNET_CONTAINER_PeerMapIterator it, | ||
1007 | void *it_cls); | ||
1008 | |||
1009 | |||
1010 | /** | ||
1011 | * @ingroup hashmap | ||
1012 | * Create an iterator for a multihashmap. | ||
1013 | * The iterator can be used to retrieve all the elements in the multihashmap | ||
1014 | * one by one, without having to handle all elements at once (in contrast to | ||
1015 | * #GNUNET_CONTAINER_multipeermap_iterate). Note that the iterator can not be | ||
1016 | * used anymore if elements have been removed from @a map after the creation of | ||
1017 | * the iterator, or 'map' has been destroyed. Adding elements to @a map may | ||
1018 | * result in skipped or repeated elements. | ||
1019 | * | ||
1020 | * @param map the map to create an iterator for | ||
1021 | * @return an iterator over the given multihashmap @a map | ||
1022 | */ | ||
1023 | struct GNUNET_CONTAINER_MultiPeerMapIterator * | ||
1024 | GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map); | ||
1025 | |||
1026 | |||
1027 | /** | ||
1028 | * @ingroup hashmap | ||
1029 | * Retrieve the next element from the hash map at the iterator's | ||
1030 | * position. If there are no elements left, #GNUNET_NO is returned, | ||
1031 | * and @a key and @a value are not modified. This operation is only | ||
1032 | * allowed if no elements have been removed from the multihashmap | ||
1033 | * since the creation of @a iter, and the map has not been destroyed. | ||
1034 | * Adding elements may result in repeating or skipping elements. | ||
1035 | * | ||
1036 | * @param iter the iterator to get the next element from | ||
1037 | * @param key pointer to store the key in, can be NULL | ||
1038 | * @param value pointer to store the value in, can be NULL | ||
1039 | * @return #GNUNET_YES we returned an element, | ||
1040 | * #GNUNET_NO if we are out of elements | ||
1041 | */ | ||
1042 | int | ||
1043 | GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, | ||
1044 | struct GNUNET_PeerIdentity *key, | ||
1045 | const void **value); | ||
1046 | |||
1047 | |||
1048 | /** | ||
1049 | * @ingroup hashmap | ||
1050 | * Destroy a multipeermap iterator. | ||
1051 | * | ||
1052 | * @param iter the iterator to destroy | ||
1053 | */ | ||
1054 | void | ||
1055 | GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter); | ||
1056 | |||
1057 | |||
1058 | /** | ||
1059 | * @ingroup hashmap | ||
1060 | * Iterate over all entries in the map that match a particular key. | ||
1061 | * | ||
1062 | * @param map the map | ||
1063 | * @param key public key that the entries must correspond to | ||
1064 | * @param it function to call on each entry | ||
1065 | * @param it_cls extra argument to @a it | ||
1066 | * @return the number of key value pairs processed, | ||
1067 | * #GNUNET_SYSERR if it aborted iteration | ||
1068 | */ | ||
1069 | int | ||
1070 | GNUNET_CONTAINER_multipeermap_get_multiple (const struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
1071 | const struct GNUNET_PeerIdentity *key, | ||
1072 | GNUNET_CONTAINER_PeerMapIterator it, | ||
1073 | void *it_cls); | ||
1074 | |||
1075 | |||
1076 | |||
835 | /* Version of multihashmap with 32 bit keys */ | 1077 | /* Version of multihashmap with 32 bit keys */ |
836 | 1078 | ||
837 | /** | 1079 | /** |
@@ -939,8 +1181,7 @@ GNUNET_CONTAINER_multihashmap32_iterate (const struct | |||
939 | * is not in the map | 1181 | * is not in the map |
940 | */ | 1182 | */ |
941 | int | 1183 | int |
942 | GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 | 1184 | GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map, |
943 | *map, | ||
944 | uint32_t key, | 1185 | uint32_t key, |
945 | const void *value); | 1186 | const void *value); |
946 | 1187 | ||
@@ -955,9 +1196,7 @@ GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 | |||
955 | * @return number of values removed | 1196 | * @return number of values removed |
956 | */ | 1197 | */ |
957 | int | 1198 | int |
958 | GNUNET_CONTAINER_multihashmap32_remove_all (struct | 1199 | GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map, |
959 | GNUNET_CONTAINER_MultiHashMap32 | ||
960 | *map, | ||
961 | uint32_t key); | 1200 | uint32_t key); |
962 | 1201 | ||
963 | 1202 | ||
@@ -972,8 +1211,7 @@ GNUNET_CONTAINER_multihashmap32_remove_all (struct | |||
972 | * #GNUNET_NO if not | 1211 | * #GNUNET_NO if not |
973 | */ | 1212 | */ |
974 | int | 1213 | int |
975 | GNUNET_CONTAINER_multihashmap32_contains (const struct | 1214 | GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map, |
976 | GNUNET_CONTAINER_MultiHashMap32 *map, | ||
977 | uint32_t key); | 1215 | uint32_t key); |
978 | 1216 | ||
979 | 1217 | ||
@@ -989,9 +1227,7 @@ GNUNET_CONTAINER_multihashmap32_contains (const struct | |||
989 | * #GNUNET_NO if not | 1227 | * #GNUNET_NO if not |
990 | */ | 1228 | */ |
991 | int | 1229 | int |
992 | GNUNET_CONTAINER_multihashmap32_contains_value (const struct | 1230 | GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map, |
993 | GNUNET_CONTAINER_MultiHashMap32 | ||
994 | *map, | ||
995 | uint32_t key, | 1231 | uint32_t key, |
996 | const void *value); | 1232 | const void *value); |
997 | 1233 | ||
@@ -1010,10 +1246,10 @@ GNUNET_CONTAINER_multihashmap32_contains_value (const struct | |||
1010 | * value already exists | 1246 | * value already exists |
1011 | */ | 1247 | */ |
1012 | int | 1248 | int |
1013 | GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 | 1249 | GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map, |
1014 | *map, uint32_t key, void *value, | 1250 | uint32_t key, |
1015 | enum GNUNET_CONTAINER_MultiHashMapOption | 1251 | void *value, |
1016 | opt); | 1252 | enum GNUNET_CONTAINER_MultiHashMapOption opt); |
1017 | 1253 | ||
1018 | 1254 | ||
1019 | /** | 1255 | /** |
@@ -1028,11 +1264,10 @@ GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 | |||
1028 | * #GNUNET_SYSERR if it aborted iteration | 1264 | * #GNUNET_SYSERR if it aborted iteration |
1029 | */ | 1265 | */ |
1030 | int | 1266 | int |
1031 | GNUNET_CONTAINER_multihashmap32_get_multiple (const struct | 1267 | GNUNET_CONTAINER_multihashmap32_get_multiple (const struct GNUNET_CONTAINER_MultiHashMap32 *map, |
1032 | GNUNET_CONTAINER_MultiHashMap32 | 1268 | uint32_t key, |
1033 | *map, uint32_t key, | 1269 | GNUNET_CONTAINER_HashMapIterator32 it, |
1034 | GNUNET_CONTAINER_HashMapIterator32 | 1270 | void *it_cls); |
1035 | it, void *it_cls); | ||
1036 | 1271 | ||
1037 | 1272 | ||
1038 | 1273 | ||