2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 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 2, 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
25 * @author Christian Grothoff
29 #ifndef GNUNET_CONTAINER_LIB_H
30 #define GNUNET_CONTAINER_LIB_H
32 /* add error and config prototypes */
33 #include "gnunet_crypto_lib.h"
34 #include <extractor.h>
39 #if 0 /* keep Emacsens' auto-indent happy */
45 /* ******************* bloomfilter ***************** */
48 * @brief bloomfilter representation (opaque)
50 struct GNUNET_CONTAINER_BloomFilter;
53 * Iterator over HashCodes.
56 * @param next set to the next hash code
57 * @return GNUNET_YES if next was updated
58 * GNUNET_NO if there are no more entries
60 typedef int (*GNUNET_HashCodeIterator) (void *cls,
61 GNUNET_HashCode * next);
64 * Load a bloom-filter from a file.
66 * @param filename the name of the file (or the prefix)
67 * @param size the size of the bloom-filter (number of
68 * bytes of storage space to use)
69 * @param k the number of GNUNET_CRYPTO_hash-functions to apply per
70 * element (number of bits set per element in the set)
71 * @return the bloomfilter
73 struct GNUNET_CONTAINER_BloomFilter *
74 GNUNET_CONTAINER_bloomfilter_load (const
84 * Create a bloom filter from raw bits.
86 * @param data the raw bits in memory (maybe NULL,
87 * in which case all bits should be considered
89 * @param size the size of the bloom-filter (number of
90 * bytes of storage space to use); also size of data
91 * -- unless data is NULL. Must be a power of 2.
92 * @param k the number of GNUNET_CRYPTO_hash-functions to apply per
93 * element (number of bits set per element in the set)
94 * @return the bloomfilter
96 struct GNUNET_CONTAINER_BloomFilter *
97 GNUNET_CONTAINER_bloomfilter_init (const
107 * Copy the raw data of this bloomfilter into
108 * the given data array.
110 * @param data where to write the data
111 * @param size the size of the given data array
112 * @return GNUNET_SYSERR if the data array of the wrong size
114 int GNUNET_CONTAINER_bloomfilter_get_raw_data (struct
115 GNUNET_CONTAINER_BloomFilter
120 * Test if an element is in the filter.
121 * @param e the element
122 * @param bf the filter
123 * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not
125 int GNUNET_CONTAINER_bloomfilter_test (struct GNUNET_CONTAINER_BloomFilter
126 *bf, const GNUNET_HashCode * e);
129 * Add an element to the filter
130 * @param bf the filter
131 * @param e the element
133 void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter
134 *bf, const GNUNET_HashCode * e);
137 * Remove an element from the filter.
138 * @param bf the filter
139 * @param e the element to remove
141 void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter
142 *bf, const GNUNET_HashCode * e);
145 * Free the space associcated with a filter
146 * in memory, flush to drive if needed (do not
147 * free the space on the drive)
148 * @param bf the filter
150 void GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter
154 * Reset a bloom filter to empty.
155 * @param bf the filter
157 void GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter
161 * Or the entries of the given raw data array with the
162 * data of the given bloom filter. Assumes that
163 * the size of the data array and the current filter
166 * @param bf the filter
167 * @param data data to OR-in
168 * @param size size of data
169 * @return GNUNET_OK on success
171 int GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
172 const char *data, size_t size);
175 * Resize a bloom filter. Note that this operation
176 * is pretty costly. Essentially, the bloom filter
177 * needs to be completely re-build.
179 * @param bf the filter
180 * @param iterator an iterator over all elements stored in the BF
181 * @param iterator_cls closure for iterator
182 * @param size the new size for the filter
183 * @param k the new number of GNUNET_CRYPTO_hash-function to apply per element
185 void GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter
187 GNUNET_HashCodeIterator iterator,
189 size_t size, unsigned int k);
191 /* ****************** metadata ******************* */
194 * Meta data to associate with a file, directory or namespace.
196 struct GNUNET_CONTAINER_MetaData;
199 * Iterator over meta data.
202 * @param type type of the meta data
203 * @param data value of the meta data
204 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
206 typedef int (*GNUNET_CONTAINER_MetaDataProcessor) (void *cls,
207 EXTRACTOR_KeywordType type,
211 * Create a fresh MetaData token.
213 * @return empty meta-data container
215 struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_create (void);
218 * Duplicate a MetaData token.
220 * @param md what to duplicate
221 * @return duplicate meta-data container
223 struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_duplicate (const
225 GNUNET_CONTAINER_MetaData
231 * @param md what to free
233 void GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData
237 * Test if two MDs are equal.
239 * @param md1 first value to check
240 * @param md2 other value to check
241 * @return GNUNET_YES if they are equal
243 int GNUNET_CONTAINER_meta_data_test_equal (const struct
244 GNUNET_CONTAINER_MetaData *md1,
246 GNUNET_CONTAINER_MetaData *md2);
252 * @param md metadata to extend
253 * @param type type of the new entry
254 * @param data value for the entry
255 * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists
257 int GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
258 EXTRACTOR_KeywordType type,
264 * @param md metadata to manipulate
265 * @param type type of the item to remove
266 * @param data specific value to remove, NULL to remove all
267 * entries of the given type
268 * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md
270 int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
271 EXTRACTOR_KeywordType type,
275 * Add the current time as the publication date
278 * @param md metadata to modify
280 void GNUNET_CONTAINER_meta_data_add_publication_date (struct
281 GNUNET_CONTAINER_MetaData
285 * Iterate over MD entries, excluding thumbnails.
287 * @param md metadata to inspect
288 * @param iter function to call on each entry
289 * @param iter_cls closure for iterator
290 * @return number of entries
292 int GNUNET_CONTAINER_meta_data_get_contents (const struct
293 GNUNET_CONTAINER_MetaData *md,
294 GNUNET_CONTAINER_MetaDataProcessor
295 iter, void *iter_cls);
298 * Get the first MD entry of the given type.
300 * @param md metadata to inspect
301 * @param type type to look for
302 * @return NULL if we do not have any such entry,
303 * otherwise client is responsible for freeing the value!
305 char *GNUNET_CONTAINER_meta_data_get_by_type (const struct
306 GNUNET_CONTAINER_MetaData *md,
307 EXTRACTOR_KeywordType type);
310 * Get the first matching MD entry of the given types.
312 * @param md metadata to inspect
313 * @param ... -1-terminated list of types
314 * @return NULL if we do not have any such entry,
315 * otherwise client is responsible for freeing the value!
317 char *GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
318 GNUNET_CONTAINER_MetaData
322 * Get a thumbnail from the meta-data (if present).
324 * @param md metadata to inspect
325 * @param thumb will be set to the thumbnail data. Must be
326 * freed by the caller!
327 * @return number of bytes in thumbnail, 0 if not available
329 size_t GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
330 GNUNET_CONTAINER_MetaData
331 *md, unsigned char **thumb);
334 * Extract meta-data from a file.
336 * @param md metadata to set
337 * @param filename name of file to inspect
338 * @param extractors plugins to use
339 * @return GNUNET_SYSERR on error, otherwise the number
340 * of meta-data items obtained
342 int GNUNET_CONTAINER_meta_data_extract_from_file (struct
343 GNUNET_CONTAINER_MetaData
344 *md, const char *filename,
345 EXTRACTOR_ExtractorList *
350 * Options for metadata serialization.
352 enum GNUNET_CONTAINER_MetaDataSerializationOptions
355 * Serialize all of the data.
357 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0,
360 * If not enough space is available, it is acceptable
361 * to only serialize some of the metadata.
363 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1,
366 * Speed is of the essence, do not allow compression.
368 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2
373 * Serialize meta-data to target.
375 * @param md metadata to serialize
376 * @param target where to write the serialized metadata
377 * @param max maximum number of bytes available
378 * @param opt is it ok to just write SOME of the
379 * meta-data to match the size constraint,
380 * possibly discarding some data?
381 * @return number of bytes written on success,
382 * -1 on error (typically: not enough
385 ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct
386 GNUNET_CONTAINER_MetaData *md,
390 GNUNET_CONTAINER_MetaDataSerializationOptions
395 * Estimate (!) the size of the meta-data in
396 * serialized form. The estimate MAY be higher
397 * than what is strictly needed.
399 * @param md metadata to inspect
400 * @param opt is it ok to just write SOME of the
401 * meta-data to match the size constraint,
402 * possibly discarding some data?
403 * @return number of bytes needed for serialization, -1 on error
405 ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
406 GNUNET_CONTAINER_MetaData
409 GNUNET_CONTAINER_MetaDataSerializationOptions
413 * Deserialize meta-data. Initializes md.
415 * @param input serialized meta-data.
416 * @param size number of bytes available
417 * @return MD on success, NULL on error (i.e.
420 struct GNUNET_CONTAINER_MetaData
421 *GNUNET_CONTAINER_meta_data_deserialize (const char *input,
425 * Does the meta-data claim that this is a directory?
426 * Checks if the mime-type is that of a GNUnet directory.
428 * @param md metadata to inspect
429 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
430 * we have no mime-type information (treat as 'GNUNET_NO')
432 int GNUNET_CONTAINER_meta_data_test_for_directory (const struct
433 GNUNET_CONTAINER_MetaData
437 /* ******************************* HashMap **************************** */
440 * Opaque handle for a HashMap.
442 struct GNUNET_CONTAINER_MultiHashMap;
445 * Options for storing values in the HashMap.
447 enum GNUNET_CONTAINER_MultiHashMapOption
450 * If a value with the given key exists, replace it.
451 * Note that the old value would NOT be freed
452 * by replace (the application has to make sure that
453 * this happens if required).
455 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE,
458 * Allow multiple values with the same key.
460 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE,
463 * There must only be one value per key; storing
464 * a value should fail if a value under the same
465 * key already exists.
467 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY,
470 * There must only be one value per key, but don't
471 * bother checking if a value already exists
472 * (faster than UNIQUE_ONLY; implemented just like
473 * MULTIPLE but this option documents better what
474 * is intended if UNIQUE is what is desired).
476 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
481 * Iterator over HashCodes.
484 * @param key current key code
485 * @param value value in the hash map
486 * @return GNUNET_YES if we should continue to
490 typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls,
491 const GNUNET_HashCode * key,
496 * Create a multi hash map.
498 * @param len initial size (map will grow as needed)
499 * @return NULL on error
501 struct GNUNET_CONTAINER_MultiHashMap
502 *GNUNET_CONTAINER_multihashmap_create (unsigned int len);
505 * Destroy a hash map. Will not free any values
506 * stored in the hash map!
510 void GNUNET_CONTAINER_multihashmap_destroy (struct
511 GNUNET_CONTAINER_MultiHashMap
515 * Given a key find a value in the
516 * map matching the key.
519 * @param key what to look for
520 * @return NULL if no value was found; note that
521 * this is indistinguishable from values that just
522 * happen to be NULL; use "contains" to test for
523 * key-value pairs with value NULL
525 void *GNUNET_CONTAINER_multihashmap_get (const struct
526 GNUNET_CONTAINER_MultiHashMap *map,
527 const GNUNET_HashCode * key);
530 * Remove the given key-value pair from the map.
531 * Note that if the key-value pair is in the map
532 * multiple times, only one of the pairs will be
536 * @param key key of the key-value pair
537 * @param value value of the key-value pair
538 * @return GNUNET_YES on success, GNUNET_NO if the key-value pair
541 int GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap
542 *map, const GNUNET_HashCode * key,
546 * Remove all entries for the given key from the map.
547 * Note that the values would not be "freed".
550 * @param key identifies values to be removed
551 * @return number of values removed
553 int GNUNET_CONTAINER_multihashmap_remove_all (struct
554 GNUNET_CONTAINER_MultiHashMap
556 const GNUNET_HashCode * key);
559 * Check if the map contains any value under the given
560 * key (including values that are NULL).
563 * @param key the key to test if a value exists for it
564 * @return GNUNET_YES if such a value exists,
567 int GNUNET_CONTAINER_multihashmap_contains (const struct
568 GNUNET_CONTAINER_MultiHashMap
570 const GNUNET_HashCode * key);
573 * Store a key-value pair in the map.
576 * @param key key to use
577 * @param value value to use
578 * @param opt options for put
579 * @return GNUNET_OK on success,
580 * GNUNET_NO if a value was replaced (with REPLACE)
581 * GNUNET_SYSERR if UNIQUE_ONLY was the option and the
582 * value already exists
584 int GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap
585 *map, const GNUNET_HashCode * key,
588 GNUNET_CONTAINER_MultiHashMapOption
592 * Get the number of key-value pairs in the map.
595 * @return the number of key value pairs
597 unsigned int GNUNET_CONTAINER_multihashmap_size (const struct
598 GNUNET_CONTAINER_MultiHashMap
603 * Iterate over all entries in the map.
606 * @param iterator function to call on each entry
607 * @param cls extra argument to it
608 * @return the number of key value pairs processed,
609 * GNUNET_SYSERR if it aborted iteration
611 int GNUNET_CONTAINER_multihashmap_iterate (const struct
612 GNUNET_CONTAINER_MultiHashMap *map,
613 GNUNET_CONTAINER_HashMapIterator
614 iterator, void *cls);
617 * Iterate over all entries in the map
618 * that match a particular key.
621 * @param key key that the entries must correspond to
622 * @param iterator function to call on each entry
623 * @param cls extra argument to it
624 * @return the number of key value pairs processed,
625 * GNUNET_SYSERR if it aborted iteration
627 int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
628 GNUNET_CONTAINER_MultiHashMap
630 const GNUNET_HashCode * key,
631 GNUNET_CONTAINER_HashMapIterator
632 iterator, void *cls);
634 * Returns the stored value of a random non-null entry
635 * in the hash table. Returns only the first value, does
636 * not go inside bucket linked list (yet). Runs with a
637 * worst case time of N, so it's not efficient in any way
640 void *GNUNET_CONTAINER_multihashmap_get_random (const struct
641 GNUNET_CONTAINER_MultiHashMap
647 /* ******************** doubly-linked list *************** */
650 * Insert an element into a DLL. Assumes
651 * that head, tail and element are structs
652 * with prev and next fields.
654 * @param head pointer to the head of the DLL
655 * @param tail pointer to the tail of the DLL
656 * @param element element to insert
658 #define GNUNET_CONTAINER_DLL_insert(head,tail,element) \
659 (element)->next = (head); \
660 (element)->prev = NULL; \
661 if ((tail) == NULL) \
664 (head)->prev = element; \
668 * Insert an element into a DLL after the given other
669 * element. Insert at the head if the other
672 * @param head pointer to the head of the DLL
673 * @param tail pointer to the tail of the DLL
674 * @param other prior element, NULL for insertion at head of DLL
675 * @param element element to insert
677 #define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) \
678 (element)->prev = (other); \
681 (element)->next = (head); \
682 (head) = (element); \
686 (element)->next = (other)->next; \
687 (other)->next = (element); \
689 if (NULL == (element)->next) \
690 (tail) = (element); \
692 (element)->next->prev = (element);
698 * Remove an element from a DLL. Assumes
699 * that head, tail and element are structs
700 * with prev and next fields.
702 * @param head pointer to the head of the DLL
703 * @param tail pointer to the tail of the DLL
704 * @param element element to remove
706 #define GNUNET_CONTAINER_DLL_remove(head,tail,element) \
707 if ((element)->prev == NULL) \
708 (head) = (element)->next; \
710 (element)->prev->next = (element)->next; \
711 if ((element)->next == NULL) \
712 (tail) = (element)->prev; \
714 (element)->next->prev = (element)->prev;
718 /* ******************** Heap *************** */
722 * Cost by which elements in a heap can be ordered.
724 typedef uint64_t GNUNET_CONTAINER_HeapCost;
728 * Heap type, either max or min. Hopefully makes the
729 * implementation more useful.
731 enum GNUNET_CONTAINER_HeapOrder
734 * Heap with the maximum cost at the root.
736 GNUNET_CONTAINER_HEAP_ORDER_MAX,
739 * Heap with the minimum cost at the root.
741 GNUNET_CONTAINER_HEAP_ORDER_MIN
748 struct GNUNET_CONTAINER_Heap;
753 * @param type should the minimum or the maximum element be the root
754 * @return NULL on error, otherwise a fresh heap
756 struct GNUNET_CONTAINER_Heap *GNUNET_CONTAINER_heap_create (enum
757 GNUNET_CONTAINER_HeapOrder
764 * @param h heap to free.
766 void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *h);
770 * Function called on elements of a heap.
773 * @param element obj stored in heap
774 * @param cost cost of the element
775 * @return GNUNET_YES if we should continue to iterate,
778 typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
780 GNUNET_CONTAINER_HeapCost cost);
784 * Iterate over all entries in the map.
786 * @param heap the heap
787 * @param iterator function to call on each entry
788 * @param iterator_cls closure for iterator
789 * @return number of items handled
790 * GNUNET_SYSERR if iteration was aborted by iterator
792 int GNUNET_CONTAINER_heap_iterate (struct GNUNET_CONTAINER_Heap *heap,
793 GNUNET_CONTAINER_HeapIterator iterator,
799 * Inserts a new item into the heap, item is always neighbor now.
800 * @param heap the heap
801 * @param element element to insert
802 * @param cost cost of the element
806 GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
807 void *element, GNUNET_CONTAINER_HeapCost cost);
811 * Removes root of the tree, is remove max if a max heap and remove min
812 * if a min heap, returns the data stored at the node.
814 * @param heap the heap
815 * @return NULL if the heap is empty
817 void *GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
821 * Returns element stored at root of tree, doesn't effect anything
823 * @param heap the heap
824 * @return NULL if the heap is empty
826 void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap);
830 * Removes any node from the tree based on the neighbor given, does
831 * not traverse the tree (backpointers) but may take more time due to
832 * percolation of nodes.
834 * @param heap the heap
835 * @param element the element to remove
836 * @return NULL if "element" was not found in the heap, otherwise element
838 void *GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap,
843 * Updates the cost of any node in the tree
845 * @param heap the heap
846 * @param element the element for which the cost is updated
847 * @param new_cost new cost for the element
851 GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
853 GNUNET_CONTAINER_HeapCost new_cost);
857 * Random walk of the tree, returns the data stored at the next random node
858 * in the walk. Calls callee with the data, or NULL if the tree is empty
859 * or some other problem crops up.
861 * @param heap the heap
862 * @return the next element from the random walk
864 void *GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap
869 * Returns the current size of the heap
871 * @param heap the heap to get the size of
872 * @return number of elements in the heap
875 GNUNET_CONTAINER_heap_get_size (struct GNUNET_CONTAINER_Heap *heap);
877 /* ******************** Singly linked list *************** */
880 * Possible ways for how data stored in the linked list
881 * might be allocated.
883 enum GNUNET_CONTAINER_SListDisposition
886 * Single-linked list must copy the buffer.
888 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
891 * Data is static, no need to copy or free.
893 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
896 * Data is dynamic, do not copy but free when done.
898 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
904 * Handle to a singly linked list
906 struct GNUNET_CONTAINER_SList;
909 * Handle to a singly linked list iterator
911 struct GNUNET_CONTAINER_SList_Iterator;
915 * Add a new element to the list
917 * @param disp memory disposition
918 * @param buf payload buffer
919 * @param len length of the buffer
921 void GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
922 enum GNUNET_CONTAINER_SListDisposition disp,
923 const void *buf, size_t len);
927 * Create a new singly linked list
928 * @return the new list
930 struct GNUNET_CONTAINER_SList *GNUNET_CONTAINER_slist_create (void);
934 * Destroy a singly linked list
935 * @param l the list to be destroyed
937 void GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l);
941 * Return the beginning of a list
944 * @return iterator pointing to the beginning, free using "GNUNET_free"
946 struct GNUNET_CONTAINER_SList_Iterator *
947 GNUNET_CONTAINER_slist_begin(struct GNUNET_CONTAINER_SList *l);
955 void GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l);
959 * Check if a list contains a certain element
961 * @param buf payload buffer to find
962 * @param len length of the payload (number of bytes in buf)
964 int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, const void *buf, size_t len);
968 * Count the elements of a list
970 * @return number of elements in the list
972 int GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l);
976 * Remove an element from the list
977 * @param i iterator that points to the element to be removed
979 void GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i);
983 * Insert an element into a list at a specific position
984 * @param before where to insert the new element
985 * @param disp memory disposition
986 * @param buf payload buffer
987 * @param len length of the payload
989 void GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
990 enum GNUNET_CONTAINER_SListDisposition disp,
996 * Advance an iterator to the next element
998 * @return GNUNET_YES on success, GNUNET_NO if the end has been reached
1000 int GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i);
1004 * Check if an iterator points beyond the end of a list
1006 * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator
1007 * points to a valid element
1009 int GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i);
1013 * Retrieve the element at a specific position in a list
1016 * @param len set to the payload length
1020 GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
1024 #if 0 /* keep Emacsens' auto-indent happy */
1032 /* ifndef GNUNET_CONTAINER_LIB_H */
1034 /* end of gnunet_container_lib.h */