aboutsummaryrefslogtreecommitdiff
path: root/src/util
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/util
parent0b49a42584ffd952f83eec54800f2c23c8066d97 (diff)
downloadgnunet-b2061e704ac6309bb7ee4427a89a1572aa9f339e.tar.gz
gnunet-b2061e704ac6309bb7ee4427a89a1572aa9f339e.zip
add GNUNET_CONTAINER_heap_peek2()
Diffstat (limited to 'src/util')
-rw-r--r--src/util/container_heap.c31
1 files changed, 28 insertions, 3 deletions
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 *