1- import type { SortingGenerator } from " ./types" ;
1+ import type { SortingGenerator } from ' ./types' ;
22
33/**
44 * The size at or below which a run is considered "small" and
@@ -25,7 +25,7 @@ function minRunLength(n: number): number {
2525/**
2626 * Sorts a subarray using insertion sort.
2727 * This is used by Timsort to extend small runs to ensure they are at least minRun long.
28- *
28+ *
2929 * @param arr - The array to sort.
3030 * @param start - Start index of the subarray.
3131 * @param end - End index of the subarray (inclusive).
@@ -51,7 +51,7 @@ function* insertionSort(
5151 * Scans forward from `start` to find a run (ascending or strictly descending).
5252 * If run is descending, it is reversed.
5353 * Returns the end index of the run (inclusive).
54- *
54+ *
5555 * @param arr - The array.
5656 * @param start - Start index to detect run.
5757 * @param n - Total length of the array.
@@ -99,10 +99,10 @@ function* countRunAndMakeAscending(
9999/**
100100 * Merges two sorted sub-runs:
101101 * arr[start..mid] and arr[mid+1..end]
102- *
102+ *
103103 * This is a standard merging procedure but may be enhanced with Timsort's "galloping" optimization.
104104 * For simplicity, we will not implement galloping here, just a standard merge.
105- *
105+ *
106106 * @param arr - The array.
107107 * @param start - Start index of first run.
108108 * @param mid - End index of first run.
@@ -145,7 +145,7 @@ function* merge(
145145
146146/**
147147 * Timsort main function:
148- *
148+ *
149149 * Steps:
150150 * 1. Calculate minRun.
151151 * 2. Identify natural runs, extend them to length at least minRun with insertion sort.
@@ -191,7 +191,7 @@ export function* timSort(arr: number[]): SortingGenerator {
191191 const shouldMerge =
192192 ( n > 2 &&
193193 runStack [ n - 3 ] [ 1 ] <= runStack [ n - 2 ] [ 1 ] + runStack [ n - 1 ] [ 1 ] ) ||
194- ( lenY <= lenZ ) ;
194+ lenY <= lenZ ;
195195
196196 if ( ! shouldMerge ) break ;
197197
0 commit comments