| ... | @@ -109,6 +109,7 @@ test "binarySearch" { | ... | @@ -109,6 +109,7 @@ test "binarySearch" { |
| 109 | | 109 | |
| 110 | /// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. | 110 | /// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. |
| 111 | /// O(1) memory (no allocator required). | 111 | /// O(1) memory (no allocator required). |
| | 112 | /// Sorts in ascending order with respect to the given `lessThan` function. |
| 112 | /// This can be expressed in terms of `insertionSortContext` but the glue | 113 | /// This can be expressed in terms of `insertionSortContext` but the glue |
| 113 | /// code is slightly longer than the direct implementation. | 114 | /// code is slightly longer than the direct implementation. |
| 114 | pub fn insertionSort( | 115 | pub fn insertionSort( |
| ... | @@ -130,6 +131,7 @@ pub fn insertionSort( | ... | @@ -130,6 +131,7 @@ pub fn insertionSort( |
| 130 | | 131 | |
| 131 | /// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. | 132 | /// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. |
| 132 | /// O(1) memory (no allocator required). | 133 | /// O(1) memory (no allocator required). |
| | 134 | /// Sorts in ascending order with respect to the given `context.lessThan` function. |
| 133 | pub fn insertionSortContext(len: usize, context: anytype) void { | 135 | pub fn insertionSortContext(len: usize, context: anytype) void { |
| 134 | var i: usize = 1; | 136 | var i: usize = 1; |
| 135 | while (i < len) : (i += 1) { | 137 | while (i < len) : (i += 1) { |
| ... | @@ -229,6 +231,7 @@ const Pull = struct { | ... | @@ -229,6 +231,7 @@ const Pull = struct { |
| 229 | | 231 | |
| 230 | /// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. | 232 | /// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. |
| 231 | /// O(1) memory (no allocator required). | 233 | /// O(1) memory (no allocator required). |
| | 234 | /// Sorts in ascending order with respect to the given `lessThan` function. |
| 232 | /// Currently implemented as block sort. | 235 | /// Currently implemented as block sort. |
| 233 | pub fn sort( | 236 | pub fn sort( |
| 234 | comptime T: type, | 237 | comptime T: type, |