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. Public Function
If the current capacity is less than new_capacity, this function will modify the deque so that it can hold exactly new_capacity items. Invalidates element pointers if additional memory is needed.
pubfnensureTotalCapacityPrecise(deque: *Self, gpa: Allocator, new_capacity: usize) Allocator.Error!void {
if (deque.buffer.len >= new_capacity) return;
constold_buffer = deque.buffer;
if (gpa.remap(old_buffer, new_capacity)) |new_buffer| {
// If the items wrap around the end of the buffer we need to do// a memcpy to prevent a gap after resizing the buffer.if (deque.head > old_buffer.len - deque.len) {
// The gap splits the items in the deque into head and tail parts.// Choose the shorter part to copy.consthead = new_buffer[deque.head..old_buffer.len];
consttail = new_buffer[0 .. deque.len - head.len];
if (head.len > tail.lenandnew_buffer.len - old_buffer.len > tail.len) {
@memcpy(new_buffer[old_buffer.len..][0..tail.len], tail);
} else {
// In this case overlap is possible if e.g. the capacity increase is 1// and head.len is greater than 1.deque.head = new_buffer.len - head.len;
@memmove(new_buffer[deque.head..][0..head.len], head);
}
}
deque.buffer = new_buffer;
} else {
constnew_buffer = trygpa.alloc(T, new_capacity);
if (deque.head < old_buffer.len - deque.len) {
@memcpy(new_buffer[0..deque.len], old_buffer[deque.head..][0..deque.len]);
} else {
consthead = old_buffer[deque.head..];
consttail = old_buffer[0 .. deque.len - head.len];
@memcpy(new_buffer[0..head.len], head);
@memcpy(new_buffer[head.len..][0..tail.len], tail);
}
deque.head = 0;
deque.buffer = new_buffer;
gpa.free(old_buffer);
}
}
If the current capacity is less than
new_capacity, this function will modify the deque so that it can hold exactlynew_capacityitems. Invalidates element pointers if additional memory is needed.