MCPcopy Create free account
hub / github.com/microsoft/SandDance / bisector

Function bisector

docs/app/js/sanddance-app.js:144997–145037  ·  view source on GitHub ↗
(f)

Source from the content-addressed store, hash-verified

144995var _ascendingJs = require("./ascending.js");
144996var _ascendingJsDefault = parcelHelpers.interopDefault(_ascendingJs);
144997function bisector(f) {
144998 let delta = f;
144999 let compare1 = f;
145000 let compare2 = f;
145001 if (f.length !== 2) {
145002 delta = (d, x)=>f(d) - x;
145003 compare1 = (0, _ascendingJsDefault.default);
145004 compare2 = (d, x)=>(0, _ascendingJsDefault.default)(f(d), x);
145005 }
145006 function left(a, x, lo = 0, hi = a.length) {
145007 if (lo < hi) {
145008 if (compare1(x, x) !== 0) return hi;
145009 do {
145010 const mid = lo + hi >>> 1;
145011 if (compare2(a[mid], x) < 0) lo = mid + 1;
145012 else hi = mid;
145013 }while (lo < hi);
145014 }
145015 return lo;
145016 }
145017 function right(a, x, lo = 0, hi = a.length) {
145018 if (lo < hi) {
145019 if (compare1(x, x) !== 0) return hi;
145020 do {
145021 const mid = lo + hi >>> 1;
145022 if (compare2(a[mid], x) <= 0) lo = mid + 1;
145023 else hi = mid;
145024 }while (lo < hi);
145025 }
145026 return lo;
145027 }
145028 function center(a, x, lo = 0, hi = a.length) {
145029 const i = left(a, x, lo, hi - 1);
145030 return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
145031 }
145032 return {
145033 left,
145034 center,
145035 right
145036 };
145037}
145038exports.default = bisector;
145039
145040},{"./ascending.js":"gutss","@parcel/transformer-js/src/esmodule-helpers.js":"jA2du"}],"d8mPJ":[function(require,module,exports) {

Callers

nothing calls this directly

Calls 1

fFunction · 0.70

Tested by

no test coverage detected