HKDF (does not work yet)
[oweals/gnunet.git] / src / include / gnunet_container_lib.h
index bbf1ba2cfe2126863ba70990553434baaeeb93fb..e35ad1b74e484fcc441cd98bc90fa8956bea9090 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -195,80 +195,113 @@ void GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter
  */
 struct GNUNET_CONTAINER_MetaData;
 
-/**
- * Iterator over meta data.
- *
- * @param cls closure
- * @param type type of the meta data
- * @param data value of the meta data
- * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
- */
-typedef int (*GNUNET_CONTAINER_MetaDataProcessor) (void *cls,
-                                                  EXTRACTOR_KeywordType type,
-                                                   const char *data);
-
 /**
  * Create a fresh MetaData token.
  * 
  * @return empty meta-data container
  */
-struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_create (void);
+struct GNUNET_CONTAINER_MetaData *
+GNUNET_CONTAINER_meta_data_create (void);
 
 /**
  * Duplicate a MetaData token.
  * 
- * @param meta what to duplicate
+ * @param md what to duplicate
  * @return duplicate meta-data container
  */
-struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_duplicate (const
-                                                                        struct
-                                                                        GNUNET_CONTAINER_MetaData
-                                                                        *meta);
+struct GNUNET_CONTAINER_MetaData *
+GNUNET_CONTAINER_meta_data_duplicate (const struct 
+                                     GNUNET_CONTAINER_MetaData *md);
 
 /**
  * Free meta data.
  *
  * @param md what to free
  */
-void GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData
-                                         *md);
+void 
+GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
 
 /**
- * Test if two MDs are equal.
+ * Test if two MDs are equal. We consider them equal if
+ * the meta types, formats and content match (we do not
+ * include the mime types and plugins names in this
+ * consideration).
  *
  * @param md1 first value to check
  * @param md2 other value to check
  * @return GNUNET_YES if they are equal
  */
-int GNUNET_CONTAINER_meta_data_test_equal (const struct
-                                           GNUNET_CONTAINER_MetaData *md1,
-                                           const struct
-                                           GNUNET_CONTAINER_MetaData *md2);
+int 
+GNUNET_CONTAINER_meta_data_test_equal (const struct
+                                      GNUNET_CONTAINER_MetaData *md1,
+                                      const struct
+                                      GNUNET_CONTAINER_MetaData *md2);
 
 
 /**
  * Extend metadata.
  *
  * @param md metadata to extend
- * @param type type of the new entry
- * @param data value for the entry
+ * @param plugin_name name of the plugin that produced this value;
+ *        special values can be used (i.e. '<zlib>' for zlib being
+ *        used in the main libextractor library and yielding
+ *        meta data).
+ * @param type libextractor-type describing the meta data
+ * @param format basic format information about data 
+ * @param data_mime_type mime-type of data (not of the original file);
+ *        can be NULL (if mime-type is not known)
+ * @param data actual meta-data found
+ * @param data_len number of bytes in data
  * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists
+ *         data_mime_type and plugin_name are not considered for "exists" checks
+ */
+int 
+GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
+                                  const char *plugin_name,
+                                  enum EXTRACTOR_MetaType type,
+                                  enum EXTRACTOR_MetaFormat format,
+                                  const char *data_mime_type,
+                                  const char *data,
+                                  size_t data_len);
+
+
+/**
+ * Extend metadata.  Merges the meta data from the second argument
+ * into the first, discarding duplicate key-value pairs.
+ *
+ * @param md metadata to extend
+ * @param in metadata to merge
  */
-int GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
-                                       EXTRACTOR_KeywordType type,
-                                       const char *data);
+void 
+GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
+                                 const struct GNUNET_CONTAINER_MetaData *in);
+
 
 /**
  * Remove an item.
  *
+ * @param md metadata to manipulate
  * @param type type of the item to remove
  * @param data specific value to remove, NULL to remove all
  *        entries of the given type
+ * @param data_len number of bytes in data
  * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md
  */
-int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
-                                       EXTRACTOR_KeywordType type,
-                                       const char *data);
+int 
+GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
+                                  enum EXTRACTOR_MetaType type,
+                                  const char *data,
+                                  size_t data_len);
+
+
+/**
+ * Remove all items in the container.
+ *
+ * @param md metadata to manipulate
+ */
+void 
+GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
+
 
 /**
  * Add the current time as the publication date
@@ -276,73 +309,71 @@ int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
  *
  * @param md metadata to modify
  */
-void GNUNET_CONTAINER_meta_data_add_publication_date (struct
-                                                      GNUNET_CONTAINER_MetaData
-                                                      *md);
+void 
+GNUNET_CONTAINER_meta_data_add_publication_date (struct
+                                                GNUNET_CONTAINER_MetaData
+                                                *md);
+
 
 /**
- * Iterate over MD entries, excluding thumbnails.
+ * Iterate over MD entries.
  *
  * @param md metadata to inspect
  * @param iter function to call on each entry
  * @param iter_cls closure for iterator
  * @return number of entries
  */
-int GNUNET_CONTAINER_meta_data_get_contents (const struct
-                                             GNUNET_CONTAINER_MetaData *md,
-                                             GNUNET_CONTAINER_MetaDataProcessor
-                                             iter, void *iter_cls);
+int GNUNET_CONTAINER_meta_data_iterate (const struct
+                                       GNUNET_CONTAINER_MetaData *md,
+                                       EXTRACTOR_MetaDataProcessor
+                                       iter, void *iter_cls);
 
 /**
- * Get the first MD entry of the given type.
+ * Get the first MD entry of the given type.  Caller
+ * is responsible for freeing the return value.
+ * Also, only meta data items that are strings (0-terminated)
+ * are returned by this function.
  *
  * @param md metadata to inspect
  * @param type type to look for
- * @return NULL if we do not have any such entry,
- *  otherwise client is responsible for freeing the value!
+ * @return NULL if no entry was found
  */
-char *GNUNET_CONTAINER_meta_data_get_by_type (const struct
-                                             GNUNET_CONTAINER_MetaData *md,
-                                              EXTRACTOR_KeywordType type);
+char *
+GNUNET_CONTAINER_meta_data_get_by_type (const struct
+                                       GNUNET_CONTAINER_MetaData *md,
+                                       enum EXTRACTOR_MetaType type);
+
 
 /**
- * Get the first matching MD entry of the given types.
+ * Get the first matching MD entry of the given types. Caller is
+ * responsible for freeing the return value.  Also, only meta data
+ * items that are strings (0-terminated) are returned by this
+ * function.
  *
  * @param md metadata to inspect
  * @param ... -1-terminated list of types
  * @return NULL if we do not have any such entry,
  *  otherwise client is responsible for freeing the value!
  */
-char *GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
-                                                     GNUNET_CONTAINER_MetaData
-                                                     *md, ...);
+char *
+GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
+                                              GNUNET_CONTAINER_MetaData
+                                              *md, ...);
 
 /**
- * Get a thumbnail from the meta-data (if present).
+ * Get a thumbnail from the meta-data (if present).  Only matches meta
+ * data with mime type "image" and binary format.
  *
  * @param md metadata to inspect
  * @param thumb will be set to the thumbnail data.  Must be
  *        freed by the caller!
  * @return number of bytes in thumbnail, 0 if not available
  */
-size_t GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
-                                                 GNUNET_CONTAINER_MetaData
-                                                 *md, unsigned char **thumb);
+size_t 
+GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
+                                         GNUNET_CONTAINER_MetaData
+                                         *md, unsigned char **thumb);
 
-/**
- * Extract meta-data from a file.
- *
- * @param md metadata to set
- * @param filename name of file to inspect
- * @param extractors plugins to use
- * @return GNUNET_SYSERR on error, otherwise the number
- *   of meta-data items obtained
- */
-int GNUNET_CONTAINER_meta_data_extract_from_file (struct
-                                                  GNUNET_CONTAINER_MetaData
-                                                  *md, const char *filename,
-                                                  EXTRACTOR_ExtractorList *
-                                                  extractors);
 
 
 /**
@@ -372,7 +403,9 @@ enum GNUNET_CONTAINER_MetaDataSerializationOptions
  * Serialize meta-data to target.
  *
  * @param md metadata to serialize
- * @param size maximum number of bytes available
+ * @param target where to write the serialized metadata;
+ *         *target can be NULL, in which case memory is allocated
+ * @param max maximum number of bytes available
  * @param opt is it ok to just write SOME of the
  *        meta-data to match the size constraint,
  *        possibly discarding some data?
@@ -382,28 +415,23 @@ enum GNUNET_CONTAINER_MetaDataSerializationOptions
  */
 ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct
                                              GNUNET_CONTAINER_MetaData *md,
-                                             char *target, 
-                                             size_t size,
+                                             char **target, 
+                                             size_t max,
                                              enum
                                           GNUNET_CONTAINER_MetaDataSerializationOptions
                                           opt);
 
+
 /**
- * Compute size of the meta-data in
- * serialized form.
+ * Get the size of the full meta-data in serialized form.
  *
  * @param md metadata to inspect
- * @param opt is it ok to just write SOME of the
- *        meta-data to match the size constraint,
- *        possibly discarding some data?
  * @return number of bytes needed for serialization, -1 on error
  */
 ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
                                                        GNUNET_CONTAINER_MetaData
-                                                       *md,
-                                                       enum
-                                                       GNUNET_CONTAINER_MetaDataSerializationOptions
-                                                       opt);
+                                                       *md);
+
 
 /**
  * Deserialize meta-data.  Initializes md.
@@ -417,18 +445,6 @@ struct GNUNET_CONTAINER_MetaData
   *GNUNET_CONTAINER_meta_data_deserialize (const char *input,
                                            size_t size);
 
-/**
- * Does the meta-data claim that this is a directory?
- * Checks if the mime-type is that of a GNUnet directory.
- *
- * @param md metadata to inspect
- * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
- *  we have no mime-type information (treat as 'GNUNET_NO')
- */
-int GNUNET_CONTAINER_meta_data_test_for_directory (const struct
-                                                   GNUNET_CONTAINER_MetaData
-                                                   *md);
-
 
 /* ******************************* HashMap **************************** */
 
@@ -442,11 +458,11 @@ struct GNUNET_CONTAINER_MultiHashMap;
  */
 enum GNUNET_CONTAINER_MultiHashMapOption
 {
+
   /**
-   * If a value with the given key exists, replace it.
-   * Note that the old value would NOT be freed
-   * by replace (the application has to make sure that
-   * this happens if required).
+   * If a value with the given key exists, replace it.  Note that the
+   * old value would NOT be freed by replace (the application has to
+   * make sure that this happens if required).
    */
   GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE,
 
@@ -456,25 +472,23 @@ enum GNUNET_CONTAINER_MultiHashMapOption
   GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE,
 
   /**
-   * There must only be one value per key; storing
-   * a value should fail if a value under the same
-   * key already exists.
+   * There must only be one value per key; storing a value should fail
+   * if a value under the same key already exists.
    */
   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY,
 
   /**
-   * There must only be one value per key, but don't
-   * bother checking if a value already exists
-   * (faster than UNIQUE_ONLY; implemented just like
-   * MULTIPLE but this option documents better what
-   * is intended if UNIQUE is what is desired).
+   * There must only be one value per key, but don't bother checking
+   * if a value already exists (faster than UNIQUE_ONLY; implemented
+   * just like MULTIPLE but this option documents better what is
+   * intended if UNIQUE is what is desired).
    */
   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
 };
 
 
 /**
- * Iterator over HashCodes.
+ * Iterator over hash map entries.
  *
  * @param cls closure
  * @param key current key code
@@ -497,6 +511,7 @@ typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls,
 struct GNUNET_CONTAINER_MultiHashMap
   *GNUNET_CONTAINER_multihashmap_create (unsigned int len);
 
+
 /**
  * Destroy a hash map.  Will not free any values
  * stored in the hash map!
@@ -507,9 +522,9 @@ void GNUNET_CONTAINER_multihashmap_destroy (struct
                                             GNUNET_CONTAINER_MultiHashMap
                                             *map);
 
+
 /**
- * Given a key find a value in the
- * map matching the key.
+ * Given a key find a value in the map matching the key.
  *
  * @param map the map
  * @param key what to look for
@@ -522,11 +537,11 @@ void *GNUNET_CONTAINER_multihashmap_get (const struct
                                          GNUNET_CONTAINER_MultiHashMap *map,
                                          const GNUNET_HashCode * key);
 
+
 /**
- * Remove the given key-value pair from the map.
- * Note that if the key-value pair is in the map
- * multiple times, only one of the pairs will be
- * removed.
+ * Remove the given key-value pair from the map.  Note that if the
+ * key-value pair is in the map multiple times, only one of the pairs
+ * will be removed.
  *
  * @param map the map
  * @param key key of the key-value pair
@@ -551,6 +566,7 @@ int GNUNET_CONTAINER_multihashmap_remove_all (struct
                                               *map,
                                               const GNUNET_HashCode * key);
 
+
 /**
  * Check if the map contains any value under the given
  * key (including values that are NULL).
@@ -565,6 +581,7 @@ int GNUNET_CONTAINER_multihashmap_contains (const struct
                                             *map,
                                             const GNUNET_HashCode * key);
 
+
 /**
  * Store a key-value pair in the map.
  *
@@ -599,24 +616,24 @@ unsigned int GNUNET_CONTAINER_multihashmap_size (const struct
  * Iterate over all entries in the map.
  *
  * @param map the map
- * @param iterator function to call on each entry
- * @param cls extra argument to it
+ * @param it function to call on each entry
+ * @param it_cls extra argument to it
  * @return the number of key value pairs processed,
  *         GNUNET_SYSERR if it aborted iteration
  */
 int GNUNET_CONTAINER_multihashmap_iterate (const struct
                                            GNUNET_CONTAINER_MultiHashMap *map,
                                            GNUNET_CONTAINER_HashMapIterator
-                                           iterator, void *cls);
+                                           it, void *it_cls);
+
 
 /**
- * Iterate over all entries in the map
- * that match a particular key.
+ * Iterate over all entries in the map that match a particular key.
  *
  * @param map the map
  * @param key key that the entries must correspond to
- * @param iterator function to call on each entry
- * @param cls extra argument to it
+ * @param it function to call on each entry
+ * @param it_cls extra argument to it
  * @return the number of key value pairs processed,
  *         GNUNET_SYSERR if it aborted iteration
  */
@@ -625,52 +642,38 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
                                                 *map,
                                                 const GNUNET_HashCode * key,
                                                 GNUNET_CONTAINER_HashMapIterator
-                                                iterator, void *cls);
-/**
- * Returns the stored value of a random non-null entry
- * in the hash table.  Returns only the first value, does
- * not go inside bucket linked list (yet).  Runs with a
- * worst case time of N, so it's not efficient in any way
- * shape or form!!!!.
- */
-void *GNUNET_CONTAINER_multihashmap_get_random (const struct
-                                                GNUNET_CONTAINER_MultiHashMap
-                                                *map);
-
-
+                                                it, void *it_cls);
 
 
 /* ******************** doubly-linked list *************** */
 
 /**
- * Insert an element into a DLL. Assumes
- * that head, tail and element are structs
- * with prev and next fields.
+ * Insert an element at the head of a DLL. Assumes that head, tail and
+ * element are structs with prev and next fields.
  *
  * @param head pointer to the head of the DLL
  * @param tail pointer to the tail of the DLL
  * @param element element to insert
  */
-#define GNUNET_CONTAINER_DLL_insert(head,tail,element) \
+#define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
   (element)->next = (head); \
   (element)->prev = NULL; \
   if ((tail) == NULL) \
     (tail) = element; \
   else \
     (head)->prev = element; \
-  (head) = (element);
+  (head) = (element); } while (0)
 
 /**
- * Insert an element into a DLL after the given other
- * element.  Insert at the head if the other
- * element is NULL.
+ * Insert an element into a DLL after the given other element.  Insert
+ * at the head if the other element is NULL.
  *
  * @param head pointer to the head of the DLL
  * @param tail pointer to the tail of the DLL
  * @param other prior element, NULL for insertion at head of DLL
  * @param element element to insert
  */
-#define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) \
+#define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
   (element)->prev = (other); \
   if (NULL == other) \
     { \
@@ -685,7 +688,7 @@ void *GNUNET_CONTAINER_multihashmap_get_random (const struct
   if (NULL == (element)->next) \
     (tail) = (element); \
   else \
-    (element)->next->prev = (element);
+    (element)->next->prev = (element); } while (0)
 
 
 
@@ -699,7 +702,7 @@ void *GNUNET_CONTAINER_multihashmap_get_random (const struct
  * @param tail pointer to the tail of the DLL
  * @param element element to remove
  */
-#define GNUNET_CONTAINER_DLL_remove(head,tail,element) \
+#define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
   if ((element)->prev == NULL) \
     (head) = (element)->next;  \
   else \
@@ -707,7 +710,7 @@ void *GNUNET_CONTAINER_multihashmap_get_random (const struct
   if ((element)->next == NULL) \
     (tail) = (element)->prev;  \
   else \
-    (element)->next->prev = (element)->prev;
+    (element)->next->prev = (element)->prev; } while (0)
 
 
 
@@ -717,7 +720,7 @@ void *GNUNET_CONTAINER_multihashmap_get_random (const struct
 /**
  * Cost by which elements in a heap can be ordered.
  */
-typedef uint64_t GNUNET_CONTAINER_HeapCost;
+typedef uint64_t GNUNET_CONTAINER_HeapCostType;
 
 
 /*
@@ -743,133 +746,322 @@ enum GNUNET_CONTAINER_HeapOrder
  */
 struct GNUNET_CONTAINER_Heap;
 
+
+
+/**
+ * Handle to a node in a heap.
+ */
+struct GNUNET_CONTAINER_HeapNode;
+
+
 /**
  * Create a new heap.
  *
- * @param type should the minimum or the maximum element be the root
- * @return NULL on error, otherwise a fresh heap
+ * @param order how should the heap be sorted?
+ * @return handle to the heap
  */
-struct GNUNET_CONTAINER_Heap *GNUNET_CONTAINER_heap_create (enum
-                                                            GNUNET_CONTAINER_HeapOrder
-                                                            type);
+struct GNUNET_CONTAINER_Heap *
+GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order);
 
 
 /**
- * Free a heap
+ * Destroys the heap.  Only call on a heap that
+ * is already empty.
  *
- * @param h heap to free.
+ * @param heap heap to destroy
  */
-void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *h);
+void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap);
 
 
 /**
- * Function called on elements of a heap.
+ * Get element stored at root of heap.
+ *
+ * @param heap heap to inspect
+ * @return NULL if heap is empty
+ */
+void *
+GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
+
+
+/**
+ * Get the current size of the heap
+ *
+ * @param heap the heap to get the size of
+ * @return number of elements stored
+ */
+unsigned int
+GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
+
+
+/**
+ * Iterator for heap
  *
  * @param cls closure
- * @param element obj stored in heap
- * @param cost cost of the element
+ * @param node internal node of the heap
+ * @param element value stored at the node
+ * @param cost cost associated with the node
  * @return GNUNET_YES if we should continue to iterate,
  *         GNUNET_NO if not.
  */
 typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
-                                              void *element,
-                                              GNUNET_CONTAINER_HeapCost cost);
+                                             struct GNUNET_CONTAINER_HeapNode *node,
+                                             void *element,
+                                              GNUNET_CONTAINER_HeapCostType cost);
 
 
 /**
- * Iterate over all entries in the map.
+ * Iterate over all entries in the heap.
  *
  * @param heap the heap
  * @param iterator function to call on each entry
  * @param iterator_cls closure for iterator
- * @return number of items handled
- *         GNUNET_SYSERR if iteration was aborted by iterator
  */
-int GNUNET_CONTAINER_heap_iterate (struct GNUNET_CONTAINER_Heap *heap,
-                                   GNUNET_CONTAINER_HeapIterator iterator,
-                                   void *iterator_cls);
+void
+GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
+                              GNUNET_CONTAINER_HeapIterator iterator,
+                              void *iterator_cls);
 
 
+/**
+ * Return a *uniform* random element from the heap.  Choose a random
+ * number between 0 and heap size and then walk directly to it.
+ * This cost can be between 0 and n, amortized cost of logN.
+ *
+ * @param heap heap to choose random element from
+ * @param max how many nodes from the heap to choose from
+ *
+ * @return data stored at the chosen random node,
+ *         NULL if the heap is empty.
+ *
+ */
+void *
+GNUNET_CONTAINER_heap_get_random (struct GNUNET_CONTAINER_Heap *heap, uint32_t max);
 
 /**
- * Inserts a new item into the heap, item is always neighbor now.
- * @param heap the heap
- * @param element element to insert
- * @param cost cost of the element
- * @return FIXME
+ * Perform a random walk of the tree.  The walk is biased
+ * towards elements closer to the root of the tree (since
+ * each walk starts at the root and ends at a random leaf).
+ * The heap internally tracks the current position of the
+ * walk.
+ *
+ * @param heap heap to walk
+ * @return data stored at the next random node in the walk;
+ *         NULL if the tree is empty.
  */
-int
-GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
-                              void *element, GNUNET_CONTAINER_HeapCost cost);
+void *
+GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
 
 
 /**
- * Removes root of the tree, is remove max if a max heap and remove min
- * if a min heap, returns the data stored at the node.
+ * Inserts a new element into the heap.
  *
- * @param heap the heap
- * @return NULL if the heap is empty
+ * @param heap heap to modify
+ * @param element element to insert
+ * @param cost cost for the element
+ * @return node for the new element
  */
-void *GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
+struct GNUNET_CONTAINER_HeapNode *
+GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
+                              void *element,
+                             GNUNET_CONTAINER_HeapCostType cost);
 
 
 /**
- * Returns element stored at root of tree, doesn't effect anything
+ * Remove root of the heap.
  *
- * @param heap the heap
- * @return NULL if the heap is empty
+ * @param heap heap to modify
+ * @return element data stored at the root node
  */
-void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap);
+void *
+GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
 
 
 /**
- * Removes any node from the tree based on the neighbor given, does
- * not traverse the tree (backpointers) but may take more time due to
- * percolation of nodes.
- *
- * @param heap the heap
- * @param element the element to remove
- * @return NULL if "element" was not found in the heap, otherwise element
+ * Removes a node from the heap.
+ * 
+ * @param heap heap to modify
+ * @param node node to remove
+ * @return element data stored at the node, NULL if heap is empty
  */
-void *GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap,
-                                         void *element);
+void *
+GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap,
+                                  struct GNUNET_CONTAINER_HeapNode *node);
 
 
 /**
  * Updates the cost of any node in the tree
  *
- * @param heap the heap
- * @param element the element for which the cost is updated
- * @param new_cost new cost for the element
- * @return FIXME
+ * @param heap heap to modify
+ * @param node node for which the cost is to be changed
+ * @param new_cost new cost for the node
  */
-int
+void
 GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
-                                   void *element,
-                                   GNUNET_CONTAINER_HeapCost new_cost);
+                                   struct GNUNET_CONTAINER_HeapNode *node, 
+                                  GNUNET_CONTAINER_HeapCostType new_cost);
+
+
+/* ******************** Singly linked list *************** */
+
+/**
+ * Possible ways for how data stored in the linked list
+ * might be allocated.
+ */ 
+enum GNUNET_CONTAINER_SListDisposition
+  {
+    /**
+     * Single-linked list must copy the buffer.
+     */
+    GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
+
+    /**
+     * Data is static, no need to copy or free.
+     */
+    GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
+
+    /**
+     * Data is dynamic, do not copy but free when done.
+     */
+    GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
+  };
+
+
+
+/**
+ * Handle to a singly linked list  
+ */
+struct GNUNET_CONTAINER_SList;
+
+/**
+ * Handle to a singly linked list iterator 
+ */
+struct GNUNET_CONTAINER_SList_Iterator;
+
+
+/**
+ * Add a new element to the list
+ * @param l list
+ * @param disp memory disposition
+ * @param buf payload buffer
+ * @param len length of the buffer
+ */
+void GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, 
+                                enum GNUNET_CONTAINER_SListDisposition disp,
+                                const void *buf, size_t len);
+
+
+/**
+ * Append a singly linked list to another
+ * @param dst list to append to
+ * @param src source
+ */
+void
+GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, struct GNUNET_CONTAINER_SList *src);
+
+
+/**
+ * Create a new singly linked list
+ * @return the new list
+ */
+struct GNUNET_CONTAINER_SList *GNUNET_CONTAINER_slist_create (void);
+
+
+/**
+ * Destroy a singly linked list
+ * @param l the list to be destroyed
+ */
+void GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l);
 
 
 /**
- * Random walk of the tree, returns the data stored at the next random node
- * in the walk.  Calls callee with the data, or NULL if the tree is empty
- * or some other problem crops up.
+ * Return the beginning of a list
  *
- * @param heap the heap
- * @return the next element from the random walk
+ * @param l list
+ * @return iterator pointing to the beginning, free using "GNUNET_free"
  */
-void *GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap
-                                           *heap);
+struct GNUNET_CONTAINER_SList_Iterator *
+GNUNET_CONTAINER_slist_begin(struct GNUNET_CONTAINER_SList *l);
 
 
 /**
- * Returns the current size of the heap
+ * Clear a list
  *
- * @param heap the heap to get the size of
- * @return number of elements in the heap
+ * @param l list
  */
-unsigned int
-GNUNET_CONTAINER_heap_get_size (struct GNUNET_CONTAINER_Heap *heap);
+void GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l);
+
+
+/**
+ * Check if a list contains a certain element
+ * @param l list
+ * @param buf payload buffer to find
+ * @param len length of the payload (number of bytes in buf)
+ */
+int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, const void *buf, size_t len);
+
+
+/**
+ * Count the elements of a list
+ * @param l list
+ * @return number of elements in the list
+ */
+int GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l);
+
+
+/**
+ * Remove an element from the list
+ * @param i iterator that points to the element to be removed
+ */
+void GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i);
+
 
+/**
+ * Insert an element into a list at a specific position
+ * @param before where to insert the new element
+ * @param disp memory disposition
+ * @param buf payload buffer
+ * @param len length of the payload
+ */
+void GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
+                                   enum GNUNET_CONTAINER_SListDisposition disp,
+                                   const void *buf, 
+                                   size_t len);
+
+
+/**
+ * Advance an iterator to the next element
+ * @param i iterator
+ * @return GNUNET_YES on success, GNUNET_NO if the end has been reached
+ */
+int GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i);
+
+
+/**
+ * Check if an iterator points beyond the end of a list
+ * @param i iterator
+ * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator
+ *         points to a valid element
+ */
+int GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i);
+
+
+/**
+ * Retrieve the element at a specific position in a list
+ *
+ * @param i iterator
+ * @param len set to the payload length
+ * @return payload
+ */
+const void *
+GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, 
+                           size_t *len);
+
+
+/**
+ * Release an iterator
+ * @param i iterator
+ */
+void GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */