Comparing version 1.1.1 to 1.1.2
@@ -63,5 +63,3 @@ 'use strict'; | ||
} else if (options.getValues) { | ||
result = result.concat(node.v[i].reduce(function (a, b) { | ||
return a.concat(b); | ||
}, [])); | ||
result.push(node.v[i]); | ||
} else { | ||
@@ -74,6 +72,8 @@ result[node.k[i]] = node.v[i]; | ||
walk(this.tree); | ||
var out = result.length && Array.isArray(result[0]) ? Array.prototype.concat.apply([], result) : result; | ||
if ((options.getKeys || options.getValues) && options.descending) { | ||
return result.reverse(); | ||
return out.reverse(); | ||
} | ||
return result; | ||
return out; | ||
} | ||
@@ -108,3 +108,2 @@ | ||
if (this.cmpFn(lo, leaf.k[leaf.k.length - 1]) === 1) { | ||
// use cmpFn here | ||
return []; | ||
@@ -128,5 +127,3 @@ } | ||
// if key at current index is upper bound, concat all vals and stop | ||
result = result.concat(leaf.v[index]).reduce(function (a, b) { | ||
return a.concat(b); | ||
}, []); | ||
result.push(leaf.v[index]); | ||
break; | ||
@@ -136,11 +133,7 @@ } | ||
// if last key is upper bound, concat all vals and stop | ||
result = result.concat(leaf.v.slice(index)).reduce(function (a, b) { | ||
return a.concat(b); | ||
}, []); | ||
result.push(leaf.v.slice(index)); | ||
break; | ||
} else if (this.cmpFn(leaf.k[leaf.k.length - 1], hi) === -1) { | ||
// if last key is smaller than upper bound, fetch next leaf and iterate | ||
result = result.concat(leaf.v.slice(index)).reduce(function (a, b) { | ||
return a.concat(b); | ||
}, []); | ||
result.push(leaf.v.slice(index)); | ||
if (leaf.n !== null) { | ||
@@ -156,5 +149,3 @@ leaf = this.fetch(leaf.n, { getLeaf: true }); | ||
for (; leaf.k[i] <= hi; i++) {} | ||
result = result.concat(leaf.v.slice(0, i)).reduce(function (a, b) { | ||
return a.concat(b); | ||
}, []); | ||
result.push(leaf.v.slice(0, i)); | ||
break; | ||
@@ -164,2 +155,8 @@ } | ||
if (Array.isArray(result[0])) { | ||
result = Array.prototype.concat.apply([], Array.prototype.concat.apply([], result)); | ||
} else { | ||
result = Array.prototype.concat.apply([], result); | ||
} | ||
if (options.descending) { | ||
@@ -166,0 +163,0 @@ result.reverse(); |
@@ -38,3 +38,3 @@ /** Class representing a B+ Tree. */ | ||
options || (options = {}); | ||
let result = (options.getKeys || options.getValues) ? [] : {}; | ||
const result = (options.getKeys || options.getValues) ? [] : {}; | ||
function walk(node) { | ||
@@ -51,3 +51,3 @@ if (node.t === 'branch') { | ||
} else if (options.getValues) { | ||
result = result.concat(node.v[i].reduce((a, b) => a.concat(b), [])); | ||
result.push(node.v[i]); | ||
} else { | ||
@@ -60,6 +60,9 @@ result[node.k[i]] = node.v[i]; | ||
walk(this.tree); | ||
const out = (result.length && Array.isArray(result[0])) ? | ||
Array.prototype.concat.apply([], result) : result; | ||
if ((options.getKeys || options.getValues) && options.descending) { | ||
return result.reverse(); | ||
return out.reverse(); | ||
} | ||
return result; | ||
return out; | ||
} | ||
@@ -89,3 +92,3 @@ | ||
} | ||
if (this.cmpFn(lo, leaf.k[leaf.k.length - 1]) === 1) { // use cmpFn here | ||
if (this.cmpFn(lo, leaf.k[leaf.k.length - 1]) === 1) { | ||
return []; | ||
@@ -109,3 +112,3 @@ } | ||
// if key at current index is upper bound, concat all vals and stop | ||
result = result.concat(leaf.v[index]).reduce((a, b) => a.concat(b), []); | ||
result.push(leaf.v[index]); | ||
break; | ||
@@ -115,7 +118,7 @@ } | ||
// if last key is upper bound, concat all vals and stop | ||
result = result.concat(leaf.v.slice(index)).reduce((a, b) => a.concat(b), []); | ||
result.push(leaf.v.slice(index)); | ||
break; | ||
} else if (this.cmpFn(leaf.k[leaf.k.length - 1], hi) === -1) { | ||
// if last key is smaller than upper bound, fetch next leaf and iterate | ||
result = result.concat(leaf.v.slice(index)).reduce((a, b) => a.concat(b), []); | ||
result.push(leaf.v.slice(index)); | ||
if (leaf.n !== null) { | ||
@@ -131,3 +134,3 @@ leaf = this.fetch(leaf.n, { getLeaf: true }); | ||
for (; leaf.k[i] <= hi; i++); | ||
result = result.concat(leaf.v.slice(0, i)).reduce((a, b) => a.concat(b), []); | ||
result.push(leaf.v.slice(0, i)); | ||
break; | ||
@@ -137,2 +140,8 @@ } | ||
if (Array.isArray(result[0])) { | ||
result = Array.prototype.concat.apply([], Array.prototype.concat.apply([], result)); | ||
} else { | ||
result = Array.prototype.concat.apply([], result); | ||
} | ||
if (options.descending) { | ||
@@ -139,0 +148,0 @@ result.reverse(); |
{ | ||
"name": "bplustree", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "test": "mocha --compilers js:babel-core/register --check-leaks test/bplustree.js && npm run build", |
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
2086
1120602