* 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)
*/
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);
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
{