import ascending from "./ascending.js";
import descending from "./descending.js";
function bisector(n) {
	let i, a, o;
	n.length === 2 ? (i = n === ascending || n === descending ? n : zero, a = n, o = n) : (i = ascending, a = (t, r) => ascending(n(t), r), o = (e, t) => n(e) - t);
	function s(e, t, n = 0, r = e.length) {
		if (n < r) {
			if (i(t, t) !== 0) return r;
			do {
				let i = n + r >>> 1;
				a(e[i], t) < 0 ? n = i + 1 : r = i;
			} while (n < r);
		}
		return n;
	}
	function c(e, t, n = 0, r = e.length) {
		if (n < r) {
			if (i(t, t) !== 0) return r;
			do {
				let i = n + r >>> 1;
				a(e[i], t) <= 0 ? n = i + 1 : r = i;
			} while (n < r);
		}
		return n;
	}
	function l(e, t, n = 0, r = e.length) {
		let i = s(e, t, n, r - 1);
		return i > n && o(e[i - 1], t) > -o(e[i], t) ? i - 1 : i;
	}
	return {
		left: s,
		center: l,
		right: c
	};
}
function zero() {
	return 0;
}
export { bisector as default };
