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. Private Function
fndoSiftDown(self: *Self, start_index: usize, target_order: Order) void {
varindex = start_index;
consthalf = self.len >> 1;
while (true) {
constfirst_grandchild_index = firstGrandchildIndex(index);
constlast_grandchild_index = first_grandchild_index + 3;
constelem = self.items[index];
if (last_grandchild_index < self.len) {
// All four grandchildren existconstindex2 = first_grandchild_index + 1;
constindex3 = index2 + 1;
// Find the best grandchildconstbest_left = self.bestItemAtIndices(first_grandchild_index, index2, target_order);
constbest_right = self.bestItemAtIndices(index3, last_grandchild_index, target_order);
constbest_grandchild = self.bestItem(best_left, best_right, target_order);
// If the item is better than or equal to its best grandchild, we are doneif (compareFn(self.context, best_grandchild.item, elem) != target_order) return;
// Otherwise, swap themself.items[best_grandchild.index] = elem;
self.items[index] = best_grandchild.item;
index = best_grandchild.index;
// We might need to swap the element with it's parentself.swapIfParentIsBetter(elem, index, target_order);
} else {
// The children or grandchildren are the last layerconstfirst_child_index = firstChildIndex(index);
if (first_child_index >= self.len) return;
constbest_descendent = self.bestDescendent(first_child_index, first_grandchild_index, target_order);
// If the item is better than or equal to its best descendant, we are doneif (compareFn(self.context, best_descendent.item, elem) != target_order) return;
// Otherwise swap themself.items[best_descendent.index] = elem;
self.items[index] = best_descendent.item;
index = best_descendent.index;
// If we didn't swap a grandchild, we are doneif (index < first_grandchild_index) return;
// We might need to swap the element with it's parentself.swapIfParentIsBetter(elem, index, target_order);
return;
}
// If we are now in the last layer, we are doneif (index >= half) return;
}
}