diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-11-01 20:49:36 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-11-01 20:49:36 +0800 |
| commit | e99f950f5018cfe737c0d1150e50d97c6e6a4823 (patch) | |
| tree | 16f329a1b22128ed67f3fcae15a9b0a030f2ccbf /node_modules/source-map/lib/binary-search.js | |
| parent | c5d8a744dd584749e0b920119b42e731e37e5f62 (diff) | |
update
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, 19 insertions, 15 deletions
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; |
