aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2014-05-06 10:26:21 +0000
committerGabor X Toth <*@tg-x.net>2014-05-06 10:26:21 +0000
commitb2061e704ac6309bb7ee4427a89a1572aa9f339e (patch)
tree1a7419be23bd4d7fe04f21def91e0a8e0e818fd8 /src
parent0b49a42584ffd952f83eec54800f2c23c8066d97 (diff)
downloadgnunet-b2061e704ac6309bb7ee4427a89a1572aa9f339e.tar.gz
gnunet-b2061e704ac6309bb7ee4427a89a1572aa9f339e.zip
add GNUNET_CONTAINER_heap_peek2()
Diffstat (limited to 'src')
-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 a9c1f4b45..1aa3ad00e 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);
1670 1670
1671/** 1671/**
1672 * @ingroup heap 1672 * @ingroup heap
1673 * Get element stored at root of heap. 1673 * Get element stored at the root of @a heap.
1674 * 1674 *
1675 * @param heap heap to inspect 1675 * @param heap Heap to inspect.
1676 * @return NULL if heap is empty 1676 * @return Element at the root, or NULL if heap is empty.
1677 */ 1677 */
1678void * 1678void *
1679GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap); 1679GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
1680 1680
1681 1681
1682/** 1682/**
1683 * Get @a element and @a cost stored at the root of @a heap.
1684 *
1685 * @param[in] heap Heap to inspect.
1686 * @param[out] element Root element is returned here.
1687 * @param[out] cost Cost of @a element is returned here.
1688 * @return #GNUNET_YES if an element is returned,
1689 * #GNUNET_NO if the heap is empty.
1690 */
1691int
1692GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
1693 void **element,
1694 GNUNET_CONTAINER_HeapCostType *cost);
1695
1696
1697/**
1683 * @ingroup heap 1698 * @ingroup heap
1684 * Get the current size of the heap 1699 * Get the current size of the heap
1685 * 1700 *
diff --git a/src/util/container_heap.c b/src/util/container_heap.c
index 54da89f7a..0c81f7491 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)
163 163
164 164
165/** 165/**
166 * Get element stored at root of heap. 166 * Get element stored at the root of @a heap.
167 * 167 *
168 * @param heap heap to inspect 168 * @param heap Heap to inspect.
169 * @return NULL if heap is empty 169 * @return Element at the root, or NULL if heap is empty.
170 */ 170 */
171void * 171void *
172GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap) 172GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap)
@@ -178,6 +178,30 @@ GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap)
178 178
179 179
180/** 180/**
181 * Get @a element and @a cost stored at the root of @a heap.
182 *
183 * @param[in] heap Heap to inspect.
184 * @param[out] element Root element is returned here.
185 * @param[out] cost Cost of @a element is returned here.
186 * @return #GNUNET_YES if an element is returned,
187 * #GNUNET_NO if the heap is empty.
188 */
189int
190GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
191 void **element,
192 GNUNET_CONTAINER_HeapCostType *cost)
193{
194 if (NULL == heap->root)
195 return GNUNET_NO;
196 if (NULL != element)
197 *element = heap->root->element;
198 if (NULL != cost)
199 *cost = heap->root->cost;
200 return GNUNET_YES;
201}
202
203
204/**
181 * Get the current size of the heap 205 * Get the current size of the heap
182 * 206 *
183 * @param heap the heap to get the size of 207 * @param heap the heap to get the size of
@@ -203,6 +227,7 @@ GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
203 return node->cost; 227 return node->cost;
204} 228}
205 229
230
206/** 231/**
207 * Iterate over the children of the given node. 232 * Iterate over the children of the given node.
208 * 233 *