{"version":3,"sources":["../src/utils/compare.ts"],"names":["requireDefined"],"mappings":";;;;;AAgBO,SAAS,cAAA,CAAe,MAAc,KAAA,EAAuB;AAClE,EAAA,IAAI,IAAA,GAAO,OAAO,OAAO,EAAA;AACzB,EAAA,OAAO,IAAA,GAAO,QAAQ,CAAA,GAAI,CAAA;AAC5B;AAiBO,SAAS,iBAAA,CAAkB,MAAc,KAAA,EAAuB;AACrE,EAAA,IAAI,IAAA,KAAS,OAAO,OAAO,CAAA;AAG3B,EAAA,IAAI,SAAA,GAAY,CAAA;AAChB,EAAA,IAAI,UAAA,GAAa,CAAA;AACjB,EAAA,OAAO,SAAA,GAAY,IAAA,CAAK,MAAA,IAAU,UAAA,GAAa,MAAM,MAAA,EAAQ;AAC3D,IAAA,MAAM,SAAA,GAAYA,gCAAA,CAAe,IAAA,CAAK,WAAA,CAAY,SAAS,CAAC,CAAA;AAC5D,IAAA,MAAM,UAAA,GAAaA,gCAAA,CAAe,KAAA,CAAM,WAAA,CAAY,UAAU,CAAC,CAAA;AAC/D,IAAA,IAAI,SAAA,KAAc,UAAA,EAAY,OAAO,SAAA,GAAY,aAAa,EAAA,GAAK,CAAA;AACnE,IAAA,SAAA,IAAa,SAAA,GAAY,QAAU,CAAA,GAAI,CAAA;AACvC,IAAA,UAAA,IAAc,UAAA,GAAa,QAAU,CAAA,GAAI,CAAA;AAAA,EAC3C;AACA,EAAA,MAAM,aAAA,GAAgB,aAAa,IAAA,CAAK,MAAA;AACxC,EAAA,MAAM,cAAA,GAAiB,cAAc,KAAA,CAAM,MAAA;AAC3C,EAAA,IAAI,aAAA,IAAiB,gBAAgB,OAAO,CAAA;AAC5C,EAAA,OAAO,gBAAgB,EAAA,GAAK,CAAA;AAC9B","file":"chunk-NYWU6CBZ.cjs","sourcesContent":["import { requireDefined } from \"./presence\";\n/**\n * Deterministic UTF-16 code-unit string comparison.\n *\n * `localeCompare` (and any `Intl`-backed collation) varies with the host's\n * ICU configuration, so two processes can order the same strings differently\n * — which turns \"sorted\" lock-acquisition sequences into cross-process\n * deadlocks and makes result/report ordering flap between environments.\n * Code-unit order is identical everywhere, matches SQLite's BINARY collation\n * for ASCII identifiers, and sorts NUL below every other character, so\n * NUL-separated composite keys compare as true tuples.\n *\n * Use this (or `Array.prototype.toSorted()` with no comparator, which is the\n * same order) for every internal ordering; locale-aware collation belongs\n * only in user-facing presentation code, which this library does not have.\n */\nexport function compareStrings(left: string, right: string): number {\n  if (left < right) return -1;\n  return left > right ? 1 : 0;\n}\n\n/**\n * Deterministic code-point string comparison — the order a SQL engine uses.\n *\n * {@link compareStrings} compares UTF-16 code *units*, which disagrees with\n * SQL byte order for astral characters: `\"\\u{10000}\"` is stored as the\n * surrogate pair `𐀀`, so code-unit order sorts it below `\"\"`\n * even though its code point (and its UTF-8 encoding) is far above. SQLite's\n * `BINARY` collation, Postgres's `C` collation, and UTF-8 byte order all agree\n * with code-point order.\n *\n * Use this wherever a JS-side ordering must reproduce an ORDER BY the database\n * could equally have performed — notably the hybrid-search fusion fallback,\n * whose ranks and page boundary must match the single-statement SQL path row\n * for row. Everywhere else {@link compareStrings} is cheaper and sufficient.\n */\nexport function compareCodePoints(left: string, right: string): number {\n  if (left === right) return 0;\n  // Walks by code point, stepping over the low surrogate of an astral pair.\n  // `codePointAt` at a valid index always yields a number.\n  let leftIndex = 0;\n  let rightIndex = 0;\n  while (leftIndex < left.length && rightIndex < right.length) {\n    const leftPoint = requireDefined(left.codePointAt(leftIndex));\n    const rightPoint = requireDefined(right.codePointAt(rightIndex));\n    if (leftPoint !== rightPoint) return leftPoint < rightPoint ? -1 : 1;\n    leftIndex += leftPoint > 0xff_ff ? 2 : 1;\n    rightIndex += rightPoint > 0xff_ff ? 2 : 1;\n  }\n  const leftExhausted = leftIndex >= left.length;\n  const rightExhausted = rightIndex >= right.length;\n  if (leftExhausted && rightExhausted) return 0;\n  return leftExhausted ? -1 : 1;\n}\n"]}