Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bisection] performance optimization

  • Loading branch information...
commit 3923a4d61db62bb49fb15b6311a22376a458c8de 1 parent d0057e1
@indutny indutny authored
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/bisection.js
View
8 lib/bisection.js
@@ -10,15 +10,15 @@
exports.Bisection = function bisection(array, x, low, high){
// The low and high bounds the inital slice of the array that needs to be searched
// this is optional
- low = low || 0;
- high = high || array.length;
+ low || (low = 0);
+ high || (high = array.length);
var mid;
if (low < 0) throw new Error('Low must be a non-negative integer');
while(low < high){
- mid = Math.floor((low + high) / 2);
+ mid = (low + high) >> 1;
if (x < array[mid]){
high = mid;
@@ -28,4 +28,4 @@ exports.Bisection = function bisection(array, x, low, high){
}
return low;
-};
+};
Please sign in to comment.
Something went wrong with that request. Please try again.