/** * Maintains a sorted array of unique numeric index values and provides * binary-search bounds over it, so range queries ($gt/$gte/$lt/$lte) can * resolve against an index instead of falling back to a full collection scan. */ export default class SortedIndexValues { /** * Index of the first element >= target (a.k.a. lower_bound). * Returns `sortedValues.length` if every element is smaller than target. */ static lowerBound(sortedValues: number[], target: number): number; /** * Index of the first element > target (a.k.a. upper_bound). * Returns `sortedValues.length` if every element is <= target. */ static upperBound(sortedValues: number[], target: number): number; /** * Inserts `value` keeping the array sorted and free of duplicates. * No-op if the value is already present. */ static insertSorted(sortedValues: number[], value: number): void; /** * Removes `value` from the sorted array, if present. */ static removeSorted(sortedValues: number[], value: number): void; /** * Builds a sorted, de-duplicated numeric array from existing hash-map keys. * Used to lazily backfill indexes created before range support existed. * Non-numeric keys are skipped (range queries only ever apply to numbers). */ static backfillFromKeys(keys: string[]): number[]; /** * Resolves the inclusive [startIndex, endIndex] slice of `sortedValues` that * satisfies the given range operators. Returns null if the range is empty. */ static resolveRange(sortedValues: number[], range: { $gt?: number; $gte?: number; $lt?: number; $lte?: number; }): { startIndex: number; endIndex: number; } | null; }