aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_container_lib.h21
-rw-r--r--src/util/container_heap.c31
2 files changed, 46 insertions, 6 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index a9c1f4b451..1aa3ad00e1 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -1670,16 +1670,31 @@ GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap);
/**
* @ingroup heap
- * Get element stored at root of heap.
+ * Get element stored at the root of @a heap.
*
- * @param heap heap to inspect
- * @return NULL if heap is empty
+ * @param heap Heap to inspect.
+ * @return Element at the root, or NULL if heap is empty.
*/
void *
GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
/**
+ * Get @a element and @a cost stored at the root of @a heap.
+ *
+ * @param[in] heap Heap to inspect.
+ * @param[out] element Root element is returned here.
+ * @param[out] cost Cost of @a element is returned here.
+ * @return #GNUNET_YES if an element is returned,
+ * #GNUNET_NO if the heap is empty.
+ */
+int
+GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
+ void **element,
+ GNUNET_CONTAINER_HeapCostType *cost);
+
+
+/**
* @ingroup heap
* Get the current size of the heap
*
diff --git a/src/util/container_heap.c b/src/util/container_heap.c
index 54da89f7a2..0c81f7491e 100644
--- a/src/util/container_heap.c
+++ b/src/util/container_heap.c
@@ -163,10 +163,10 @@ GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap)
/**
- * Get element stored at root of heap.
+ * Get element stored at the root of @a heap.
*
- * @param heap heap to inspect
- * @return NULL if heap is empty
+ * @param heap Heap to inspect.
+ * @return Element at the root, or NULL if heap is empty.
*/
void *
GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap)
@@ -178,6 +178,30 @@ GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap)
/**
+ * Get @a element and @a cost stored at the root of @a heap.
+ *
+ * @param[in] heap Heap to inspect.
+ * @param[out] element Root element is returned here.
+ * @param[out] cost Cost of @a element is returned here.
+ * @return #GNUNET_YES if an element is returned,
+ * #GNUNET_NO if the heap is empty.
+ */
+int
+GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
+ void **element,
+ GNUNET_CONTAINER_HeapCostType *cost)
+{
+ if (NULL == heap->root)
+ return GNUNET_NO;
+ if (NULL != element)
+ *element = heap->root->element;
+ if (NULL != cost)
+ *cost = heap->root->cost;
+ return GNUNET_YES;
+}
+
+
+/**
* Get the current size of the heap
*
* @param heap the heap to get the size of
@@ -203,6 +227,7 @@ GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
return node->cost;
}
+
/**
* Iterate over the children of the given node.
*