aboutsummaryrefslogtreecommitdiff
path: root/lib/std/priority_queue.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/priority_queue.zig')
-rw-r--r--lib/std/priority_queue.zig7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig
index ebc13a9974..45b275f790 100644
--- a/lib/std/priority_queue.zig
+++ b/lib/std/priority_queue.zig
@@ -219,7 +219,12 @@ pub fn PriorityQueue(comptime T: type, comptime Context: type, comptime compareF
}
pub fn update(self: *Self, elem: T, new_elem: T) !void {
- var update_index: usize = std.mem.indexOfScalar(T, self.items[0..self.len], elem) orelse return error.ElementNotFound;
+ const update_index = blk: {
+ for (self.items) |item, idx| {
+ if (compareFn(self.context, item, elem).compare(.eq)) break :blk idx;
+ }
+ return error.ElementNotFound;
+ };
const old_elem: T = self.items[update_index];
self.items[update_index] = new_elem;
switch (compareFn(self.context, new_elem, old_elem)) {