Skip to content

Commit 30bf036

Browse files
committed
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 ziglang#9918
1 parent 0e26c61 commit 30bf036

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/std/priority_queue.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ pub fn PriorityQueue(comptime T: type, comptime Context: type, comptime compareF
219219
}
220220

221221
pub fn update(self: *Self, elem: T, new_elem: T) !void {
222-
var update_index: usize = std.mem.indexOfScalar(T, self.items[0..self.len], elem) orelse return error.ElementNotFound;
222+
const update_index = blk: {
223+
for (self.items) |item, idx| {
224+
if (compareFn(self.context, item, elem).compare(.eq)) break :blk idx;
225+
}
226+
return error.ElementNotFound;
227+
};
223228
const old_elem: T = self.items[update_index];
224229
self.items[update_index] = new_elem;
225230
switch (compareFn(self.context, new_elem, old_elem)) {

0 commit comments

Comments
 (0)