diff options
| author | VÖRÖSKŐI András <voroskoi@gmail.com> | 2022-07-25 06:57:04 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-25 18:12:32 +0300 |
| commit | 370793a36b3de34ead8456553a2aa2c56f0d3de8 (patch) | |
| tree | 86309f221fccbd8f769464901cc95374dcf6f63d /lib/std/priority_dequeue.zig | |
| parent | 9a3dacc00ed805cb70b3b656f28de73185206b13 (diff) | |
| download | zig-370793a36b3de34ead8456553a2aa2c56f0d3de8.tar.gz zig-370793a36b3de34ead8456553a2aa2c56f0d3de8.zip | |
PriorityDequeue: use compareFn in update() method
Diffstat (limited to 'lib/std/priority_dequeue.zig')
| -rw-r--r-- | lib/std/priority_dequeue.zig | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/std/priority_dequeue.zig b/lib/std/priority_dequeue.zig index 62b1491168..228c6d62ae 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); } |
