diff --git a/README.md b/README.md index c4db217..ae0b53a 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ Returns an index of some item in the array `== y`. The following comments apply to the above methods: -* `array` can be either an array or an [`ndarray`](https://github.com/mikolalysenko/ndarray) * `cmp` is a comparison function, just like what you would pass to `Array.sort()` * `y` will always be the second argument passed to `cmp`, so you can ignore it if you are just binary searching on a predicate. * Assumes the array is sorted as would be the case if you called `Array.sort(cmp)` on it @@ -46,4 +45,4 @@ The following comments apply to the above methods: * `bounds.eq` will return the first found item with the given index. It can be a little faster than the other methods if you just want to find some random match and do not care where it is. ## Credits -(c) 2013 Mikola Lysenko. MIT License \ No newline at end of file +(c) 2013 Mikola Lysenko. MIT License diff --git a/package.json b/package.json index 9611e24..bae5f7d 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,10 @@ }, "dependencies": {}, "devDependencies": { - "tape": "~2.0.0", - "tap": "~0.4.4", - "ndarray": "~1.0.8" + "tape": "^4.0.0" }, "scripts": { - "test": "tap test/*.js" + "test": "tape test/*.js" }, "repository": { "type": "git", diff --git a/search-bounds.js b/search-bounds.js index 79d293a..a20d1f0 100644 --- a/search-bounds.js +++ b/search-bounds.js @@ -1,11 +1,11 @@ "use strict" -function compileSearch(funcName, predicate, reversed, extraArgs, useNdarray, earlyOut) { +function compileSearch(funcName, predicate, reversed, extraArgs, earlyOut) { var code = [ "function ", funcName, "(a,l,h,", extraArgs.join(","), "){", earlyOut ? "" : "var i=", (reversed ? "l-1" : "h+1"), ";while(l<=h){\ -var m=(l+h)>>>1,x=a", useNdarray ? ".get(m)" : "[m]"] +var m=(l+h)>>>1,x=a[m]"] if(earlyOut) { if(predicate.indexOf("c") < 0) { code.push(";if(x===y){return m}else if(x<=y){") @@ -31,22 +31,14 @@ var m=(l+h)>>>1,x=a", useNdarray ? ".get(m)" : "[m]"] function compileBoundsSearch(predicate, reversed, suffix, earlyOut) { var result = new Function([ - compileSearch("A", "x" + predicate + "y", reversed, ["y"], false, earlyOut), - compileSearch("B", "x" + predicate + "y", reversed, ["y"], true, earlyOut), - compileSearch("P", "c(x,y)" + predicate + "0", reversed, ["y", "c"], false, earlyOut), - compileSearch("Q", "c(x,y)" + predicate + "0", reversed, ["y", "c"], true, earlyOut), + compileSearch("A", "x" + predicate + "y", reversed, ["y"], earlyOut), + compileSearch("P", "c(x,y)" + predicate + "0", reversed, ["y", "c"], earlyOut), "function dispatchBsearch", suffix, "(a,y,c,l,h){\ -if(a.shape){\ if(typeof(c)==='function'){\ -return Q(a,(l===undefined)?0:l|0,(h===undefined)?a.shape[0]-1:h|0,y,c)\ +return P(a,(l===void 0)?0:l|0,(h===void 0)?a.length-1:h|0,y,c)\ }else{\ -return B(a,(c===undefined)?0:c|0,(l===undefined)?a.shape[0]-1:l|0,y)\ -}}else{\ -if(typeof(c)==='function'){\ -return P(a,(l===undefined)?0:l|0,(h===undefined)?a.length-1:h|0,y,c)\ -}else{\ -return A(a,(c===undefined)?0:c|0,(l===undefined)?a.length-1:l|0,y)\ -}}}\ +return A(a,(c===void 0)?0:c|0,(l===void 0)?a.length-1:l|0,y)\ +}}\ return dispatchBsearch", suffix].join("")) return result() } diff --git a/test/test.js b/test/test.js index 4df8bcd..476d204 100644 --- a/test/test.js +++ b/test/test.js @@ -2,7 +2,6 @@ var tape = require("tape") var bounds = require("../search-bounds.js") -var ndarray = require("ndarray") tape("greaterThanEquals", function(t) { @@ -18,7 +17,7 @@ tape("greaterThanEquals", function(t) { t.equals(lb(arr, values[i]), j) } } - + checkArray([0,1,1,1,2], [-1, 0, 1, 2, 0.5, 1.5, 5]) t.equals(lb([0,2,5,6], 0), 0) @@ -32,7 +31,7 @@ tape("greaterThanEquals", function(t) { function cmp(a,b) { return a - b } - + t.equals(lb([0,1,1,1,2], -1, cmp), 0) t.equals(lb([0,1,1,1,2], 0, cmp), 0) t.equals(lb([0,1,1,1,2], 1, cmp), 1) @@ -133,4 +132,4 @@ tape("equals", function(t) { checkArray([0,1,1,1,2], [-1, 0, 1, 2, 0.5, 1.5, 5]) t.end() -}) \ No newline at end of file +})