74#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
75#error "Only <gnunet_util_lib.h> can be included directly."
78#ifndef GNUNET_HASHMAP_LIB_H
79#define GNUNET_HASHMAP_LIB_H
138#define GNUNET_CONTAINER_MULTIMAP_MAX_KEY_SIZE 1024
441#define GNUNET_CONTAINER_MULTIMAP_CHECK_(cond) \
442 ((void) sizeof (char[(cond) ? 1 : -1]))
454#define GNUNET_CONTAINER_MULTIMAP_DEFINE_COMMON_(prefix, MapType, IterType, \
459 static inline GNUNET_UNUSED void \
460 prefix ## _destroy (struct MapType *map) \
462 GNUNET_CONTAINER_multimap_destroy_ ( \
463 (struct GNUNET_CONTAINER_MultiMap *) map); \
466 static inline GNUNET_UNUSED unsigned int \
467 prefix ## _size (const struct MapType *map) \
469 return GNUNET_CONTAINER_multimap_size_ ( \
470 (const struct GNUNET_CONTAINER_MultiMap *) map); \
473 static inline GNUNET_UNUSED unsigned int \
474 prefix ## _clear (struct MapType *map) \
476 return GNUNET_CONTAINER_multimap_clear_ ( \
477 (struct GNUNET_CONTAINER_MultiMap *) map); \
480 static inline GNUNET_UNUSED struct IterType * \
481 prefix ## _iterator_create (const struct MapType *map) \
483 return (struct IterType *) \
484 GNUNET_CONTAINER_multimap_iterator_create_ ( \
485 (const struct GNUNET_CONTAINER_MultiMap *) map); \
488 static inline GNUNET_UNUSED void \
489 prefix ## _iterator_destroy (struct IterType *iter) \
491 GNUNET_CONTAINER_multimap_iterator_destroy_ ( \
492 (struct GNUNET_CONTAINER_MultiMapIterator *) iter); \
495 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
496 prefix ## _iterator_next_value_ (struct IterType *iter, \
498 const ValueType **value) \
501 enum GNUNET_GenericReturnValue ret; \
503 ret = GNUNET_CONTAINER_multimap_iterator_next_ ( \
504 (struct GNUNET_CONTAINER_MultiMapIterator *) iter, \
507 if ((GNUNET_YES == ret) && (NULL != value)) \
509 *value = (const ValueType *) v; \
589#define GNUNET_CONTAINER_MULTIMAP_DEFINE_PTRKEY(prefix, MapType, IterType, \
590 CbType, KeyType, ValueType) \
591 GNUNET_CONTAINER_MULTIMAP_DEFINE_COMMON_ (prefix, MapType, IterType, \
594 typedef enum GNUNET_GenericReturnValue \
595 (*CbType)(void *cls, \
596 const KeyType *key, \
599 struct prefix ## _Trampoline_ \
605 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
606 prefix ## _trampoline_ (void *cls, \
610 const struct prefix ## _Trampoline_ *t = \
611 (const struct prefix ## _Trampoline_ *) cls; \
613 return t->cb (t->cb_cls, \
614 (const KeyType *) key, \
615 (ValueType *) value); \
618 static inline GNUNET_UNUSED struct MapType * \
619 prefix ## _create (unsigned int len, \
620 int do_not_copy_keys) \
622 GNUNET_CONTAINER_MULTIMAP_CHECK_ ( \
623 sizeof (KeyType) <= GNUNET_CONTAINER_MULTIMAP_MAX_KEY_SIZE); \
624 GNUNET_CONTAINER_MULTIMAP_CHECK_ (__alignof__ (KeyType) <= 8); \
625 return (struct MapType *) GNUNET_CONTAINER_multimap_create_ ( \
629 ? GNUNET_CONTAINER_MULTIMAP_FLAG_DO_NOT_COPY_KEYS \
630 : GNUNET_CONTAINER_MULTIMAP_FLAG_NONE); \
633 static inline GNUNET_UNUSED struct MapType * \
634 prefix ## _create_unprotected (unsigned int len, \
635 int do_not_copy_keys) \
637 GNUNET_CONTAINER_MULTIMAP_CHECK_ ( \
638 sizeof (KeyType) <= GNUNET_CONTAINER_MULTIMAP_MAX_KEY_SIZE); \
639 GNUNET_CONTAINER_MULTIMAP_CHECK_ (__alignof__ (KeyType) <= 8); \
640 return (struct MapType *) GNUNET_CONTAINER_multimap_create_ ( \
643 (enum GNUNET_CONTAINER_MultiMapFlags) \
644 (GNUNET_CONTAINER_MULTIMAP_FLAG_UNPROTECTED \
645 | (do_not_copy_keys \
646 ? GNUNET_CONTAINER_MULTIMAP_FLAG_DO_NOT_COPY_KEYS \
647 : GNUNET_CONTAINER_MULTIMAP_FLAG_NONE))); \
650 static inline GNUNET_UNUSED ValueType * \
651 prefix ## _get (const struct MapType *map, \
652 const KeyType *key) \
654 return (ValueType *) GNUNET_CONTAINER_multimap_get_ ( \
655 (const struct GNUNET_CONTAINER_MultiMap *) map, \
659 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
660 prefix ## _contains (const struct MapType *map, \
661 const KeyType *key) \
663 return GNUNET_CONTAINER_multimap_contains_ ( \
664 (const struct GNUNET_CONTAINER_MultiMap *) map, \
668 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
669 prefix ## _contains_value (const struct MapType *map, \
670 const KeyType *key, \
671 const ValueType *value) \
673 return GNUNET_CONTAINER_multimap_contains_value_ ( \
674 (const struct GNUNET_CONTAINER_MultiMap *) map, \
679 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
680 prefix ## _put (struct MapType *map, \
681 const KeyType *key, \
683 enum GNUNET_CONTAINER_MultiHashMapOption opt) \
685 return GNUNET_CONTAINER_multimap_put_ ( \
686 (struct GNUNET_CONTAINER_MultiMap *) map, \
692 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
693 prefix ## _remove (struct MapType *map, \
694 const KeyType *key, \
695 const ValueType *value) \
697 return GNUNET_CONTAINER_multimap_remove_ ( \
698 (struct GNUNET_CONTAINER_MultiMap *) map, \
703 static inline GNUNET_UNUSED int \
704 prefix ## _remove_all (struct MapType *map, \
705 const KeyType *key) \
707 return GNUNET_CONTAINER_multimap_remove_all_ ( \
708 (struct GNUNET_CONTAINER_MultiMap *) map, \
712 static inline GNUNET_UNUSED int \
713 prefix ## _iterate (struct MapType *map, \
717 struct prefix ## _Trampoline_ t; \
721 return GNUNET_CONTAINER_multimap_iterate_ ( \
722 (struct GNUNET_CONTAINER_MultiMap *) map, \
723 (NULL == it) ? NULL : &prefix ## _trampoline_, \
727 static inline GNUNET_UNUSED int \
728 prefix ## _get_multiple (struct MapType *map, \
729 const KeyType *key, \
733 struct prefix ## _Trampoline_ t; \
737 return GNUNET_CONTAINER_multimap_get_multiple_ ( \
738 (struct GNUNET_CONTAINER_MultiMap *) map, \
740 (NULL == it) ? NULL : &prefix ## _trampoline_, \
744 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
745 prefix ## _iterator_next (struct IterType *iter, \
747 const ValueType **value) \
749 return prefix ## _iterator_next_value_ (iter, \
784#define GNUNET_CONTAINER_MULTIMAP_DEFINE_VALKEY(prefix, MapType, IterType, \
785 CbType, KeyType, ValueType) \
786 GNUNET_CONTAINER_MULTIMAP_DEFINE_COMMON_ (prefix, MapType, IterType, \
789 typedef enum GNUNET_GenericReturnValue \
790 (*CbType)(void *cls, \
794 struct prefix ## _Trampoline_ \
800 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
801 prefix ## _trampoline_ (void *cls, \
805 const struct prefix ## _Trampoline_ *t = \
806 (const struct prefix ## _Trampoline_ *) cls; \
809 memcpy (&k, key, sizeof (k)); \
810 return t->cb (t->cb_cls, \
812 (ValueType *) value); \
815 static inline GNUNET_UNUSED struct MapType * \
816 prefix ## _create (unsigned int len) \
818 GNUNET_CONTAINER_MULTIMAP_CHECK_ (sizeof (KeyType) <= 8); \
819 return (struct MapType *) GNUNET_CONTAINER_multimap_create_ ( \
822 GNUNET_CONTAINER_MULTIMAP_FLAG_NONE); \
825 static inline GNUNET_UNUSED struct MapType * \
826 prefix ## _create_unprotected (unsigned int len) \
828 GNUNET_CONTAINER_MULTIMAP_CHECK_ (sizeof (KeyType) <= 8); \
829 return (struct MapType *) GNUNET_CONTAINER_multimap_create_ ( \
832 GNUNET_CONTAINER_MULTIMAP_FLAG_UNPROTECTED); \
835 static inline GNUNET_UNUSED ValueType * \
836 prefix ## _get (const struct MapType *map, \
839 return (ValueType *) GNUNET_CONTAINER_multimap_get_ ( \
840 (const struct GNUNET_CONTAINER_MultiMap *) map, \
844 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
845 prefix ## _contains (const struct MapType *map, \
848 return GNUNET_CONTAINER_multimap_contains_ ( \
849 (const struct GNUNET_CONTAINER_MultiMap *) map, \
853 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
854 prefix ## _contains_value (const struct MapType *map, \
856 const ValueType *value) \
858 return GNUNET_CONTAINER_multimap_contains_value_ ( \
859 (const struct GNUNET_CONTAINER_MultiMap *) map, \
864 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
865 prefix ## _put (struct MapType *map, \
868 enum GNUNET_CONTAINER_MultiHashMapOption opt) \
870 return GNUNET_CONTAINER_multimap_put_ ( \
871 (struct GNUNET_CONTAINER_MultiMap *) map, \
877 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
878 prefix ## _remove (struct MapType *map, \
880 const ValueType *value) \
882 return GNUNET_CONTAINER_multimap_remove_ ( \
883 (struct GNUNET_CONTAINER_MultiMap *) map, \
888 static inline GNUNET_UNUSED int \
889 prefix ## _remove_all (struct MapType *map, \
892 return GNUNET_CONTAINER_multimap_remove_all_ ( \
893 (struct GNUNET_CONTAINER_MultiMap *) map, \
897 static inline GNUNET_UNUSED int \
898 prefix ## _iterate (struct MapType *map, \
902 struct prefix ## _Trampoline_ t; \
906 return GNUNET_CONTAINER_multimap_iterate_ ( \
907 (struct GNUNET_CONTAINER_MultiMap *) map, \
908 (NULL == it) ? NULL : &prefix ## _trampoline_, \
912 static inline GNUNET_UNUSED int \
913 prefix ## _get_multiple (struct MapType *map, \
918 struct prefix ## _Trampoline_ t; \
922 return GNUNET_CONTAINER_multimap_get_multiple_ ( \
923 (struct GNUNET_CONTAINER_MultiMap *) map, \
925 (NULL == it) ? NULL : &prefix ## _trampoline_, \
929 static inline GNUNET_UNUSED enum GNUNET_GenericReturnValue \
930 prefix ## _iterator_next (struct IterType *iter, \
932 const ValueType **value) \
934 return prefix ## _iterator_next_value_ (iter, \
954 GNUNET_CONTAINER_multihashmap,
955 GNUNET_CONTAINER_MultiHashMap,
956 GNUNET_CONTAINER_MultiHashMapIterator,
970 GNUNET_CONTAINER_multipeermap,
971 GNUNET_CONTAINER_MultiPeerMap,
972 GNUNET_CONTAINER_MultiPeerMapIterator,
986 GNUNET_CONTAINER_multishortmap,
987 GNUNET_CONTAINER_MultiShortmap,
988 GNUNET_CONTAINER_MultiShortmapIterator,
1002 GNUNET_CONTAINER_multiuuidmap,
1003 GNUNET_CONTAINER_MultiUuidmap,
1004 GNUNET_CONTAINER_MultiUuidmapIterator,
1018 GNUNET_CONTAINER_multihashmap32,
1019 GNUNET_CONTAINER_MultiHashMap32,
1020 GNUNET_CONTAINER_MultiHashMap32Iterator,
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
cryptographic primitives for GNUnet
int GNUNET_CONTAINER_multimap_iterate_(struct GNUNET_CONTAINER_MultiMap *map, GNUNET_CONTAINER_MultiMapIteratorCallback it, void *it_cls)
Call a function on every key-value pair of a map.
unsigned int GNUNET_CONTAINER_multimap_clear_(struct GNUNET_CONTAINER_MultiMap *map)
Remove all key-value pairs from a map.
struct GNUNET_CONTAINER_MultiMapIterator * GNUNET_CONTAINER_multimap_iterator_create_(const struct GNUNET_CONTAINER_MultiMap *map)
Create an iterator over a map.
#define GNUNET_CONTAINER_MULTIMAP_DEFINE_VALKEY(prefix, MapType, IterType, CbType, KeyType, ValueType)
Define a hash map type whose keys are passed by value, for keys of up to 8 bytes such as integers.
enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_ShortmapIterator)(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_PeerMapIterator)(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
void GNUNET_CONTAINER_multimap_iterator_destroy_(struct GNUNET_CONTAINER_MultiMapIterator *iter)
Destroy an iterator.
enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiHashMapIterator32Callback)(void *cls, uint32_t key, void *value)
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multimap_contains_(const struct GNUNET_CONTAINER_MultiMap *map, const void *key)
Check if the map has any value stored under a key.
enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiMapIteratorCallback)(void *cls, const void *key, void *value)
Iterator over the entries of a map with untyped keys and values.
GNUNET_CONTAINER_MultiHashMapOption
Options for storing values in the HashMap.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multimap_remove_(struct GNUNET_CONTAINER_MultiMap *map, const void *key, const void *value)
Remove a key-value pair from a map.
void GNUNET_CONTAINER_multimap_destroy_(struct GNUNET_CONTAINER_MultiMap *map)
Destroy a map.
#define GNUNET_CONTAINER_MULTIMAP_DEFINE_PTRKEY(prefix, MapType, IterType, CbType, KeyType, ValueType)
Define a hash map type whose keys are passed by pointer.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multimap_put_(struct GNUNET_CONTAINER_MultiMap *map, const void *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in a map.
unsigned int GNUNET_CONTAINER_multimap_size_(const struct GNUNET_CONTAINER_MultiMap *map)
Get the number of key-value pairs in a map.
void * GNUNET_CONTAINER_multimap_get_(const struct GNUNET_CONTAINER_MultiMap *map, const void *key)
Get a value stored under a key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multimap_iterator_next_(struct GNUNET_CONTAINER_MultiMapIterator *iter, void *key, const void **value)
Get the next key-value pair from an iterator.
struct GNUNET_CONTAINER_MultiMap * GNUNET_CONTAINER_multimap_create_(unsigned int len, size_t key_size, enum GNUNET_CONTAINER_MultiMapFlags flags)
Create a map.
enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiUuidmapIteratorCallback)(void *cls, const struct GNUNET_Uuid *key, void *value)
int GNUNET_CONTAINER_multimap_remove_all_(struct GNUNET_CONTAINER_MultiMap *map, const void *key)
Remove all values stored under a key from a map.
int GNUNET_CONTAINER_multimap_get_multiple_(struct GNUNET_CONTAINER_MultiMap *map, const void *key, GNUNET_CONTAINER_MultiMapIteratorCallback it, void *it_cls)
Call a function on every value stored under a key.
GNUNET_CONTAINER_MultiMapFlags
Flags for GNUNET_CONTAINER_multimap_create_().
enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiHashMapIteratorCallback)(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multimap_contains_value_(const struct GNUNET_CONTAINER_MultiMap *map, const void *key, const void *value)
Check if the map has a particular key-value pair.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
If a value with the given key exists, replace it.
@ GNUNET_CONTAINER_MULTIMAP_FLAG_NONE
Copy keys longer than 8 bytes into the map.
@ GNUNET_CONTAINER_MULTIMAP_FLAG_UNPROTECTED
Do not protect the map against hash flooding.
@ GNUNET_CONTAINER_MULTIMAP_FLAG_DO_NOT_COPY_KEYS
Do not copy keys longer than 8 bytes into the map, only keep a pointer to them.
GNUNET_GenericReturnValue
Named constants for return values.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Internal representation of a map.
size_t key_size
Size of the keys in bytes.
The identity of the host (wraps the signing key of the peer).
A UUID, a 128 bit "random" value.