Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bplustree

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bplustree - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

25

dist/bplustree.js
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -215,3 +213,3 @@

var returned, leaf, i, length, remainder;
var returned, leaf, index, i, length, remainder;
return regeneratorRuntime.wrap(function values$(_context) {

@@ -224,3 +222,3 @@ while (1) {

if ((typeof key === 'undefined' ? 'undefined' : _typeof(key)) === undefined) {
if (typeof key === 'undefined') {
key = -Infinity;

@@ -244,5 +242,10 @@ keyNotFound = 'right';

i = 0;
index = leaf.k.indexOf(key);
case 8:
if (index === -1) {
index = 0;
}
i = index;
case 10:
if (!(i < leaf.v.length)) {

@@ -265,3 +268,3 @@ _context.next = 26;

if (!(remainder >= 0)) {
_context.next = 15;
_context.next = 17;
break;

@@ -272,8 +275,4 @@ }

case 15:
_context.next = 17;
return leaf.v[i];
case 17:
if (!(target && leaf.v[i].indexOf(target) !== -1)) {
if (!(target === leaf.v[i][0])) {
_context.next = 19;

@@ -299,3 +298,3 @@ break;

i++;
_context.next = 8;
_context.next = 10;
break;

@@ -302,0 +301,0 @@

@@ -165,3 +165,3 @@ import 'regenerator-runtime/runtime';

let leaf;
if (typeof key === undefined) {
if (typeof key === 'undefined') {
key = -Infinity;

@@ -176,3 +176,7 @@ keyNotFound = 'right';

while (true) {
for (let i = 0; i < leaf.v.length; i++) {
let index = leaf.k.indexOf(key);
if (index === -1) {
index = 0;
}
for (let i = index; i < leaf.v.length; i++) {
const length = leaf.v[i].length;

@@ -185,5 +189,4 @@ returned += length;

}
yield leaf.v[i];
}
if (target && leaf.v[i].indexOf(target) !== -1) {
if (target === leaf.v[i][0]) {
return leaf.v[i];

@@ -190,0 +193,0 @@ }

{
"name": "bplustree",
"version": "1.2.0",
"version": "1.2.1",
"scripts": {

@@ -5,0 +5,0 @@ "test": "mocha --compilers js:babel-core/register --check-leaks test/bplustree.js && npm run build",

@@ -134,9 +134,9 @@ /* eslint-env node, mocha */

it('should generate', () => {
const tree = setup();
let tree = setup();
let generator;
// limit is respected
generator = tree.values({ key: 2, targetValue: 'n', limit: 4 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
generator = tree.values({ key: 2, target: 'n', limit: 4 });
assert.deepEqual(generator.next(), { value: ['b'], done: false });
assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: true });
assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });
assert.deepEqual(generator.next(), { value: ['d'], done: true });

@@ -158,11 +158,10 @@ // limit is respected

// limit is respected although targetValue isn't found
generator = tree.values({ key: 2, targetValue: 'n', limit: 4 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
// limit is respected although target isn't found
generator = tree.values({ key: 2, target: 'n', limit: 4 });
assert.deepEqual(generator.next(), { value: ['b'], done: false });
assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: true });
assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });
assert.deepEqual(generator.next(), { value: ['d'], done: true });
// targetValue is respected before limit is reached
generator = tree.values({ key: 2, targetValue: 'n', limit: 10 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
// target is respected before limit is reached
generator = tree.values({ key: 2, target: 'n', limit: 10 });
assert.deepEqual(generator.next(), { value: ['b'], done: false });

@@ -174,12 +173,12 @@ assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });

assert.deepEqual(generator.next(), { value: ['h'], done: false });
assert.deepEqual(generator.next(), { value: ['m'], done: true });
assert.deepEqual(generator.next(), { value: ['m'], done: false });
assert.deepEqual(generator.next(), { value: ['n'], done: true });
// key doesn't exist: not there
// user might want to use `keyNotFound`
generator = tree.values({ key: 7, targetValue: 'n', limit: 10 });
generator = tree.values({ key: 7, target: 'n', limit: 10 });
assert.deepEqual(generator.next(), { value: false, done: true });
// limit is bigger than the number of remaining values
generator = tree.values({ key: 2, targetValue: 'n', limit: 250 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
generator = tree.values({ key: 2, target: 'n', limit: 250 });
assert.deepEqual(generator.next(), { value: ['b'], done: false });

@@ -192,8 +191,8 @@ assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });

assert.deepEqual(generator.next(), { value: ['m'], done: false });
assert.deepEqual(generator.next(), { value: ['n'], done: false });
assert.deepEqual(generator.next(), { value: ['p'], done: true });
assert.deepEqual(generator.next(), { value: ['n'], done: true });
// continues
assert.deepEqual(generator.next(), { value: undefined, done: true });
// targetValue not found, generate until the end
generator = tree.values({ key: 2, targetValue: 'z' });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
// target not found, generate until the end
generator = tree.values({ key: 2, target: 'zz' });
assert.deepEqual(generator.next(), { value: ['b'], done: false });

@@ -209,4 +208,4 @@ assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });

// targetValue not found, generate until the end
generator = tree.values({ key: 8, targetValue: 'z' });
// target not found, generate until the end
generator = tree.values({ key: 8, target: 'zzz' });
assert.deepEqual(generator.next(), { value: ['h'], done: false });

@@ -217,5 +216,4 @@ assert.deepEqual(generator.next(), { value: ['m'], done: false });

// targetValue not found, generate until limit
generator = tree.values({ key: 2, targetValue: 'z', limit: 10 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
// target not found, generate until limit
generator = tree.values({ key: 2, target: 'z', limit: 10 });
assert.deepEqual(generator.next(), { value: ['b'], done: false });

@@ -227,5 +225,6 @@ assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });

assert.deepEqual(generator.next(), { value: ['h'], done: false });
assert.deepEqual(generator.next(), { value: ['m'], done: true });
assert.deepEqual(generator.next(), { value: ['m'], done: false });
assert.deepEqual(generator.next(), { value: ['n'], done: true });
// no targetValue
// no target
generator = tree.values({ key: 1, limit: 10 });

@@ -242,5 +241,3 @@ assert.deepEqual(generator.next(), { value: ['z'], done: false });

// no limit
generator = tree.values({ key: 2, targetValue: 'n' });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b'], done: false });
generator = tree.values({ key: 3, target: 'n' });
assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });

@@ -252,8 +249,6 @@ assert.deepEqual(generator.next(), { value: ['d'], done: false });

assert.deepEqual(generator.next(), { value: ['m'], done: false });
assert.deepEqual(generator.next(), { value: ['n'], done: false });
assert.deepEqual(generator.next(), { value: ['p'], done: true });
assert.deepEqual(generator.next(), { value: ['n'], done: true });
// no limit
generator = tree.values({ key: 2 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b'], done: false });

@@ -270,15 +265,67 @@ assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });

// no key, assume first key, limit respected
generator = tree.values({ targetValue: 'n', limit: 5 });
assert.deepEqual(generator.next(), { value: ['n'], done: false });
assert.deepEqual(generator.next(), { value: ['p'], done: true });
generator = tree.values({ target: 'n', limit: 5 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b'], done: false });
assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });
assert.deepEqual(generator.next(), { value: ['d'], done: true });
// no key, assume first key, targetValue
generator = tree.values({ targetValue: 'd', limit: 10 });
assert.deepEqual(generator.next(), { value: ['n'], done: false });
assert.deepEqual(generator.next(), { value: ['p'], done: true });
// no key, assume first key, target
generator = tree.values({ target: 'd', limit: 10 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b'], done: false });
assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });
assert.deepEqual(generator.next(), { value: ['d'], done: true });
// nothing, generate everything
generator = tree.values();
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b'], done: false });
assert.deepEqual(generator.next(), { value: ['c', 'c2'], done: false });
assert.deepEqual(generator.next(), { value: ['d'], done: false });
assert.deepEqual(generator.next(), { value: ['e'], done: false });
assert.deepEqual(generator.next(), { value: ['f', 'g'], done: false });
assert.deepEqual(generator.next(), { value: ['h'], done: false });
assert.deepEqual(generator.next(), { value: ['m'], done: false });
assert.deepEqual(generator.next(), { value: ['n'], done: false });
assert.deepEqual(generator.next(), { value: ['p'], done: true });
tree = new BPlusTree({ order: 6, debug: true });
const data = [[1, 'z'], [2, 'b'], [2, 'b2'], [2, 'b3'], [2, 'b4'], [5, 'e']];
for (let i = 0; i < data.length; i++) {
tree.store(data[i][0], data[i][1]);
}
// limit is respected
generator = tree.values({ key: 1, limit: 1 });
assert.deepEqual(generator.next(), { value: ['z'], done: true });
// limit is respected
generator = tree.values({ key: 1, limit: 2 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b'], done: true });
// limit is respected
generator = tree.values({ key: 1, limit: 3 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b', 'b2'], done: true });
// limit is respected
generator = tree.values({ key: 1, limit: 4 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b', 'b2', 'b3'], done: true });
// limit is respected
generator = tree.values({ key: 1, limit: 5 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b', 'b2', 'b3', 'b4'], done: true });
// limit is respected
generator = tree.values({ key: 1, limit: 6 });
assert.deepEqual(generator.next(), { value: ['z'], done: false });
assert.deepEqual(generator.next(), { value: ['b', 'b2', 'b3', 'b4'], done: false });
assert.deepEqual(generator.next(), { value: ['e'], done: true });
// limit is respected
generator = tree.values({ key: 2, limit: 2 });
assert.deepEqual(generator.next(), { value: ['b', 'b2'], done: true });
});

@@ -285,0 +332,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc