heap: fix heap_remove()
Remove should shuffle items in both directions, not just down. It is required, because `max` node could be not the actual maximum value in the tree. fix #1267 Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
70c42563c1
commit
e002340e50
@ -227,6 +227,13 @@ HEAP_EXPORT(void heap_remove(struct heap* heap,
|
||||
break;
|
||||
heap_node_swap(heap, child, smallest);
|
||||
}
|
||||
|
||||
/* Walk up the subtree and check that each parent is less than the node
|
||||
* this is required, because `max` node is not guaranteed to be the
|
||||
* actual maximum in tree
|
||||
*/
|
||||
while (child->parent != NULL && less_than(child, child->parent))
|
||||
heap_node_swap(heap, child->parent, child);
|
||||
}
|
||||
|
||||
HEAP_EXPORT(void heap_dequeue(struct heap* heap, heap_compare_fn less_than)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user