- else if (del_node == root->root)
- return GNUNET_CONTAINER_heap_remove_root (root);
-
- ret = del_node->element;
- last = getPos (root, root->size);
-
- old_cost = del_node->cost;
- del_node->element = last->element;
- del_node->cost = last->cost;
-
- if (last->parent->left_child == last)
- last->parent->left_child = NULL;
- if (last->parent->right_child == last)
- last->parent->right_child = NULL;
-
- if (root->traversal_pos == last)
- {
- root->traversal_pos = root->root;
- }
- GNUNET_free (last);
- root->size--;
-
- if (del_node->cost > old_cost)
- {
- if (root->type == GNUNET_CONTAINER_HEAP_ORDER_MAX)
- percolateHeap (del_node, root);
- else if (root->type == GNUNET_CONTAINER_HEAP_ORDER_MIN)
- percolateDownHeap (del_node, root);
- }
- else if (del_node->cost < old_cost)
- {
- if (root->type == GNUNET_CONTAINER_HEAP_ORDER_MAX)
- percolateDownHeap (del_node, root);
- else if (root->type == GNUNET_CONTAINER_HEAP_ORDER_MIN)
- percolateHeap (del_node, root);
- }
-
+ heap->size--;
+ ret = root->element;
+ if (root->left_child == NULL)
+ {
+ heap->root = root->right_child;
+ if (root->right_child != NULL)
+ root->right_child->parent = NULL;
+ }
+ else if (root->right_child == NULL)
+ {
+ heap->root = root->left_child;
+ root->left_child->parent = NULL;
+ }
+ else
+ {
+ root->left_child->parent = NULL;
+ root->right_child->parent = NULL;
+ heap->root = root->left_child;
+ insert_node (heap, heap->root, root->right_child);
+ }
+ if (heap->walk_pos == root)
+ heap->walk_pos = heap->root;
+ GNUNET_free (root);
+#if EXTRA_CHECKS
+ GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
+ (heap->size == heap->root->tree_size + 1));
+ CHECK (heap->root);
+#endif