diff options
Diffstat (limited to 'node_modules/source-map/lib/binary-search.js')
| -rw-r--r-- | node_modules/source-map/lib/binary-search.js | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/node_modules/source-map/lib/binary-search.js b/node_modules/source-map/lib/binary-search.js index 010ac941..d6f898ea 100644 --- a/node_modules/source-map/lib/binary-search.js +++ b/node_modules/source-map/lib/binary-search.js @@ -31,13 +31,12 @@ function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { // // 3. We did not find the exact element, and there is no next-closest // element than the one we are searching for, so we return -1. - var mid = Math.floor((aHigh - aLow) / 2) + aLow; - var cmp = aCompare(aNeedle, aHaystack[mid], true); + const mid = Math.floor((aHigh - aLow) / 2) + aLow; + const cmp = aCompare(aNeedle, aHaystack[mid], true); if (cmp === 0) { // Found the element we are looking for. return mid; - } - else if (cmp > 0) { + } else if (cmp > 0) { // Our needle is greater than aHaystack[mid]. if (aHigh - mid > 1) { // The element is in the upper half. @@ -48,24 +47,21 @@ function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { // we are in termination case (3) or (2) and return the appropriate thing. if (aBias == exports.LEAST_UPPER_BOUND) { return aHigh < aHaystack.length ? aHigh : -1; - } else { - return mid; } + return mid; } - else { - // Our needle is less than aHaystack[mid]. - if (mid - aLow > 1) { - // The element is in the lower half. - return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); - } - // we are in termination case (3) or (2) and return the appropriate thing. - if (aBias == exports.LEAST_UPPER_BOUND) { - return mid; - } else { - return aLow < 0 ? -1 : aLow; - } + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; } + return aLow < 0 ? -1 : aLow; } /** @@ -91,7 +87,7 @@ exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { return -1; } - var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + let index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare, aBias || exports.GREATEST_LOWER_BOUND); if (index < 0) { return -1; |
