"use client";
import { ascendingDefined as D, compareDefined as m } from "./sort.js";
function z(n, s, o = 0, t = 1 / 0, M) {
  if (s = Math.floor(s), o = Math.floor(Math.max(0, o)), t = Math.floor(Math.min(n.length - 1, t)), !(o <= s && s <= t)) return n;
  for (M = M === void 0 ? D : m(M); t > o; ) {
    if (t - o > 600) {
      const c = t - o + 1, h = s - o + 1, w = Math.log(c), f = 0.5 * Math.exp(2 * w / 3), l = 0.5 * Math.sqrt(w * f * (c - f) / c) * (h - c / 2 < 0 ? -1 : 1), x = Math.max(o, Math.floor(s - h * f / c + l)), q = Math.min(t, Math.floor(s + (c - h) * f / c + l));
      z(n, s, x, q, M);
    }
    const d = n[s];
    let e = o, i = t;
    for (u(n, o, s), M(n[t], d) > 0 && u(n, o, t); e < i; ) {
      for (u(n, e, i), ++e, --i; M(n[e], d) < 0; ) ++e;
      for (; M(n[i], d) > 0; ) --i;
    }
    M(n[o], d) === 0 ? u(n, o, i) : (++i, u(n, i, t)), i <= s && (o = i + 1), s <= i && (t = i - 1);
  }
  return n;
}
function u(n, s, o) {
  const t = n[s];
  n[s] = n[o], n[o] = t;
}
export {
  z as default
};
