| ... | @@ -34,7 +34,9 @@ pub fn insertion( | ... | @@ -34,7 +34,9 @@ pub fn insertion( |
| 34 | | 34 | |
| 35 | /// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. | 35 | /// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. |
| 36 | /// O(1) memory (no allocator required). | 36 | /// O(1) memory (no allocator required). |
| 37 | /// Sorts in ascending order with respect to the given `lessThan` function. | 37 | /// `context` must have methods `swap` and `lessThan`, |
| | 38 | /// which each take 2 `usize` parameters indicating the index of an item. |
| | 39 | /// Sorts in ascending order with respect to `lessThan`. |
| 38 | pub fn insertionContext(a: usize, b: usize, context: anytype) void { | 40 | pub fn insertionContext(a: usize, b: usize, context: anytype) void { |
| 39 | assert(a <= b); | 41 | assert(a <= b); |
| 40 | | 42 | |
| ... | @@ -73,7 +75,9 @@ pub fn heap( | ... | @@ -73,7 +75,9 @@ pub fn heap( |
| 73 | | 75 | |
| 74 | /// Unstable in-place sort. O(n*log(n)) best case, worst case and average case. | 76 | /// Unstable in-place sort. O(n*log(n)) best case, worst case and average case. |
| 75 | /// O(1) memory (no allocator required). | 77 | /// O(1) memory (no allocator required). |
| 76 | /// Sorts in ascending order with respect to the given `lessThan` function. | 78 | /// `context` must have methods `swap` and `lessThan`, |
| | 79 | /// which each take 2 `usize` parameters indicating the index of an item. |
| | 80 | /// Sorts in ascending order with respect to `lessThan`. |
| 77 | pub fn heapContext(a: usize, b: usize, context: anytype) void { | 81 | pub fn heapContext(a: usize, b: usize, context: anytype) void { |
| 78 | assert(a <= b); | 82 | assert(a <= b); |
| 79 | // build the heap in linear time. | 83 | // build the heap in linear time. |