getting mysql to work
[oweals/gnunet.git] / src / include / gnunet_container_lib.h
index 21ee59688a196a9f455a4f231a43e093b2710c82..e35ad1b74e484fcc441cd98bc90fa8956bea9090 100644 (file)
@@ -243,7 +243,7 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct
  *
  * @param md metadata to extend
  * @param plugin_name name of the plugin that produced this value;
- *        special values can be used (i.e. '<zlib>' for zlib being
+ *        special values can be used (i.e. '&lt;zlib&gt;' for zlib being
  *        used in the main libextractor library and yielding
  *        meta data).
  * @param type libextractor-type describing the meta data
@@ -265,6 +265,18 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
                                   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
+ */
+void 
+GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
+                                 const struct GNUNET_CONTAINER_MetaData *in);
+
+
 /**
  * Remove an item.
  *
@@ -282,6 +294,15 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
                                   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
  * to the meta-data.
@@ -353,21 +374,6 @@ 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,
-                                             struct EXTRACTOR_PluginList *
-                                             extractors);
 
 
 /**
@@ -439,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 **************************** */
 
@@ -654,34 +648,32 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
 /* ******************** 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) \
     { \
@@ -696,7 +688,7 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
   if (NULL == (element)->next) \
     (tail) = (element); \
   else \
-    (element)->next->prev = (element);
+    (element)->next->prev = (element); } while (0)
 
 
 
@@ -710,7 +702,7 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (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 \
@@ -718,7 +710,7 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
   if ((element)->next == NULL) \
     (tail) = (element)->prev;  \
   else \
-    (element)->next->prev = (element)->prev;
+    (element)->next->prev = (element)->prev; } while (0)
 
 
 
@@ -830,6 +822,21 @@ GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
                               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);
+
 /**
  * Perform a random walk of the tree.  The walk is biased
  * towards elements closer to the root of the tree (since