2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 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>
36 #ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
37 /* hack for LE < 0.6.3 */
38 #define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
44 #if 0 /* keep Emacsens' auto-indent happy */
50 /* ******************* bloomfilter ***************** */
53 * @brief bloomfilter representation (opaque)
55 struct GNUNET_CONTAINER_BloomFilter;
58 * Iterator over HashCodes.
61 * @param next set to the next hash code
62 * @return GNUNET_YES if next was updated
63 * GNUNET_NO if there are no more entries
65 typedef int (*GNUNET_HashCodeIterator) (void *cls,
66 GNUNET_HashCode * next);
70 * Load a bloom-filter from a file.
72 * @param filename the name of the file (or the prefix)
73 * @param size the size of the bloom-filter (number of
74 * bytes of storage space to use)
75 * @param k the number of GNUNET_CRYPTO_hash-functions to apply per
76 * element (number of bits set per element in the set)
77 * @return the bloomfilter
79 struct GNUNET_CONTAINER_BloomFilter *
80 GNUNET_CONTAINER_bloomfilter_load (const
91 * Create a bloom filter from raw bits.
93 * @param data the raw bits in memory (maybe NULL,
94 * in which case all bits should be considered
96 * @param size the size of the bloom-filter (number of
97 * bytes of storage space to use); also size of data
98 * -- unless data is NULL. Must be a power of 2.
99 * @param k the number of GNUNET_CRYPTO_hash-functions to apply per
100 * element (number of bits set per element in the set)
101 * @return the bloomfilter
103 struct GNUNET_CONTAINER_BloomFilter *
104 GNUNET_CONTAINER_bloomfilter_init (const
115 * Copy the raw data of this bloomfilter into
116 * the given data array.
118 * @param data where to write the data
119 * @param size the size of the given data array
120 * @return GNUNET_SYSERR if the data array of the wrong size
122 int GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
123 GNUNET_CONTAINER_BloomFilter
129 * Test if an element is in the filter.
130 * @param e the element
131 * @param bf the filter
132 * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not
134 int GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
135 *bf, const GNUNET_HashCode * e);
139 * Add an element to the filter
140 * @param bf the filter
141 * @param e the element
143 void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter
144 *bf, const GNUNET_HashCode * e);
148 * Remove an element from the filter.
149 * @param bf the filter
150 * @param e the element to remove
152 void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter
153 *bf, const GNUNET_HashCode * e);
157 * Create a copy of a bloomfilter.
159 * @param bf the filter
162 struct GNUNET_CONTAINER_BloomFilter *
163 GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf);
168 * Free the space associcated with a filter
169 * in memory, flush to drive if needed (do not
170 * free the space on the drive)
171 * @param bf the filter
173 void GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter
178 * Get size of the bloom filter.
180 * @param bf the filter
181 * @return number of bytes used for the data of the bloom filter
184 GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
189 * Reset a bloom filter to empty.
190 * @param bf the filter
192 void GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter
196 * Or the entries of the given raw data array with the
197 * data of the given bloom filter. Assumes that
198 * the size of the data array and the current filter
201 * @param bf the filter
202 * @param data data to OR-in
203 * @param size size of data
204 * @return GNUNET_OK on success
206 int GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
207 const char *data, size_t size);
210 * Or the entries of the given raw data array with the
211 * data of the given bloom filter. Assumes that
212 * the size of the data array and the current filter
215 * @param bf the filter
216 * @param to_or the bloomfilter to or-in
217 * @param size number of bytes in data
220 GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
221 const struct GNUNET_CONTAINER_BloomFilter *to_or,
225 * Resize a bloom filter. Note that this operation
226 * is pretty costly. Essentially, the bloom filter
227 * needs to be completely re-build.
229 * @param bf the filter
230 * @param iterator an iterator over all elements stored in the BF
231 * @param iterator_cls closure for iterator
232 * @param size the new size for the filter
233 * @param k the new number of GNUNET_CRYPTO_hash-function to apply per element
235 void GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter
237 GNUNET_HashCodeIterator iterator,
239 size_t size, unsigned int k);
241 /* ****************** metadata ******************* */
244 * Meta data to associate with a file, directory or namespace.
246 struct GNUNET_CONTAINER_MetaData;
249 * Create a fresh MetaData token.
251 * @return empty meta-data container
253 struct GNUNET_CONTAINER_MetaData *
254 GNUNET_CONTAINER_meta_data_create (void);
257 * Duplicate a MetaData token.
259 * @param md what to duplicate
260 * @return duplicate meta-data container
262 struct GNUNET_CONTAINER_MetaData *
263 GNUNET_CONTAINER_meta_data_duplicate (const struct
264 GNUNET_CONTAINER_MetaData *md);
269 * @param md what to free
272 GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
275 * Test if two MDs are equal. We consider them equal if
276 * the meta types, formats and content match (we do not
277 * include the mime types and plugins names in this
280 * @param md1 first value to check
281 * @param md2 other value to check
282 * @return GNUNET_YES if they are equal
285 GNUNET_CONTAINER_meta_data_test_equal (const struct
286 GNUNET_CONTAINER_MetaData *md1,
288 GNUNET_CONTAINER_MetaData *md2);
294 * @param md metadata to extend
295 * @param plugin_name name of the plugin that produced this value;
296 * special values can be used (i.e. '<zlib>' for zlib being
297 * used in the main libextractor library and yielding
299 * @param type libextractor-type describing the meta data
300 * @param format basic format information about data
301 * @param data_mime_type mime-type of data (not of the original file);
302 * can be NULL (if mime-type is not known)
303 * @param data actual meta-data found
304 * @param data_len number of bytes in data
305 * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists
306 * data_mime_type and plugin_name are not considered for "exists" checks
309 GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
310 const char *plugin_name,
311 enum EXTRACTOR_MetaType type,
312 enum EXTRACTOR_MetaFormat format,
313 const char *data_mime_type,
319 * Extend metadata. Merges the meta data from the second argument
320 * into the first, discarding duplicate key-value pairs.
322 * @param md metadata to extend
323 * @param in metadata to merge
326 GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
327 const struct GNUNET_CONTAINER_MetaData *in);
333 * @param md metadata to manipulate
334 * @param type type of the item to remove
335 * @param data specific value to remove, NULL to remove all
336 * entries of the given type
337 * @param data_len number of bytes in data
338 * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md
341 GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
342 enum EXTRACTOR_MetaType type,
348 * Remove all items in the container.
350 * @param md metadata to manipulate
353 GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
357 * Add the current time as the publication date
360 * @param md metadata to modify
363 GNUNET_CONTAINER_meta_data_add_publication_date (struct
364 GNUNET_CONTAINER_MetaData
369 * Iterate over MD entries.
371 * @param md metadata to inspect
372 * @param iter function to call on each entry
373 * @param iter_cls closure for iterator
374 * @return number of entries
376 int GNUNET_CONTAINER_meta_data_iterate (const struct
377 GNUNET_CONTAINER_MetaData *md,
378 EXTRACTOR_MetaDataProcessor
379 iter, void *iter_cls);
382 * Get the first MD entry of the given type. Caller
383 * is responsible for freeing the return value.
384 * Also, only meta data items that are strings (0-terminated)
385 * are returned by this function.
387 * @param md metadata to inspect
388 * @param type type to look for
389 * @return NULL if no entry was found
392 GNUNET_CONTAINER_meta_data_get_by_type (const struct
393 GNUNET_CONTAINER_MetaData *md,
394 enum EXTRACTOR_MetaType type);
398 * Get the first matching MD entry of the given types. Caller is
399 * responsible for freeing the return value. Also, only meta data
400 * items that are strings (0-terminated) are returned by this
403 * @param md metadata to inspect
404 * @param ... -1-terminated list of types
405 * @return NULL if we do not have any such entry,
406 * otherwise client is responsible for freeing the value!
409 GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
410 GNUNET_CONTAINER_MetaData
414 * Get a thumbnail from the meta-data (if present). Only matches meta
415 * data with mime type "image" and binary format.
417 * @param md metadata to inspect
418 * @param thumb will be set to the thumbnail data. Must be
419 * freed by the caller!
420 * @return number of bytes in thumbnail, 0 if not available
423 GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
424 GNUNET_CONTAINER_MetaData
425 *md, unsigned char **thumb);
430 * Options for metadata serialization.
432 enum GNUNET_CONTAINER_MetaDataSerializationOptions
435 * Serialize all of the data.
437 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0,
440 * If not enough space is available, it is acceptable
441 * to only serialize some of the metadata.
443 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1,
446 * Speed is of the essence, do not allow compression.
448 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2
453 * Serialize meta-data to target.
455 * @param md metadata to serialize
456 * @param target where to write the serialized metadata;
457 * *target can be NULL, in which case memory is allocated
458 * @param max maximum number of bytes available
459 * @param opt is it ok to just write SOME of the
460 * meta-data to match the size constraint,
461 * possibly discarding some data?
462 * @return number of bytes written on success,
463 * -1 on error (typically: not enough
467 GNUNET_CONTAINER_meta_data_serialize (const struct
468 GNUNET_CONTAINER_MetaData *md,
472 GNUNET_CONTAINER_MetaDataSerializationOptions
477 * Get the size of the full meta-data in serialized form.
479 * @param md metadata to inspect
480 * @return number of bytes needed for serialization, -1 on error
483 GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
484 GNUNET_CONTAINER_MetaData
489 * Deserialize meta-data. Initializes md.
491 * @param input serialized meta-data.
492 * @param size number of bytes available
493 * @return MD on success, NULL on error (i.e.
496 struct GNUNET_CONTAINER_MetaData *
497 GNUNET_CONTAINER_meta_data_deserialize (const char *input,
501 /* ******************************* HashMap **************************** */
504 * Opaque handle for a HashMap.
506 struct GNUNET_CONTAINER_MultiHashMap;
509 * Options for storing values in the HashMap.
511 enum GNUNET_CONTAINER_MultiHashMapOption
515 * If a value with the given key exists, replace it. Note that the
516 * old value would NOT be freed by replace (the application has to
517 * make sure that this happens if required).
519 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE,
522 * Allow multiple values with the same key.
524 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE,
527 * There must only be one value per key; storing a value should fail
528 * if a value under the same key already exists.
530 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY,
533 * There must only be one value per key, but don't bother checking
534 * if a value already exists (faster than UNIQUE_ONLY; implemented
535 * just like MULTIPLE but this option documents better what is
536 * intended if UNIQUE is what is desired).
538 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
543 * Iterator over hash map entries.
546 * @param key current key code
547 * @param value value in the hash map
548 * @return GNUNET_YES if we should continue to
552 typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls,
553 const GNUNET_HashCode * key,
558 * Create a multi hash map.
560 * @param len initial size (map will grow as needed)
561 * @return NULL on error
563 struct GNUNET_CONTAINER_MultiHashMap
564 *GNUNET_CONTAINER_multihashmap_create (unsigned int len);
568 * Destroy a hash map. Will not free any values
569 * stored in the hash map!
573 void GNUNET_CONTAINER_multihashmap_destroy (struct
574 GNUNET_CONTAINER_MultiHashMap
579 * Given a key find a value in the map matching the key.
582 * @param key what to look for
583 * @return NULL if no value was found; note that
584 * this is indistinguishable from values that just
585 * happen to be NULL; use "contains" to test for
586 * key-value pairs with value NULL
588 void *GNUNET_CONTAINER_multihashmap_get (const struct
589 GNUNET_CONTAINER_MultiHashMap *map,
590 const GNUNET_HashCode * key);
594 * Remove the given key-value pair from the map. Note that if the
595 * key-value pair is in the map multiple times, only one of the pairs
599 * @param key key of the key-value pair
600 * @param value value of the key-value pair
601 * @return GNUNET_YES on success, GNUNET_NO if the key-value pair
604 int GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap
605 *map, const GNUNET_HashCode * key,
609 * Remove all entries for the given key from the map.
610 * Note that the values would not be "freed".
613 * @param key identifies values to be removed
614 * @return number of values removed
616 int GNUNET_CONTAINER_multihashmap_remove_all (struct
617 GNUNET_CONTAINER_MultiHashMap
619 const GNUNET_HashCode * key);
623 * Check if the map contains any value under the given
624 * key (including values that are NULL).
627 * @param key the key to test if a value exists for it
628 * @return GNUNET_YES if such a value exists,
631 int GNUNET_CONTAINER_multihashmap_contains (const struct
632 GNUNET_CONTAINER_MultiHashMap
634 const GNUNET_HashCode * key);
638 * Check if the map contains the given value under the given
642 * @param key the key to test if a value exists for it
643 * @param value value to test for
644 * @return GNUNET_YES if such a value exists,
647 int GNUNET_CONTAINER_multihashmap_contains_value (const struct
648 GNUNET_CONTAINER_MultiHashMap
650 const GNUNET_HashCode * key,
655 * Store a key-value pair in the map.
658 * @param key key to use
659 * @param value value to use
660 * @param opt options for put
661 * @return GNUNET_OK on success,
662 * GNUNET_NO if a value was replaced (with REPLACE)
663 * GNUNET_SYSERR if UNIQUE_ONLY was the option and the
664 * value already exists
666 int GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap
667 *map, const GNUNET_HashCode * key,
670 GNUNET_CONTAINER_MultiHashMapOption
674 * Get the number of key-value pairs in the map.
677 * @return the number of key value pairs
679 unsigned int GNUNET_CONTAINER_multihashmap_size (const struct
680 GNUNET_CONTAINER_MultiHashMap
685 * Iterate over all entries in the map.
688 * @param it function to call on each entry
689 * @param it_cls extra argument to it
690 * @return the number of key value pairs processed,
691 * GNUNET_SYSERR if it aborted iteration
693 int GNUNET_CONTAINER_multihashmap_iterate (const struct
694 GNUNET_CONTAINER_MultiHashMap *map,
695 GNUNET_CONTAINER_HashMapIterator
700 * Iterate over all entries in the map that match a particular key.
703 * @param key key that the entries must correspond to
704 * @param it function to call on each entry
705 * @param it_cls extra argument to it
706 * @return the number of key value pairs processed,
707 * GNUNET_SYSERR if it aborted iteration
709 int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
710 GNUNET_CONTAINER_MultiHashMap
712 const GNUNET_HashCode * key,
713 GNUNET_CONTAINER_HashMapIterator
717 /* ******************** doubly-linked list *************** */
720 * Insert an element at the head of a DLL. Assumes that head, tail and
721 * element are structs with prev and next fields.
723 * @param head pointer to the head of the DLL
724 * @param tail pointer to the tail of the DLL
725 * @param element element to insert
727 #define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
728 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
729 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
730 (element)->next = (head); \
731 (element)->prev = NULL; \
732 if ((tail) == NULL) \
735 (head)->prev = element; \
736 (head) = (element); } while (0)
740 * Insert an element at the tail of a DLL. Assumes that head, tail and
741 * element are structs with prev and next fields.
743 * @param head pointer to the head of the DLL
744 * @param tail pointer to the tail of the DLL
745 * @param element element to insert
747 #define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \
748 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
749 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
750 (element)->prev = (tail); \
751 (element)->next = NULL; \
752 if ((head) == NULL) \
755 (tail)->next = element; \
756 (tail) = (element); } while (0)
760 * Insert an element into a DLL after the given other element. Insert
761 * at the head if the other element is NULL.
763 * @param head pointer to the head of the DLL
764 * @param tail pointer to the tail of the DLL
765 * @param other prior element, NULL for insertion at head of DLL
766 * @param element element to insert
768 #define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
769 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
770 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
771 (element)->prev = (other); \
774 (element)->next = (head); \
775 (head) = (element); \
779 (element)->next = (other)->next; \
780 (other)->next = (element); \
782 if (NULL == (element)->next) \
783 (tail) = (element); \
785 (element)->next->prev = (element); } while (0)
789 * Insert an element into a DLL before the given other element. Insert
790 * at the tail if the other element is NULL.
792 * @param head pointer to the head of the DLL
793 * @param tail pointer to the tail of the DLL
794 * @param other prior element, NULL for insertion at head of DLL
795 * @param element element to insert
797 #define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
798 GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
799 GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
800 (element)->next = (other); \
803 (element)->prev = (tail); \
804 (tail) = (element); \
808 (element)->prev = (other)->prev; \
809 (other)->prev = (element); \
811 if (NULL == (element)->prev) \
812 (head) = (element); \
814 (element)->prev->next = (element); } while (0)
818 * Remove an element from a DLL. Assumes
819 * that head, tail and element are structs
820 * with prev and next fields.
822 * @param head pointer to the head of the DLL
823 * @param tail pointer to the tail of the DLL
824 * @param element element to remove
826 #define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
827 GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
828 GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
829 if ((element)->prev == NULL) \
830 (head) = (element)->next; \
832 (element)->prev->next = (element)->next; \
833 if ((element)->next == NULL) \
834 (tail) = (element)->prev; \
836 (element)->next->prev = (element)->prev; \
837 (element)->next = NULL; \
838 (element)->prev = NULL; } while (0)
842 /* ******************** Heap *************** */
846 * Cost by which elements in a heap can be ordered.
848 typedef uint64_t GNUNET_CONTAINER_HeapCostType;
852 * Heap type, either max or min. Hopefully makes the
853 * implementation more useful.
855 enum GNUNET_CONTAINER_HeapOrder
858 * Heap with the maximum cost at the root.
860 GNUNET_CONTAINER_HEAP_ORDER_MAX,
863 * Heap with the minimum cost at the root.
865 GNUNET_CONTAINER_HEAP_ORDER_MIN
872 struct GNUNET_CONTAINER_Heap;
877 * Handle to a node in a heap.
879 struct GNUNET_CONTAINER_HeapNode;
885 * @param order how should the heap be sorted?
886 * @return handle to the heap
888 struct GNUNET_CONTAINER_Heap *
889 GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order);
893 * Destroys the heap. Only call on a heap that
896 * @param heap heap to destroy
898 void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap);
902 * Get element stored at root of heap.
904 * @param heap heap to inspect
905 * @return NULL if heap is empty
908 GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
912 * Get the current size of the heap
914 * @param heap the heap to get the size of
915 * @return number of elements stored
918 GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
925 * @param node internal node of the heap
926 * @param element value stored at the node
927 * @param cost cost associated with the node
928 * @return GNUNET_YES if we should continue to iterate,
931 typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
932 struct GNUNET_CONTAINER_HeapNode *node,
934 GNUNET_CONTAINER_HeapCostType cost);
938 * Iterate over all entries in the heap.
940 * @param heap the heap
941 * @param iterator function to call on each entry
942 * @param iterator_cls closure for iterator
945 GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
946 GNUNET_CONTAINER_HeapIterator iterator,
951 * Return a *uniform* random element from the heap. Choose a random
952 * number between 0 and heap size and then walk directly to it.
953 * This cost can be between 0 and n, amortized cost of logN.
955 * @param heap heap to choose random element from
956 * @param max how many nodes from the heap to choose from
958 * @return data stored at the chosen random node,
959 * NULL if the heap is empty.
963 GNUNET_CONTAINER_heap_get_random (struct GNUNET_CONTAINER_Heap *heap,
968 * Perform a random walk of the tree. The walk is biased
969 * towards elements closer to the root of the tree (since
970 * each walk starts at the root and ends at a random leaf).
971 * The heap internally tracks the current position of the
974 * @param heap heap to walk
975 * @return data stored at the next random node in the walk;
976 * NULL if the tree is empty.
979 GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
983 * Inserts a new element into the heap.
985 * @param heap heap to modify
986 * @param element element to insert
987 * @param cost cost for the element
988 * @return node for the new element
990 struct GNUNET_CONTAINER_HeapNode *
991 GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
993 GNUNET_CONTAINER_HeapCostType cost);
997 * Remove root of the heap.
999 * @param heap heap to modify
1000 * @return element data stored at the root node
1003 GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
1007 * Removes a node from the heap.
1009 * @param heap heap to modify
1010 * @param node node to remove
1011 * @return element data stored at the node, NULL if heap is empty
1014 GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap,
1015 struct GNUNET_CONTAINER_HeapNode *node);
1019 * Updates the cost of any node in the tree
1021 * @param heap heap to modify
1022 * @param node node for which the cost is to be changed
1023 * @param new_cost new cost for the node
1026 GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
1027 struct GNUNET_CONTAINER_HeapNode *node,
1028 GNUNET_CONTAINER_HeapCostType new_cost);
1031 /* ******************** Singly linked list *************** */
1034 * Possible ways for how data stored in the linked list
1035 * might be allocated.
1037 enum GNUNET_CONTAINER_SListDisposition
1040 * Single-linked list must copy the buffer.
1042 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
1045 * Data is static, no need to copy or free.
1047 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
1050 * Data is dynamic, do not copy but free when done.
1052 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
1058 * Handle to a singly linked list
1060 struct GNUNET_CONTAINER_SList;
1063 * Handle to a singly linked list iterator
1065 struct GNUNET_CONTAINER_SList_Iterator;
1069 * Add a new element to the list
1071 * @param disp memory disposition
1072 * @param buf payload buffer
1073 * @param len length of the buffer
1075 void GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
1076 enum GNUNET_CONTAINER_SListDisposition disp,
1077 const void *buf, size_t len);
1081 * Add a new element to the end of the list
1083 * @param disp memory disposition
1084 * @param buf payload buffer
1085 * @param len length of the buffer
1087 void GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
1088 enum GNUNET_CONTAINER_SListDisposition disp,
1089 const void *buf, size_t len);
1093 * Append a singly linked list to another
1094 * @param dst list to append to
1098 GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, struct GNUNET_CONTAINER_SList *src);
1102 * Create a new singly linked list
1103 * @return the new list
1105 struct GNUNET_CONTAINER_SList *GNUNET_CONTAINER_slist_create (void);
1109 * Destroy a singly linked list
1110 * @param l the list to be destroyed
1112 void GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l);
1116 * Return the beginning of a list
1119 * @return iterator pointing to the beginning, free using "GNUNET_free"
1121 struct GNUNET_CONTAINER_SList_Iterator *
1122 GNUNET_CONTAINER_slist_begin(struct GNUNET_CONTAINER_SList *l);
1130 void GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l);
1134 * Check if a list contains a certain element
1136 * @param buf payload buffer to find
1137 * @param len length of the payload (number of bytes in buf)
1139 int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, const void *buf, size_t len);
1143 * Count the elements of a list
1145 * @return number of elements in the list
1147 int GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l);
1151 * Remove an element from the list
1152 * @param i iterator that points to the element to be removed
1154 void GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i);
1158 * Insert an element into a list at a specific position
1159 * @param before where to insert the new element
1160 * @param disp memory disposition
1161 * @param buf payload buffer
1162 * @param len length of the payload
1164 void GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
1165 enum GNUNET_CONTAINER_SListDisposition disp,
1171 * Advance an iterator to the next element
1173 * @return GNUNET_YES on success, GNUNET_NO if the end has been reached
1175 int GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i);
1179 * Check if an iterator points beyond the end of a list
1181 * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator
1182 * points to a valid element
1184 int GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i);
1188 * Retrieve the element at a specific position in a list
1191 * @param len set to the payload length
1195 GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
1200 * Release an iterator
1203 void GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i);
1206 #if 0 /* keep Emacsens' auto-indent happy */
1214 /* ifndef GNUNET_CONTAINER_LIB_H */
1216 /* end of gnunet_container_lib.h */