From 36741870a53e0d4fbefb97b618035c3ca43854aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=96R=C3=96SK=C5=90I=20Andr=C3=A1s?= Date: Mon, 25 Jul 2022 06:57:04 +0200 Subject: [PATCH] PriorityDequeue: use compareFn in update() method --- lib/std/priority_dequeue.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/std/priority_dequeue.zig b/lib/std/priority_dequeue.zig index 62b1491168b7..228c6d62ae84 100644 --- a/lib/std/priority_dequeue.zig +++ b/lib/std/priority_dequeue.zig @@ -391,7 +391,12 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar } pub fn update(self: *Self, elem: T, new_elem: T) !void { - var old_index: usize = std.mem.indexOfScalar(T, self.items[0..self.len], elem) orelse return error.ElementNotFound; + const old_index = blk: { + for (self.items) |item, idx| { + if (compareFn(self.context, item, elem).compare(.eq)) break :blk idx; + } + return error.ElementNotFound; + }; _ = self.removeIndex(old_index); self.addUnchecked(new_elem); }