pub fn insertionContext(a: usize, b: usize, context: anytype) void a: usizeb: usizecontext42
43
44
45
46
47
48
49
50
51
52pub fn insertionContext(a: usize, b: usize, context: anytype) void {
assert(a <= b);
var i = a + 1;
while (i < b) : (i += 1) {
var j = i;
while (j > a and context.lessThan(j, j - 1)) : (j -= 1) {
context.swap(j, j - 1);
}
}
}
Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. O(1) memory (no allocator required).
contextmust have methodsswapandlessThan, which each take 2usizeparameters indicating the index of an item. Sorts in ascending order with respect tolessThan.