UNPKG

@actyx/sdk

Version:
42 lines 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInsertionIndex = exports.binarySearch = void 0; /* * Actyx SDK: Functions for writing distributed apps * deployed on peer-to-peer networks, without any servers. * * Copyright (C) 2021 Actyx AG */ const binarySearch = (a, e, c) => { let m = 0; let n = a.length - 1; while (m <= n) { const k = (n + m) >> 1; const cmp = c(e, a[k]); if (cmp > 0) { m = k + 1; } else if (cmp < 0) { n = k - 1; } else { return k; } } return -m - 1; }; exports.binarySearch = binarySearch; const getInsertionIndex = (a, e, c) => { let low = 0; let high = a.length; while (low < high) { const mid = (low + high) >>> 1; if (c(a[mid], e) < 0) low = mid + 1; else high = mid; } return low; }; exports.getInsertionIndex = getInsertionIndex; //# sourceMappingURL=binarySearch.js.map