Returns now GNUNET_SYSERR
[oweals/gnunet.git] / src / util / container_heap.c
index dbb391ac4e5e949feaf802af40993be7c9195f47..7cd30a0a740c784a04d90fd1f172ac1b59dd2c8b 100644 (file)
@@ -267,6 +267,7 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap)
  * Insert the given node 'node' into the subtree starting
  * at 'pos' (while keeping the tree somewhat balanced).
  *
+ * @param heap heap to modify
  * @param pos existing tree
  * @param node node to insert (which may be a subtree itself)
  */
@@ -278,7 +279,9 @@ insert_node (struct GNUNET_CONTAINER_Heap *heap,
   struct GNUNET_CONTAINER_HeapNode *parent;
 
   GNUNET_assert (node->parent == NULL);
-  while ( (pos->cost < node->cost) ^ (heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) )
+  while ( (heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) 
+         ? (pos->cost >= node->cost) 
+         : (pos->cost <= node->cost) )
     {
       /* node is descendent of pos */
       pos->tree_size += (1 + node->tree_size);
@@ -375,8 +378,7 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap)
   else if (root->right_child == NULL)
     {
       heap->root = root->left_child;
-      if (root->left_child != NULL)
-       root->left_child->parent = NULL;
+      root->left_child->parent = NULL;
     }
   else
     {