From e99f950f5018cfe737c0d1150e50d97c6e6a4823 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 1 Nov 2023 20:49:36 +0800 Subject: update --- node_modules/source-map/lib/binary-search.js | 34 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'node_modules/source-map/lib/binary-search.js') diff --git a/node_modules/source-map/lib/binary-search.js b/node_modules/source-map/lib/binary-search.js index d6f898ea..010ac941 100644 --- a/node_modules/source-map/lib/binary-search.js +++ b/node_modules/source-map/lib/binary-search.js @@ -31,12 +31,13 @@ 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. - const mid = Math.floor((aHigh - aLow) / 2) + aLow; - const cmp = aCompare(aNeedle, aHaystack[mid], true); + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var 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. @@ -47,21 +48,24 @@ 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; - } - - // 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); } + 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; + // 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; + } } - return aLow < 0 ? -1 : aLow; } /** @@ -87,7 +91,7 @@ exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { return -1; } - let index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare, aBias || exports.GREATEST_LOWER_BOUND); if (index < 0) { return -1; -- cgit v1.2.3