import type { Comparator , Fn3 , TypedArray } from "@thi.ng/api" ; import { compare } from "@thi.ng/compare/compare" ; import { swap } from "./swap.js" ; remarks Supports sorting of sub-ranges only, via optionally given
 * `start`/`end` indices (both inclusive).
 *
 * Uses Hoare partitioning scheme.  {@link @thi.ng/compare#compare} is
 * used as default comparator and  swap from this package as
 * default swap function. Also see  multiSwap .
 *
 *  https example param arr param _cmp param _swap param start param end export function quickSort < T > ( arr , _cmp ? , _swap ? , start ? , end ? ) ; export function quickSort < T extends TypedArray > ( arr , _cmp ? , _swap ? , start ? , end ? ) ; export function quickSort ( arr , _cmp = compare , _swap = swap , start = 0 , end = arr . length - 1 ) { if ( start < end ) { const pivot = arr [ start + ( ( end - start ) >> 1 ) ] ; let s = start - 1 ; let e = end + 1 ; while ( true ) { do { s ++ ; } while ( _cmp ( arr [ s ] , pivot ) < 0 ) ; do { e -- ; } while ( _cmp ( arr [ e ] , pivot ) > 0 ) ; if ( s >= e ) break ; _swap ( arr , s , e ) ; } quickSort ( arr , _cmp , _swap , start , e ) ; quickSort ( arr , _cmp , _swap , e + 1 , end ) ; } return arr ; }