Commit 1dfbb97
committed
fix(flowcontrol): call up() after down() in maxMinHeap.Remove
Remove swaps position i with the last element then calls down() but
not up(). When the last element comes from a different subtree, the
ancestor relationship can break:
Before: After Remove(index=3, time=1):
0 0
/ \ / \
5 50 5 50
/ \ \ / \
1 4 40 40 4
Last element (index 5, time=40) swaps into index 3.
down(3): no children, no-op.
Node 1 (min-level, time=5) must be lowest-priority in {5, 40, 4}.
time=40 has lower priority than time=5 -- heap property violated.
Add the missing up(i) call after down(i). If down moved the element,
up is a no-op at the new position (and vice versa).
Signed-off-by: RishabhSaini <rishabhsaini01@gmail.com>1 parent 28b36f1 commit 1dfbb97
1 file changed
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
289 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
290 | 292 | | |
| 293 | + | |
291 | 294 | | |
292 | 295 | | |
293 | 296 | | |
| |||
0 commit comments