mirror of
https://github.com/ziglang/zig.git
synced 2026-01-03 12:03:19 +00:00
Fix update might change an element no longer in the queue
This commit is contained in:
parent
4600b489a6
commit
c6986f29f9
@ -389,7 +389,7 @@ pub fn PriorityDequeue(comptime T: type) type {
|
||||
}
|
||||
|
||||
pub fn update(self: *Self, elem: T, new_elem: T) !void {
|
||||
var old_index: usize = std.mem.indexOfScalar(T, self.items, elem) orelse return error.ElementNotFound;
|
||||
var old_index: usize = std.mem.indexOfScalar(T, self.items[0 .. self.len - 1], elem) orelse return error.ElementNotFound;
|
||||
_ = self.removeIndex(old_index);
|
||||
self.addUnchecked(new_elem);
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ pub fn PriorityQueue(comptime T: type) type {
|
||||
}
|
||||
|
||||
pub fn update(self: *Self, elem: T, new_elem: T) !void {
|
||||
var update_index: usize = std.mem.indexOfScalar(T, self.items, elem) orelse return error.ElementNotFound;
|
||||
var update_index: usize = std.mem.indexOfScalar(T, self.items[0 .. self.len - 1], elem) orelse return error.ElementNotFound;
|
||||
const old_elem: T = self.items[update_index];
|
||||
self.items[update_index] = new_elem;
|
||||
if (self.compareFn(new_elem, old_elem)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user