binary-search
Advanced tools
Comparing version 1.3.5 to 1.3.6
16
index.js
@@ -23,16 +23,18 @@ module.exports = function(haystack, needle, comparator, low, high) { | ||
while(low <= high) { | ||
/* Note that "(low + high) >>> 1" may overflow, and results in a typecast | ||
* to double (which gives the wrong results). */ | ||
mid = low + (high - low >> 1); | ||
// The naive `low + high >>> 1` could fail for array lengths > 2**31 | ||
// because `>>>` converts its operands to int32. `low + (high - low >>> 1)` | ||
// works for array lengths <= 2**32-1 which is also Javascript's max array | ||
// length. | ||
mid = low + ((high - low) >>> 1); | ||
cmp = +comparator(haystack[mid], needle, mid, haystack); | ||
/* Too low. */ | ||
// Too low. | ||
if(cmp < 0.0) | ||
low = mid + 1; | ||
/* Too high. */ | ||
// Too high. | ||
else if(cmp > 0.0) | ||
high = mid - 1; | ||
/* Key found. */ | ||
// Key found. | ||
else | ||
@@ -42,4 +44,4 @@ return mid; | ||
/* Key not found. */ | ||
// Key not found. | ||
return ~low; | ||
} |
{ | ||
"name": "binary-search", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "tiny binary search function with comparators", | ||
@@ -5,0 +5,0 @@ "license": "CC0-1.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5717
94