+unsigned int
+GNUNET_CONTAINER_multihashmap32_size (const struct
+ GNUNET_CONTAINER_MultiHashMap32 *map);
+
+
+/**
+ * @ingroup hashmap
+ * Given a key find a value in the map matching the key.
+ *
+ * @param map the map
+ * @param key what to look for
+ * @return NULL if no value was found; note that
+ * this is indistinguishable from values that just
+ * happen to be NULL; use "contains" to test for
+ * key-value pairs with value NULL
+ */
+void *
+GNUNET_CONTAINER_multihashmap32_get (const struct
+ GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key);
+
+
+/**
+ * @ingroup hashmap
+ * Iterate over all entries in the map.
+ *
+ * @param map the map
+ * @param it function to call on each entry
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed,
+ * #GNUNET_SYSERR if it aborted iteration
+ */
+int
+GNUNET_CONTAINER_multihashmap32_iterate (const struct
+ GNUNET_CONTAINER_MultiHashMap32 *map,
+ GNUNET_CONTAINER_HashMapIterator32 it,
+ void *it_cls);
+
+
+/**
+ * @ingroup hashmap
+ * Remove the given key-value pair from the map. Note that if the
+ * key-value pair is in the map multiple times, only one of the pairs
+ * will be removed.
+ *
+ * @param map the map
+ * @param key key of the key-value pair
+ * @param value value of the key-value pair
+ * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
+ * is not in the map
+ */
+int
+GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key,
+ const void *value);
+
+
+/**
+ * @ingroup hashmap
+ * Remove all entries for the given key from the map.
+ * Note that the values would not be "freed".
+ *
+ * @param map the map
+ * @param key identifies values to be removed
+ * @return number of values removed
+ */
+int
+GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key);
+
+
+/**
+ * @ingroup hashmap
+ * Check if the map contains any value under the given
+ * key (including values that are NULL).
+ *
+ * @param map the map
+ * @param key the key to test if a value exists for it
+ * @return #GNUNET_YES if such a value exists,
+ * #GNUNET_NO if not
+ */
+int
+GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key);
+
+
+/**
+ * @ingroup hashmap
+ * Check if the map contains the given value under the given
+ * key.
+ *
+ * @param map the map
+ * @param key the key to test if a value exists for it
+ * @param value value to test for
+ * @return #GNUNET_YES if such a value exists,
+ * #GNUNET_NO if not
+ */
+int
+GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key,
+ const void *value);
+
+
+/**
+ * @ingroup hashmap
+ * Store a key-value pair in the map.
+ *
+ * @param map the map
+ * @param key key to use
+ * @param value value to use
+ * @param opt options for put
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO if a value was replaced (with REPLACE)
+ * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
+ * value already exists
+ */
+int
+GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key,
+ void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt);
+
+
+/**
+ * @ingroup hashmap
+ * Iterate over all entries in the map that match a particular key.
+ *
+ * @param map the map
+ * @param key key that the entries must correspond to
+ * @param it function to call on each entry
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed,
+ * #GNUNET_SYSERR if it aborted iteration
+ */
+int
+GNUNET_CONTAINER_multihashmap32_get_multiple (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key,
+ GNUNET_CONTAINER_HashMapIterator32 it,
+ void *it_cls);
+
+
+/**
+ * Create an iterator for a 32-bit multihashmap.
+ * The iterator can be used to retrieve all the elements in the multihashmap
+ * one by one, without having to handle all elements at once (in contrast to
+ * #GNUNET_CONTAINER_multihashmap32_iterate). Note that the iterator can not be
+ * used anymore if elements have been removed from 'map' after the creation of
+ * the iterator, or 'map' has been destroyed. Adding elements to 'map' may
+ * result in skipped or repeated elements.
+ *
+ * @param map the map to create an iterator for
+ * @return an iterator over the given multihashmap map
+ */
+struct GNUNET_CONTAINER_MultiHashMap32Iterator *
+GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap32 *map);
+
+
+/**
+ * Retrieve the next element from the hash map at the iterator's position.
+ * If there are no elements left, GNUNET_NO is returned, and 'key' and 'value'
+ * are not modified.
+ * This operation is only allowed if no elements have been removed from the
+ * multihashmap since the creation of 'iter', and the map has not been destroyed.
+ * Adding elements may result in repeating or skipping elements.
+ *
+ * @param iter the iterator to get the next element from
+ * @param key pointer to store the key in, can be NULL
+ * @param value pointer to store the value in, can be NULL
+ * @return #GNUNET_YES we returned an element,
+ * #GNUNET_NO if we are out of elements
+ */
+int
+GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
+ uint32_t *key,
+ const void **value);
+
+
+/**
+ * Destroy a 32-bit multihashmap iterator.
+ *
+ * @param iter the iterator to destroy
+ */
+void
+GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
+
+
+/* ******************** doubly-linked list *************** */
+/* To avoid mistakes: head->prev == tail->next == NULL */
+
+/**
+ * @ingroup dll
+ * Insert an element at the head of a DLL. Assumes that head, tail and
+ * element are structs with prev and next fields.
+ *
+ * @param head pointer to the head of the DLL
+ * @param tail pointer to the tail of the DLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
+ GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
+ GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
+ (element)->next = (head); \
+ (element)->prev = NULL; \
+ if ((tail) == NULL) \
+ (tail) = element; \
+ else \
+ (head)->prev = element; \
+ (head) = (element); } while (0)
+
+
+/**
+ * @ingroup dll
+ * Insert an element at the tail of a DLL. Assumes that head, tail and
+ * element are structs with prev and next fields.
+ *
+ * @param head pointer to the head of the DLL
+ * @param tail pointer to the tail of the DLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \
+ GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
+ GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
+ (element)->prev = (tail); \
+ (element)->next = NULL; \
+ if ((head) == NULL) \
+ (head) = element; \
+ else \
+ (tail)->next = element; \
+ (tail) = (element); } while (0)
+
+
+/**
+ * @ingroup dll
+ * Insert an element into a DLL after the given other element. Insert
+ * at the head if the other element is NULL.
+ *
+ * @param head pointer to the head of the DLL
+ * @param tail pointer to the tail of the DLL
+ * @param other prior element, NULL for insertion at head of DLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
+ GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
+ GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
+ (element)->prev = (other); \
+ if (NULL == other) \
+ { \
+ (element)->next = (head); \
+ (head) = (element); \
+ } \
+ else \
+ { \
+ (element)->next = (other)->next; \
+ (other)->next = (element); \
+ } \
+ if (NULL == (element)->next) \
+ (tail) = (element); \
+ else \
+ (element)->next->prev = (element); } while (0)
+
+
+/**
+ * @ingroup dll
+ * Insert an element into a DLL before the given other element. Insert
+ * at the tail if the other element is NULL.
+ *
+ * @param head pointer to the head of the DLL
+ * @param tail pointer to the tail of the DLL
+ * @param other prior element, NULL for insertion at head of DLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
+ GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
+ GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
+ (element)->next = (other); \
+ if (NULL == other) \
+ { \
+ (element)->prev = (tail); \
+ (tail) = (element); \
+ } \
+ else \
+ { \
+ (element)->prev = (other)->prev; \
+ (other)->prev = (element); \
+ } \
+ if (NULL == (element)->prev) \
+ (head) = (element); \
+ else \
+ (element)->prev->next = (element); } while (0)
+
+
+/**
+ * @ingroup dll
+ * Remove an element from a DLL. Assumes that head, tail and
+ * element point to structs with prev and next fields.
+ *
+ * Using the head or tail pointer as the element
+ * argument does NOT work with this macro.
+ * Make sure to store head/tail in another pointer
+ * and use it to remove the head or tail of the list.
+ *
+ * @param head pointer to the head of the DLL
+ * @param tail pointer to the tail of the DLL
+ * @param element element to remove
+ */
+#define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
+ GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
+ GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
+ if ((element)->prev == NULL) \
+ (head) = (element)->next; \
+ else \
+ (element)->prev->next = (element)->next; \
+ if ((element)->next == NULL) \
+ (tail) = (element)->prev; \
+ else \
+ (element)->next->prev = (element)->prev; \
+ (element)->next = NULL; \
+ (element)->prev = NULL; } while (0)
+
+
+/* ************ Multi-DLL interface, allows DLL elements to be
+ in multiple lists at the same time *********************** */
+
+/**
+ * @ingroup dll
+ * Insert an element at the head of a MDLL. Assumes that head, tail and
+ * element are structs with prev and next fields.
+ *
+ * @param mdll suffix name for the next and prev pointers in the element
+ * @param head pointer to the head of the MDLL
+ * @param tail pointer to the tail of the MDLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \
+ GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
+ GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
+ (element)->next_##mdll = (head); \
+ (element)->prev_##mdll = NULL; \
+ if ((tail) == NULL) \
+ (tail) = element; \
+ else \
+ (head)->prev_##mdll = element; \
+ (head) = (element); } while (0)
+
+
+/**
+ * @ingroup dll
+ * Insert an element at the tail of a MDLL. Assumes that head, tail and
+ * element are structs with prev and next fields.
+ *
+ * @param mdll suffix name for the next and prev pointers in the element
+ * @param head pointer to the head of the MDLL
+ * @param tail pointer to the tail of the MDLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \
+ GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
+ GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
+ (element)->prev_##mdll = (tail); \
+ (element)->next_##mdll = NULL; \
+ if ((head) == NULL) \
+ (head) = element; \
+ else \
+ (tail)->next_##mdll = element; \
+ (tail) = (element); } while (0)
+
+
+/**
+ * @ingroup dll
+ * Insert an element into a MDLL after the given other element. Insert
+ * at the head if the other element is NULL.
+ *
+ * @param mdll suffix name for the next and prev pointers in the element
+ * @param head pointer to the head of the MDLL
+ * @param tail pointer to the tail of the MDLL
+ * @param other prior element, NULL for insertion at head of MDLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \
+ GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
+ GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
+ (element)->prev_##mdll = (other); \
+ if (NULL == other) \
+ { \
+ (element)->next_##mdll = (head); \
+ (head) = (element); \
+ } \
+ else \
+ { \
+ (element)->next_##mdll = (other)->next_##mdll; \
+ (other)->next_##mdll = (element); \
+ } \
+ if (NULL == (element)->next_##mdll) \
+ (tail) = (element); \
+ else \
+ (element)->next->prev_##mdll = (element); } while (0)
+
+
+/**
+ * @ingroup dll
+ * Insert an element into a MDLL before the given other element. Insert
+ * at the tail if the other element is NULL.
+ *
+ * @param mdll suffix name for the next and prev pointers in the element
+ * @param head pointer to the head of the MDLL
+ * @param tail pointer to the tail of the MDLL
+ * @param other prior element, NULL for insertion at head of MDLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \
+ GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
+ GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
+ (element)->next_##mdll = (other); \
+ if (NULL == other) \
+ { \
+ (element)->prev = (tail); \
+ (tail) = (element); \
+ } \
+ else \
+ { \
+ (element)->prev_##mdll = (other)->prev_##mdll; \
+ (other)->prev_##mdll = (element); \
+ } \
+ if (NULL == (element)->prev_##mdll) \
+ (head) = (element); \
+ else \
+ (element)->prev_##mdll->next_##mdll = (element); } while (0)
+
+
+/**
+ * @ingroup dll
+ * Remove an element from a MDLL. Assumes
+ * that head, tail and element are structs
+ * with prev and next fields.
+ *
+ * @param mdll suffix name for the next and prev pointers in the element
+ * @param head pointer to the head of the MDLL
+ * @param tail pointer to the tail of the MDLL
+ * @param element element to remove
+ */
+#define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \
+ GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \
+ GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \
+ if ((element)->prev_##mdll == NULL) \
+ (head) = (element)->next_##mdll; \
+ else \
+ (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \
+ if ((element)->next_##mdll == NULL) \
+ (tail) = (element)->prev_##mdll; \
+ else \
+ (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \
+ (element)->next_##mdll = NULL; \
+ (element)->prev_##mdll = NULL; } while (0)
+
+
+
+/**
+ * Insertion sort of @a element into DLL from @a head to @a tail
+ * sorted by @a comparator.
+ *
+ * @param TYPE element type of the elements, i.e. `struct ListElement`
+ * @param comparator function like memcmp() to compare elements; takes
+ * three arguments, the @a comparator_cls and two elements,
+ * returns an `int` (-1, 0 or 1)
+ * @param comparator_cls closure for @a comparator
+ * @param[in,out] head head of DLL
+ * @param[in,out] tail tail of DLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE,comparator,comparator_cls,head,tail,element) do { \
+ if ( (NULL == head) || \
+ (0 < comparator (comparator_cls, \
+ element, \
+ head)) ) \
+ { \
+ /* insert at head, element < head */ \
+ GNUNET_CONTAINER_DLL_insert (head, \
+ tail, \
+ element); \
+ } \
+ else \
+ { \
+ TYPE *pos; \
+ \
+ for (pos = head; \
+ NULL != pos; \
+ pos = pos->next) \
+ if (0 < \
+ comparator (comparator_cls, \
+ element, \
+ pos)) \
+ break; /* element < pos */ \
+ if (NULL == pos) /* => element > tail */ \
+ { \
+ GNUNET_CONTAINER_DLL_insert_tail (head, \
+ tail, \
+ element); \
+ } \
+ else /* prev < element < pos */ \
+ { \
+ GNUNET_CONTAINER_DLL_insert_after (head, \
+ tail, \
+ pos->prev, \
+ element); \
+ } \
+ } \
+} while (0)
+
+
+/* ******************** Heap *************** */
+
+
+/**
+ * @ingroup heap
+ * Cost by which elements in a heap can be ordered.
+ */
+typedef uint64_t GNUNET_CONTAINER_HeapCostType;
+
+
+/**
+ * @ingroup heap
+ * Heap type, either max or min.
+ */
+enum GNUNET_CONTAINER_HeapOrder
+{
+ /**
+ * @ingroup heap
+ * Heap with the maximum cost at the root.
+ */
+ GNUNET_CONTAINER_HEAP_ORDER_MAX,
+
+ /**
+ * @ingroup heap
+ * Heap with the minimum cost at the root.
+ */
+ GNUNET_CONTAINER_HEAP_ORDER_MIN
+};
+
+
+/**
+ * @ingroup heap
+ * Handle to a Heap.
+ */
+struct GNUNET_CONTAINER_Heap;
+
+
+/**
+ * @ingroup heap
+ * Handle to a node in a heap.
+ */
+struct GNUNET_CONTAINER_HeapNode;
+
+
+/**
+ * @ingroup heap
+ * Create a new heap.
+ *
+ * @param order how should the heap be sorted?
+ * @return handle to the heap
+ */
+struct GNUNET_CONTAINER_Heap *
+GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order);
+
+
+/**
+ * @ingroup heap
+ * Destroys the heap. Only call on a heap that
+ * is already empty.
+ *
+ * @param heap heap to destroy
+ */
+void
+GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap);
+
+
+/**
+ * @ingroup heap
+ * Get element stored at the root of @a heap.
+ *
+ * @param heap Heap to inspect.
+ * @return Element at the root, or NULL if heap is empty.
+ */
+void *
+GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
+
+
+/**
+ * Get @a element and @a cost stored at the root of @a heap.
+ *
+ * @param[in] heap Heap to inspect.
+ * @param[out] element Root element is returned here.
+ * @param[out] cost Cost of @a element is returned here.
+ * @return #GNUNET_YES if an element is returned,
+ * #GNUNET_NO if the heap is empty.
+ */
+int
+GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
+ void **element,
+ GNUNET_CONTAINER_HeapCostType *cost);
+
+
+/**
+ * @ingroup heap
+ * Get the current size of the heap
+ *
+ * @param heap the heap to get the size of
+ * @return number of elements stored
+ */
+unsigned int
+GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
+
+
+/**
+ * @ingroup heap
+ * Get the current cost of the node
+ *
+ * @param node the node to get the cost of
+ * @return cost of the node
+ */
+GNUNET_CONTAINER_HeapCostType
+GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *node);
+
+
+/**
+ * @ingroup heap
+ * Iterator for heap
+ *
+ * @param cls closure
+ * @param node internal node of the heap
+ * @param element value stored at the node
+ * @param cost cost associated with the node
+ * @return #GNUNET_YES if we should continue to iterate,
+ * #GNUNET_NO if not.
+ */
+typedef int
+(*GNUNET_CONTAINER_HeapIterator) (void *cls,
+ struct GNUNET_CONTAINER_HeapNode *node,
+ void *element,
+ GNUNET_CONTAINER_HeapCostType cost);
+
+
+/**
+ * @ingroup heap
+ * Iterate over all entries in the heap.
+ *
+ * @param heap the heap
+ * @param iterator function to call on each entry
+ * @param iterator_cls closure for @a iterator
+ */
+void
+GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
+ GNUNET_CONTAINER_HeapIterator iterator,
+ void *iterator_cls);
+
+/**
+ * @ingroup heap
+ * Perform a random walk of the tree. The walk is biased
+ * towards elements closer to the root of the tree (since
+ * each walk starts at the root and ends at a random leaf).
+ * The heap internally tracks the current position of the
+ * walk.
+ *
+ * @param heap heap to walk
+ * @return data stored at the next random node in the walk;
+ * NULL if the tree is empty.
+ */
+void *
+GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
+
+
+/**
+ * @ingroup heap
+ * Inserts a new element into the heap.
+ *
+ * @param heap heap to modify
+ * @param element element to insert
+ * @param cost cost for the element
+ * @return node for the new element
+ */
+struct GNUNET_CONTAINER_HeapNode *
+GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
+ void *element,
+ GNUNET_CONTAINER_HeapCostType cost);
+
+
+/**
+ * @ingroup heap
+ * Remove root of the heap.
+ *
+ * @param heap heap to modify
+ * @return element data stored at the root node
+ */
+void *
+GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
+
+
+/**
+ * @ingroup heap
+ * Removes a node from the heap.
+ *
+ * @param node node to remove
+ * @return element data stored at the node, NULL if heap is empty
+ */
+void *
+GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
+
+
+/**
+ * @ingroup heap
+ * Updates the cost of any node in the tree
+ *
+ * @param node node for which the cost is to be changed
+ * @param new_cost new cost for the node
+ */
+void
+GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node,
+ GNUNET_CONTAINER_HeapCostType new_cost);