aboutsummaryrefslogtreecommitdiff
path: root/lib/std/priority_queue.zig
diff options
context:
space:
mode:
authorZander Khan <git@zander.xyz>2021-01-16 18:11:26 +0000
committerZander Khan <git@zander.xyz>2021-01-16 18:11:26 +0000
commitc6986f29f94ee404ae3a3221449dc4af5599ca1f (patch)
treeaa59a32a53037ce289b0dd4ef0b9f6ec9969c2f6 /lib/std/priority_queue.zig
parent4600b489a6daf3990afc8464dd7f2b9a1a4efa72 (diff)
downloadzig-c6986f29f94ee404ae3a3221449dc4af5599ca1f.tar.gz
zig-c6986f29f94ee404ae3a3221449dc4af5599ca1f.zip
Fix update might change an element no longer in the queue
Diffstat (limited to 'lib/std/priority_queue.zig')
-rw-r--r--lib/std/priority_queue.zig2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig
index a5f9209e86..6e286f1cea 100644
--- a/lib/std/priority_queue.zig
+++ b/lib/std/priority_queue.zig
@@ -199,7 +199,7 @@ pub fn PriorityQueue(comptime T: type) type {
}
pub fn update(self: *Self, elem: T, new_elem: T) !void {
- var update_index: usize = std.mem.indexOfScalar(T, self.items, elem) orelse return error.ElementNotFound;
+ var update_index: usize = std.mem.indexOfScalar(T, self.items[0 .. self.len - 1], elem) orelse return error.ElementNotFound;
const old_elem: T = self.items[update_index];
self.items[update_index] = new_elem;
if (self.compareFn(new_elem, old_elem)) {