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_HashCodes.
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_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 * @ingroup bloomfilter
190 * Get size of the bloom filter.
192 * @param bf the filter
193 * @return number of bytes used for the data of the bloom filter
196 GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter *bf);
200 * @ingroup bloomfilter
201 * Reset a Bloom filter to empty.
203 * @param bf the filter
206 GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf);
210 * @ingroup bloomfilter
211 * "or" the entries of the given raw data array with the
212 * data of the given Bloom filter. Assumes that
213 * the @a size of the @a data array and the current filter
216 * @param bf the filter
217 * @param data data to OR-in
218 * @param size size of @a data
219 * @return #GNUNET_OK on success
222 GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
223 const char *data, size_t size);
227 * @ingroup bloomfilter
228 * "or" the entries of the given raw data array with the
229 * data of the given Bloom filter. Assumes that
230 * the size of the two filters matches.
232 * @param bf the filter
233 * @param to_or the bloomfilter to or-in
234 * @return #GNUNET_OK on success
237 GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
238 const struct GNUNET_CONTAINER_BloomFilter *to_or);
241 * @ingroup bloomfilter
242 * Resize a bloom filter. Note that this operation
243 * is pretty costly. Essentially, the Bloom filter
244 * needs to be completely re-build.
246 * @param bf the filter
247 * @param iterator an iterator over all elements stored in the BF
248 * @param iterator_cls closure for @a iterator
249 * @param size the new size for the filter
250 * @param k the new number of #GNUNET_CRYPTO_hash-function to apply per element
253 GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
254 GNUNET_HashCodeIterator iterator,
255 void *iterator_cls, size_t size,
259 /* ****************** metadata ******************* */
263 * Meta data to associate with a file, directory or namespace.
265 struct GNUNET_CONTAINER_MetaData;
269 * Create a fresh meta data container.
271 * @return empty meta-data container
273 struct GNUNET_CONTAINER_MetaData *
274 GNUNET_CONTAINER_meta_data_create (void);
279 * Duplicate a MetaData token.
281 * @param md what to duplicate
282 * @return duplicate meta-data container
284 struct GNUNET_CONTAINER_MetaData *
285 GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
292 * @param md what to free
295 GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
300 * Test if two MDs are equal. We consider them equal if
301 * the meta types, formats and content match (we do not
302 * include the mime types and plugins names in this
305 * @param md1 first value to check
306 * @param md2 other value to check
307 * @return #GNUNET_YES if they are equal
310 GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData *md1,
311 const struct GNUNET_CONTAINER_MetaData *md2);
318 * @param md metadata to extend
319 * @param plugin_name name of the plugin that produced this value;
320 * special values can be used (i.e. '<zlib>' for zlib being
321 * used in the main libextractor library and yielding
323 * @param type libextractor-type describing the meta data
324 * @param format basic format information about data
325 * @param data_mime_type mime-type of data (not of the original file);
326 * can be NULL (if mime-type is not known)
327 * @param data actual meta-data found
328 * @param data_size number of bytes in data
329 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
330 * data_mime_type and plugin_name are not considered for "exists" checks
333 GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
334 const char *plugin_name,
335 enum EXTRACTOR_MetaType type,
336 enum EXTRACTOR_MetaFormat format,
337 const char *data_mime_type, const char *data,
343 * Extend metadata. Merges the meta data from the second argument
344 * into the first, discarding duplicate key-value pairs.
346 * @param md metadata to extend
347 * @param in metadata to merge
350 GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
351 const struct GNUNET_CONTAINER_MetaData *in);
358 * @param md metadata to manipulate
359 * @param type type of the item to remove
360 * @param data specific value to remove, NULL to remove all
361 * entries of the given type
362 * @param data_size number of bytes in data
363 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
366 GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
367 enum EXTRACTOR_MetaType type,
368 const char *data, size_t data_size);
373 * Remove all items in the container.
375 * @param md metadata to manipulate
378 GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
383 * Add the current time as the publication date
386 * @param md metadata to modify
389 GNUNET_CONTAINER_meta_data_add_publication_date (struct
390 GNUNET_CONTAINER_MetaData *md);
395 * Iterate over MD entries.
397 * @param md metadata to inspect
398 * @param iter function to call on each entry, return 0 to continue to iterate
399 * and 1 to abort iteration in this function (GNU libextractor API!)
400 * @param iter_cls closure for @a iter
401 * @return number of entries
404 GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
405 EXTRACTOR_MetaDataProcessor iter,
411 * Get the first MD entry of the given type. Caller
412 * is responsible for freeing the return value.
413 * Also, only meta data items that are strings (0-terminated)
414 * are returned by this function.
416 * @param md metadata to inspect
417 * @param type type to look for
418 * @return NULL if no entry was found
421 GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData
422 *md, enum EXTRACTOR_MetaType type);
427 * Get the first matching MD entry of the given types. Caller is
428 * responsible for freeing the return value. Also, only meta data
429 * items that are strings (0-terminated) are returned by this
432 * @param md metadata to inspect
433 * @param ... -1-terminated list of types
434 * @return NULL if we do not have any such entry,
435 * otherwise client is responsible for freeing the value!
438 GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
439 GNUNET_CONTAINER_MetaData *md,
444 * Get a thumbnail from the meta-data (if present). Only matches meta
445 * data with mime type "image" and binary format.
447 * @param md metadata to inspect
448 * @param thumb will be set to the thumbnail data. Must be
449 * freed by the caller!
450 * @return number of bytes in thumbnail, 0 if not available
453 GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData
454 *md, unsigned char **thumb);
460 * Options for metadata serialization.
462 enum GNUNET_CONTAINER_MetaDataSerializationOptions
466 * Serialize all of the data.
468 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0,
472 * If not enough space is available, it is acceptable
473 * to only serialize some of the metadata.
475 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1,
479 * Speed is of the essence, do not allow compression.
481 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2
487 * Serialize meta-data to target.
489 * @param md metadata to serialize
490 * @param target where to write the serialized metadata;
491 * *target can be NULL, in which case memory is allocated
492 * @param max maximum number of bytes available
493 * @param opt is it ok to just write SOME of the
494 * meta-data to match the size constraint,
495 * possibly discarding some data?
496 * @return number of bytes written on success,
497 * -1 on error (typically: not enough
501 GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
502 *md, char **target, size_t max,
504 GNUNET_CONTAINER_MetaDataSerializationOptions
510 * Get the size of the full meta-data in serialized form.
512 * @param md metadata to inspect
513 * @return number of bytes needed for serialization, -1 on error
516 GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
517 GNUNET_CONTAINER_MetaData *md);
522 * Deserialize meta-data. Initializes md.
524 * @param input serialized meta-data.
525 * @param size number of bytes available
526 * @return MD on success, NULL on error (i.e.
529 struct GNUNET_CONTAINER_MetaData *
530 GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size);
533 /* ******************************* HashMap **************************** */
537 * Opaque handle for a HashMap.
539 struct GNUNET_CONTAINER_MultiHashMap;
543 * Opaque handle to an iterator over
546 struct GNUNET_CONTAINER_MultiHashMapIterator;
550 * Options for storing values in the HashMap.
552 enum GNUNET_CONTAINER_MultiHashMapOption
557 * If a value with the given key exists, replace it. Note that the
558 * old value would NOT be freed by replace (the application has to
559 * make sure that this happens if required).
561 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE,
565 * Allow multiple values with the same key.
567 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE,
571 * There must only be one value per key; storing a value should fail
572 * if a value under the same key already exists.
574 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY,
577 * @ingroup hashmap There must only be one value per key, but don't
578 * bother checking if a value already exists (faster than
579 * #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY; implemented
580 * just like #GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE but this
581 * option documents better what is intended if
582 * #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY is what is
585 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
591 * Iterator over hash map entries.
594 * @param key current key code
595 * @param value value in the hash map
596 * @return #GNUNET_YES if we should continue to
600 typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls,
601 const struct GNUNET_HashCode *key,
607 * Create a multi hash map.
609 * @param len initial size (map will grow as needed)
610 * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
611 * #GNUNET_YES means that on 'put', the 'key' does not have
612 * to be copied as the destination of the pointer is
613 * guaranteed to be life as long as the value is stored in
614 * the hashmap. This can significantly reduce memory
615 * consumption, but of course is also a recipie for
616 * heap corruption if the assumption is not true. Only
617 * use this if (1) memory use is important in this case and
618 * (2) you have triple-checked that the invariant holds
619 * @return NULL on error
621 struct GNUNET_CONTAINER_MultiHashMap *
622 GNUNET_CONTAINER_multihashmap_create (unsigned int len,
623 int do_not_copy_keys);
628 * Destroy a hash map. Will not free any values
629 * stored in the hash map!
634 GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map);
639 * Given a key find a value in the map matching the key.
642 * @param key what to look for
643 * @return NULL if no value was found; note that
644 * this is indistinguishable from values that just
645 * happen to be NULL; use "contains" to test for
646 * key-value pairs with value NULL
649 GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map,
650 const struct GNUNET_HashCode *key);
655 * Remove the given key-value pair from the map. Note that if the
656 * key-value pair is in the map multiple times, only one of the pairs
660 * @param key key of the key-value pair
661 * @param value value of the key-value pair
662 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
666 GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
667 const struct GNUNET_HashCode *key,
672 * Remove all entries for the given key from the map.
673 * Note that the values would not be "freed".
676 * @param key identifies values to be removed
677 * @return number of values removed
680 GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map,
681 const struct GNUNET_HashCode *key);
686 * Check if the map contains any value under the given
687 * key (including values that are NULL).
690 * @param key the key to test if a value exists for it
691 * @return #GNUNET_YES if such a value exists,
695 GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map,
696 const struct GNUNET_HashCode * key);
701 * Check if the map contains the given value under the given
705 * @param key the key to test if a value exists for it
706 * @param value value to test for
707 * @return #GNUNET_YES if such a value exists,
711 GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map,
712 const struct GNUNET_HashCode *key,
718 * Store a key-value pair in the map.
721 * @param key key to use
722 * @param value value to use
723 * @param opt options for put
724 * @return #GNUNET_OK on success,
725 * #GNUNET_NO if a value was replaced (with REPLACE)
726 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
727 * value already exists
730 GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
731 const struct GNUNET_HashCode * key, void *value,
732 enum GNUNET_CONTAINER_MultiHashMapOption
737 * Get the number of key-value pairs in the map.
740 * @return the number of key value pairs
743 GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap
749 * Iterate over all entries in the map.
752 * @param it function to call on each entry
753 * @param it_cls extra argument to @a it
754 * @return the number of key value pairs processed,
755 * #GNUNET_SYSERR if it aborted iteration
758 GNUNET_CONTAINER_multihashmap_iterate (const struct
759 GNUNET_CONTAINER_MultiHashMap *map,
760 GNUNET_CONTAINER_HashMapIterator it,
766 * Create an iterator for a multihashmap.
767 * The iterator can be used to retrieve all the elements in the multihashmap
768 * one by one, without having to handle all elements at once (in contrast to
769 * #GNUNET_CONTAINER_multihashmap_iterate). Note that the iterator can not be
770 * used anymore if elements have been removed from 'map' after the creation of
771 * the iterator, or 'map' has been destroyed. Adding elements to 'map' may
772 * result in skipped or repeated elements.
774 * @param map the map to create an iterator for
775 * @return an iterator over the given multihashmap @a map
777 struct GNUNET_CONTAINER_MultiHashMapIterator *
778 GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map);
783 * Retrieve the next element from the hash map at the iterator's
784 * position. If there are no elements left, #GNUNET_NO is returned,
785 * and @a key and @a value are not modified. This operation is only
786 * allowed if no elements have been removed from the multihashmap
787 * since the creation of @a iter, and the map has not been destroyed.
788 * Adding elements may result in repeating or skipping elements.
790 * @param iter the iterator to get the next element from
791 * @param key pointer to store the key in, can be NULL
792 * @param value pointer to store the value in, can be NULL
793 * @return #GNUNET_YES we returned an element,
794 * #GNUNET_NO if we are out of elements
797 GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
798 struct GNUNET_HashCode *key,
804 * Destroy a multihashmap iterator.
806 * @param iter the iterator to destroy
809 GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
814 * Iterate over all entries in the map that match a particular key.
817 * @param key key that the entries must correspond to
818 * @param it function to call on each entry
819 * @param it_cls extra argument to @a it
820 * @return the number of key value pairs processed,
821 * #GNUNET_SYSERR if it aborted iteration
824 GNUNET_CONTAINER_multihashmap_get_multiple (const struct
825 GNUNET_CONTAINER_MultiHashMap *map,
826 const struct GNUNET_HashCode * key,
827 GNUNET_CONTAINER_HashMapIterator it,
831 /* ***************** Version of Multihashmap for peer identities ****************** */
835 * Iterator over hash map entries.
838 * @param key current public key
839 * @param value value in the hash map
840 * @return #GNUNET_YES if we should continue to
844 typedef int (*GNUNET_CONTAINER_PeerMapIterator) (void *cls,
845 const struct GNUNET_PeerIdentity *key,
851 * Create a multi peer map (hash map for public keys of peers).
853 * @param len initial size (map will grow as needed)
854 * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
855 * #GNUNET_YES means that on 'put', the 'key' does not have
856 * to be copied as the destination of the pointer is
857 * guaranteed to be life as long as the value is stored in
858 * the hashmap. This can significantly reduce memory
859 * consumption, but of course is also a recipie for
860 * heap corruption if the assumption is not true. Only
861 * use this if (1) memory use is important in this case and
862 * (2) you have triple-checked that the invariant holds
863 * @return NULL on error
865 struct GNUNET_CONTAINER_MultiPeerMap *
866 GNUNET_CONTAINER_multipeermap_create (unsigned int len,
867 int do_not_copy_keys);
872 * Destroy a hash map. Will not free any values
873 * stored in the hash map!
878 GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map);
883 * Given a key find a value in the map matching the key.
886 * @param key what to look for
887 * @return NULL if no value was found; note that
888 * this is indistinguishable from values that just
889 * happen to be NULL; use "contains" to test for
890 * key-value pairs with value NULL
893 GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map,
894 const struct GNUNET_PeerIdentity *key);
899 * Remove the given key-value pair from the map. Note that if the
900 * key-value pair is in the map multiple times, only one of the pairs
904 * @param key key of the key-value pair
905 * @param value value of the key-value pair
906 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
910 GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map,
911 const struct GNUNET_PeerIdentity * key,
916 * Remove all entries for the given key from the map.
917 * Note that the values would not be "freed".
920 * @param key identifies values to be removed
921 * @return number of values removed
924 GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map,
925 const struct GNUNET_PeerIdentity *key);
930 * Check if the map contains any value under the given
931 * key (including values that are NULL).
934 * @param key the key to test if a value exists for it
935 * @return #GNUNET_YES if such a value exists,
939 GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map,
940 const struct GNUNET_PeerIdentity *key);
945 * Check if the map contains the given value under the given
949 * @param key the key to test if a value exists for it
950 * @param value value to test for
951 * @return #GNUNET_YES if such a value exists,
955 GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map,
956 const struct GNUNET_PeerIdentity * key,
962 * Store a key-value pair in the map.
965 * @param key key to use
966 * @param value value to use
967 * @param opt options for put
968 * @return #GNUNET_OK on success,
969 * #GNUNET_NO if a value was replaced (with REPLACE)
970 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
971 * value already exists
974 GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map,
975 const struct GNUNET_PeerIdentity *key,
977 enum GNUNET_CONTAINER_MultiHashMapOption opt);
982 * Get the number of key-value pairs in the map.
985 * @return the number of key value pairs
988 GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map);
993 * Iterate over all entries in the map.
996 * @param it function to call on each entry
997 * @param it_cls extra argument to @a it
998 * @return the number of key value pairs processed,
999 * #GNUNET_SYSERR if it aborted iteration
1002 GNUNET_CONTAINER_multipeermap_iterate (const struct GNUNET_CONTAINER_MultiPeerMap *map,
1003 GNUNET_CONTAINER_PeerMapIterator it,
1009 * Create an iterator for a multihashmap.
1010 * The iterator can be used to retrieve all the elements in the multihashmap
1011 * one by one, without having to handle all elements at once (in contrast to
1012 * #GNUNET_CONTAINER_multipeermap_iterate). Note that the iterator can not be
1013 * used anymore if elements have been removed from @a map after the creation of
1014 * the iterator, or 'map' has been destroyed. Adding elements to @a map may
1015 * result in skipped or repeated elements.
1017 * @param map the map to create an iterator for
1018 * @return an iterator over the given multihashmap @a map
1020 struct GNUNET_CONTAINER_MultiPeerMapIterator *
1021 GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map);
1026 * Retrieve the next element from the hash map at the iterator's
1027 * position. If there are no elements left, #GNUNET_NO is returned,
1028 * and @a key and @a value are not modified. This operation is only
1029 * allowed if no elements have been removed from the multihashmap
1030 * since the creation of @a iter, and the map has not been destroyed.
1031 * Adding elements may result in repeating or skipping elements.
1033 * @param iter the iterator to get the next element from
1034 * @param key pointer to store the key in, can be NULL
1035 * @param value pointer to store the value in, can be NULL
1036 * @return #GNUNET_YES we returned an element,
1037 * #GNUNET_NO if we are out of elements
1040 GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
1041 struct GNUNET_PeerIdentity *key,
1042 const void **value);
1047 * Destroy a multipeermap iterator.
1049 * @param iter the iterator to destroy
1052 GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter);
1057 * Iterate over all entries in the map that match a particular key.
1059 * @param map the map
1060 * @param key public key that the entries must correspond to
1061 * @param it function to call on each entry
1062 * @param it_cls extra argument to @a it
1063 * @return the number of key value pairs processed,
1064 * #GNUNET_SYSERR if it aborted iteration
1067 GNUNET_CONTAINER_multipeermap_get_multiple (const struct GNUNET_CONTAINER_MultiPeerMap *map,
1068 const struct GNUNET_PeerIdentity *key,
1069 GNUNET_CONTAINER_PeerMapIterator it,
1074 /* Version of multihashmap with 32 bit keys */
1078 * Opaque handle for the 32-bit key HashMap.
1080 struct GNUNET_CONTAINER_MultiHashMap32;
1085 * Opaque handle to an iterator over
1086 * a 32-bit key multihashmap.
1088 struct GNUNET_CONTAINER_MultiHashMap32Iterator;
1093 * Iterator over hash map entries.
1095 * @param cls closure
1096 * @param key current key code
1097 * @param value value in the hash map
1098 * @return #GNUNET_YES if we should continue to
1100 * #GNUNET_NO if not.
1102 typedef int (*GNUNET_CONTAINER_HashMapIterator32) (void *cls,
1109 * Create a 32-bit key multi hash map.
1111 * @param len initial size (map will grow as needed)
1112 * @return NULL on error
1114 struct GNUNET_CONTAINER_MultiHashMap32 *
1115 GNUNET_CONTAINER_multihashmap32_create (unsigned int len);
1120 * Destroy a 32-bit key hash map. Will not free any values
1121 * stored in the hash map!
1123 * @param map the map
1126 GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32
1132 * Get the number of key-value pairs in the map.
1134 * @param map the map
1135 * @return the number of key value pairs
1138 GNUNET_CONTAINER_multihashmap32_size (const struct
1139 GNUNET_CONTAINER_MultiHashMap32 *map);
1144 * Given a key find a value in the map matching the key.
1146 * @param map the map
1147 * @param key what to look for
1148 * @return NULL if no value was found; note that
1149 * this is indistinguishable from values that just
1150 * happen to be NULL; use "contains" to test for
1151 * key-value pairs with value NULL
1154 GNUNET_CONTAINER_multihashmap32_get (const struct
1155 GNUNET_CONTAINER_MultiHashMap32 *map,
1161 * Iterate over all entries in the map.
1163 * @param map the map
1164 * @param it function to call on each entry
1165 * @param it_cls extra argument to @a it
1166 * @return the number of key value pairs processed,
1167 * #GNUNET_SYSERR if it aborted iteration
1170 GNUNET_CONTAINER_multihashmap32_iterate (const struct
1171 GNUNET_CONTAINER_MultiHashMap32 *map,
1172 GNUNET_CONTAINER_HashMapIterator32 it,
1178 * Remove the given key-value pair from the map. Note that if the
1179 * key-value pair is in the map multiple times, only one of the pairs
1182 * @param map the map
1183 * @param key key of the key-value pair
1184 * @param value value of the key-value pair
1185 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1189 GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1196 * Remove all entries for the given key from the map.
1197 * Note that the values would not be "freed".
1199 * @param map the map
1200 * @param key identifies values to be removed
1201 * @return number of values removed
1204 GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1210 * Check if the map contains any value under the given
1211 * key (including values that are NULL).
1213 * @param map the map
1214 * @param key the key to test if a value exists for it
1215 * @return #GNUNET_YES if such a value exists,
1219 GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1225 * Check if the map contains the given value under the given
1228 * @param map the map
1229 * @param key the key to test if a value exists for it
1230 * @param value value to test for
1231 * @return #GNUNET_YES if such a value exists,
1235 GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1242 * Store a key-value pair in the map.
1244 * @param map the map
1245 * @param key key to use
1246 * @param value value to use
1247 * @param opt options for put
1248 * @return #GNUNET_OK on success,
1249 * #GNUNET_NO if a value was replaced (with REPLACE)
1250 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1251 * value already exists
1254 GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1257 enum GNUNET_CONTAINER_MultiHashMapOption opt);
1262 * Iterate over all entries in the map that match a particular key.
1264 * @param map the map
1265 * @param key key that the entries must correspond to
1266 * @param it function to call on each entry
1267 * @param it_cls extra argument to @a it
1268 * @return the number of key value pairs processed,
1269 * #GNUNET_SYSERR if it aborted iteration
1272 GNUNET_CONTAINER_multihashmap32_get_multiple (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1274 GNUNET_CONTAINER_HashMapIterator32 it,
1279 * Create an iterator for a 32-bit multihashmap.
1280 * The iterator can be used to retrieve all the elements in the multihashmap
1281 * one by one, without having to handle all elements at once (in contrast to
1282 * #GNUNET_CONTAINER_multihashmap32_iterate). Note that the iterator can not be
1283 * used anymore if elements have been removed from 'map' after the creation of
1284 * the iterator, or 'map' has been destroyed. Adding elements to 'map' may
1285 * result in skipped or repeated elements.
1287 * @param map the map to create an iterator for
1288 * @return an iterator over the given multihashmap map
1290 struct GNUNET_CONTAINER_MultiHashMap32Iterator *
1291 GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap32 *map);
1295 * Retrieve the next element from the hash map at the iterator's position.
1296 * If there are no elements left, GNUNET_NO is returned, and 'key' and 'value'
1298 * This operation is only allowed if no elements have been removed from the
1299 * multihashmap since the creation of 'iter', and the map has not been destroyed.
1300 * Adding elements may result in repeating or skipping elements.
1302 * @param iter the iterator to get the next element from
1303 * @param key pointer to store the key in, can be NULL
1304 * @param value pointer to store the value in, can be NULL
1305 * @return #GNUNET_YES we returned an element,
1306 * #GNUNET_NO if we are out of elements
1309 GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
1311 const void **value);
1315 * Destroy a 32-bit multihashmap iterator.
1317 * @param iter the iterator to destroy
1320 GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
1323 /* ******************** doubly-linked list *************** */
1324 /* To avoid mistakes: head->prev == tail->next == NULL */
1328 * Insert an element at the head of a DLL. Assumes that head, tail and
1329 * element are structs with prev and next fields.
1331 * @param head pointer to the head of the DLL
1332 * @param tail pointer to the tail of the DLL
1333 * @param element element to insert
1335 #define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
1336 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1337 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1338 (element)->next = (head); \
1339 (element)->prev = NULL; \
1340 if ((tail) == NULL) \
1343 (head)->prev = element; \
1344 (head) = (element); } while (0)
1349 * Insert an element at the tail of a DLL. Assumes that head, tail and
1350 * element are structs with prev and next fields.
1352 * @param head pointer to the head of the DLL
1353 * @param tail pointer to the tail of the DLL
1354 * @param element element to insert
1356 #define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \
1357 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1358 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1359 (element)->prev = (tail); \
1360 (element)->next = NULL; \
1361 if ((head) == NULL) \
1364 (tail)->next = element; \
1365 (tail) = (element); } while (0)
1370 * Insert an element into a DLL after the given other element. Insert
1371 * at the head if the other element is NULL.
1373 * @param head pointer to the head of the DLL
1374 * @param tail pointer to the tail of the DLL
1375 * @param other prior element, NULL for insertion at head of DLL
1376 * @param element element to insert
1378 #define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
1379 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1380 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1381 (element)->prev = (other); \
1382 if (NULL == other) \
1384 (element)->next = (head); \
1385 (head) = (element); \
1389 (element)->next = (other)->next; \
1390 (other)->next = (element); \
1392 if (NULL == (element)->next) \
1393 (tail) = (element); \
1395 (element)->next->prev = (element); } while (0)
1400 * Insert an element into a DLL before the given other element. Insert
1401 * at the tail if the other element is NULL.
1403 * @param head pointer to the head of the DLL
1404 * @param tail pointer to the tail of the DLL
1405 * @param other prior element, NULL for insertion at head of DLL
1406 * @param element element to insert
1408 #define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
1409 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1410 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1411 (element)->next = (other); \
1412 if (NULL == other) \
1414 (element)->prev = (tail); \
1415 (tail) = (element); \
1419 (element)->prev = (other)->prev; \
1420 (other)->prev = (element); \
1422 if (NULL == (element)->prev) \
1423 (head) = (element); \
1425 (element)->prev->next = (element); } while (0)
1430 * Remove an element from a DLL. Assumes that head, tail and
1431 * element point to structs with prev and next fields.
1433 * Using the head or tail pointer as the element
1434 * argument does NOT work with this macro.
1435 * Make sure to store head/tail in another pointer
1436 * and use it to remove the head or tail of the list.
1438 * @param head pointer to the head of the DLL
1439 * @param tail pointer to the tail of the DLL
1440 * @param element element to remove
1442 #define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
1443 GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
1444 GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
1445 if ((element)->prev == NULL) \
1446 (head) = (element)->next; \
1448 (element)->prev->next = (element)->next; \
1449 if ((element)->next == NULL) \
1450 (tail) = (element)->prev; \
1452 (element)->next->prev = (element)->prev; \
1453 (element)->next = NULL; \
1454 (element)->prev = NULL; } while (0)
1457 /* ************ Multi-DLL interface, allows DLL elements to be
1458 in multiple lists at the same time *********************** */
1462 * Insert an element at the head of a MDLL. Assumes that head, tail and
1463 * element are structs with prev and next fields.
1465 * @param mdll suffix name for the next and prev pointers in the element
1466 * @param head pointer to the head of the MDLL
1467 * @param tail pointer to the tail of the MDLL
1468 * @param element element to insert
1470 #define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \
1471 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1472 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1473 (element)->next_##mdll = (head); \
1474 (element)->prev_##mdll = NULL; \
1475 if ((tail) == NULL) \
1478 (head)->prev_##mdll = element; \
1479 (head) = (element); } while (0)
1484 * Insert an element at the tail of a MDLL. Assumes that head, tail and
1485 * element are structs with prev and next fields.
1487 * @param mdll suffix name for the next and prev pointers in the element
1488 * @param head pointer to the head of the MDLL
1489 * @param tail pointer to the tail of the MDLL
1490 * @param element element to insert
1492 #define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \
1493 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1494 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1495 (element)->prev_##mdll = (tail); \
1496 (element)->next_##mdll = NULL; \
1497 if ((head) == NULL) \
1500 (tail)->next_##mdll = element; \
1501 (tail) = (element); } while (0)
1506 * Insert an element into a MDLL after the given other element. Insert
1507 * at the head if the other element is NULL.
1509 * @param mdll suffix name for the next and prev pointers in the element
1510 * @param head pointer to the head of the MDLL
1511 * @param tail pointer to the tail of the MDLL
1512 * @param other prior element, NULL for insertion at head of MDLL
1513 * @param element element to insert
1515 #define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \
1516 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1517 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1518 (element)->prev_##mdll = (other); \
1519 if (NULL == other) \
1521 (element)->next_##mdll = (head); \
1522 (head) = (element); \
1526 (element)->next_##mdll = (other)->next_##mdll; \
1527 (other)->next_##mdll = (element); \
1529 if (NULL == (element)->next_##mdll) \
1530 (tail) = (element); \
1532 (element)->next->prev_##mdll = (element); } while (0)
1537 * Insert an element into a MDLL before the given other element. Insert
1538 * at the tail if the other element is NULL.
1540 * @param mdll suffix name for the next and prev pointers in the element
1541 * @param head pointer to the head of the MDLL
1542 * @param tail pointer to the tail of the MDLL
1543 * @param other prior element, NULL for insertion at head of MDLL
1544 * @param element element to insert
1546 #define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \
1547 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1548 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1549 (element)->next_##mdll = (other); \
1550 if (NULL == other) \
1552 (element)->prev = (tail); \
1553 (tail) = (element); \
1557 (element)->prev_##mdll = (other)->prev_##mdll; \
1558 (other)->prev_##mdll = (element); \
1560 if (NULL == (element)->prev_##mdll) \
1561 (head) = (element); \
1563 (element)->prev_##mdll->next_##mdll = (element); } while (0)
1568 * Remove an element from a MDLL. Assumes
1569 * that head, tail and element are structs
1570 * with prev and next fields.
1572 * @param mdll suffix name for the next and prev pointers in the element
1573 * @param head pointer to the head of the MDLL
1574 * @param tail pointer to the tail of the MDLL
1575 * @param element element to remove
1577 #define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \
1578 GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \
1579 GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \
1580 if ((element)->prev_##mdll == NULL) \
1581 (head) = (element)->next_##mdll; \
1583 (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \
1584 if ((element)->next_##mdll == NULL) \
1585 (tail) = (element)->prev_##mdll; \
1587 (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \
1588 (element)->next_##mdll = NULL; \
1589 (element)->prev_##mdll = NULL; } while (0)
1593 /* ******************** Heap *************** */
1598 * Cost by which elements in a heap can be ordered.
1600 typedef uint64_t GNUNET_CONTAINER_HeapCostType;
1605 * Heap type, either max or min.
1607 enum GNUNET_CONTAINER_HeapOrder
1611 * Heap with the maximum cost at the root.
1613 GNUNET_CONTAINER_HEAP_ORDER_MAX,
1617 * Heap with the minimum cost at the root.
1619 GNUNET_CONTAINER_HEAP_ORDER_MIN
1627 struct GNUNET_CONTAINER_Heap;
1632 * Handle to a node in a heap.
1634 struct GNUNET_CONTAINER_HeapNode;
1639 * Create a new heap.
1641 * @param order how should the heap be sorted?
1642 * @return handle to the heap
1644 struct GNUNET_CONTAINER_Heap *
1645 GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order);
1650 * Destroys the heap. Only call on a heap that
1653 * @param heap heap to destroy
1656 GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap);
1661 * Get element stored at root of heap.
1663 * @param heap heap to inspect
1664 * @return NULL if heap is empty
1667 GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
1672 * Get the current size of the heap
1674 * @param heap the heap to get the size of
1675 * @return number of elements stored
1678 GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
1683 * Get the current cost of the node
1685 * @param node the node to get the cost of
1686 * @return cost of the node
1688 GNUNET_CONTAINER_HeapCostType
1689 GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
1696 * @param cls closure
1697 * @param node internal node of the heap
1698 * @param element value stored at the node
1699 * @param cost cost associated with the node
1700 * @return #GNUNET_YES if we should continue to iterate,
1701 * #GNUNET_NO if not.
1703 typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
1704 struct GNUNET_CONTAINER_HeapNode *
1705 node, void *element,
1706 GNUNET_CONTAINER_HeapCostType
1712 * Iterate over all entries in the heap.
1714 * @param heap the heap
1715 * @param iterator function to call on each entry
1716 * @param iterator_cls closure for @a iterator
1719 GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
1720 GNUNET_CONTAINER_HeapIterator iterator,
1721 void *iterator_cls);
1725 * Perform a random walk of the tree. The walk is biased
1726 * towards elements closer to the root of the tree (since
1727 * each walk starts at the root and ends at a random leaf).
1728 * The heap internally tracks the current position of the
1731 * @param heap heap to walk
1732 * @return data stored at the next random node in the walk;
1733 * NULL if the tree is empty.
1736 GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
1741 * Inserts a new element into the heap.
1743 * @param heap heap to modify
1744 * @param element element to insert
1745 * @param cost cost for the element
1746 * @return node for the new element
1748 struct GNUNET_CONTAINER_HeapNode *
1749 GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element,
1750 GNUNET_CONTAINER_HeapCostType cost);
1755 * Remove root of the heap.
1757 * @param heap heap to modify
1758 * @return element data stored at the root node
1761 GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
1766 * Removes a node from the heap.
1768 * @param node node to remove
1769 * @return element data stored at the node, NULL if heap is empty
1772 GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
1777 * Updates the cost of any node in the tree
1779 * @param heap heap to modify
1780 * @param node node for which the cost is to be changed
1781 * @param new_cost new cost for the node
1784 GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
1785 struct GNUNET_CONTAINER_HeapNode *node,
1786 GNUNET_CONTAINER_HeapCostType new_cost);
1789 /* ******************** Singly linked list *************** */
1792 * Possible ways for how data stored in the linked list
1793 * might be allocated.
1794 * @deprecated use DLL macros
1796 enum GNUNET_CONTAINER_SListDisposition
1799 * Single-linked list must copy the buffer.
1800 * @deprecated use DLL macros
1802 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
1805 * Data is static, no need to copy or free.
1806 * @deprecated use DLL macros
1808 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
1811 * Data is dynamic, do not copy but free when done.
1812 * @deprecated use DLL macros
1814 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
1820 * Handle to a singly linked list
1821 * @deprecated use DLL macros
1823 struct GNUNET_CONTAINER_SList;
1826 * Handle to a singly linked list iterator
1827 * @deprecated use DLL macros
1829 struct GNUNET_CONTAINER_SList_Iterator
1832 * Linked list that we are iterating over.
1834 struct GNUNET_CONTAINER_SList *list;
1837 * Last element accessed.
1839 struct GNUNET_CONTAINER_SList_Elem *last;
1842 * Current list element.
1844 struct GNUNET_CONTAINER_SList_Elem *elem;
1850 * Add a new element to the list
1852 * @param disp memory disposition
1853 * @param buf payload buffer
1854 * @param len length of the buffer
1855 * @deprecated use DLL macros
1858 GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
1859 enum GNUNET_CONTAINER_SListDisposition disp,
1860 const void *buf, size_t len);
1864 * Add a new element to the end of the list
1866 * @param disp memory disposition
1867 * @param buf payload buffer
1868 * @param len length of the buffer
1869 * @deprecated use DLL macros
1872 GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
1873 enum GNUNET_CONTAINER_SListDisposition disp,
1874 const void *buf, size_t len);
1878 * Append a singly linked list to another
1879 * @param dst list to append to
1881 * @deprecated use DLL macros
1884 GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
1885 struct GNUNET_CONTAINER_SList *src);
1889 * Create a new singly linked list
1890 * @return the new list
1891 * @deprecated use DLL macros
1893 struct GNUNET_CONTAINER_SList *
1894 GNUNET_CONTAINER_slist_create (void);
1898 * Destroy a singly linked list
1899 * @param l the list to be destroyed
1900 * @deprecated use DLL macros
1903 GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l);
1907 * Return the beginning of a list
1910 * @return iterator pointing to the beginning (by value! Either allocate the
1911 * structure on the stack, or use GNUNET_malloc() yourself! All other
1912 * functions do take pointer to this struct though)
1913 * @deprecated use DLL macros
1915 struct GNUNET_CONTAINER_SList_Iterator
1916 GNUNET_CONTAINER_slist_begin (struct GNUNET_CONTAINER_SList *l);
1923 * @deprecated use DLL macros
1926 GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l);
1930 * Check if a list contains a certain element
1932 * @param buf payload buffer to find
1933 * @param len length of the payload (number of bytes in buf)
1934 * @return GNUNET_YES if found, GNUNET_NO otherwise
1935 * @deprecated use DLL macros
1938 GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
1939 const void *buf, size_t len);
1942 * Check if a list contains a certain element using 'compare' function
1945 * @param buf payload buffer to find
1946 * @param len length of the payload (number of bytes in buf)
1947 * @param compare comparison function
1949 * @return NULL if the 'buf' could not be found, pointer to the
1950 * list element, if found
1951 * @deprecated use DLL macros
1954 GNUNET_CONTAINER_slist_contains2 (const struct GNUNET_CONTAINER_SList *l,
1955 const void *buf, size_t len,
1956 int (*compare)(const void *, const size_t, const void *, const size_t));
1958 * Count the elements of a list
1960 * @return number of elements in the list
1961 * @deprecated use DLL macros
1964 GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l);
1968 * Remove an element from the list
1969 * @param i iterator that points to the element to be removed
1970 * @deprecated use DLL macros
1973 GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i);
1977 * Insert an element into a list at a specific position
1978 * @param before where to insert the new element
1979 * @param disp memory disposition
1980 * @param buf payload buffer
1981 * @param len length of the payload
1982 * @deprecated use DLL macros
1985 GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
1986 enum GNUNET_CONTAINER_SListDisposition disp,
1987 const void *buf, size_t len);
1991 * Advance an iterator to the next element
1993 * @return GNUNET_YES on success, GNUNET_NO if the end has been reached
1994 * @deprecated use DLL macros
1997 GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i);
2001 * Check if an iterator points beyond the end of a list
2003 * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator
2004 * points to a valid element
2005 * @deprecated use DLL macros
2008 GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i);
2012 * Retrieve the element at a specific position in a list
2015 * @param len set to the payload length
2017 * @deprecated use DLL macros
2020 GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
2025 * Release an iterator
2027 * @deprecated use DLL macros
2030 GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i);
2033 #if 0 /* keep Emacsens' auto-indent happy */
2041 /* ifndef GNUNET_CONTAINER_LIB_H */
2043 /* end of gnunet_container_lib.h */