| ... | @@ -219,7 +219,12 @@ pub fn PriorityQueue(comptime T: type, comptime Context: type, comptime compareF | ... | @@ -219,7 +219,12 @@ pub fn PriorityQueue(comptime T: type, comptime Context: type, comptime compareF |
| 219 | } | 219 | } |
| 220 | | 220 | |
| 221 | pub fn update(self: *Self, elem: T, new_elem: T) !void { | 221 | 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 | }; |
| 223 | const old_elem: T = self.items[update_index]; | 228 | const old_elem: T = self.items[update_index]; |
| 224 | self.items[update_index] = new_elem; | 229 | self.items[update_index] = new_elem; |
| 225 | switch (compareFn(self.context, new_elem, old_elem)) { | 230 | switch (compareFn(self.context, new_elem, old_elem)) { |