2 This file is part of GNUnet.
3 (C) 2001-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_container_lib.h
23 * @brief container classes for GNUnet
24 * @author Christian Grothoff
26 * @defgroup hashmap multi hash-map
27 * @defgroup heap min- or max-heap with arbitrary element removal
28 * @defgroup bloomfilter Bloom filter (probabilistic set tests)
29 * @defgroup dll Doubly-linked list
30 * @defgroup metadata Meta data (GNU libextractor key-value pairs)
33 #ifndef GNUNET_CONTAINER_LIB_H
34 #define GNUNET_CONTAINER_LIB_H
36 /* add error and config prototypes */
37 #include "gnunet_crypto_lib.h"
38 #include <extractor.h>
40 #ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
41 /* hack for LE < 0.6.3 */
42 #define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
48 #if 0 /* keep Emacsens' auto-indent happy */
54 /* ******************* bloomfilter ***************** */
57 * @brief bloomfilter representation (opaque)
58 * @ingroup bloomfilter
60 struct GNUNET_CONTAINER_BloomFilter;
64 * @ingroup bloomfilter
65 * Iterator over `struct GNUNET_HashCode`.
68 * @param next set to the next hash code
69 * @return #GNUNET_YES if next was updated
70 * #GNUNET_NO if there are no more entries
73 (*GNUNET_CONTAINER_HashCodeIterator) (void *cls,
74 struct GNUNET_HashCode *next);
78 * @ingroup bloomfilter
79 * Load a Bloom filter from a file.
81 * @param filename the name of the file (or the prefix)
82 * @param size the size of the bloom-filter (number of
83 * bytes of storage space to use); will be rounded up
85 * @param k the number of #GNUNET_CRYPTO_hash-functions to apply per
86 * element (number of bits set per element in the set)
87 * @return the bloomfilter
89 struct GNUNET_CONTAINER_BloomFilter *
90 GNUNET_CONTAINER_bloomfilter_load (const char *filename,
96 * @ingroup bloomfilter
97 * Create a Bloom filter from raw bits.
99 * @param data the raw bits in memory (maybe NULL,
100 * in which case all bits should be considered
102 * @param size the size of the bloom-filter (number of
103 * bytes of storage space to use); also size of @a data
104 * -- unless data is NULL. Must be a power of 2.
105 * @param k the number of #GNUNET_CRYPTO_hash-functions to apply per
106 * element (number of bits set per element in the set)
107 * @return the bloomfilter
109 struct GNUNET_CONTAINER_BloomFilter *
110 GNUNET_CONTAINER_bloomfilter_init (const char *data,
116 * @ingroup bloomfilter
117 * Copy the raw data of this Bloom filter into
118 * the given data array.
120 * @param data where to write the data
121 * @param size the size of the given @a data array
122 * @return #GNUNET_SYSERR if the data array of the wrong size
125 GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct GNUNET_CONTAINER_BloomFilter *bf,
131 * @ingroup bloomfilter
132 * Test if an element is in the filter.
134 * @param e the element
135 * @param bf the filter
136 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
139 GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf,
140 const struct GNUNET_HashCode *e);
144 * @ingroup bloomfilter
145 * Add an element to the filter.
147 * @param bf the filter
148 * @param e the element
151 GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
152 const struct GNUNET_HashCode *e);
156 * @ingroup bloomfilter
157 * Remove an element from the filter.
159 * @param bf the filter
160 * @param e the element to remove
163 GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
164 const struct GNUNET_HashCode *e);
168 * @ingroup bloomfilter
169 * Create a copy of a bloomfilter.
171 * @param bf the filter
174 struct GNUNET_CONTAINER_BloomFilter *
175 GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf);
180 * @ingroup bloomfilter
181 * Free the space associcated with a filter
182 * in memory, flush to drive if needed (do not
183 * free the space on the drive).
185 * @param bf the filter
188 GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter *bf);
192 * Get the number of the addresses set per element in the bloom filter.
194 * @param bf the filter
195 * @return addresses set per element in the bf
198 GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter *bf);
202 * @ingroup bloomfilter
203 * Get size of the bloom filter.
205 * @param bf the filter
206 * @return number of bytes used for the data of the bloom filter
209 GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter *bf);
213 * @ingroup bloomfilter
214 * Reset a Bloom filter to empty.
216 * @param bf the filter
219 GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf);
223 * @ingroup bloomfilter
224 * "or" the entries of the given raw data array with the
225 * data of the given Bloom filter. Assumes that
226 * the @a size of the @a data array and the current filter
229 * @param bf the filter
230 * @param data data to OR-in
231 * @param size size of @a data
232 * @return #GNUNET_OK on success
235 GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
236 const char *data, size_t size);
240 * @ingroup bloomfilter
241 * "or" the entries of the given raw data array with the
242 * data of the given Bloom filter. Assumes that
243 * the size of the two filters matches.
245 * @param bf the filter
246 * @param to_or the bloomfilter to or-in
247 * @return #GNUNET_OK on success
250 GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
251 const struct GNUNET_CONTAINER_BloomFilter *to_or);
255 * @ingroup bloomfilter
256 * Resize a bloom filter. Note that this operation
257 * is pretty costly. Essentially, the Bloom filter
258 * needs to be completely re-build.
260 * @param bf the filter
261 * @param iterator an iterator over all elements stored in the BF
262 * @param iterator_cls closure for @a iterator
263 * @param size the new size for the filter
264 * @param k the new number of #GNUNET_CRYPTO_hash-function to apply per element
267 GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
268 GNUNET_CONTAINER_HashCodeIterator iterator,
274 /* ****************** metadata ******************* */
278 * Meta data to associate with a file, directory or namespace.
280 struct GNUNET_CONTAINER_MetaData;
285 * Create a fresh meta data container.
287 * @return empty meta-data container
289 struct GNUNET_CONTAINER_MetaData *
290 GNUNET_CONTAINER_meta_data_create (void);
295 * Duplicate a MetaData token.
297 * @param md what to duplicate
298 * @return duplicate meta-data container
300 struct GNUNET_CONTAINER_MetaData *
301 GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData *md);
308 * @param md what to free
311 GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
316 * Test if two MDs are equal. We consider them equal if
317 * the meta types, formats and content match (we do not
318 * include the mime types and plugins names in this
321 * @param md1 first value to check
322 * @param md2 other value to check
323 * @return #GNUNET_YES if they are equal
326 GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData *md1,
327 const struct GNUNET_CONTAINER_MetaData *md2);
334 * @param md metadata to extend
335 * @param plugin_name name of the plugin that produced this value;
336 * special values can be used (i.e. '<zlib>' for zlib being
337 * used in the main libextractor library and yielding
339 * @param type libextractor-type describing the meta data
340 * @param format basic format information about data
341 * @param data_mime_type mime-type of data (not of the original file);
342 * can be NULL (if mime-type is not known)
343 * @param data actual meta-data found
344 * @param data_size number of bytes in data
345 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
346 * data_mime_type and plugin_name are not considered for "exists" checks
349 GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
350 const char *plugin_name,
351 enum EXTRACTOR_MetaType type,
352 enum EXTRACTOR_MetaFormat format,
353 const char *data_mime_type,
360 * Extend metadata. Merges the meta data from the second argument
361 * into the first, discarding duplicate key-value pairs.
363 * @param md metadata to extend
364 * @param in metadata to merge
367 GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
368 const struct GNUNET_CONTAINER_MetaData *in);
375 * @param md metadata to manipulate
376 * @param type type of the item to remove
377 * @param data specific value to remove, NULL to remove all
378 * entries of the given type
379 * @param data_size number of bytes in data
380 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
383 GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
384 enum EXTRACTOR_MetaType type,
391 * Remove all items in the container.
393 * @param md metadata to manipulate
396 GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
401 * Add the current time as the publication date
404 * @param md metadata to modify
407 GNUNET_CONTAINER_meta_data_add_publication_date (struct GNUNET_CONTAINER_MetaData *md);
412 * Iterate over MD entries.
414 * @param md metadata to inspect
415 * @param iter function to call on each entry, return 0 to continue to iterate
416 * and 1 to abort iteration in this function (GNU libextractor API!)
417 * @param iter_cls closure for @a iter
418 * @return number of entries
421 GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
422 EXTRACTOR_MetaDataProcessor iter,
428 * Get the first MD entry of the given type. Caller
429 * is responsible for freeing the return value.
430 * Also, only meta data items that are strings (0-terminated)
431 * are returned by this function.
433 * @param md metadata to inspect
434 * @param type type to look for
435 * @return NULL if no entry was found
438 GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData *md,
439 enum EXTRACTOR_MetaType type);
444 * Get the first matching MD entry of the given types. Caller is
445 * responsible for freeing the return value. Also, only meta data
446 * items that are strings (0-terminated) are returned by this
449 * @param md metadata to inspect
450 * @param ... -1-terminated list of types
451 * @return NULL if we do not have any such entry,
452 * otherwise client is responsible for freeing the value!
455 GNUNET_CONTAINER_meta_data_get_first_by_types (const struct GNUNET_CONTAINER_MetaData *md,
460 * Get a thumbnail from the meta-data (if present). Only matches meta
461 * data with mime type "image" and binary format.
463 * @param md metadata to inspect
464 * @param thumb will be set to the thumbnail data. Must be
465 * freed by the caller!
466 * @return number of bytes in thumbnail, 0 if not available
469 GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData *md,
470 unsigned char **thumb);
476 * Options for metadata serialization.
478 enum GNUNET_CONTAINER_MetaDataSerializationOptions
482 * Serialize all of the data.
484 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0,
488 * If not enough space is available, it is acceptable
489 * to only serialize some of the metadata.
491 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1,
495 * Speed is of the essence, do not allow compression.
497 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2
503 * Serialize meta-data to target.
505 * @param md metadata to serialize
506 * @param target where to write the serialized metadata;
507 * *target can be NULL, in which case memory is allocated
508 * @param max maximum number of bytes available
509 * @param opt is it ok to just write SOME of the
510 * meta-data to match the size constraint,
511 * possibly discarding some data?
512 * @return number of bytes written on success,
513 * -1 on error (typically: not enough
517 GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData *md,
520 enum GNUNET_CONTAINER_MetaDataSerializationOptions opt);
525 * Get the size of the full meta-data in serialized form.
527 * @param md metadata to inspect
528 * @return number of bytes needed for serialization, -1 on error
531 GNUNET_CONTAINER_meta_data_get_serialized_size (const struct GNUNET_CONTAINER_MetaData *md);
536 * Deserialize meta-data. Initializes md.
538 * @param input serialized meta-data.
539 * @param size number of bytes available
540 * @return MD on success, NULL on error (i.e.
543 struct GNUNET_CONTAINER_MetaData *
544 GNUNET_CONTAINER_meta_data_deserialize (const char *input,
548 /* ******************************* HashMap **************************** */
552 * Opaque handle for a HashMap.
554 struct GNUNET_CONTAINER_MultiHashMap;
558 * Opaque handle to an iterator over
561 struct GNUNET_CONTAINER_MultiHashMapIterator;
565 * Options for storing values in the HashMap.
567 enum GNUNET_CONTAINER_MultiHashMapOption
572 * If a value with the given key exists, replace it. Note that the
573 * old value would NOT be freed by replace (the application has to
574 * make sure that this happens if required).
576 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE,
580 * Allow multiple values with the same key.
582 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE,
586 * There must only be one value per key; storing a value should fail
587 * if a value under the same key already exists.
589 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY,
592 * @ingroup hashmap There must only be one value per key, but don't
593 * bother checking if a value already exists (faster than
594 * #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY; implemented
595 * just like #GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE but this
596 * option documents better what is intended if
597 * #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY is what is
600 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
606 * Iterator over hash map entries.
609 * @param key current key code
610 * @param value value in the hash map
611 * @return #GNUNET_YES if we should continue to
615 typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls,
616 const struct GNUNET_HashCode *key,
622 * Create a multi hash map.
624 * @param len initial size (map will grow as needed)
625 * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
626 * #GNUNET_YES means that on 'put', the 'key' does not have
627 * to be copied as the destination of the pointer is
628 * guaranteed to be life as long as the value is stored in
629 * the hashmap. This can significantly reduce memory
630 * consumption, but of course is also a recipie for
631 * heap corruption if the assumption is not true. Only
632 * use this if (1) memory use is important in this case and
633 * (2) you have triple-checked that the invariant holds
634 * @return NULL on error
636 struct GNUNET_CONTAINER_MultiHashMap *
637 GNUNET_CONTAINER_multihashmap_create (unsigned int len,
638 int do_not_copy_keys);
643 * Destroy a hash map. Will not free any values
644 * stored in the hash map!
649 GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map);
654 * Given a key find a value in the map matching the key.
657 * @param key what to look for
658 * @return NULL if no value was found; note that
659 * this is indistinguishable from values that just
660 * happen to be NULL; use "contains" to test for
661 * key-value pairs with value NULL
664 GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map,
665 const struct GNUNET_HashCode *key);
670 * Remove the given key-value pair from the map. Note that if the
671 * key-value pair is in the map multiple times, only one of the pairs
675 * @param key key of the key-value pair
676 * @param value value of the key-value pair
677 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
681 GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
682 const struct GNUNET_HashCode *key,
687 * Remove all entries for the given key from the map.
688 * Note that the values would not be "freed".
691 * @param key identifies values to be removed
692 * @return number of values removed
695 GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map,
696 const struct GNUNET_HashCode *key);
701 * Check if the map contains any value under the given
702 * key (including values that are NULL).
705 * @param key the key to test if a value exists for it
706 * @return #GNUNET_YES if such a value exists,
710 GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map,
711 const struct GNUNET_HashCode * key);
716 * Check if the map contains the given value under the given
720 * @param key the key to test if a value exists for it
721 * @param value value to test for
722 * @return #GNUNET_YES if such a value exists,
726 GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map,
727 const struct GNUNET_HashCode *key,
733 * Store a key-value pair in the map.
736 * @param key key to use
737 * @param value value to use
738 * @param opt options for put
739 * @return #GNUNET_OK on success,
740 * #GNUNET_NO if a value was replaced (with REPLACE)
741 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
742 * value already exists
745 GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
746 const struct GNUNET_HashCode *key,
748 enum GNUNET_CONTAINER_MultiHashMapOption
753 * Get the number of key-value pairs in the map.
756 * @return the number of key value pairs
759 GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap
765 * Iterate over all entries in the map.
768 * @param it function to call on each entry
769 * @param it_cls extra argument to @a it
770 * @return the number of key value pairs processed,
771 * #GNUNET_SYSERR if it aborted iteration
774 GNUNET_CONTAINER_multihashmap_iterate (const struct
775 GNUNET_CONTAINER_MultiHashMap *map,
776 GNUNET_CONTAINER_HashMapIterator it,
782 * Create an iterator for a multihashmap.
783 * The iterator can be used to retrieve all the elements in the multihashmap
784 * one by one, without having to handle all elements at once (in contrast to
785 * #GNUNET_CONTAINER_multihashmap_iterate). Note that the iterator can not be
786 * used anymore if elements have been removed from 'map' after the creation of
787 * the iterator, or 'map' has been destroyed. Adding elements to 'map' may
788 * result in skipped or repeated elements.
790 * @param map the map to create an iterator for
791 * @return an iterator over the given multihashmap @a map
793 struct GNUNET_CONTAINER_MultiHashMapIterator *
794 GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map);
799 * Retrieve the next element from the hash map at the iterator's
800 * position. If there are no elements left, #GNUNET_NO is returned,
801 * and @a key and @a value are not modified. This operation is only
802 * allowed if no elements have been removed from the multihashmap
803 * since the creation of @a iter, and the map has not been destroyed.
804 * Adding elements may result in repeating or skipping elements.
806 * @param iter the iterator to get the next element from
807 * @param key pointer to store the key in, can be NULL
808 * @param value pointer to store the value in, can be NULL
809 * @return #GNUNET_YES we returned an element,
810 * #GNUNET_NO if we are out of elements
813 GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
814 struct GNUNET_HashCode *key,
820 * Destroy a multihashmap iterator.
822 * @param iter the iterator to destroy
825 GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
830 * Iterate over all entries in the map that match a particular key.
833 * @param key key that the entries must correspond to
834 * @param it function to call on each entry
835 * @param it_cls extra argument to @a it
836 * @return the number of key value pairs processed,
837 * #GNUNET_SYSERR if it aborted iteration
840 GNUNET_CONTAINER_multihashmap_get_multiple (const struct GNUNET_CONTAINER_MultiHashMap *map,
841 const struct GNUNET_HashCode *key,
842 GNUNET_CONTAINER_HashMapIterator it,
846 /* ***************** Version of Multihashmap for peer identities ****************** */
850 * Iterator over hash map entries.
853 * @param key current public key
854 * @param value value in the hash map
855 * @return #GNUNET_YES if we should continue to
859 typedef int (*GNUNET_CONTAINER_PeerMapIterator) (void *cls,
860 const struct GNUNET_PeerIdentity *key,
864 struct GNUNET_CONTAINER_MultiPeerMap;
867 * Create a multi peer map (hash map for public keys of peers).
869 * @param len initial size (map will grow as needed)
870 * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
871 * #GNUNET_YES means that on 'put', the 'key' does not have
872 * to be copied as the destination of the pointer is
873 * guaranteed to be life as long as the value is stored in
874 * the hashmap. This can significantly reduce memory
875 * consumption, but of course is also a recipie for
876 * heap corruption if the assumption is not true. Only
877 * use this if (1) memory use is important in this case and
878 * (2) you have triple-checked that the invariant holds
879 * @return NULL on error
881 struct GNUNET_CONTAINER_MultiPeerMap *
882 GNUNET_CONTAINER_multipeermap_create (unsigned int len,
883 int do_not_copy_keys);
888 * Destroy a hash map. Will not free any values
889 * stored in the hash map!
894 GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map);
899 * Given a key find a value in the map matching the key.
902 * @param key what to look for
903 * @return NULL if no value was found; note that
904 * this is indistinguishable from values that just
905 * happen to be NULL; use "contains" to test for
906 * key-value pairs with value NULL
909 GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map,
910 const struct GNUNET_PeerIdentity *key);
915 * Remove the given key-value pair from the map. Note that if the
916 * key-value pair is in the map multiple times, only one of the pairs
920 * @param key key of the key-value pair
921 * @param value value of the key-value pair
922 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
926 GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map,
927 const struct GNUNET_PeerIdentity * key,
932 * Remove all entries for the given key from the map.
933 * Note that the values would not be "freed".
936 * @param key identifies values to be removed
937 * @return number of values removed
940 GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map,
941 const struct GNUNET_PeerIdentity *key);
946 * Check if the map contains any value under the given
947 * key (including values that are NULL).
950 * @param key the key to test if a value exists for it
951 * @return #GNUNET_YES if such a value exists,
955 GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map,
956 const struct GNUNET_PeerIdentity *key);
961 * Check if the map contains the given value under the given
965 * @param key the key to test if a value exists for it
966 * @param value value to test for
967 * @return #GNUNET_YES if such a value exists,
971 GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map,
972 const struct GNUNET_PeerIdentity * key,
978 * Store a key-value pair in the map.
981 * @param key key to use
982 * @param value value to use
983 * @param opt options for put
984 * @return #GNUNET_OK on success,
985 * #GNUNET_NO if a value was replaced (with REPLACE)
986 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
987 * value already exists
990 GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map,
991 const struct GNUNET_PeerIdentity *key,
993 enum GNUNET_CONTAINER_MultiHashMapOption opt);
998 * Get the number of key-value pairs in the map.
1000 * @param map the map
1001 * @return the number of key value pairs
1004 GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map);
1009 * Iterate over all entries in the map.
1011 * @param map the map
1012 * @param it function to call on each entry
1013 * @param it_cls extra argument to @a it
1014 * @return the number of key value pairs processed,
1015 * #GNUNET_SYSERR if it aborted iteration
1018 GNUNET_CONTAINER_multipeermap_iterate (const struct GNUNET_CONTAINER_MultiPeerMap *map,
1019 GNUNET_CONTAINER_PeerMapIterator it,
1023 struct GNUNET_CONTAINER_MultiPeerMapIterator;
1026 * Create an iterator for a multihashmap.
1027 * The iterator can be used to retrieve all the elements in the multihashmap
1028 * one by one, without having to handle all elements at once (in contrast to
1029 * #GNUNET_CONTAINER_multipeermap_iterate). Note that the iterator can not be
1030 * used anymore if elements have been removed from @a map after the creation of
1031 * the iterator, or 'map' has been destroyed. Adding elements to @a map may
1032 * result in skipped or repeated elements.
1034 * @param map the map to create an iterator for
1035 * @return an iterator over the given multihashmap @a map
1037 struct GNUNET_CONTAINER_MultiPeerMapIterator *
1038 GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map);
1043 * Retrieve the next element from the hash map at the iterator's
1044 * position. If there are no elements left, #GNUNET_NO is returned,
1045 * and @a key and @a value are not modified. This operation is only
1046 * allowed if no elements have been removed from the multihashmap
1047 * since the creation of @a iter, and the map has not been destroyed.
1048 * Adding elements may result in repeating or skipping elements.
1050 * @param iter the iterator to get the next element from
1051 * @param key pointer to store the key in, can be NULL
1052 * @param value pointer to store the value in, can be NULL
1053 * @return #GNUNET_YES we returned an element,
1054 * #GNUNET_NO if we are out of elements
1057 GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
1058 struct GNUNET_PeerIdentity *key,
1059 const void **value);
1064 * Destroy a multipeermap iterator.
1066 * @param iter the iterator to destroy
1069 GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter);
1074 * Iterate over all entries in the map that match a particular key.
1076 * @param map the map
1077 * @param key public key that the entries must correspond to
1078 * @param it function to call on each entry
1079 * @param it_cls extra argument to @a it
1080 * @return the number of key value pairs processed,
1081 * #GNUNET_SYSERR if it aborted iteration
1084 GNUNET_CONTAINER_multipeermap_get_multiple (const struct GNUNET_CONTAINER_MultiPeerMap *map,
1085 const struct GNUNET_PeerIdentity *key,
1086 GNUNET_CONTAINER_PeerMapIterator it,
1091 /* Version of multihashmap with 32 bit keys */
1095 * Opaque handle for the 32-bit key HashMap.
1097 struct GNUNET_CONTAINER_MultiHashMap32;
1102 * Opaque handle to an iterator over
1103 * a 32-bit key multihashmap.
1105 struct GNUNET_CONTAINER_MultiHashMap32Iterator;
1110 * Iterator over hash map entries.
1112 * @param cls closure
1113 * @param key current key code
1114 * @param value value in the hash map
1115 * @return #GNUNET_YES if we should continue to
1117 * #GNUNET_NO if not.
1119 typedef int (*GNUNET_CONTAINER_HashMapIterator32) (void *cls,
1126 * Create a 32-bit key multi hash map.
1128 * @param len initial size (map will grow as needed)
1129 * @return NULL on error
1131 struct GNUNET_CONTAINER_MultiHashMap32 *
1132 GNUNET_CONTAINER_multihashmap32_create (unsigned int len);
1137 * Destroy a 32-bit key hash map. Will not free any values
1138 * stored in the hash map!
1140 * @param map the map
1143 GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32
1149 * Get the number of key-value pairs in the map.
1151 * @param map the map
1152 * @return the number of key value pairs
1155 GNUNET_CONTAINER_multihashmap32_size (const struct
1156 GNUNET_CONTAINER_MultiHashMap32 *map);
1161 * Given a key find a value in the map matching the key.
1163 * @param map the map
1164 * @param key what to look for
1165 * @return NULL if no value was found; note that
1166 * this is indistinguishable from values that just
1167 * happen to be NULL; use "contains" to test for
1168 * key-value pairs with value NULL
1171 GNUNET_CONTAINER_multihashmap32_get (const struct
1172 GNUNET_CONTAINER_MultiHashMap32 *map,
1178 * Iterate over all entries in the map.
1180 * @param map the map
1181 * @param it function to call on each entry
1182 * @param it_cls extra argument to @a it
1183 * @return the number of key value pairs processed,
1184 * #GNUNET_SYSERR if it aborted iteration
1187 GNUNET_CONTAINER_multihashmap32_iterate (const struct
1188 GNUNET_CONTAINER_MultiHashMap32 *map,
1189 GNUNET_CONTAINER_HashMapIterator32 it,
1195 * Remove the given key-value pair from the map. Note that if the
1196 * key-value pair is in the map multiple times, only one of the pairs
1199 * @param map the map
1200 * @param key key of the key-value pair
1201 * @param value value of the key-value pair
1202 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1206 GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1213 * Remove all entries for the given key from the map.
1214 * Note that the values would not be "freed".
1216 * @param map the map
1217 * @param key identifies values to be removed
1218 * @return number of values removed
1221 GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1227 * Check if the map contains any value under the given
1228 * key (including values that are NULL).
1230 * @param map the map
1231 * @param key the key to test if a value exists for it
1232 * @return #GNUNET_YES if such a value exists,
1236 GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1242 * Check if the map contains the given value under the given
1245 * @param map the map
1246 * @param key the key to test if a value exists for it
1247 * @param value value to test for
1248 * @return #GNUNET_YES if such a value exists,
1252 GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1259 * Store a key-value pair in the map.
1261 * @param map the map
1262 * @param key key to use
1263 * @param value value to use
1264 * @param opt options for put
1265 * @return #GNUNET_OK on success,
1266 * #GNUNET_NO if a value was replaced (with REPLACE)
1267 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1268 * value already exists
1271 GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1274 enum GNUNET_CONTAINER_MultiHashMapOption opt);
1279 * Iterate over all entries in the map that match a particular key.
1281 * @param map the map
1282 * @param key key that the entries must correspond to
1283 * @param it function to call on each entry
1284 * @param it_cls extra argument to @a it
1285 * @return the number of key value pairs processed,
1286 * #GNUNET_SYSERR if it aborted iteration
1289 GNUNET_CONTAINER_multihashmap32_get_multiple (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1291 GNUNET_CONTAINER_HashMapIterator32 it,
1296 * Create an iterator for a 32-bit multihashmap.
1297 * The iterator can be used to retrieve all the elements in the multihashmap
1298 * one by one, without having to handle all elements at once (in contrast to
1299 * #GNUNET_CONTAINER_multihashmap32_iterate). Note that the iterator can not be
1300 * used anymore if elements have been removed from 'map' after the creation of
1301 * the iterator, or 'map' has been destroyed. Adding elements to 'map' may
1302 * result in skipped or repeated elements.
1304 * @param map the map to create an iterator for
1305 * @return an iterator over the given multihashmap map
1307 struct GNUNET_CONTAINER_MultiHashMap32Iterator *
1308 GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap32 *map);
1312 * Retrieve the next element from the hash map at the iterator's position.
1313 * If there are no elements left, GNUNET_NO is returned, and 'key' and 'value'
1315 * This operation is only allowed if no elements have been removed from the
1316 * multihashmap since the creation of 'iter', and the map has not been destroyed.
1317 * Adding elements may result in repeating or skipping elements.
1319 * @param iter the iterator to get the next element from
1320 * @param key pointer to store the key in, can be NULL
1321 * @param value pointer to store the value in, can be NULL
1322 * @return #GNUNET_YES we returned an element,
1323 * #GNUNET_NO if we are out of elements
1326 GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
1328 const void **value);
1332 * Destroy a 32-bit multihashmap iterator.
1334 * @param iter the iterator to destroy
1337 GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
1340 /* ******************** doubly-linked list *************** */
1341 /* To avoid mistakes: head->prev == tail->next == NULL */
1345 * Insert an element at the head of a DLL. Assumes that head, tail and
1346 * element are structs with prev and next fields.
1348 * @param head pointer to the head of the DLL
1349 * @param tail pointer to the tail of the DLL
1350 * @param element element to insert
1352 #define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
1353 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1354 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1355 (element)->next = (head); \
1356 (element)->prev = NULL; \
1357 if ((tail) == NULL) \
1360 (head)->prev = element; \
1361 (head) = (element); } while (0)
1366 * Insert an element at the tail of a DLL. Assumes that head, tail and
1367 * element are structs with prev and next fields.
1369 * @param head pointer to the head of the DLL
1370 * @param tail pointer to the tail of the DLL
1371 * @param element element to insert
1373 #define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \
1374 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1375 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1376 (element)->prev = (tail); \
1377 (element)->next = NULL; \
1378 if ((head) == NULL) \
1381 (tail)->next = element; \
1382 (tail) = (element); } while (0)
1387 * Insert an element into a DLL after the given other element. Insert
1388 * at the head if the other element is NULL.
1390 * @param head pointer to the head of the DLL
1391 * @param tail pointer to the tail of the DLL
1392 * @param other prior element, NULL for insertion at head of DLL
1393 * @param element element to insert
1395 #define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
1396 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1397 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1398 (element)->prev = (other); \
1399 if (NULL == other) \
1401 (element)->next = (head); \
1402 (head) = (element); \
1406 (element)->next = (other)->next; \
1407 (other)->next = (element); \
1409 if (NULL == (element)->next) \
1410 (tail) = (element); \
1412 (element)->next->prev = (element); } while (0)
1417 * Insert an element into a DLL before the given other element. Insert
1418 * at the tail if the other element is NULL.
1420 * @param head pointer to the head of the DLL
1421 * @param tail pointer to the tail of the DLL
1422 * @param other prior element, NULL for insertion at head of DLL
1423 * @param element element to insert
1425 #define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
1426 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1427 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1428 (element)->next = (other); \
1429 if (NULL == other) \
1431 (element)->prev = (tail); \
1432 (tail) = (element); \
1436 (element)->prev = (other)->prev; \
1437 (other)->prev = (element); \
1439 if (NULL == (element)->prev) \
1440 (head) = (element); \
1442 (element)->prev->next = (element); } while (0)
1447 * Remove an element from a DLL. Assumes that head, tail and
1448 * element point to structs with prev and next fields.
1450 * Using the head or tail pointer as the element
1451 * argument does NOT work with this macro.
1452 * Make sure to store head/tail in another pointer
1453 * and use it to remove the head or tail of the list.
1455 * @param head pointer to the head of the DLL
1456 * @param tail pointer to the tail of the DLL
1457 * @param element element to remove
1459 #define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
1460 GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
1461 GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
1462 if ((element)->prev == NULL) \
1463 (head) = (element)->next; \
1465 (element)->prev->next = (element)->next; \
1466 if ((element)->next == NULL) \
1467 (tail) = (element)->prev; \
1469 (element)->next->prev = (element)->prev; \
1470 (element)->next = NULL; \
1471 (element)->prev = NULL; } while (0)
1474 /* ************ Multi-DLL interface, allows DLL elements to be
1475 in multiple lists at the same time *********************** */
1479 * Insert an element at the head of a MDLL. Assumes that head, tail and
1480 * element are structs with prev and next fields.
1482 * @param mdll suffix name for the next and prev pointers in the element
1483 * @param head pointer to the head of the MDLL
1484 * @param tail pointer to the tail of the MDLL
1485 * @param element element to insert
1487 #define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \
1488 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1489 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1490 (element)->next_##mdll = (head); \
1491 (element)->prev_##mdll = NULL; \
1492 if ((tail) == NULL) \
1495 (head)->prev_##mdll = element; \
1496 (head) = (element); } while (0)
1501 * Insert an element at the tail of a MDLL. Assumes that head, tail and
1502 * element are structs with prev and next fields.
1504 * @param mdll suffix name for the next and prev pointers in the element
1505 * @param head pointer to the head of the MDLL
1506 * @param tail pointer to the tail of the MDLL
1507 * @param element element to insert
1509 #define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \
1510 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1511 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1512 (element)->prev_##mdll = (tail); \
1513 (element)->next_##mdll = NULL; \
1514 if ((head) == NULL) \
1517 (tail)->next_##mdll = element; \
1518 (tail) = (element); } while (0)
1523 * Insert an element into a MDLL after the given other element. Insert
1524 * at the head if the other element is NULL.
1526 * @param mdll suffix name for the next and prev pointers in the element
1527 * @param head pointer to the head of the MDLL
1528 * @param tail pointer to the tail of the MDLL
1529 * @param other prior element, NULL for insertion at head of MDLL
1530 * @param element element to insert
1532 #define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \
1533 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1534 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1535 (element)->prev_##mdll = (other); \
1536 if (NULL == other) \
1538 (element)->next_##mdll = (head); \
1539 (head) = (element); \
1543 (element)->next_##mdll = (other)->next_##mdll; \
1544 (other)->next_##mdll = (element); \
1546 if (NULL == (element)->next_##mdll) \
1547 (tail) = (element); \
1549 (element)->next->prev_##mdll = (element); } while (0)
1554 * Insert an element into a MDLL before the given other element. Insert
1555 * at the tail if the other element is NULL.
1557 * @param mdll suffix name for the next and prev pointers in the element
1558 * @param head pointer to the head of the MDLL
1559 * @param tail pointer to the tail of the MDLL
1560 * @param other prior element, NULL for insertion at head of MDLL
1561 * @param element element to insert
1563 #define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \
1564 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1565 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1566 (element)->next_##mdll = (other); \
1567 if (NULL == other) \
1569 (element)->prev = (tail); \
1570 (tail) = (element); \
1574 (element)->prev_##mdll = (other)->prev_##mdll; \
1575 (other)->prev_##mdll = (element); \
1577 if (NULL == (element)->prev_##mdll) \
1578 (head) = (element); \
1580 (element)->prev_##mdll->next_##mdll = (element); } while (0)
1585 * Remove an element from a MDLL. Assumes
1586 * that head, tail and element are structs
1587 * with prev and next fields.
1589 * @param mdll suffix name for the next and prev pointers in the element
1590 * @param head pointer to the head of the MDLL
1591 * @param tail pointer to the tail of the MDLL
1592 * @param element element to remove
1594 #define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \
1595 GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \
1596 GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \
1597 if ((element)->prev_##mdll == NULL) \
1598 (head) = (element)->next_##mdll; \
1600 (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \
1601 if ((element)->next_##mdll == NULL) \
1602 (tail) = (element)->prev_##mdll; \
1604 (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \
1605 (element)->next_##mdll = NULL; \
1606 (element)->prev_##mdll = NULL; } while (0)
1610 /* ******************** Heap *************** */
1615 * Cost by which elements in a heap can be ordered.
1617 typedef uint64_t GNUNET_CONTAINER_HeapCostType;
1622 * Heap type, either max or min.
1624 enum GNUNET_CONTAINER_HeapOrder
1628 * Heap with the maximum cost at the root.
1630 GNUNET_CONTAINER_HEAP_ORDER_MAX,
1634 * Heap with the minimum cost at the root.
1636 GNUNET_CONTAINER_HEAP_ORDER_MIN
1644 struct GNUNET_CONTAINER_Heap;
1649 * Handle to a node in a heap.
1651 struct GNUNET_CONTAINER_HeapNode;
1656 * Create a new heap.
1658 * @param order how should the heap be sorted?
1659 * @return handle to the heap
1661 struct GNUNET_CONTAINER_Heap *
1662 GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order);
1667 * Destroys the heap. Only call on a heap that
1670 * @param heap heap to destroy
1673 GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap);
1678 * Get element stored at the root of @a heap.
1680 * @param heap Heap to inspect.
1681 * @return Element at the root, or NULL if heap is empty.
1684 GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
1688 * Get @a element and @a cost stored at the root of @a heap.
1690 * @param[in] heap Heap to inspect.
1691 * @param[out] element Root element is returned here.
1692 * @param[out] cost Cost of @a element is returned here.
1693 * @return #GNUNET_YES if an element is returned,
1694 * #GNUNET_NO if the heap is empty.
1697 GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
1699 GNUNET_CONTAINER_HeapCostType *cost);
1704 * Get the current size of the heap
1706 * @param heap the heap to get the size of
1707 * @return number of elements stored
1710 GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
1715 * Get the current cost of the node
1717 * @param node the node to get the cost of
1718 * @return cost of the node
1720 GNUNET_CONTAINER_HeapCostType
1721 GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
1728 * @param cls closure
1729 * @param node internal node of the heap
1730 * @param element value stored at the node
1731 * @param cost cost associated with the node
1732 * @return #GNUNET_YES if we should continue to iterate,
1733 * #GNUNET_NO if not.
1735 typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
1736 struct GNUNET_CONTAINER_HeapNode *
1737 node, void *element,
1738 GNUNET_CONTAINER_HeapCostType
1744 * Iterate over all entries in the heap.
1746 * @param heap the heap
1747 * @param iterator function to call on each entry
1748 * @param iterator_cls closure for @a iterator
1751 GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
1752 GNUNET_CONTAINER_HeapIterator iterator,
1753 void *iterator_cls);
1757 * Perform a random walk of the tree. The walk is biased
1758 * towards elements closer to the root of the tree (since
1759 * each walk starts at the root and ends at a random leaf).
1760 * The heap internally tracks the current position of the
1763 * @param heap heap to walk
1764 * @return data stored at the next random node in the walk;
1765 * NULL if the tree is empty.
1768 GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
1773 * Inserts a new element into the heap.
1775 * @param heap heap to modify
1776 * @param element element to insert
1777 * @param cost cost for the element
1778 * @return node for the new element
1780 struct GNUNET_CONTAINER_HeapNode *
1781 GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element,
1782 GNUNET_CONTAINER_HeapCostType cost);
1787 * Remove root of the heap.
1789 * @param heap heap to modify
1790 * @return element data stored at the root node
1793 GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
1798 * Removes a node from the heap.
1800 * @param node node to remove
1801 * @return element data stored at the node, NULL if heap is empty
1804 GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
1809 * Updates the cost of any node in the tree
1811 * @param heap heap to modify
1812 * @param node node for which the cost is to be changed
1813 * @param new_cost new cost for the node
1816 GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
1817 struct GNUNET_CONTAINER_HeapNode *node,
1818 GNUNET_CONTAINER_HeapCostType new_cost);
1821 #if 0 /* keep Emacsens' auto-indent happy */
1829 /* ifndef GNUNET_CONTAINER_LIB_H */
1831 /* end of gnunet_container_lib.h */