gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8631 - GNUnet/src/util/containers


From: gnunet
Subject: [GNUnet-SVN] r8631 - GNUnet/src/util/containers
Date: Tue, 7 Jul 2009 12:42:02 -0600

Author: nevans
Date: 2009-07-07 12:42:02 -0600 (Tue, 07 Jul 2009)
New Revision: 8631

Modified:
   GNUnet/src/util/containers/heap.c
   GNUnet/src/util/containers/heaptest.c
Log:
fixed remove last element of heap bug

Modified: GNUnet/src/util/containers/heap.c
===================================================================
--- GNUnet/src/util/containers/heap.c   2009-07-05 21:25:20 UTC (rev 8630)
+++ GNUnet/src/util/containers/heap.c   2009-07-07 18:42:02 UTC (rev 8631)
@@ -331,6 +331,8 @@
 
   if (del_node == NULL)
     return NULL;
+  else if (del_node == root->root)
+    return GNUNET_CONTAINER_heap_remove_root(root);
 
   ret = del_node->element;
   last = getPos (root, root->size);
@@ -410,6 +412,14 @@
   ret = root_node->element;
   last = getPos (root, root->size);
 
+  if ((root_node == last) && (root->size == 1)) /* We are removing the last 
node in the heap!*/
+  {
+    root->root = NULL;
+    root->traversal_pos = NULL;
+    root->size = 0;
+    return ret;
+  }
+
   if (last->parent->left_child == last)
     last->parent->left_child = NULL;
   else if (last->parent->right_child == last)

Modified: GNUnet/src/util/containers/heaptest.c
===================================================================
--- GNUnet/src/util/containers/heaptest.c       2009-07-05 21:25:20 UTC (rev 
8630)
+++ GNUnet/src/util/containers/heaptest.c       2009-07-07 18:42:02 UTC (rev 
8631)
@@ -104,7 +104,11 @@
 
   GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
   fprintf (stdout, "\n");
+
+  GNUNET_CONTAINER_heap_destroy(myHeap);
+
   return 0;
+
 }
 
 /* end of heaptest.c */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]