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 * Iterator over hash map entries.
1087 * @param cls closure
1088 * @param key current key code
1089 * @param value value in the hash map
1090 * @return #GNUNET_YES if we should continue to
1092 * #GNUNET_NO if not.
1094 typedef int (*GNUNET_CONTAINER_HashMapIterator32) (void *cls,
1101 * Create a 32-bit key multi hash map.
1103 * @param len initial size (map will grow as needed)
1104 * @return NULL on error
1106 struct GNUNET_CONTAINER_MultiHashMap32 *
1107 GNUNET_CONTAINER_multihashmap32_create (unsigned int len);
1112 * Destroy a 32-bit key hash map. Will not free any values
1113 * stored in the hash map!
1115 * @param map the map
1118 GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32
1124 * Get the number of key-value pairs in the map.
1126 * @param map the map
1127 * @return the number of key value pairs
1130 GNUNET_CONTAINER_multihashmap32_size (const struct
1131 GNUNET_CONTAINER_MultiHashMap32 *map);
1136 * Given a key find a value in the map matching the key.
1138 * @param map the map
1139 * @param key what to look for
1140 * @return NULL if no value was found; note that
1141 * this is indistinguishable from values that just
1142 * happen to be NULL; use "contains" to test for
1143 * key-value pairs with value NULL
1146 GNUNET_CONTAINER_multihashmap32_get (const struct
1147 GNUNET_CONTAINER_MultiHashMap32 *map,
1153 * Iterate over all entries in the map.
1155 * @param map the map
1156 * @param it function to call on each entry
1157 * @param it_cls extra argument to @a it
1158 * @return the number of key value pairs processed,
1159 * #GNUNET_SYSERR if it aborted iteration
1162 GNUNET_CONTAINER_multihashmap32_iterate (const struct
1163 GNUNET_CONTAINER_MultiHashMap32 *map,
1164 GNUNET_CONTAINER_HashMapIterator32 it,
1170 * Remove the given key-value pair from the map. Note that if the
1171 * key-value pair is in the map multiple times, only one of the pairs
1174 * @param map the map
1175 * @param key key of the key-value pair
1176 * @param value value of the key-value pair
1177 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1181 GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1188 * Remove all entries for the given key from the map.
1189 * Note that the values would not be "freed".
1191 * @param map the map
1192 * @param key identifies values to be removed
1193 * @return number of values removed
1196 GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1202 * Check if the map contains any value under the given
1203 * key (including values that are NULL).
1205 * @param map the map
1206 * @param key the key to test if a value exists for it
1207 * @return #GNUNET_YES if such a value exists,
1211 GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1217 * Check if the map contains the given value under the given
1220 * @param map the map
1221 * @param key the key to test if a value exists for it
1222 * @param value value to test for
1223 * @return #GNUNET_YES if such a value exists,
1227 GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1234 * Store a key-value pair in the map.
1236 * @param map the map
1237 * @param key key to use
1238 * @param value value to use
1239 * @param opt options for put
1240 * @return #GNUNET_OK on success,
1241 * #GNUNET_NO if a value was replaced (with REPLACE)
1242 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1243 * value already exists
1246 GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map,
1249 enum GNUNET_CONTAINER_MultiHashMapOption opt);
1254 * Iterate over all entries in the map that match a particular key.
1256 * @param map the map
1257 * @param key key that the entries must correspond to
1258 * @param it function to call on each entry
1259 * @param it_cls extra argument to @a it
1260 * @return the number of key value pairs processed,
1261 * #GNUNET_SYSERR if it aborted iteration
1264 GNUNET_CONTAINER_multihashmap32_get_multiple (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
1266 GNUNET_CONTAINER_HashMapIterator32 it,
1272 /* ******************** doubly-linked list *************** */
1273 /* To avoid mistakes: head->prev == tail->next == NULL */
1277 * Insert an element at the head of a DLL. Assumes that head, tail and
1278 * element are structs with prev and next fields.
1280 * @param head pointer to the head of the DLL
1281 * @param tail pointer to the tail of the DLL
1282 * @param element element to insert
1284 #define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
1285 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1286 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1287 (element)->next = (head); \
1288 (element)->prev = NULL; \
1289 if ((tail) == NULL) \
1292 (head)->prev = element; \
1293 (head) = (element); } while (0)
1298 * Insert an element at the tail of a DLL. Assumes that head, tail and
1299 * element are structs with prev and next fields.
1301 * @param head pointer to the head of the DLL
1302 * @param tail pointer to the tail of the DLL
1303 * @param element element to insert
1305 #define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \
1306 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1307 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1308 (element)->prev = (tail); \
1309 (element)->next = NULL; \
1310 if ((head) == NULL) \
1313 (tail)->next = element; \
1314 (tail) = (element); } while (0)
1319 * Insert an element into a DLL after the given other element. Insert
1320 * at the head if the other element is NULL.
1322 * @param head pointer to the head of the DLL
1323 * @param tail pointer to the tail of the DLL
1324 * @param other prior element, NULL for insertion at head of DLL
1325 * @param element element to insert
1327 #define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
1328 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1329 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1330 (element)->prev = (other); \
1331 if (NULL == other) \
1333 (element)->next = (head); \
1334 (head) = (element); \
1338 (element)->next = (other)->next; \
1339 (other)->next = (element); \
1341 if (NULL == (element)->next) \
1342 (tail) = (element); \
1344 (element)->next->prev = (element); } while (0)
1349 * Insert an element into a DLL before the given other element. Insert
1350 * at the tail if the other element is NULL.
1352 * @param head pointer to the head of the DLL
1353 * @param tail pointer to the tail of the DLL
1354 * @param other prior element, NULL for insertion at head of DLL
1355 * @param element element to insert
1357 #define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
1358 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
1359 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
1360 (element)->next = (other); \
1361 if (NULL == other) \
1363 (element)->prev = (tail); \
1364 (tail) = (element); \
1368 (element)->prev = (other)->prev; \
1369 (other)->prev = (element); \
1371 if (NULL == (element)->prev) \
1372 (head) = (element); \
1374 (element)->prev->next = (element); } while (0)
1379 * Remove an element from a DLL. Assumes that head, tail and
1380 * element point to structs with prev and next fields.
1382 * Using the head or tail pointer as the element
1383 * argument does NOT work with this macro.
1384 * Make sure to store head/tail in another pointer
1385 * and use it to remove the head or tail of the list.
1387 * @param head pointer to the head of the DLL
1388 * @param tail pointer to the tail of the DLL
1389 * @param element element to remove
1391 #define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
1392 GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
1393 GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
1394 if ((element)->prev == NULL) \
1395 (head) = (element)->next; \
1397 (element)->prev->next = (element)->next; \
1398 if ((element)->next == NULL) \
1399 (tail) = (element)->prev; \
1401 (element)->next->prev = (element)->prev; \
1402 (element)->next = NULL; \
1403 (element)->prev = NULL; } while (0)
1406 /* ************ Multi-DLL interface, allows DLL elements to be
1407 in multiple lists at the same time *********************** */
1411 * Insert an element at the head of a MDLL. Assumes that head, tail and
1412 * element are structs with prev and next fields.
1414 * @param mdll suffix name for the next and prev pointers in the element
1415 * @param head pointer to the head of the MDLL
1416 * @param tail pointer to the tail of the MDLL
1417 * @param element element to insert
1419 #define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \
1420 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1421 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1422 (element)->next_##mdll = (head); \
1423 (element)->prev_##mdll = NULL; \
1424 if ((tail) == NULL) \
1427 (head)->prev_##mdll = element; \
1428 (head) = (element); } while (0)
1433 * Insert an element at the tail of a MDLL. Assumes that head, tail and
1434 * element are structs with prev and next fields.
1436 * @param mdll suffix name for the next and prev pointers in the element
1437 * @param head pointer to the head of the MDLL
1438 * @param tail pointer to the tail of the MDLL
1439 * @param element element to insert
1441 #define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \
1442 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1443 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1444 (element)->prev_##mdll = (tail); \
1445 (element)->next_##mdll = NULL; \
1446 if ((head) == NULL) \
1449 (tail)->next_##mdll = element; \
1450 (tail) = (element); } while (0)
1455 * Insert an element into a MDLL after the given other element. Insert
1456 * at the head if the other element is NULL.
1458 * @param mdll suffix name for the next and prev pointers in the element
1459 * @param head pointer to the head of the MDLL
1460 * @param tail pointer to the tail of the MDLL
1461 * @param other prior element, NULL for insertion at head of MDLL
1462 * @param element element to insert
1464 #define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \
1465 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1466 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1467 (element)->prev_##mdll = (other); \
1468 if (NULL == other) \
1470 (element)->next_##mdll = (head); \
1471 (head) = (element); \
1475 (element)->next_##mdll = (other)->next_##mdll; \
1476 (other)->next_##mdll = (element); \
1478 if (NULL == (element)->next_##mdll) \
1479 (tail) = (element); \
1481 (element)->next->prev_##mdll = (element); } while (0)
1486 * Insert an element into a MDLL before the given other element. Insert
1487 * at the tail if the other element is NULL.
1489 * @param mdll suffix name for the next and prev pointers in the element
1490 * @param head pointer to the head of the MDLL
1491 * @param tail pointer to the tail of the MDLL
1492 * @param other prior element, NULL for insertion at head of MDLL
1493 * @param element element to insert
1495 #define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \
1496 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
1497 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
1498 (element)->next_##mdll = (other); \
1499 if (NULL == other) \
1501 (element)->prev = (tail); \
1502 (tail) = (element); \
1506 (element)->prev_##mdll = (other)->prev_##mdll; \
1507 (other)->prev_##mdll = (element); \
1509 if (NULL == (element)->prev_##mdll) \
1510 (head) = (element); \
1512 (element)->prev_##mdll->next_##mdll = (element); } while (0)
1517 * Remove an element from a MDLL. Assumes
1518 * that head, tail and element are structs
1519 * with prev and next fields.
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 element element to remove
1526 #define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \
1527 GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \
1528 GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \
1529 if ((element)->prev_##mdll == NULL) \
1530 (head) = (element)->next_##mdll; \
1532 (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \
1533 if ((element)->next_##mdll == NULL) \
1534 (tail) = (element)->prev_##mdll; \
1536 (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \
1537 (element)->next_##mdll = NULL; \
1538 (element)->prev_##mdll = NULL; } while (0)
1542 /* ******************** Heap *************** */
1547 * Cost by which elements in a heap can be ordered.
1549 typedef uint64_t GNUNET_CONTAINER_HeapCostType;
1554 * Heap type, either max or min.
1556 enum GNUNET_CONTAINER_HeapOrder
1560 * Heap with the maximum cost at the root.
1562 GNUNET_CONTAINER_HEAP_ORDER_MAX,
1566 * Heap with the minimum cost at the root.
1568 GNUNET_CONTAINER_HEAP_ORDER_MIN
1576 struct GNUNET_CONTAINER_Heap;
1581 * Handle to a node in a heap.
1583 struct GNUNET_CONTAINER_HeapNode;
1588 * Create a new heap.
1590 * @param order how should the heap be sorted?
1591 * @return handle to the heap
1593 struct GNUNET_CONTAINER_Heap *
1594 GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order);
1599 * Destroys the heap. Only call on a heap that
1602 * @param heap heap to destroy
1605 GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap);
1610 * Get element stored at root of heap.
1612 * @param heap heap to inspect
1613 * @return NULL if heap is empty
1616 GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
1621 * Get the current size of the heap
1623 * @param heap the heap to get the size of
1624 * @return number of elements stored
1627 GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
1632 * Get the current cost of the node
1634 * @param node the node to get the cost of
1635 * @return cost of the node
1637 GNUNET_CONTAINER_HeapCostType
1638 GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
1645 * @param cls closure
1646 * @param node internal node of the heap
1647 * @param element value stored at the node
1648 * @param cost cost associated with the node
1649 * @return #GNUNET_YES if we should continue to iterate,
1650 * #GNUNET_NO if not.
1652 typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
1653 struct GNUNET_CONTAINER_HeapNode *
1654 node, void *element,
1655 GNUNET_CONTAINER_HeapCostType
1661 * Iterate over all entries in the heap.
1663 * @param heap the heap
1664 * @param iterator function to call on each entry
1665 * @param iterator_cls closure for @a iterator
1668 GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
1669 GNUNET_CONTAINER_HeapIterator iterator,
1670 void *iterator_cls);
1674 * Perform a random walk of the tree. The walk is biased
1675 * towards elements closer to the root of the tree (since
1676 * each walk starts at the root and ends at a random leaf).
1677 * The heap internally tracks the current position of the
1680 * @param heap heap to walk
1681 * @return data stored at the next random node in the walk;
1682 * NULL if the tree is empty.
1685 GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
1690 * Inserts a new element into the heap.
1692 * @param heap heap to modify
1693 * @param element element to insert
1694 * @param cost cost for the element
1695 * @return node for the new element
1697 struct GNUNET_CONTAINER_HeapNode *
1698 GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element,
1699 GNUNET_CONTAINER_HeapCostType cost);
1704 * Remove root of the heap.
1706 * @param heap heap to modify
1707 * @return element data stored at the root node
1710 GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
1715 * Removes a node from the heap.
1717 * @param node node to remove
1718 * @return element data stored at the node, NULL if heap is empty
1721 GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
1726 * Updates the cost of any node in the tree
1728 * @param heap heap to modify
1729 * @param node node for which the cost is to be changed
1730 * @param new_cost new cost for the node
1733 GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
1734 struct GNUNET_CONTAINER_HeapNode *node,
1735 GNUNET_CONTAINER_HeapCostType new_cost);
1738 /* ******************** Singly linked list *************** */
1741 * Possible ways for how data stored in the linked list
1742 * might be allocated.
1743 * @deprecated use DLL macros
1745 enum GNUNET_CONTAINER_SListDisposition
1748 * Single-linked list must copy the buffer.
1749 * @deprecated use DLL macros
1751 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
1754 * Data is static, no need to copy or free.
1755 * @deprecated use DLL macros
1757 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
1760 * Data is dynamic, do not copy but free when done.
1761 * @deprecated use DLL macros
1763 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
1769 * Handle to a singly linked list
1770 * @deprecated use DLL macros
1772 struct GNUNET_CONTAINER_SList;
1775 * Handle to a singly linked list iterator
1776 * @deprecated use DLL macros
1778 struct GNUNET_CONTAINER_SList_Iterator
1781 * Linked list that we are iterating over.
1783 struct GNUNET_CONTAINER_SList *list;
1786 * Last element accessed.
1788 struct GNUNET_CONTAINER_SList_Elem *last;
1791 * Current list element.
1793 struct GNUNET_CONTAINER_SList_Elem *elem;
1799 * Add a new element to the list
1801 * @param disp memory disposition
1802 * @param buf payload buffer
1803 * @param len length of the buffer
1804 * @deprecated use DLL macros
1807 GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
1808 enum GNUNET_CONTAINER_SListDisposition disp,
1809 const void *buf, size_t len);
1813 * Add a new element to the end of the list
1815 * @param disp memory disposition
1816 * @param buf payload buffer
1817 * @param len length of the buffer
1818 * @deprecated use DLL macros
1821 GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
1822 enum GNUNET_CONTAINER_SListDisposition disp,
1823 const void *buf, size_t len);
1827 * Append a singly linked list to another
1828 * @param dst list to append to
1830 * @deprecated use DLL macros
1833 GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
1834 struct GNUNET_CONTAINER_SList *src);
1838 * Create a new singly linked list
1839 * @return the new list
1840 * @deprecated use DLL macros
1842 struct GNUNET_CONTAINER_SList *
1843 GNUNET_CONTAINER_slist_create (void);
1847 * Destroy a singly linked list
1848 * @param l the list to be destroyed
1849 * @deprecated use DLL macros
1852 GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l);
1856 * Return the beginning of a list
1859 * @return iterator pointing to the beginning (by value! Either allocate the
1860 * structure on the stack, or use GNUNET_malloc() yourself! All other
1861 * functions do take pointer to this struct though)
1862 * @deprecated use DLL macros
1864 struct GNUNET_CONTAINER_SList_Iterator
1865 GNUNET_CONTAINER_slist_begin (struct GNUNET_CONTAINER_SList *l);
1872 * @deprecated use DLL macros
1875 GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l);
1879 * Check if a list contains a certain element
1881 * @param buf payload buffer to find
1882 * @param len length of the payload (number of bytes in buf)
1883 * @return GNUNET_YES if found, GNUNET_NO otherwise
1884 * @deprecated use DLL macros
1887 GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
1888 const void *buf, size_t len);
1891 * Check if a list contains a certain element using 'compare' function
1894 * @param buf payload buffer to find
1895 * @param len length of the payload (number of bytes in buf)
1896 * @param compare comparison function
1898 * @return NULL if the 'buf' could not be found, pointer to the
1899 * list element, if found
1900 * @deprecated use DLL macros
1903 GNUNET_CONTAINER_slist_contains2 (const struct GNUNET_CONTAINER_SList *l,
1904 const void *buf, size_t len,
1905 int (*compare)(const void *, const size_t, const void *, const size_t));
1907 * Count the elements of a list
1909 * @return number of elements in the list
1910 * @deprecated use DLL macros
1913 GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l);
1917 * Remove an element from the list
1918 * @param i iterator that points to the element to be removed
1919 * @deprecated use DLL macros
1922 GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i);
1926 * Insert an element into a list at a specific position
1927 * @param before where to insert the new element
1928 * @param disp memory disposition
1929 * @param buf payload buffer
1930 * @param len length of the payload
1931 * @deprecated use DLL macros
1934 GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
1935 enum GNUNET_CONTAINER_SListDisposition disp,
1936 const void *buf, size_t len);
1940 * Advance an iterator to the next element
1942 * @return GNUNET_YES on success, GNUNET_NO if the end has been reached
1943 * @deprecated use DLL macros
1946 GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i);
1950 * Check if an iterator points beyond the end of a list
1952 * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator
1953 * points to a valid element
1954 * @deprecated use DLL macros
1957 GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i);
1961 * Retrieve the element at a specific position in a list
1964 * @param len set to the payload length
1966 * @deprecated use DLL macros
1969 GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
1974 * Release an iterator
1976 * @deprecated use DLL macros
1979 GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i);
1982 #if 0 /* keep Emacsens' auto-indent happy */
1990 /* ifndef GNUNET_CONTAINER_LIB_H */
1992 /* end of gnunet_container_lib.h */