'use strict'; function compareFnDefault(item, target) { if (typeof target !== typeof item) return -1; if (target < item) return 1; if (target > item) return -1; return 0; } function parse(length, options) { var _a, _b, _c, _d, _e, _f; var max = Math.floor(length - 1); var lo = Math.floor(Math.min((_a = options === null || options === void 0 ? void 0 : options.lower) !== null && _a !== void 0 ? _a : 0, (_b = options === null || options === void 0 ? void 0 : options.upper) !== null && _b !== void 0 ? _b : max)); var hi = Math.floor(Math.max((_c = options === null || options === void 0 ? void 0 : options.lower) !== null && _c !== void 0 ? _c : 0, (_d = options === null || options === void 0 ? void 0 : options.upper) !== null && _d !== void 0 ? _d : max)); var lower = Math.max(0, Math.min(lo, max)); var upper = Math.min(Math.max(0, hi), max); return { compareFn: (_e = options === null || options === void 0 ? void 0 : options.compareFn) !== null && _e !== void 0 ? _e : compareFnDefault, lower: lower, upper: upper, rightmost: (_f = options === null || options === void 0 ? void 0 : options.rightmost) !== null && _f !== void 0 ? _f : false, }; } function compare(gt, strict, list, target, options) { if (list.length === 0) return -1; var _a = parse(list.length, options), compareFn = _a.compareFn, lower = _a.lower, upper = _a.upper; var lo = lower; var hi = upper; var index = -1; while (lo <= hi) { var mid = Math.floor(lo + (hi - lo) / 2); var x = compareFn(list[mid], target); if (gt) { if (x > 0 || (!strict && x === 0)) { index = mid; hi = mid - 1; } else { lo = mid + 1; } } else { if (x < 0 || (!strict && x === 0)) { index = mid; lo = mid + 1; } else { hi = mid - 1; } } } return index; } function eq(list, target, options) { if (list.length === 0) return -1; var _a = parse(list.length, options), compareFn = _a.compareFn, lower = _a.lower, upper = _a.upper, rightmost = _a.rightmost; var lo = lower; var hi = upper; var index = -1; while (lo <= hi) { var mid = Math.floor(lo + (hi - lo) / 2); var x = compareFn(list[mid], target); if (x < 0) { lo = mid + 1; } else if (x > 0) { hi = mid - 1; } else { index = mid; if (rightmost) lo = mid + 1; else hi = mid - 1; } } return index; } function gt(list, target, options) { return compare(true, true, list, target, options); } function gte(list, target, options) { return compare(true, false, list, target, options); } function lt(list, target, options) { return compare(false, true, list, target, options); } function lte(list, target, options) { return compare(false, false, list, target, options); } exports.eq = eq; exports.gt = gt; exports.gte = gte; exports.lt = lt; exports.lte = lte;