[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r9017 - GNUnet/src/util/containers
From: |
gnunet |
Subject: |
[GNUnet-SVN] r9017 - GNUnet/src/util/containers |
Date: |
Tue, 22 Sep 2009 16:01:49 -0600 |
Author: nevans
Date: 2009-09-22 16:01:48 -0600 (Tue, 22 Sep 2009)
New Revision: 9017
Modified:
GNUnet/src/util/containers/heap.c
Log:
added peek
Modified: GNUnet/src/util/containers/heap.c
===================================================================
--- GNUnet/src/util/containers/heap.c 2009-09-22 21:57:17 UTC (rev 9016)
+++ GNUnet/src/util/containers/heap.c 2009-09-22 22:01:48 UTC (rev 9017)
@@ -123,6 +123,16 @@
return heap;
}
+void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *root)
+{
+ if ((root == NULL) || (root->root == NULL))
+ {
+ return NULL;
+ }
+
+ return root->root->element;
+}
+
void
GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap)
{
@@ -141,21 +151,18 @@
{
struct GNUNET_CONTAINER_heap_node *ret;
ret = NULL;
- if ((node != NULL) && (node->element == element))
- {
- ret = node;
- }
+ if (node == NULL)
+ return NULL;
- if ((ret == NULL) && (node != NULL) && (node->left_child != NULL))
- {
- ret = find_element (node->left_child, element);
- }
+ if (node->element == element)
+ return node;
- if ((ret == NULL) && (node != NULL) && (node->right_child != NULL))
- {
- ret = find_element (node->right_child, element);
- }
+ if (node->left_child != NULL)
+ ret = find_element (node->left_child, element);
+ if (node->right_child != NULL)
+ ret = find_element (node->right_child, element);
+
return ret;
}
@@ -417,10 +424,8 @@
struct GNUNET_CONTAINER_heap_node *root_node;
struct GNUNET_CONTAINER_heap_node *last;
- if (root == NULL)
+ if ((root == NULL) || (root->size == 0) || (root->root == NULL))
return NULL;
- if ((root->size == 0) || (root_node == NULL))
- return NULL;
root_node = root->root;
ret = root_node->element;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r9017 - GNUnet/src/util/containers,
gnunet <=