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;
63 * @ingroup bloomfilter
64 * Iterator over `struct GNUNET_HashCode`.
67 * @param next set to the next hash code
68 * @return #GNUNET_YES if next was updated
69 * #GNUNET_NO if there are no more entries
71 typedef int (*GNUNET_CONTAINER_HashCodeIterator) (void *cls,
72 struct GNUNET_HashCode *next);
76 * @ingroup bloomfilter
77 * Load a Bloom filter from a file.
79 * @param filename the name of the file (or the prefix)
80 * @param size the size of the bloom-filter (number of
81 * bytes of storage space to use); will be rounded up
83 * @param k the number of #GNUNET_CRYPTO_hash-functions to apply per
84 * element (number of bits set per element in the set)
85 * @return the bloomfilter
87 struct GNUNET_CONTAINER_BloomFilter *
88 GNUNET_CONTAINER_bloomfilter_load (const char *filename,
94 * @ingroup bloomfilter
95 * Create a Bloom filter from raw bits.
97 * @param data the raw bits in memory (maybe NULL,
98 * in which case all bits should be considered
100 * @param size the size of the bloom-filter (number of
101 * bytes of storage space to use); also size of @a data
102 * -- unless data is NULL. Must be a power of 2.
103 * @param k the number of #GNUNET_CRYPTO_hash-functions to apply per
104 * element (number of bits set per element in the set)
105 * @return the bloomfilter
107 struct GNUNET_CONTAINER_BloomFilter *
108 GNUNET_CONTAINER_bloomfilter_init (const char *data,
114 * @ingroup bloomfilter
115 * Copy the raw data of this Bloom filter into
116 * the given data array.
118 * @param data where to write the data
119 * @param size the size of the given @a data array
120 * @return #GNUNET_SYSERR if the data array of the wrong size
123 GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct GNUNET_CONTAINER_BloomFilter *bf,
124 char *data, size_t size);
128 * @ingroup bloomfilter
129 * Test if an element is in the filter.
131 * @param e the element
132 * @param bf the filter
133 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
136 GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf,
137 const struct GNUNET_HashCode *e);
141 * @ingroup bloomfilter
142 * Add an element to the filter.
144 * @param bf the filter
145 * @param e the element
148 GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
149 const struct GNUNET_HashCode *e);
153 * @ingroup bloomfilter
154 * Remove an element from the filter.
156 * @param bf the filter
157 * @param e the element to remove
160 GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
161 const struct GNUNET_HashCode *e);
165 * @ingroup bloomfilter
166 * Create a copy of a bloomfilter.
168 * @param bf the filter
171 struct GNUNET_CONTAINER_BloomFilter *
172 GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf);
177 * @ingroup bloomfilter
178 * Free the space associcated with a filter
179 * in memory, flush to drive if needed (do not
180 * free the space on the drive).
182 * @param bf the filter
185 GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter *bf);
189 * Get the number of the addresses set per element in the bloom filter.
191 * @param bf the filter
192 * @return addresses set per element in the bf
195 GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter *bf);
198 * @ingroup bloomfilter
199 * Get size of the bloom filter.
201 * @param bf the filter
202 * @return number of bytes used for the data of the bloom filter
205 GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter *bf);
209 * @ingroup bloomfilter
210 * Reset a Bloom filter to empty.
212 * @param bf the filter
215 GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf);
219 * @ingroup bloomfilter
220 * "or" the entries of the given raw data array with the
221 * data of the given Bloom filter. Assumes that
222 * the @a size of the @a data array and the current filter
225 * @param bf the filter
226 * @param data data to OR-in
227 * @param size size of @a data
228 * @return #GNUNET_OK on success
231 GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
232 const char *data, size_t size);
236 * @ingroup bloomfilter
237 * "or" the entries of the given raw data array with the
238 * data of the given Bloom filter. Assumes that
239 * the size of the two filters matches.
241 * @param bf the filter
242 * @param to_or the bloomfilter to or-in
243 * @return #GNUNET_OK on success
246 GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
247 const struct GNUNET_CONTAINER_BloomFilter *to_or);
250 * @ingroup bloomfilter
251 * Resize a bloom filter. Note that this operation
252 * is pretty costly. Essentially, the Bloom filter
253 * needs to be completely re-build.
255 * @param bf the filter
256 * @param iterator an iterator over all elements stored in the BF
257 * @param iterator_cls closure for @a iterator
258 * @param size the new size for the filter
259 * @param k the new number of #GNUNET_CRYPTO_hash-function to apply per element
262 GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
263 GNUNET_CONTAINER_HashCodeIterator iterator,
264 void *iterator_cls, size_t size,
268 /* ****************** metadata ******************* */
272 * Meta data to associate with a file, directory or namespace.
274 struct GNUNET_CONTAINER_MetaData;
278 * Create a fresh meta data container.
280 * @return empty meta-data container
282 struct GNUNET_CONTAINER_MetaData *
283 GNUNET_CONTAINER_meta_data_create (void);
288 * Duplicate a MetaData token.
290 * @param md what to duplicate
291 * @return duplicate meta-data container
293 struct GNUNET_CONTAINER_MetaData *
294 GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
301 * @param md what to free
304 GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
309 * Test if two MDs are equal. We consider them equal if
310 * the meta types, formats and content match (we do not
311 * include the mime types and plugins names in this
314 * @param md1 first value to check
315 * @param md2 other value to check
316 * @return #GNUNET_YES if they are equal
319 GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData *md1,
320 const struct GNUNET_CONTAINER_MetaData *md2);
327 * @param md metadata to extend
328 * @param plugin_name name of the plugin that produced this value;
329 * special values can be used (i.e. '<zlib>' for zlib being
330 * used in the main libextractor library and yielding
332 * @param type libextractor-type describing the meta data
333 * @param format basic format information about data
334 * @param data_mime_type mime-type of data (not of the original file);
335 * can be NULL (if mime-type is not known)
336 * @param data actual meta-data found
337 * @param data_size number of bytes in data
338 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
339 * data_mime_type and plugin_name are not considered for "exists" checks
342 GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
343 const char *plugin_name,
344 enum EXTRACTOR_MetaType type,
345 enum EXTRACTOR_MetaFormat format,
346 const char *data_mime_type, const char *data,
352 * Extend metadata. Merges the meta data from the second argument
353 * into the first, discarding duplicate key-value pairs.
355 * @param md metadata to extend
356 * @param in metadata to merge
359 GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
360 const struct GNUNET_CONTAINER_MetaData *in);
367 * @param md metadata to manipulate
368 * @param type type of the item to remove
369 * @param data specific value to remove, NULL to remove all
370 * entries of the given type
371 * @param data_size number of bytes in data
372 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
375 GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
376 enum EXTRACTOR_MetaType type,
377 const char *data, size_t data_size);
382 * Remove all items in the container.
384 * @param md metadata to manipulate
387 GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
392 * Add the current time as the publication date
395 * @param md metadata to modify
398 GNUNET_CONTAINER_meta_data_add_publication_date (struct
399 GNUNET_CONTAINER_MetaData *md);
404 * Iterate over MD entries.
406 * @param md metadata to inspect
407 * @param iter function to call on each entry, return 0 to continue to iterate
408 * and 1 to abort iteration in this function (GNU libextractor API!)
409 * @param iter_cls closure for @a iter
410 * @return number of entries
413 GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
414 EXTRACTOR_MetaDataProcessor iter,
420 * Get the first MD entry of the given type. Caller
421 * is responsible for freeing the return value.
422 * Also, only meta data items that are strings (0-terminated)
423 * are returned by this function.
425 * @param md metadata to inspect
426 * @param type type to look for
427 * @return NULL if no entry was found
430 GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData
431 *md, enum EXTRACTOR_MetaType type);
436 * Get the first matching MD entry of the given types. Caller is
437 * responsible for freeing the return value. Also, only meta data
438 * items that are strings (0-terminated) are returned by this
441 * @param md metadata to inspect
442 * @param ... -1-terminated list of types
443 * @return NULL if we do not have any such entry,
444 * otherwise client is responsible for freeing the value!
447 GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
448 GNUNET_CONTAINER_MetaData *md,
453 * Get a thumbnail from the meta-data (if present). Only matches meta
454 * data with mime type "image" and binary format.
456 * @param md metadata to inspect
457 * @param thumb will be set to the thumbnail data. Must be
458 * freed by the caller!
459 * @return number of bytes in thumbnail, 0 if not available
462 GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData
463 *md, unsigned char **thumb);
469 * Options for metadata serialization.
471 enum GNUNET_CONTAINER_MetaDataSerializationOptions
475 * Serialize all of the data.
477 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0,
481 * If not enough space is available, it is acceptable
482 * to only serialize some of the metadata.
484 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1,
488 * Speed is of the essence, do not allow compression.
490 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2
496 * Serialize meta-data to target.
498 * @param md metadata to serialize
499 * @param target where to write the serialized metadata;
500 * *target can be NULL, in which case memory is allocated
501 * @param max maximum number of bytes available
502 * @param opt is it ok to just write SOME of the
503 * meta-data to match the size constraint,
504 * possibly discarding some data?
505 * @return number of bytes written on success,
506 * -1 on error (typically: not enough
510 GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
511 *md, char **target, size_t max,
513 GNUNET_CONTAINER_MetaDataSerializationOptions
519 * Get the size of the full meta-data in serialized form.
521 * @param md metadata to inspect
522 * @return number of bytes needed for serialization, -1 on error
525 GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
526 GNUNET_CONTAINER_MetaData *md);
531 * Deserialize meta-data. Initializes md.
533 * @param input serialized meta-data.
534 * @param size number of bytes available
535 * @return MD on success, NULL on error (i.e.
538 struct GNUNET_CONTAINER_MetaData *
539 GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size);
542 /* ******************************* HashMap **************************** */
546 * Opaque handle for a HashMap.
548 struct GNUNET_CONTAINER_MultiHashMap;
552 * Opaque handle to an iterator over
555 struct GNUNET_CONTAINER_MultiHashMapIterator;
559 * Options for storing values in the HashMap.
561 enum GNUNET_CONTAINER_MultiHashMapOption
566 * If a value with the given key exists, replace it. Note that the
567 * old value would NOT be freed by replace (the application has to
568 * make sure that this happens if required).
570 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE,
574 * Allow multiple values with the same key.
576 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE,
580 * There must only be one value per key; storing a value should fail
581 * if a value under the same key already exists.
583 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY,
586 * @ingroup hashmap There must only be one value per key, but don't
587 * bother checking if a value already exists (faster than
588 * #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY; implemented
589 * just like #GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE but this
590 * option documents better what is intended if
591 * #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY is what is
594 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
600 * Iterator over hash map entries.
603 * @param key current key code
604 * @param value value in the hash map
605 * @return #GNUNET_YES if we should continue to
609 typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls,
610 const struct GNUNET_HashCode *key,
616 * Create a multi hash map.
618 * @param len initial size (map will grow as needed)
619 * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
620 * #GNUNET_YES means that on 'put', the 'key' does not have
621 * to be copied as the destination of the pointer is
622 * guaranteed to be life as long as the value is stored in
623 * the hashmap. This can significantly reduce memory
624 * consumption, but of course is also a recipie for
625 * heap corruption if the assumption is not true. Only
626 * use this if (1) memory use is important in this case and
627 * (2) you have triple-checked that the invariant holds
628 * @return NULL on error
630 struct GNUNET_CONTAINER_MultiHashMap *
631 GNUNET_CONTAINER_multihashmap_create (unsigned int len,
632 int do_not_copy_keys);
637 * Destroy a hash map. Will not free any values
638 * stored in the hash map!
643 GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map);
648 * Given a key find a value in the map matching the key.
651 * @param key what to look for
652 * @return NULL if no value was found; note that
653 * this is indistinguishable from values that just
654 * happen to be NULL; use "contains" to test for
655 * key-value pairs with value NULL
658 GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map,
659 const struct GNUNET_HashCode *key);
664 * Remove the given key-value pair from the map. Note that if the
665 * key-value pair is in the map multiple times, only one of the pairs
669 * @param key key of the key-value pair
670 * @param value value of the key-value pair
671 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
675 GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
676 const struct GNUNET_HashCode *key,
681 * Remove all entries for the given key from the map.
682 * Note that the values would not be "freed".
685 * @param key identifies values to be removed
686 * @return number of values removed
689 GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map,
690 const struct GNUNET_HashCode *key);
695 * Check if the map contains any value under the given
696 * key (including values that are NULL).
699 * @param key the key to test if a value exists for it
700 * @return #GNUNET_YES if such a value exists,
704 GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map,
705 const struct GNUNET_HashCode * key);
710 * Check if the map contains the given value under the given
714 * @param key the key to test if a value exists for it
715 * @param value value to test for
716 * @return #GNUNET_YES if such a value exists,
720 GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map,
721 const struct GNUNET_HashCode *key,
727 * Store a key-value pair in the map.
730 * @param key key to use
731 * @param value value to use
732 * @param opt options for put
733 * @return #GNUNET_OK on success,
734 * #GNUNET_NO if a value was replaced (with REPLACE)
735 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
736 * value already exists
739 GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
740 const struct GNUNET_HashCode *key,
742 enum GNUNET_CONTAINER_MultiHashMapOption
747 * Get the number of key-value pairs in the map.
750 * @return the number of key value pairs
753 GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap
759 * Iterate over all entries in the map.
762 * @param it function to call on each entry
763 * @param it_cls extra argument to @a it
764 * @return the number of key value pairs processed,
765 * #GNUNET_SYSERR if it aborted iteration
768 GNUNET_CONTAINER_multihashmap_iterate (const struct
769 GNUNET_CONTAINER_MultiHashMap *map,
770 GNUNET_CONTAINER_HashMapIterator it,
776 * Create an iterator for a multihashmap.
777 * The iterator can be used to retrieve all the elements in the multihashmap
778 * one by one, without having to handle all elements at once (in contrast to
779 * #GNUNET_CONTAINER_multihashmap_iterate). Note that the iterator can not be
780 * used anymore if elements have been removed from 'map' after the creation of
781 * the iterator, or 'map' has been destroyed. Adding elements to 'map' may
782 * result in skipped or repeated elements.
784 * @param map the map to create an iterator for
785 * @return an iterator over the given multihashmap @a map
787 struct GNUNET_CONTAINER_MultiHashMapIterator *
788 GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map);
793 * Retrieve the next element from the hash map at the iterator's
794 * position. If there are no elements left, #GNUNET_NO is returned,
795 * and @a key and @a value are not modified. This operation is only
796 * allowed if no elements have been removed from the multihashmap
797 * since the creation of @a iter, and the map has not been destroyed.
798 * Adding elements may result in repeating or skipping elements.
800 * @param iter the iterator to get the next element from
801 * @param key pointer to store the key in, can be NULL
802 * @param value pointer to store the value in, can be NULL
803 * @return #GNUNET_YES we returned an element,
804 * #GNUNET_NO if we are out of elements
807 GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
808 struct GNUNET_HashCode *key,
814 * Destroy a multihashmap iterator.
816 * @param iter the iterator to destroy
819 GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
824 * Iterate over all entries in the map that match a particular key.
827 * @param key key that the entries must correspond to
828 * @param it function to call on each entry
829 * @param it_cls extra argument to @a it
830 * @return the number of key value pairs processed,
831 * #GNUNET_SYSERR if it aborted iteration
834 GNUNET_CONTAINER_multihashmap_get_multiple (const struct
835 GNUNET_CONTAINER_MultiHashMap *map,
836 const struct GNUNET_HashCode * key,
837 GNUNET_CONTAINER_HashMapIterator it,
841 /* ***************** Version of Multihashmap for peer identities ****************** */
845 * Iterator over hash map entries.
848 * @param key current public key
849 * @param value value in the hash map
850 * @return #GNUNET_YES if we should continue to
854 typedef int (*GNUNET_CONTAINER_PeerMapIterator) (void *cls,
855 const struct GNUNET_PeerIdentity *key,
859 struct GNUNET_CONTAINER_MultiPeerMap;
862 * Create a multi peer map (hash map for public keys of peers).
864 * @param len initial size (map will grow as needed)
865 * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
866 * #GNUNET_YES means that on 'put', the 'key' does not have
867 * to be copied as the destination of the pointer is
868 * guaranteed to be life as long as the value is stored in
869 * the hashmap. This can significantly reduce memory
870 * consumption, but of course is also a recipie for
871 * heap corruption if the assumption is not true. Only
872 * use this if (1) memory use is important in this case and
873 * (2) you have triple-checked that the invariant holds
874 * @return NULL on error
876 struct GNUNET_CONTAINER_MultiPeerMap *
877 GNUNET_CONTAINER_multipeermap_create (unsigned int len,
878 int do_not_copy_keys);
883 * Destroy a hash map. Will not free any values
884 * stored in the hash map!
889 GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map);
894 * Given a key find a value in the map matching the key.
897 * @param key what to look for
898 * @return NULL if no value was found; note that
899 * this is indistinguishable from values that just
900 * happen to be NULL; use "contains" to test for
901 * key-value pairs with value NULL
904 GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map,
905 const struct GNUNET_PeerIdentity *key);
910 * Remove the given key-value pair from the map. Note that if the
911 * key-value pair is in the map multiple times, only one of the pairs
915 * @param key key of the key-value pair
916 * @param value value of the key-value pair
917 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
921 GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map,
922 const struct GNUNET_PeerIdentity * key,
927 * Remove all entries for the given key from the map.
928 * Note that the values would not be "freed".
931 * @param key identifies values to be removed
932 * @return number of values removed
935 GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map,
936 const struct GNUNET_PeerIdentity *key);
941 * Check if the map contains any value under the given
942 * key (including values that are NULL).
945 * @param key the key to test if a value exists for it
946 * @return #GNUNET_YES if such a value exists,
950 GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map,
951 const struct GNUNET_PeerIdentity *key);
956 * Check if the map contains the given value under the given
960 * @param key the key to test if a value exists for it
961 * @param value value to test for
962 * @return #GNUNET_YES if such a value exists,
966 GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map,
967 const struct GNUNET_PeerIdentity * key,
973 * Store a key-value pair in the map.
976 * @param key key to use
977 * @param value value to use
978 * @param opt options for put
979 * @return #GNUNET_OK on success,
980 * #GNUNET_NO if a value was replaced (with REPLACE)
981 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
982 * value already exists
985 GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map,
986 const struct GNUNET_PeerIdentity *key,
988 enum GNUNET_CONTAINER_MultiHashMapOption opt);
993 * Get the number of key-value pairs in the map.
996 * @return the number of key value pairs
999 GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map);
1004 * Iterate over all entries in the map.
1006 * @param map the map
1007 * @param it function to call on each entry
1008 * @param it_cls extra argument to @a it
1009 * @return the number of key value pairs processed,
1010 * #GNUNET_SYSERR if it aborted iteration
1013 GNUNET_CONTAINER_multipeermap_iterate (const struct GNUNET_CONTAINER_MultiPeerMap *map,
1014 GNUNET_CONTAINER_PeerMapIterator it,
1018 struct GNUNET_CONTAINER_MultiPeerMapIterator;
1021 * Create an iterator for a multihashmap.
1022 * The iterator can be used to retrieve all the elements in the multihashmap
1023 * one by one, without having to handle all elements at once (in contrast to
1024 * #GNUNET_CONTAINER_multipeermap_iterate). Note that the iterator can not be
1025 * used anymore if elements have been removed from @a map after the creation of
1026 * the iterator, or 'map' has been destroyed. Adding elements to @a map may
1027 * result in skipped or repeated elements.
1029 * @param map the map to create an iterator for
1030 * @return an iterator over the given multihashmap @a map
1032 struct GNUNET_CONTAINER_MultiPeerMapIterator *
1033 GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map);
1038 * Retrieve the next element from the hash map at the iterator's
1039 * position. If there are no elements left, #GNUNET_NO is returned,
1040 * and @a key and @a value are not modified. This operation is only
1041 * allowed if no elements have been removed from the multihashmap
1042 * since the creation of @a iter, and the map has not been destroyed.
1043 * Adding elements may result in repeating or skipping elements.
1045 * @param iter the iterator to get the next element from
1046 * @param key pointer to store the key in, can be NULL
1047 * @param value pointer to store the value in, can be NULL
1048 * @return #GNUNET_YES we returned an element,
1049 * #GNUNET_NO if we are out of elements
1052 GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
1053 struct GNUNET_PeerIdentity *key,
1054 const void **value);
1059 * Destroy a multipeermap iterator.
1061 * @param iter the iterator to destroy
1064 GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter);
1069 * Iterate over all entries in the map that match a particular key.
1071 * @param map the map
1072 * @param key public key that the entries must correspond to
1073 * @param it function to call on each entry
1074 * @param it_cls extra argument to @a it
1075 * @return the number of key value pairs processed,
1076 * #GNUNET_SYSERR if it aborted iteration
1079 GNUNET_CONTAINER_multipeermap_get_multiple (const struct GNUNET_CONTAINER_MultiPeerMap *map,
1080 const struct GNUNET_PeerIdentity *key,
1081 GNUNET_CONTAINER_PeerMapIterator it,
1086 /* Version of multihashmap with 32 bit keys */
1090 * Opaque handle for the 32-bit key HashMap.
1092 struct GNUNET_CONTAINER_MultiHashMap32;
1097 * Opaque handle to an iterator over
1098 * a 32-bit key multihashmap.
1100 struct GNUNET_CONTAINER_MultiHashMap32Iterator;
1105 * Iterator over hash map entries.
1107 * @param cls closure
1108 * @param key current key code
1109 * @param value value in the hash map
1110 * @return #GNUNET_YES if we should continue to
1112 * #GNUNET_NO if not.
1114 typedef int (*GNUNET_CONTAINER_HashMapIterator32) (void *cls,
1121 * Create a 32-bit key multi hash map.
1123 * @param len initial size (map will grow as needed)
1124 * @return NULL on error
1126 struct GNUNET_CONTAINER_MultiHashMap32 *
1127 GNUNET_CONTAINER_multihashmap32_create (unsigned int len);
1132 * Destroy a 32-bit key hash map. Will not free any values
1133 * stored in the hash map!
1135 * @param map the map
1138 GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32
1144 * Get the number of key-value pairs in the map.
1146 * @param map the map
1147 * @return the number of key value pairs
1150 GNUNET_CONTAINER_multihashmap32_size (const struct
1151 GNUNET_CONTAINER_MultiHashMap32 *map);
1156 * Given a key find a value in the map matching the key.
1158 * @param map the map
1159 * @param key what to look for
1160 * @return NULL if no value was found; note that
1161 * this is indistinguishable from values that just
1162 * happen to be NULL; use "contains" to test for
1163 * key-value pairs with value NULL
1166 GNUNET_CONTAINER_multihashmap32_get (const struct
1167 GNUNET_CONTAINER_MultiHashMap32 *map,
1173 * Iterate over all entries in the map.
1175 * @param map the map
1176 * @param it function to call on each entry
1177 * @param it_cls extra argument to @a it
1178 * @return the number of key value pairs processed,
1179 * #GNUNET_SYSERR if it aborted iteration
1182 GNUNET_CONTAINER_multihashmap32_iterate (const struct
1183 GNUNET_CONTAINER_MultiHashMap32 *map,
1184 GNUNET_CONTAINER_HashMapIterator32 it,
1190 * Remove the given key-value pair from the map. Note that if the
1191 * key-value pair is in the map multiple times, only one of the pairs
1194 * @param map the map
1195 * @param key key of the key-value pair
1196 * @param value value of the key-value pair
1197 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1201 GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1208 * Remove all entries for the given key from the map.
1209 * Note that the values would not be "freed".
1211 * @param map the map
1212 * @param key identifies values to be removed
1213 * @return number of values removed
1216 GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1222 * Check if the map contains any value under the given
1223 * key (including values that are NULL).
1225 * @param map the map
1226 * @param key the key to test if a value exists for it
1227 * @return #GNUNET_YES if such a value exists,
1231 GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1237 * Check if the map contains the given value under the given
1240 * @param map the map
1241 * @param key the key to test if a value exists for it
1242 * @param value value to test for
1243 * @return #GNUNET_YES if such a value exists,
1247 GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1254 * Store a key-value pair in the map.
1256 * @param map the map
1257 * @param key key to use
1258 * @param value value to use
1259 * @param opt options for put
1260 * @return #GNUNET_OK on success,
1261 * #GNUNET_NO if a value was replaced (with REPLACE)
1262 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1263 * value already exists
1266 GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1269 enum GNUNET_CONTAINER_MultiHashMapOption opt);
1274 * Iterate over all entries in the map that match a particular key.
1276 * @param map the map
1277 * @param key key that the entries must correspond to
1278 * @param it function to call on each entry
1279 * @param it_cls extra argument to @a it
1280 * @return the number of key value pairs processed,
1281 * #GNUNET_SYSERR if it aborted iteration
1284 GNUNET_CONTAINER_multihashmap32_get_multiple (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1286 GNUNET_CONTAINER_HashMapIterator32 it,
1291 * Create an iterator for a 32-bit multihashmap.
1292 * The iterator can be used to retrieve all the elements in the multihashmap
1293 * one by one, without having to handle all elements at once (in contrast to
1294 * #GNUNET_CONTAINER_multihashmap32_iterate). Note that the iterator can not be
1295 * used anymore if elements have been removed from 'map' after the creation of
1296 * the iterator, or 'map' has been destroyed. Adding elements to 'map' may
1297 * result in skipped or repeated elements.
1299 * @param map the map to create an iterator for
1300 * @return an iterator over the given multihashmap map
1302 struct GNUNET_CONTAINER_MultiHashMap32Iterator *
1303 GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap32 *map);
1307 * Retrieve the next element from the hash map at the iterator's position.
1308 * If there are no elements left, GNUNET_NO is returned, and 'key' and 'value'
1310 * This operation is only allowed if no elements have been removed from the
1311 * multihashmap since the creation of 'iter', and the map has not been destroyed.
1312 * Adding elements may result in repeating or skipping elements.
1314 * @param iter the iterator to get the next element from
1315 * @param key pointer to store the key in, can be NULL
1316 * @param value pointer to store the value in, can be NULL
1317 * @return #GNUNET_YES we returned an element,
1318 * #GNUNET_NO if we are out of elements
1321 GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
1323 const void **value);
1327 * Destroy a 32-bit multihashmap iterator.
1329 * @param iter the iterator to destroy
1332 GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
1335 /* ******************** doubly-linked list *************** */
1336 /* To avoid mistakes: head->prev == tail->next == NULL */
1340 * Insert an element at the head of a DLL. Assumes that head, tail and
1341 * element are structs with prev and next fields.
1343 * @param head pointer to the head of the DLL
1344 * @param tail pointer to the tail of the DLL
1345 * @param element element to insert
1347 #define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
1348 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1349 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1350 (element)->next = (head); \
1351 (element)->prev = NULL; \
1352 if ((tail) == NULL) \
1355 (head)->prev = element; \
1356 (head) = (element); } while (0)
1361 * Insert an element at the tail of a DLL. Assumes that head, tail and
1362 * element are structs with prev and next fields.
1364 * @param head pointer to the head of the DLL
1365 * @param tail pointer to the tail of the DLL
1366 * @param element element to insert
1368 #define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \
1369 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1370 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1371 (element)->prev = (tail); \
1372 (element)->next = NULL; \
1373 if ((head) == NULL) \
1376 (tail)->next = element; \
1377 (tail) = (element); } while (0)
1382 * Insert an element into a DLL after the given other element. Insert
1383 * at the head if the other element is NULL.
1385 * @param head pointer to the head of the DLL
1386 * @param tail pointer to the tail of the DLL
1387 * @param other prior element, NULL for insertion at head of DLL
1388 * @param element element to insert
1390 #define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
1391 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1392 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1393 (element)->prev = (other); \
1394 if (NULL == other) \
1396 (element)->next = (head); \
1397 (head) = (element); \
1401 (element)->next = (other)->next; \
1402 (other)->next = (element); \
1404 if (NULL == (element)->next) \
1405 (tail) = (element); \
1407 (element)->next->prev = (element); } while (0)
1412 * Insert an element into a DLL before the given other element. Insert
1413 * at the tail if the other element is NULL.
1415 * @param head pointer to the head of the DLL
1416 * @param tail pointer to the tail of the DLL
1417 * @param other prior element, NULL for insertion at head of DLL
1418 * @param element element to insert
1420 #define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
1421 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1422 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1423 (element)->next = (other); \
1424 if (NULL == other) \
1426 (element)->prev = (tail); \
1427 (tail) = (element); \
1431 (element)->prev = (other)->prev; \
1432 (other)->prev = (element); \
1434 if (NULL == (element)->prev) \
1435 (head) = (element); \
1437 (element)->prev->next = (element); } while (0)
1442 * Remove an element from a DLL. Assumes that head, tail and
1443 * element point to structs with prev and next fields.
1445 * Using the head or tail pointer as the element
1446 * argument does NOT work with this macro.
1447 * Make sure to store head/tail in another pointer
1448 * and use it to remove the head or tail of the list.
1450 * @param head pointer to the head of the DLL
1451 * @param tail pointer to the tail of the DLL
1452 * @param element element to remove
1454 #define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
1455 GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
1456 GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
1457 if ((element)->prev == NULL) \
1458 (head) = (element)->next; \
1460 (element)->prev->next = (element)->next; \
1461 if ((element)->next == NULL) \
1462 (tail) = (element)->prev; \
1464 (element)->next->prev = (element)->prev; \
1465 (element)->next = NULL; \
1466 (element)->prev = NULL; } while (0)
1469 /* ************ Multi-DLL interface, allows DLL elements to be
1470 in multiple lists at the same time *********************** */
1474 * Insert an element at the head of a MDLL. Assumes that head, tail and
1475 * element are structs with prev and next fields.
1477 * @param mdll suffix name for the next and prev pointers in the element
1478 * @param head pointer to the head of the MDLL
1479 * @param tail pointer to the tail of the MDLL
1480 * @param element element to insert
1482 #define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \
1483 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1484 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1485 (element)->next_##mdll = (head); \
1486 (element)->prev_##mdll = NULL; \
1487 if ((tail) == NULL) \
1490 (head)->prev_##mdll = element; \
1491 (head) = (element); } while (0)
1496 * Insert an element at the tail of a MDLL. Assumes that head, tail and
1497 * element are structs with prev and next fields.
1499 * @param mdll suffix name for the next and prev pointers in the element
1500 * @param head pointer to the head of the MDLL
1501 * @param tail pointer to the tail of the MDLL
1502 * @param element element to insert
1504 #define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \
1505 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1506 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1507 (element)->prev_##mdll = (tail); \
1508 (element)->next_##mdll = NULL; \
1509 if ((head) == NULL) \
1512 (tail)->next_##mdll = element; \
1513 (tail) = (element); } while (0)
1518 * Insert an element into a MDLL after the given other element. Insert
1519 * at the head if the other element is NULL.
1521 * @param mdll suffix name for the next and prev pointers in the element
1522 * @param head pointer to the head of the MDLL
1523 * @param tail pointer to the tail of the MDLL
1524 * @param other prior element, NULL for insertion at head of MDLL
1525 * @param element element to insert
1527 #define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \
1528 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1529 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1530 (element)->prev_##mdll = (other); \
1531 if (NULL == other) \
1533 (element)->next_##mdll = (head); \
1534 (head) = (element); \
1538 (element)->next_##mdll = (other)->next_##mdll; \
1539 (other)->next_##mdll = (element); \
1541 if (NULL == (element)->next_##mdll) \
1542 (tail) = (element); \
1544 (element)->next->prev_##mdll = (element); } while (0)
1549 * Insert an element into a MDLL before the given other element. Insert
1550 * at the tail if the other element is NULL.
1552 * @param mdll suffix name for the next and prev pointers in the element
1553 * @param head pointer to the head of the MDLL
1554 * @param tail pointer to the tail of the MDLL
1555 * @param other prior element, NULL for insertion at head of MDLL
1556 * @param element element to insert
1558 #define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \
1559 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1560 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1561 (element)->next_##mdll = (other); \
1562 if (NULL == other) \
1564 (element)->prev = (tail); \
1565 (tail) = (element); \
1569 (element)->prev_##mdll = (other)->prev_##mdll; \
1570 (other)->prev_##mdll = (element); \
1572 if (NULL == (element)->prev_##mdll) \
1573 (head) = (element); \
1575 (element)->prev_##mdll->next_##mdll = (element); } while (0)
1580 * Remove an element from a MDLL. Assumes
1581 * that head, tail and element are structs
1582 * with prev and next fields.
1584 * @param mdll suffix name for the next and prev pointers in the element
1585 * @param head pointer to the head of the MDLL
1586 * @param tail pointer to the tail of the MDLL
1587 * @param element element to remove
1589 #define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \
1590 GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \
1591 GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \
1592 if ((element)->prev_##mdll == NULL) \
1593 (head) = (element)->next_##mdll; \
1595 (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \
1596 if ((element)->next_##mdll == NULL) \
1597 (tail) = (element)->prev_##mdll; \
1599 (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \
1600 (element)->next_##mdll = NULL; \
1601 (element)->prev_##mdll = NULL; } while (0)
1605 /* ******************** Heap *************** */
1610 * Cost by which elements in a heap can be ordered.
1612 typedef uint64_t GNUNET_CONTAINER_HeapCostType;
1617 * Heap type, either max or min.
1619 enum GNUNET_CONTAINER_HeapOrder
1623 * Heap with the maximum cost at the root.
1625 GNUNET_CONTAINER_HEAP_ORDER_MAX,
1629 * Heap with the minimum cost at the root.
1631 GNUNET_CONTAINER_HEAP_ORDER_MIN
1639 struct GNUNET_CONTAINER_Heap;
1644 * Handle to a node in a heap.
1646 struct GNUNET_CONTAINER_HeapNode;
1651 * Create a new heap.
1653 * @param order how should the heap be sorted?
1654 * @return handle to the heap
1656 struct GNUNET_CONTAINER_Heap *
1657 GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order);
1662 * Destroys the heap. Only call on a heap that
1665 * @param heap heap to destroy
1668 GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap);
1673 * Get element stored at the root of @a heap.
1675 * @param heap Heap to inspect.
1676 * @return Element at the root, or NULL if heap is empty.
1679 GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
1683 * Get @a element and @a cost stored at the root of @a heap.
1685 * @param[in] heap Heap to inspect.
1686 * @param[out] element Root element is returned here.
1687 * @param[out] cost Cost of @a element is returned here.
1688 * @return #GNUNET_YES if an element is returned,
1689 * #GNUNET_NO if the heap is empty.
1692 GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
1694 GNUNET_CONTAINER_HeapCostType *cost);
1699 * Get the current size of the heap
1701 * @param heap the heap to get the size of
1702 * @return number of elements stored
1705 GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
1710 * Get the current cost of the node
1712 * @param node the node to get the cost of
1713 * @return cost of the node
1715 GNUNET_CONTAINER_HeapCostType
1716 GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
1723 * @param cls closure
1724 * @param node internal node of the heap
1725 * @param element value stored at the node
1726 * @param cost cost associated with the node
1727 * @return #GNUNET_YES if we should continue to iterate,
1728 * #GNUNET_NO if not.
1730 typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
1731 struct GNUNET_CONTAINER_HeapNode *
1732 node, void *element,
1733 GNUNET_CONTAINER_HeapCostType
1739 * Iterate over all entries in the heap.
1741 * @param heap the heap
1742 * @param iterator function to call on each entry
1743 * @param iterator_cls closure for @a iterator
1746 GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
1747 GNUNET_CONTAINER_HeapIterator iterator,
1748 void *iterator_cls);
1752 * Perform a random walk of the tree. The walk is biased
1753 * towards elements closer to the root of the tree (since
1754 * each walk starts at the root and ends at a random leaf).
1755 * The heap internally tracks the current position of the
1758 * @param heap heap to walk
1759 * @return data stored at the next random node in the walk;
1760 * NULL if the tree is empty.
1763 GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
1768 * Inserts a new element into the heap.
1770 * @param heap heap to modify
1771 * @param element element to insert
1772 * @param cost cost for the element
1773 * @return node for the new element
1775 struct GNUNET_CONTAINER_HeapNode *
1776 GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element,
1777 GNUNET_CONTAINER_HeapCostType cost);
1782 * Remove root of the heap.
1784 * @param heap heap to modify
1785 * @return element data stored at the root node
1788 GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
1793 * Removes a node from the heap.
1795 * @param node node to remove
1796 * @return element data stored at the node, NULL if heap is empty
1799 GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
1804 * Updates the cost of any node in the tree
1806 * @param heap heap to modify
1807 * @param node node for which the cost is to be changed
1808 * @param new_cost new cost for the node
1811 GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
1812 struct GNUNET_CONTAINER_HeapNode *node,
1813 GNUNET_CONTAINER_HeapCostType new_cost);
1816 /* ******************** Singly linked list *************** */
1819 * Possible ways for how data stored in the linked list
1820 * might be allocated.
1821 * @deprecated use DLL macros
1823 enum GNUNET_CONTAINER_SListDisposition
1826 * Single-linked list must copy the buffer.
1827 * @deprecated use DLL macros
1829 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
1832 * Data is static, no need to copy or free.
1833 * @deprecated use DLL macros
1835 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
1838 * Data is dynamic, do not copy but free when done.
1839 * @deprecated use DLL macros
1841 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
1844 struct GNUNET_CONTAINER_SList_Elem;
1848 * Handle to a singly linked list
1849 * @deprecated use DLL macros
1851 struct GNUNET_CONTAINER_SList;
1854 * Handle to a singly linked list iterator
1855 * @deprecated use DLL macros
1857 struct GNUNET_CONTAINER_SList_Iterator
1860 * Linked list that we are iterating over.
1862 struct GNUNET_CONTAINER_SList *list;
1865 * Last element accessed.
1867 struct GNUNET_CONTAINER_SList_Elem *last;
1870 * Current list element.
1872 struct GNUNET_CONTAINER_SList_Elem *elem;
1878 * Add a new element to the list
1880 * @param disp memory disposition
1881 * @param buf payload buffer
1882 * @param len length of the buffer
1883 * @deprecated use DLL macros
1886 GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
1887 enum GNUNET_CONTAINER_SListDisposition disp,
1888 const void *buf, size_t len);
1892 * Add a new element to the end of the list
1894 * @param disp memory disposition
1895 * @param buf payload buffer
1896 * @param len length of the buffer
1897 * @deprecated use DLL macros
1900 GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
1901 enum GNUNET_CONTAINER_SListDisposition disp,
1902 const void *buf, size_t len);
1906 * Append a singly linked list to another
1907 * @param dst list to append to
1909 * @deprecated use DLL macros
1912 GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
1913 struct GNUNET_CONTAINER_SList *src);
1917 * Create a new singly linked list
1918 * @return the new list
1919 * @deprecated use DLL macros
1921 struct GNUNET_CONTAINER_SList *
1922 GNUNET_CONTAINER_slist_create (void);
1926 * Destroy a singly linked list
1927 * @param l the list to be destroyed
1928 * @deprecated use DLL macros
1931 GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l);
1935 * Return the beginning of a list
1938 * @return iterator pointing to the beginning (by value! Either allocate the
1939 * structure on the stack, or use GNUNET_malloc() yourself! All other
1940 * functions do take pointer to this struct though)
1941 * @deprecated use DLL macros
1943 struct GNUNET_CONTAINER_SList_Iterator
1944 GNUNET_CONTAINER_slist_begin (struct GNUNET_CONTAINER_SList *l);
1951 * @deprecated use DLL macros
1954 GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l);
1958 * Check if a list contains a certain element
1960 * @param buf payload buffer to find
1961 * @param len length of the payload (number of bytes in buf)
1962 * @return GNUNET_YES if found, GNUNET_NO otherwise
1963 * @deprecated use DLL macros
1966 GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
1967 const void *buf, size_t len);
1970 * Check if a list contains a certain element using 'compare' function
1973 * @param buf payload buffer to find
1974 * @param len length of the payload (number of bytes in buf)
1975 * @param compare comparison function
1977 * @return NULL if the 'buf' could not be found, pointer to the
1978 * list element, if found
1979 * @deprecated use DLL macros
1982 GNUNET_CONTAINER_slist_contains2 (const struct GNUNET_CONTAINER_SList *l,
1983 const void *buf, size_t len,
1984 int (*compare)(const void *, const size_t, const void *, const size_t));
1986 * Count the elements of a list
1988 * @return number of elements in the list
1989 * @deprecated use DLL macros
1992 GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l);
1996 * Remove an element from the list
1997 * @param i iterator that points to the element to be removed
1998 * @deprecated use DLL macros
2001 GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i);
2005 * Insert an element into a list at a specific position
2006 * @param before where to insert the new element
2007 * @param disp memory disposition
2008 * @param buf payload buffer
2009 * @param len length of the payload
2010 * @deprecated use DLL macros
2013 GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
2014 enum GNUNET_CONTAINER_SListDisposition disp,
2015 const void *buf, size_t len);
2019 * Advance an iterator to the next element
2021 * @return GNUNET_YES on success, GNUNET_NO if the end has been reached
2022 * @deprecated use DLL macros
2025 GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i);
2029 * Check if an iterator points beyond the end of a list
2031 * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator
2032 * points to a valid element
2033 * @deprecated use DLL macros
2036 GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i);
2040 * Retrieve the element at a specific position in a list
2043 * @param len set to the payload length
2045 * @deprecated use DLL macros
2048 GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
2053 * Release an iterator
2055 * @deprecated use DLL macros
2058 GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i);
2061 #if 0 /* keep Emacsens' auto-indent happy */
2069 /* ifndef GNUNET_CONTAINER_LIB_H */
2071 /* end of gnunet_container_lib.h */