mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Merge pull request #5194 from Feoramund/fix-5067
Fix off-by-one error in `priority_queue.remove`
This commit is contained in:
@@ -133,12 +133,10 @@ pop_safe :: proc(pq: ^$Q/Priority_Queue($T), loc := #caller_location) -> (value:
|
|||||||
remove :: proc(pq: ^$Q/Priority_Queue($T), i: int) -> (value: T, ok: bool) {
|
remove :: proc(pq: ^$Q/Priority_Queue($T), i: int) -> (value: T, ok: bool) {
|
||||||
n := builtin.len(pq.queue)
|
n := builtin.len(pq.queue)
|
||||||
if 0 <= i && i < n {
|
if 0 <= i && i < n {
|
||||||
if n != i {
|
pq.swap(pq.queue[:], i, n-1)
|
||||||
pq.swap(pq.queue[:], i, n)
|
_shift_down(pq, i, n-1)
|
||||||
_shift_down(pq, i, n)
|
_shift_up(pq, i)
|
||||||
_shift_up(pq, i)
|
value, ok = builtin.pop(&pq.queue), true
|
||||||
}
|
|
||||||
value, ok = builtin.pop_safe(&pq.queue)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user