diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-05-21 16:21:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-21 16:21:14 +0200 |
| commit | a2c0720fb046187bb00f5f3beeab4e9c284b18f0 (patch) | |
| tree | 9897ea8335032e8f28ca910b8a88416dbb77110a | |
| parent | 96bbd944dc1bc873be9b7b162b67237dd28fdd8f (diff) | |
| parent | 1662ab10af9187a91a8b26867074a797237aa28a (diff) | |
Merge pull request #5194 from Feoramund/fix-5067
Fix off-by-one error in `priority_queue.remove`
| -rw-r--r-- | core/container/priority_queue/priority_queue.odin | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/core/container/priority_queue/priority_queue.odin b/core/container/priority_queue/priority_queue.odin index 7387a8d09..c62a821f4 100644 --- a/core/container/priority_queue/priority_queue.odin +++ b/core/container/priority_queue/priority_queue.odin @@ -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) { n := builtin.len(pq.queue) if 0 <= i && i < n { - if n != i { - pq.swap(pq.queue[:], i, n) - _shift_down(pq, i, n) - _shift_up(pq, i) - } - value, ok = builtin.pop_safe(&pq.queue) + pq.swap(pq.queue[:], i, n-1) + _shift_down(pq, i, n-1) + _shift_up(pq, i) + value, ok = builtin.pop(&pq.queue), true } return } |