Skip to content

Commit d047eee

Browse files
committed
remove ndarray support
1 parent c20038c commit d047eee

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Returns an index of some item in the array `== y`.
3232

3333
The following comments apply to the above methods:
3434

35-
* `array` can be either an array or an [`ndarray`](https://github.com/mikolalysenko/ndarray)
3635
* `cmp` is a comparison function, just like what you would pass to `Array.sort()`
3736
* `y` will always be the second argument passed to `cmp`, so you can ignore it if you are just binary searching on a predicate.
3837
* 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:
4645
* `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.
4746

4847
## Credits
49-
(c) 2013 Mikola Lysenko. MIT License
48+
(c) 2013 Mikola Lysenko. MIT License

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
},
99
"dependencies": {},
1010
"devDependencies": {
11-
"tape": "~2.0.0",
12-
"tap": "~0.4.4",
13-
"ndarray": "~1.0.8"
11+
"tape": "^4.0.0"
1412
},
1513
"scripts": {
16-
"test": "tap test/*.js"
14+
"test": "tape test/*.js"
1715
},
1816
"repository": {
1917
"type": "git",

search-bounds.js

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use strict"
22

3-
function compileSearch(funcName, predicate, reversed, extraArgs, useNdarray, earlyOut) {
3+
function compileSearch(funcName, predicate, reversed, extraArgs, earlyOut) {
44
var code = [
55
"function ", funcName, "(a,l,h,", extraArgs.join(","), "){",
66
earlyOut ? "" : "var i=", (reversed ? "l-1" : "h+1"),
77
";while(l<=h){\
8-
var m=(l+h)>>>1,x=a", useNdarray ? ".get(m)" : "[m]"]
8+
var m=(l+h)>>>1,x=a[m]"]
99
if(earlyOut) {
1010
if(predicate.indexOf("c") < 0) {
1111
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]"]
3131

3232
function compileBoundsSearch(predicate, reversed, suffix, earlyOut) {
3333
var result = new Function([
34-
compileSearch("A", "x" + predicate + "y", reversed, ["y"], false, earlyOut),
35-
compileSearch("B", "x" + predicate + "y", reversed, ["y"], true, earlyOut),
36-
compileSearch("P", "c(x,y)" + predicate + "0", reversed, ["y", "c"], false, earlyOut),
37-
compileSearch("Q", "c(x,y)" + predicate + "0", reversed, ["y", "c"], true, earlyOut),
34+
compileSearch("A", "x" + predicate + "y", reversed, ["y"], earlyOut),
35+
compileSearch("P", "c(x,y)" + predicate + "0", reversed, ["y", "c"], earlyOut),
3836
"function dispatchBsearch", suffix, "(a,y,c,l,h){\
39-
if(a.shape){\
4037
if(typeof(c)==='function'){\
41-
return Q(a,(l===undefined)?0:l|0,(h===undefined)?a.shape[0]-1:h|0,y,c)\
38+
return P(a,(l===void 0)?0:l|0,(h===void 0)?a.length-1:h|0,y,c)\
4239
}else{\
43-
return B(a,(c===undefined)?0:c|0,(l===undefined)?a.shape[0]-1:l|0,y)\
44-
}}else{\
45-
if(typeof(c)==='function'){\
46-
return P(a,(l===undefined)?0:l|0,(h===undefined)?a.length-1:h|0,y,c)\
47-
}else{\
48-
return A(a,(c===undefined)?0:c|0,(l===undefined)?a.length-1:l|0,y)\
49-
}}}\
40+
return A(a,(c===void 0)?0:c|0,(l===void 0)?a.length-1:l|0,y)\
41+
}}\
5042
return dispatchBsearch", suffix].join(""))
5143
return result()
5244
}

test/test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
var tape = require("tape")
44
var bounds = require("../search-bounds.js")
5-
var ndarray = require("ndarray")
65

76
tape("greaterThanEquals", function(t) {
87

@@ -18,7 +17,7 @@ tape("greaterThanEquals", function(t) {
1817
t.equals(lb(arr, values[i]), j)
1918
}
2019
}
21-
20+
2221
checkArray([0,1,1,1,2], [-1, 0, 1, 2, 0.5, 1.5, 5])
2322

2423
t.equals(lb([0,2,5,6], 0), 0)
@@ -32,7 +31,7 @@ tape("greaterThanEquals", function(t) {
3231
function cmp(a,b) {
3332
return a - b
3433
}
35-
34+
3635
t.equals(lb([0,1,1,1,2], -1, cmp), 0)
3736
t.equals(lb([0,1,1,1,2], 0, cmp), 0)
3837
t.equals(lb([0,1,1,1,2], 1, cmp), 1)
@@ -133,4 +132,4 @@ tape("equals", function(t) {
133132
checkArray([0,1,1,1,2], [-1, 0, 1, 2, 0.5, 1.5, 5])
134133

135134
t.end()
136-
})
135+
})

0 commit comments

Comments
 (0)