Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › priority_queue › PriorityQueue › update Public Function update Doc Source Public Function std.priority_queue.PriorityQueue.update
pub fn update (self : *Self , elem : T , new_elem : T ) !void Params self : *Self elem : T new_elem : T File priority_queue.zig: 236
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252 pub fn update (self : *Self , elem : T , new_elem : T ) !void {
const update_index = blk : {
var idx : usize = 0 ;
while (idx < self .items .len ) : (idx += 1 ) {
const item = self .items [idx ];
if (compareFn (self .context , item , elem ) == .eq ) break :blk idx ;
}
return error .ElementNotFound ;
};
const old_elem : T = self .items [update_index ];
self .items [update_index ] = new_elem ;
switch (compareFn (self .context , new_elem , old_elem )) {
.lt => siftUp (self , update_index ),
.gt => siftDown (self , update_index ),
.eq => {}, // Nothing to do as the items have equal priority
}
}
Replace an element in the queue with a new element, maintaining priority. If the element being updated doesn't exist, return
error.ElementNotFound.