Skip to content

Commit 370793a

Browse files
voroskoiVexu
authored andcommitted
PriorityDequeue: use compareFn in update() method
1 parent 9a3dacc commit 370793a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/std/priority_dequeue.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,12 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
391391
}
392392

393393
pub fn update(self: *Self, elem: T, new_elem: T) !void {
394-
var old_index: usize = std.mem.indexOfScalar(T, self.items[0..self.len], elem) orelse return error.ElementNotFound;
394+
const old_index = blk: {
395+
for (self.items) |item, idx| {
396+
if (compareFn(self.context, item, elem).compare(.eq)) break :blk idx;
397+
}
398+
return error.ElementNotFound;
399+
};
395400
_ = self.removeIndex(old_index);
396401
self.addUnchecked(new_elem);
397402
}

0 commit comments

Comments
 (0)