1
This commit is contained in:
6
nodejs/node_modules/sorted-array-functions/.travis.yml
generated
vendored
Executable file
6
nodejs/node_modules/sorted-array-functions/.travis.yml
generated
vendored
Executable file
@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '0.10'
|
||||
- '0.12'
|
||||
- '4'
|
||||
- '6'
|
||||
21
nodejs/node_modules/sorted-array-functions/LICENSE
generated
vendored
Executable file
21
nodejs/node_modules/sorted-array-functions/LICENSE
generated
vendored
Executable file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Mathias Buus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
71
nodejs/node_modules/sorted-array-functions/README.md
generated
vendored
Executable file
71
nodejs/node_modules/sorted-array-functions/README.md
generated
vendored
Executable file
@ -0,0 +1,71 @@
|
||||
# sorted-array-functions
|
||||
|
||||
Maintain and search through a sorted array using some low level functions
|
||||
|
||||
```
|
||||
npm install sorted-array-functions
|
||||
```
|
||||
|
||||
[](http://travis-ci.org/mafintosh/sorted-array-functions)
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
var sorted = require('sorted-array-functions')
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 1)
|
||||
sorted.add(list, 4)
|
||||
sorted.add(list, 2)
|
||||
|
||||
console.log(list) // prints out [1, 2, 4]
|
||||
console.log(sorted.has(list, 2)) // returns true
|
||||
console.log(sorted.has(list, 3)) // returns false
|
||||
console.log(sorted.eq(list, 2)) // returns 1 (the index)
|
||||
console.log(sorted.gt(list, 2)) // returns 2
|
||||
console.log(sorted.gt(list, 4)) // returns -1
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
#### `sorted.add(list, value, [compare])`
|
||||
|
||||
Insert a new value into the list sorted.
|
||||
Optionally you can use a custom compare function that returns, `compare(a, b)` that returns 1 if `a > b`, 0 if `a === b` and -1 if `a < b`.
|
||||
|
||||
#### `var bool = sorted.remove(list, value, [compare])`
|
||||
|
||||
Remove a value. Returns true if the value was in the list.
|
||||
|
||||
#### `var bool = sorted.has(list, value, [compare])`
|
||||
|
||||
Check if a value is in the list.
|
||||
|
||||
#### `var index = sorted.eq(list, value, [compare])`
|
||||
|
||||
Get the index of a value in the list (uses binary search).
|
||||
If the value could not be found -1 is returned.
|
||||
|
||||
#### `var index = sorted.gte(list, value, [compare])`
|
||||
|
||||
Get the index of the first value that is `>=`.
|
||||
If the value could not be found -1 is returned.
|
||||
|
||||
#### `var index = sorted.gt(list, value, [compare])`
|
||||
|
||||
Get the index of the first value that is `>`.
|
||||
If the value could not be found -1 is returned.
|
||||
|
||||
#### `var index = sorted.lte(list, value, [compare])`
|
||||
|
||||
Get the index of the first value that is `<=`.
|
||||
If the value could not be found -1 is returned.
|
||||
|
||||
#### `var index = sorted.lt(list, value, [compare])`
|
||||
|
||||
Get the index of the first value that is `<`.
|
||||
If the value could not be found -1 is returned.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
13
nodejs/node_modules/sorted-array-functions/example.js
generated
vendored
Executable file
13
nodejs/node_modules/sorted-array-functions/example.js
generated
vendored
Executable file
@ -0,0 +1,13 @@
|
||||
var sorted = require('./')
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 1)
|
||||
sorted.add(list, 4)
|
||||
sorted.add(list, 2)
|
||||
|
||||
console.log(list) // prints out [1, 2, 4]
|
||||
console.log(sorted.has(list, 2)) // returns true
|
||||
console.log(sorted.has(list, 3)) // returns false
|
||||
console.log(sorted.eq(list, 2)) // returns 1 (the index)
|
||||
console.log(sorted.gt(list, 2)) // returns 2
|
||||
console.log(sorted.gt(list, 4)) // returns -1
|
||||
160
nodejs/node_modules/sorted-array-functions/index.js
generated
vendored
Executable file
160
nodejs/node_modules/sorted-array-functions/index.js
generated
vendored
Executable file
@ -0,0 +1,160 @@
|
||||
exports.add = add
|
||||
exports.remove = remove
|
||||
exports.has = has
|
||||
exports.eq = eq
|
||||
exports.lte = lte
|
||||
exports.lt = lt
|
||||
exports.gte = gte
|
||||
exports.gt = gt
|
||||
exports.nearest = nearest
|
||||
|
||||
function defaultCmp (a, b) {
|
||||
if (a === b) return 0
|
||||
return a > b ? 1 : -1
|
||||
}
|
||||
|
||||
function add (list, value, cmp) {
|
||||
if (!cmp) cmp = defaultCmp
|
||||
|
||||
var top = list.push(value) - 1
|
||||
|
||||
while (top) {
|
||||
if (cmp(list[top - 1], value) < 0) return
|
||||
list[top] = list[top - 1]
|
||||
list[top - 1] = value
|
||||
top--
|
||||
}
|
||||
}
|
||||
|
||||
function lte (list, value, cmp) {
|
||||
if (!cmp) cmp = defaultCmp
|
||||
|
||||
var i = indexOf(list, value, cmp)
|
||||
if (i === -1) return -1
|
||||
|
||||
for (; i >= 0; i--) {
|
||||
var c = cmp(list[i], value)
|
||||
if (c <= 0) return i
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
function lt (list, value, cmp) {
|
||||
if (!cmp) cmp = defaultCmp
|
||||
|
||||
var i = indexOf(list, value, cmp)
|
||||
if (i === -1) return -1
|
||||
|
||||
for (; i >= 0; i--) {
|
||||
var c = cmp(list[i], value)
|
||||
if (c < 0) return i
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
function gte (list, value, cmp) {
|
||||
if (!cmp) cmp = defaultCmp
|
||||
|
||||
var i = indexOf(list, value, cmp)
|
||||
if (i === -1) return -1
|
||||
|
||||
for (; i < list.length; i++) {
|
||||
var c = cmp(list[i], value)
|
||||
if (c >= 0) return i
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
function gt (list, value, cmp) {
|
||||
if (!cmp) cmp = defaultCmp
|
||||
|
||||
var i = indexOf(list, value, cmp)
|
||||
if (i === -1) return -1
|
||||
|
||||
for (; i < list.length; i++) {
|
||||
var c = cmp(list[i], value)
|
||||
if (c > 0) return i
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
function eq (list, value, cmp) {
|
||||
if (!cmp) cmp = defaultCmp
|
||||
|
||||
var i = indexOf(list, value, cmp)
|
||||
if (i === -1) return -1
|
||||
return cmp(list[i], value) === 0 ? i : -1
|
||||
}
|
||||
|
||||
function nearest (list, value, cmp) {
|
||||
if (!cmp) cmp = defaultCmp
|
||||
|
||||
var len = list.length
|
||||
var top = len - 1
|
||||
var btm = 0
|
||||
var mid = -1
|
||||
var trending = 1 // 0 = down, 2 = up
|
||||
|
||||
while (top >= btm && btm >= 0 && top < len) {
|
||||
mid = Math.floor((top + btm) / 2)
|
||||
|
||||
var c = cmp(list[mid], value)
|
||||
if (c === 0) return mid
|
||||
|
||||
if (c >= 0) {
|
||||
if (trending === 1) trending = 0
|
||||
else if (trending === 2) {
|
||||
if (Math.abs(list[mid] - value) > Math.abs(list[mid - 1] - value)) return mid - 1
|
||||
return mid
|
||||
}
|
||||
|
||||
top = mid - 1
|
||||
} else {
|
||||
if (trending === 1) trending = 2
|
||||
else if (trending === 0) return mid
|
||||
|
||||
btm = mid + 1
|
||||
}
|
||||
}
|
||||
|
||||
return mid
|
||||
}
|
||||
|
||||
function indexOf (list, value, cmp) {
|
||||
if (!cmp) cmp = defaultCmp
|
||||
|
||||
var len = list.length
|
||||
var top = len - 1
|
||||
var btm = 0
|
||||
var mid = -1
|
||||
|
||||
while (top >= btm && btm >= 0 && top < len) {
|
||||
mid = Math.floor((top + btm) / 2)
|
||||
|
||||
var c = cmp(list[mid], value)
|
||||
if (c === 0) return mid
|
||||
|
||||
if (c >= 0) {
|
||||
top = mid - 1
|
||||
} else {
|
||||
btm = mid + 1
|
||||
}
|
||||
}
|
||||
|
||||
return mid
|
||||
}
|
||||
|
||||
function has (list, value, cmp) {
|
||||
return eq(list, value, cmp) > -1
|
||||
}
|
||||
|
||||
function remove (list, value, cmp) {
|
||||
var i = eq(list, value, cmp)
|
||||
if (i === -1) return false
|
||||
list.splice(i, 1)
|
||||
return true
|
||||
}
|
||||
55
nodejs/node_modules/sorted-array-functions/package.json
generated
vendored
Executable file
55
nodejs/node_modules/sorted-array-functions/package.json
generated
vendored
Executable file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"sorted-array-functions@1.2.0",
|
||||
"/www/wwwroot/Adminx.cc/nodejs"
|
||||
]
|
||||
],
|
||||
"_from": "sorted-array-functions@1.2.0",
|
||||
"_id": "sorted-array-functions@1.2.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-sWpjPhIZJtqO77GN+LD8dDsDKcWZ9GCOJNqKzi1tvtjGIzwfoyuRH8S0psunmc6Z5P+qfDqztSbwYR5X/e1UTg==",
|
||||
"_location": "/sorted-array-functions",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "sorted-array-functions@1.2.0",
|
||||
"name": "sorted-array-functions",
|
||||
"escapedName": "sorted-array-functions",
|
||||
"rawSpec": "1.2.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.2.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-schedule"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/sorted-array-functions/-/sorted-array-functions-1.2.0.tgz",
|
||||
"_spec": "1.2.0",
|
||||
"_where": "/www/wwwroot/Adminx.cc/nodejs",
|
||||
"author": {
|
||||
"name": "Mathias Buus",
|
||||
"url": "@mafintosh"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/sorted-array-functions/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Maintain and search through a sorted array using some low level functions",
|
||||
"devDependencies": {
|
||||
"standard": "^8.4.0",
|
||||
"tape": "^4.6.2"
|
||||
},
|
||||
"homepage": "https://github.com/mafintosh/sorted-array-functions",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "sorted-array-functions",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mafintosh/sorted-array-functions.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test.js"
|
||||
},
|
||||
"version": "1.2.0"
|
||||
}
|
||||
366
nodejs/node_modules/sorted-array-functions/test.js
generated
vendored
Executable file
366
nodejs/node_modules/sorted-array-functions/test.js
generated
vendored
Executable file
@ -0,0 +1,366 @@
|
||||
var tape = require('tape')
|
||||
var sorted = require('./')
|
||||
|
||||
tape('add', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 3)
|
||||
sorted.add(list, 4)
|
||||
sorted.add(list, 3)
|
||||
sorted.add(list, 9)
|
||||
sorted.add(list, 0)
|
||||
sorted.add(list, 5)
|
||||
sorted.add(list, 8)
|
||||
|
||||
t.same(list, [0, 3, 3, 4, 5, 8, 9])
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('remove', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 3)
|
||||
sorted.add(list, 4)
|
||||
sorted.add(list, 3)
|
||||
sorted.add(list, 9)
|
||||
sorted.add(list, 0)
|
||||
sorted.add(list, 5)
|
||||
sorted.add(list, 8)
|
||||
|
||||
sorted.remove(list, 3)
|
||||
sorted.remove(list, 5)
|
||||
sorted.remove(list, 6)
|
||||
|
||||
t.same(list, [0, 3, 4, 8, 9])
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('has', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 3)
|
||||
t.same(sorted.has(list, 3), true)
|
||||
t.same(sorted.has(list, 2), false)
|
||||
|
||||
sorted.add(list, 5)
|
||||
t.same(sorted.has(list, 5), true)
|
||||
t.same(sorted.has(list, 3), true)
|
||||
t.same(sorted.has(list, 2), false)
|
||||
|
||||
sorted.add(list, 1)
|
||||
t.same(sorted.has(list, 1), true)
|
||||
t.same(sorted.has(list, 5), true)
|
||||
t.same(sorted.has(list, 3), true)
|
||||
t.same(sorted.has(list, 2), false)
|
||||
t.same(sorted.has(list, 8), false)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('eq', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 3)
|
||||
t.same(sorted.eq(list, 3), 0)
|
||||
t.same(sorted.eq(list, 2), -1)
|
||||
|
||||
sorted.add(list, 5)
|
||||
t.same(sorted.eq(list, 5), 1)
|
||||
t.same(sorted.eq(list, 3), 0)
|
||||
t.same(sorted.eq(list, 2), -1)
|
||||
|
||||
sorted.add(list, 1)
|
||||
t.same(sorted.eq(list, 1), 0)
|
||||
t.same(sorted.eq(list, 5), 2)
|
||||
t.same(sorted.eq(list, 3), 1)
|
||||
t.same(sorted.eq(list, 2), -1)
|
||||
t.same(sorted.eq(list, 8), -1)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('gte', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 3)
|
||||
t.same(sorted.gte(list, 3), 0)
|
||||
t.same(sorted.gte(list, 2), 0)
|
||||
|
||||
sorted.add(list, 5)
|
||||
t.same(sorted.gte(list, 5), 1)
|
||||
t.same(sorted.gte(list, 3), 0)
|
||||
t.same(sorted.gte(list, 2), 0)
|
||||
|
||||
sorted.add(list, 1)
|
||||
t.same(sorted.gte(list, 1), 0)
|
||||
t.same(sorted.gte(list, 5), 2)
|
||||
t.same(sorted.gte(list, 3), 1)
|
||||
t.same(sorted.gte(list, 2), 1)
|
||||
t.same(sorted.gte(list, 8), -1)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('gt', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 3)
|
||||
t.same(sorted.gt(list, 3), -1)
|
||||
t.same(sorted.gt(list, 2), 0)
|
||||
|
||||
sorted.add(list, 5)
|
||||
t.same(sorted.gt(list, 5), -1)
|
||||
t.same(sorted.gt(list, 3), 1)
|
||||
t.same(sorted.gt(list, 2), 0)
|
||||
|
||||
sorted.add(list, 1)
|
||||
t.same(sorted.gt(list, 1), 1)
|
||||
t.same(sorted.gt(list, 5), -1)
|
||||
t.same(sorted.gt(list, 3), 2)
|
||||
t.same(sorted.gt(list, 2), 1)
|
||||
t.same(sorted.gt(list, 8), -1)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('lte', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 3)
|
||||
t.same(sorted.lte(list, 3), 0)
|
||||
t.same(sorted.lte(list, 2), -1)
|
||||
|
||||
sorted.add(list, 5)
|
||||
t.same(sorted.lte(list, 6), 1)
|
||||
t.same(sorted.lte(list, 5), 1)
|
||||
t.same(sorted.lte(list, 3), 0)
|
||||
t.same(sorted.lte(list, 2), -1)
|
||||
|
||||
sorted.add(list, 1)
|
||||
t.same(sorted.lte(list, 1), 0)
|
||||
t.same(sorted.lte(list, 5), 2)
|
||||
t.same(sorted.lte(list, 3), 1)
|
||||
t.same(sorted.lte(list, 2), 0)
|
||||
t.same(sorted.lte(list, 8), 2)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('lt', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 3)
|
||||
t.same(sorted.lt(list, 3), -1)
|
||||
t.same(sorted.lt(list, 2), -1)
|
||||
t.same(sorted.lt(list, 4), 0)
|
||||
|
||||
sorted.add(list, 5)
|
||||
t.same(sorted.lt(list, 6), 1)
|
||||
t.same(sorted.lt(list, 5), 0)
|
||||
t.same(sorted.lt(list, 3), -1)
|
||||
t.same(sorted.lt(list, 2), -1)
|
||||
|
||||
sorted.add(list, 1)
|
||||
t.same(sorted.lt(list, 1), -1)
|
||||
t.same(sorted.lt(list, 5), 1)
|
||||
t.same(sorted.lt(list, 3), 0)
|
||||
t.same(sorted.lt(list, 2), 0)
|
||||
t.same(sorted.lt(list, 8), 2)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom compare add', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
sorted.add(list, {foo: 4}, cmp)
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
sorted.add(list, {foo: 9}, cmp)
|
||||
sorted.add(list, {foo: 0}, cmp)
|
||||
sorted.add(list, {foo: 5}, cmp)
|
||||
sorted.add(list, {foo: 8}, cmp)
|
||||
|
||||
t.same(list, [{foo: 0}, {foo: 3}, {foo: 3}, {foo: 4}, {foo: 5}, {foo: 8}, {foo: 9}])
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom compare remove', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
sorted.add(list, {foo: 4}, cmp)
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
sorted.add(list, {foo: 9}, cmp)
|
||||
sorted.add(list, {foo: 0}, cmp)
|
||||
sorted.add(list, {foo: 5}, cmp)
|
||||
sorted.add(list, {foo: 8}, cmp)
|
||||
|
||||
sorted.remove(list, {foo: 3}, cmp)
|
||||
sorted.remove(list, {foo: 5}, cmp)
|
||||
sorted.remove(list, {foo: 6}, cmp)
|
||||
|
||||
t.same(list, [{foo: 0}, {foo: 3}, {foo: 4}, {foo: 8}, {foo: 9}])
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom compare has', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
t.same(sorted.has(list, {foo: 3}, cmp), true)
|
||||
t.same(sorted.has(list, {foo: 2}, cmp), false)
|
||||
|
||||
sorted.add(list, {foo: 5}, cmp)
|
||||
t.same(sorted.has(list, {foo: 5}, cmp), true)
|
||||
t.same(sorted.has(list, {foo: 3}, cmp), true)
|
||||
t.same(sorted.has(list, {foo: 2}, cmp), false)
|
||||
|
||||
sorted.add(list, {foo: 1}, cmp)
|
||||
t.same(sorted.has(list, {foo: 1}, cmp), true)
|
||||
t.same(sorted.has(list, {foo: 5}, cmp), true)
|
||||
t.same(sorted.has(list, {foo: 3}, cmp), true)
|
||||
t.same(sorted.has(list, {foo: 2}, cmp), false)
|
||||
t.same(sorted.has(list, {foo: 8}, cmp), false)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom compare eq', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
t.same(sorted.eq(list, {foo: 3}, cmp), 0)
|
||||
t.same(sorted.eq(list, {foo: 2}, cmp), -1)
|
||||
|
||||
sorted.add(list, {foo: 5}, cmp)
|
||||
t.same(sorted.eq(list, {foo: 5}, cmp), 1)
|
||||
t.same(sorted.eq(list, {foo: 3}, cmp), 0)
|
||||
t.same(sorted.eq(list, {foo: 2}, cmp), -1)
|
||||
|
||||
sorted.add(list, {foo: 1}, cmp)
|
||||
t.same(sorted.eq(list, {foo: 1}, cmp), 0)
|
||||
t.same(sorted.eq(list, {foo: 5}, cmp), 2)
|
||||
t.same(sorted.eq(list, {foo: 3}, cmp), 1)
|
||||
t.same(sorted.eq(list, {foo: 2}, cmp), -1)
|
||||
t.same(sorted.eq(list, {foo: 8}, cmp), -1)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom compare gte', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
t.same(sorted.gte(list, {foo: 3}, cmp), 0)
|
||||
t.same(sorted.gte(list, {foo: 2}, cmp), 0)
|
||||
|
||||
sorted.add(list, {foo: 5}, cmp)
|
||||
t.same(sorted.gte(list, {foo: 5}, cmp), 1)
|
||||
t.same(sorted.gte(list, {foo: 3}, cmp), 0)
|
||||
t.same(sorted.gte(list, {foo: 2}, cmp), 0)
|
||||
|
||||
sorted.add(list, {foo: 1}, cmp)
|
||||
t.same(sorted.gte(list, {foo: 1}, cmp), 0)
|
||||
t.same(sorted.gte(list, {foo: 5}, cmp), 2)
|
||||
t.same(sorted.gte(list, {foo: 3}, cmp), 1)
|
||||
t.same(sorted.gte(list, {foo: 2}, cmp), 1)
|
||||
t.same(sorted.gte(list, {foo: 8}, cmp), -1)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom compare gt', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
t.same(sorted.gt(list, {foo: 3}, cmp), -1)
|
||||
t.same(sorted.gt(list, {foo: 2}, cmp), 0)
|
||||
|
||||
sorted.add(list, {foo: 5}, cmp)
|
||||
t.same(sorted.gt(list, {foo: 5}, cmp), -1)
|
||||
t.same(sorted.gt(list, {foo: 3}, cmp), 1)
|
||||
t.same(sorted.gt(list, {foo: 2}, cmp), 0)
|
||||
|
||||
sorted.add(list, {foo: 1}, cmp)
|
||||
t.same(sorted.gt(list, {foo: 1}, cmp), 1)
|
||||
t.same(sorted.gt(list, {foo: 5}, cmp), -1)
|
||||
t.same(sorted.gt(list, {foo: 3}, cmp), 2)
|
||||
t.same(sorted.gt(list, {foo: 2}, cmp), 1)
|
||||
t.same(sorted.gt(list, {foo: 8}, cmp), -1)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom compare lte', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
t.same(sorted.lte(list, {foo: 3}, cmp), 0)
|
||||
t.same(sorted.lte(list, {foo: 2}, cmp), -1)
|
||||
|
||||
sorted.add(list, {foo: 5}, cmp)
|
||||
t.same(sorted.lte(list, {foo: 6}, cmp), 1)
|
||||
t.same(sorted.lte(list, {foo: 5}, cmp), 1)
|
||||
t.same(sorted.lte(list, {foo: 3}, cmp), 0)
|
||||
t.same(sorted.lte(list, {foo: 2}, cmp), -1)
|
||||
|
||||
sorted.add(list, {foo: 1}, cmp)
|
||||
t.same(sorted.lte(list, {foo: 1}, cmp), 0)
|
||||
t.same(sorted.lte(list, {foo: 5}, cmp), 2)
|
||||
t.same(sorted.lte(list, {foo: 3}, cmp), 1)
|
||||
t.same(sorted.lte(list, {foo: 2}, cmp), 0)
|
||||
t.same(sorted.lte(list, {foo: 8}, cmp), 2)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom compare lt', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, {foo: 3}, cmp)
|
||||
t.same(sorted.lt(list, {foo: 3}, cmp), -1)
|
||||
t.same(sorted.lt(list, {foo: 2}, cmp), -1)
|
||||
t.same(sorted.lt(list, {foo: 4}, cmp), 0)
|
||||
|
||||
sorted.add(list, {foo: 5}, cmp)
|
||||
t.same(sorted.lt(list, {foo: 6}, cmp), 1)
|
||||
t.same(sorted.lt(list, {foo: 5}, cmp), 0)
|
||||
t.same(sorted.lt(list, {foo: 3}, cmp), -1)
|
||||
t.same(sorted.lt(list, {foo: 2}, cmp), -1)
|
||||
|
||||
sorted.add(list, {foo: 1}, cmp)
|
||||
t.same(sorted.lt(list, {foo: 1}, cmp), -1)
|
||||
t.same(sorted.lt(list, {foo: 5}, cmp), 1)
|
||||
t.same(sorted.lt(list, {foo: 3}, cmp), 0)
|
||||
t.same(sorted.lt(list, {foo: 2}, cmp), 0)
|
||||
t.same(sorted.lt(list, {foo: 8}, cmp), 2)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('find nearest value', function (t) {
|
||||
var list = []
|
||||
|
||||
sorted.add(list, 0.001)
|
||||
sorted.add(list, 10)
|
||||
sorted.add(list, 20)
|
||||
sorted.add(list, 30)
|
||||
sorted.add(list, 40)
|
||||
sorted.add(list, 50)
|
||||
sorted.add(list, 70)
|
||||
|
||||
t.equal(sorted.nearest(list, 66), 6)
|
||||
t.equal(sorted.nearest(list, 51), 5)
|
||||
t.equal(sorted.nearest(list, 1), 0)
|
||||
t.equal(sorted.nearest(list, 0), 0)
|
||||
t.equal(sorted.nearest(list, 69.999), 6)
|
||||
t.equal(sorted.nearest(list, 72), 6)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
function cmp (a, b) {
|
||||
return a.foo - b.foo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user