UNPKG

646 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3// Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound
4// Used to compute insertion index to keep queue sorted after insertion
5function lowerBound(array, value, comparator) {
6 let first = 0;
7 let count = array.length;
8 while (count > 0) {
9 const step = (count / 2) | 0;
10 let it = first + step;
11 if (comparator(array[it], value) <= 0) {
12 first = ++it;
13 count -= step + 1;
14 }
15 else {
16 count = step;
17 }
18 }
19 return first;
20}
21exports.default = lowerBound;