|
@ -1132,7 +1132,8 @@ exports.mergeOptions = function (mergeTarget, options, option) { |
|
|
* |
|
|
* |
|
|
* @param {{byStart: Item[], byEnd: Item[]}} orderedItems |
|
|
* @param {{byStart: Item[], byEnd: Item[]}} orderedItems |
|
|
* @param {{start: number, end: number}} range |
|
|
* @param {{start: number, end: number}} range |
|
|
* @param {Boolean} byEnd |
|
|
|
|
|
|
|
|
* @param {String} field |
|
|
|
|
|
* @param {String} field2 |
|
|
* @returns {number} |
|
|
* @returns {number} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
@ -1143,11 +1144,15 @@ exports.binarySearch = function(orderedItems, range, field, field2) { |
|
|
var found = false; |
|
|
var found = false; |
|
|
var low = 0; |
|
|
var low = 0; |
|
|
var high = array.length; |
|
|
var high = array.length; |
|
|
|
|
|
var newLow = low; |
|
|
|
|
|
var newHigh = high; |
|
|
var guess = Math.floor(0.5*(high+low)); |
|
|
var guess = Math.floor(0.5*(high+low)); |
|
|
var newGuess; |
|
|
var newGuess; |
|
|
var value; |
|
|
var value; |
|
|
|
|
|
|
|
|
if (high == 0) {guess = -1;} |
|
|
|
|
|
|
|
|
if (high == 0) { |
|
|
|
|
|
guess = -1; |
|
|
|
|
|
} |
|
|
else if (high == 1) { |
|
|
else if (high == 1) { |
|
|
value = field2 === undefined ? array[guess][field] : array[guess][field][field2]; |
|
|
value = field2 === undefined ? array[guess][field] : array[guess][field][field2]; |
|
|
if ((value > range.start - interval) && (value < range.end)) { |
|
|
if ((value > range.start - interval) && (value < range.end)) { |
|
@ -1159,26 +1164,28 @@ exports.binarySearch = function(orderedItems, range, field, field2) { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
high -= 1; |
|
|
high -= 1; |
|
|
|
|
|
|
|
|
while (found == false) { |
|
|
while (found == false) { |
|
|
value = field2 === undefined ? array[guess][field] : array[guess][field][field2]; |
|
|
value = field2 === undefined ? array[guess][field] : array[guess][field][field2]; |
|
|
|
|
|
|
|
|
if ((value > range.start - interval) && (value < range.end)) { |
|
|
if ((value > range.start - interval) && (value < range.end)) { |
|
|
found = true; |
|
|
found = true; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
if (value < range.start - interval) { // it is too small --> increase low
|
|
|
if (value < range.start - interval) { // it is too small --> increase low
|
|
|
low = Math.floor(0.5*(high+low)); |
|
|
|
|
|
|
|
|
newLow = Math.floor(0.5*(high+low)); |
|
|
} |
|
|
} |
|
|
else { // it is too big --> decrease high
|
|
|
else { // it is too big --> decrease high
|
|
|
high = Math.floor(0.5*(high+low)); |
|
|
|
|
|
|
|
|
newHigh = Math.floor(0.5*(high+low)); |
|
|
} |
|
|
} |
|
|
newGuess = Math.floor(0.5*(high+low)); |
|
|
|
|
|
// not in list;
|
|
|
// not in list;
|
|
|
if (guess == newGuess) { |
|
|
|
|
|
|
|
|
if (low == newLow && high == newHigh) { |
|
|
guess = -1; |
|
|
guess = -1; |
|
|
found = true; |
|
|
found = true; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
guess = newGuess; |
|
|
|
|
|
|
|
|
high = newHigh; low = newLow; |
|
|
|
|
|
guess = Math.floor(0.5*(high+low)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -1198,7 +1205,8 @@ exports.binarySearch = function(orderedItems, range, field, field2) { |
|
|
* |
|
|
* |
|
|
* @param {Array} orderedItems |
|
|
* @param {Array} orderedItems |
|
|
* @param {{start: number, end: number}} target |
|
|
* @param {{start: number, end: number}} target |
|
|
* @param {Boolean} byEnd |
|
|
|
|
|
|
|
|
* @param {String} field |
|
|
|
|
|
* @param {String} sidePreference 'before' or 'after' |
|
|
* @returns {number} |
|
|
* @returns {number} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
@ -1207,6 +1215,8 @@ exports.binarySearchGeneric = function(orderedItems, target, field, sidePreferen |
|
|
var found = false; |
|
|
var found = false; |
|
|
var low = 0; |
|
|
var low = 0; |
|
|
var high = array.length; |
|
|
var high = array.length; |
|
|
|
|
|
var newLow = low; |
|
|
|
|
|
var newHigh = high; |
|
|
var guess = Math.floor(0.5*(high+low)); |
|
|
var guess = Math.floor(0.5*(high+low)); |
|
|
var newGuess; |
|
|
var newGuess; |
|
|
var prevValue, value, nextValue; |
|
|
var prevValue, value, nextValue; |
|
@ -1252,12 +1262,13 @@ exports.binarySearchGeneric = function(orderedItems, target, field, sidePreferen |
|
|
} |
|
|
} |
|
|
newGuess = Math.floor(0.5*(high+low)); |
|
|
newGuess = Math.floor(0.5*(high+low)); |
|
|
// not in list;
|
|
|
// not in list;
|
|
|
if (guess == newGuess) { |
|
|
|
|
|
guess = -2; |
|
|
|
|
|
|
|
|
if (low == newLow && high == newHigh) { |
|
|
|
|
|
guess = -1; |
|
|
found = true; |
|
|
found = true; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
guess = newGuess; |
|
|
|
|
|
|
|
|
high = newHigh; low = newLow; |
|
|
|
|
|
guess = Math.floor(0.5*(high+low)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|