From 48a61ce9f6678210d306b6141cafcf55d163bafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=96R=C3=96SK=C5=90I=20Andr=C3=A1s?= Date: Sun, 17 Jul 2022 22:42:31 +0200 Subject: [PATCH] PriorityQueue: use compareFn in update() update() calls mem.indexOfScalar() which uses `==` for comparing items, which fails when the operator is not supported. As PirorityQueue needs a comparing function anyway we can use `.eq` results to identify matching objects. closes #9918 --- lib/std/priority_queue.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig index ebc13a99742b..45b275f79045 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)) {