Socket
Socket
Sign inDemoInstall

@rimbu/list

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rimbu/list - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1

dist/main/builder/leaf/tree-builder.js

9

dist/main/builder/gen-builder.js

@@ -82,8 +82,11 @@ "use strict";

else {
if (index === 0)
if (index === 0) {
return _this.prepend(value);
if (index > _this.length || -index > _this.length + 1)
}
if (index > _this.length || -index > _this.length + 1) {
return _this.append(value);
if (index < 0)
}
if (index < 0) {
return _this.insert(_this.length + index, value);
}
_this.builder.insert(index, value);

@@ -90,0 +93,0 @@ _this.builder = _this.builder.normalized();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NonLeafTreeBuilder = exports.LeafTreeBuilder = exports.TreeBuilderBase = void 0;
var tslib_1 = require("tslib");
exports.TreeBuilderBase = void 0;
var common_1 = require("@rimbu/common");
var list_custom_1 = require("../../list-custom");
var TreeBuilderBase = /** @class */ (function () {

@@ -193,4 +191,5 @@ function TreeBuilderBase() {

});
if (undefined !== delta)
if (undefined !== delta) {
return;
}
}

@@ -377,241 +376,2 @@ else if (this.right.nrChildren < this.context.maxBlockSize) {

exports.TreeBuilderBase = TreeBuilderBase;
var LeafTreeBuilder = /** @class */ (function (_super) {
(0, tslib_1.__extends)(LeafTreeBuilder, _super);
function LeafTreeBuilder(context, source, _left, _right, _middle, length) {
if (length === void 0) { length = (_a = source === null || source === void 0 ? void 0 : source.length) !== null && _a !== void 0 ? _a : 0; }
var _a;
var _this = _super.call(this) || this;
_this.context = context;
_this.source = source;
_this._left = _left;
_this._right = _right;
_this._middle = _middle;
_this.length = length;
return _this;
}
LeafTreeBuilder.prototype.prepareMutate = function () {
if (undefined !== this.source) {
this._left = this.context.leafBlockBuilderSource(this.source.left);
this._right = this.context.leafBlockBuilderSource(this.source.right);
this._middle =
null === this.source.middle
? undefined
: (0, list_custom_1.createNonLeaf)(this.source.middle);
this.source = undefined;
}
};
Object.defineProperty(LeafTreeBuilder.prototype, "level", {
get: function () {
return 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(LeafTreeBuilder.prototype, "left", {
get: function () {
this.prepareMutate();
return this._left;
},
set: function (value) {
this.prepareMutate();
this._left = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(LeafTreeBuilder.prototype, "right", {
get: function () {
this.prepareMutate();
return this._right;
},
set: function (value) {
this.prepareMutate();
this._right = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(LeafTreeBuilder.prototype, "middle", {
get: function () {
this.prepareMutate();
return this._middle;
},
set: function (value) {
this.prepareMutate();
this._middle = value;
},
enumerable: false,
configurable: true
});
LeafTreeBuilder.prototype.getChildLength = function () {
return 1;
};
LeafTreeBuilder.prototype.appendChildren = function (children, from) {
if (children.length === 0 || from >= children.length)
return;
if (this.right.nrChildren < this.context.maxBlockSize) {
var items = children.slice(from, from + this.context.maxBlockSize - this.right.nrChildren);
this.right.children = this.right.children.concat(items);
this.length += items.length;
this.appendChildren(children, from + items.length);
return;
}
var block = children.slice(from, from + this.context.maxBlockSize);
this.appendMiddle(this.right);
this.right = this.context.leafBlockBuilder(block);
this.length += block.length;
this.appendChildren(children, from + block.length);
};
LeafTreeBuilder.prototype.normalized = function () {
if (this.length <= this.context.maxBlockSize) {
this.left.concat(this.right);
return this.left;
}
if (undefined !== this.middle) {
if (this.middle.length + this.left.length <= this.context.maxBlockSize) {
this.left.concat(this.middle.first());
this.middle = undefined;
}
else if (this.middle.length + this.right.length <=
this.context.maxBlockSize) {
var newRight = this.middle.last();
newRight.concat(this.right);
this.right = newRight;
this.middle = undefined;
}
}
return this;
};
LeafTreeBuilder.prototype.get = function (index, otherwise) {
if (undefined !== this.source)
return this.source.get(index, otherwise);
return _super.prototype.get.call(this, index, otherwise);
};
LeafTreeBuilder.prototype.build = function () {
if (undefined !== this.source)
return this.source;
return this.context.leafTree(this.left.build(), this.right.build(), undefined === this.middle ? null : this.middle.build());
};
LeafTreeBuilder.prototype.buildMap = function (f) {
if (undefined !== this.source)
return this.source.map(f);
return this.context.leafTree(this.left.buildMap(f), this.right.buildMap(f), undefined === this.middle ? null : this.middle.buildMap(f));
};
return LeafTreeBuilder;
}(TreeBuilderBase));
exports.LeafTreeBuilder = LeafTreeBuilder;
var NonLeafTreeBuilder = /** @class */ (function (_super) {
(0, tslib_1.__extends)(NonLeafTreeBuilder, _super);
function NonLeafTreeBuilder(context, level, source, _left, _right, _middle, length) {
if (length === void 0) { length = (_a = source === null || source === void 0 ? void 0 : source.length) !== null && _a !== void 0 ? _a : 0; }
var _a;
var _this = _super.call(this) || this;
_this.context = context;
_this.level = level;
_this.source = source;
_this._left = _left;
_this._right = _right;
_this._middle = _middle;
_this.length = length;
return _this;
}
NonLeafTreeBuilder.prototype.prepareMutate = function () {
if (undefined !== this.source) {
this._left = (0, list_custom_1.createFromBlock)(this.source.left);
this._right = (0, list_custom_1.createFromBlock)(this.source.right);
this._middle =
null === this.source.middle
? undefined
: (0, list_custom_1.createNonLeaf)(this.source.middle);
this.source = undefined;
}
};
Object.defineProperty(NonLeafTreeBuilder.prototype, "left", {
get: function () {
this.prepareMutate();
return this._left;
},
set: function (value) {
this.prepareMutate();
this._left = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NonLeafTreeBuilder.prototype, "right", {
get: function () {
this.prepareMutate();
return this._right;
},
set: function (value) {
this.prepareMutate();
this._right = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NonLeafTreeBuilder.prototype, "middle", {
get: function () {
this.prepareMutate();
return this._middle;
},
set: function (value) {
this.prepareMutate();
this._middle = value;
},
enumerable: false,
configurable: true
});
NonLeafTreeBuilder.prototype.getChildLength = function (child) {
return child.length;
};
NonLeafTreeBuilder.prototype.modifyFirstChild = function (f) {
var delta = this.left.modifyFirstChild(f);
if (undefined !== delta)
this.length += delta;
return delta;
};
NonLeafTreeBuilder.prototype.modifyLastChild = function (f) {
var delta = this.right.modifyLastChild(f);
if (undefined !== delta)
this.length += delta;
return delta;
};
NonLeafTreeBuilder.prototype.normalized = function () {
if (undefined === this.middle) {
if (this.left.nrChildren + this.right.nrChildren <=
this.context.maxBlockSize) {
this.left.concat(this.right);
return this.left;
}
}
else {
this.middle = this.middle.normalized();
}
return this;
};
NonLeafTreeBuilder.prototype.first = function () {
return this.left.first();
};
NonLeafTreeBuilder.prototype.last = function () {
return this.right.last();
};
NonLeafTreeBuilder.prototype.get = function (index, otherwise) {
if (undefined !== this.source)
return this.source.get(index);
return _super.prototype.get.call(this, index, otherwise);
};
NonLeafTreeBuilder.prototype.build = function () {
if (undefined !== this.source)
return this.source;
return this.context.nonLeafTree(this.left.build(), this.right.build(), undefined === this.middle ? null : this.middle.build(), this.level);
};
NonLeafTreeBuilder.prototype.buildMap = function (f) {
if (undefined !== this.source)
return this.source.map(f);
return this.context.nonLeafTree(this.left.buildMap(f), this.right.buildMap(f), undefined === this.middle ? null : this.middle.buildMap(f), this.level);
};
return NonLeafTreeBuilder;
}(TreeBuilderBase));
exports.NonLeafTreeBuilder = NonLeafTreeBuilder;
//# sourceMappingURL=tree-builder.js.map

@@ -187,3 +187,3 @@ "use strict";

ListContext.prototype.isNonLeafBlockBuilder = function (obj) {
return obj instanceof list_custom_1.LeafTreeBuilder;
return obj instanceof list_custom_1.NonLeafBlockBuilder;
};

@@ -190,0 +190,0 @@ return ListContext;

@@ -19,2 +19,4 @@ "use strict";

(0, tslib_1.__exportStar)(require("./builder/tree/tree-builder"), exports);
(0, tslib_1.__exportStar)(require("./builder/leaf/tree-builder"), exports);
(0, tslib_1.__exportStar)(require("./builder/nonleaf/tree-builder"), exports);
(0, tslib_1.__exportStar)(require("./implementation/nonleaf/nonleaf-tree"), exports);

@@ -21,0 +23,0 @@ (0, tslib_1.__exportStar)(require("./builder/nonleaf/block-builder"), exports);

@@ -78,8 +78,11 @@ import { RimbuError } from '@rimbu/base';

else {
if (index === 0)
if (index === 0) {
return this.prepend(value);
if (index > this.length || -index > this.length + 1)
}
if (index > this.length || -index > this.length + 1) {
return this.append(value);
if (index < 0)
}
if (index < 0) {
return this.insert(this.length + index, value);
}
this.builder.insert(index, value);

@@ -86,0 +89,0 @@ this.builder = this.builder.normalized();

import { TraverseState } from '@rimbu/common';
import { createFromBlock, createNonLeaf } from '../../list-custom';
export class TreeBuilderBase {

@@ -183,4 +182,5 @@ get(index, otherwise) {

});
if (undefined !== delta)
if (undefined !== delta) {
return;
}
}

@@ -362,205 +362,2 @@ else if (this.right.nrChildren < this.context.maxBlockSize) {

}
export class LeafTreeBuilder extends TreeBuilderBase {
constructor(context, source, _left, _right, _middle, length) {
var _a;
if (length === void 0) { length = (_a = source === null || source === void 0 ? void 0 : source.length) !== null && _a !== void 0 ? _a : 0; }
super();
this.context = context;
this.source = source;
this._left = _left;
this._right = _right;
this._middle = _middle;
this.length = length;
}
prepareMutate() {
if (undefined !== this.source) {
this._left = this.context.leafBlockBuilderSource(this.source.left);
this._right = this.context.leafBlockBuilderSource(this.source.right);
this._middle =
null === this.source.middle
? undefined
: createNonLeaf(this.source.middle);
this.source = undefined;
}
}
get level() {
return 0;
}
get left() {
this.prepareMutate();
return this._left;
}
set left(value) {
this.prepareMutate();
this._left = value;
}
get right() {
this.prepareMutate();
return this._right;
}
set right(value) {
this.prepareMutate();
this._right = value;
}
get middle() {
this.prepareMutate();
return this._middle;
}
set middle(value) {
this.prepareMutate();
this._middle = value;
}
getChildLength() {
return 1;
}
appendChildren(children, from) {
if (children.length === 0 || from >= children.length)
return;
if (this.right.nrChildren < this.context.maxBlockSize) {
const items = children.slice(from, from + this.context.maxBlockSize - this.right.nrChildren);
this.right.children = this.right.children.concat(items);
this.length += items.length;
this.appendChildren(children, from + items.length);
return;
}
const block = children.slice(from, from + this.context.maxBlockSize);
this.appendMiddle(this.right);
this.right = this.context.leafBlockBuilder(block);
this.length += block.length;
this.appendChildren(children, from + block.length);
}
normalized() {
if (this.length <= this.context.maxBlockSize) {
this.left.concat(this.right);
return this.left;
}
if (undefined !== this.middle) {
if (this.middle.length + this.left.length <= this.context.maxBlockSize) {
this.left.concat(this.middle.first());
this.middle = undefined;
}
else if (this.middle.length + this.right.length <=
this.context.maxBlockSize) {
const newRight = this.middle.last();
newRight.concat(this.right);
this.right = newRight;
this.middle = undefined;
}
}
return this;
}
get(index, otherwise) {
if (undefined !== this.source)
return this.source.get(index, otherwise);
return super.get(index, otherwise);
}
build() {
if (undefined !== this.source)
return this.source;
return this.context.leafTree(this.left.build(), this.right.build(), undefined === this.middle ? null : this.middle.build());
}
buildMap(f) {
if (undefined !== this.source)
return this.source.map(f);
return this.context.leafTree(this.left.buildMap(f), this.right.buildMap(f), undefined === this.middle ? null : this.middle.buildMap(f));
}
}
export class NonLeafTreeBuilder extends TreeBuilderBase {
constructor(context, level, source, _left, _right, _middle, length) {
var _a;
if (length === void 0) { length = (_a = source === null || source === void 0 ? void 0 : source.length) !== null && _a !== void 0 ? _a : 0; }
super();
this.context = context;
this.level = level;
this.source = source;
this._left = _left;
this._right = _right;
this._middle = _middle;
this.length = length;
}
prepareMutate() {
if (undefined !== this.source) {
this._left = createFromBlock(this.source.left);
this._right = createFromBlock(this.source.right);
this._middle =
null === this.source.middle
? undefined
: createNonLeaf(this.source.middle);
this.source = undefined;
}
}
get left() {
this.prepareMutate();
return this._left;
}
set left(value) {
this.prepareMutate();
this._left = value;
}
get right() {
this.prepareMutate();
return this._right;
}
set right(value) {
this.prepareMutate();
this._right = value;
}
get middle() {
this.prepareMutate();
return this._middle;
}
set middle(value) {
this.prepareMutate();
this._middle = value;
}
getChildLength(child) {
return child.length;
}
modifyFirstChild(f) {
const delta = this.left.modifyFirstChild(f);
if (undefined !== delta)
this.length += delta;
return delta;
}
modifyLastChild(f) {
const delta = this.right.modifyLastChild(f);
if (undefined !== delta)
this.length += delta;
return delta;
}
normalized() {
if (undefined === this.middle) {
if (this.left.nrChildren + this.right.nrChildren <=
this.context.maxBlockSize) {
this.left.concat(this.right);
return this.left;
}
}
else {
this.middle = this.middle.normalized();
}
return this;
}
first() {
return this.left.first();
}
last() {
return this.right.last();
}
get(index, otherwise) {
if (undefined !== this.source)
return this.source.get(index);
return super.get(index, otherwise);
}
build() {
if (undefined !== this.source)
return this.source;
return this.context.nonLeafTree(this.left.build(), this.right.build(), undefined === this.middle ? null : this.middle.build(), this.level);
}
buildMap(f) {
if (undefined !== this.source)
return this.source.map(f);
return this.context.nonLeafTree(this.left.buildMap(f), this.right.buildMap(f), undefined === this.middle ? null : this.middle.buildMap(f), this.level);
}
}
//# sourceMappingURL=tree-builder.js.map

@@ -160,5 +160,5 @@ import { RimbuError } from '@rimbu/base';

isNonLeafBlockBuilder(obj) {
return obj instanceof LeafTreeBuilder;
return obj instanceof NonLeafBlockBuilder;
}
}
//# sourceMappingURL=context.js.map

@@ -16,2 +16,4 @@ export * from './implementation/block';

export * from './builder/tree/tree-builder';
export * from './builder/leaf/tree-builder';
export * from './builder/nonleaf/tree-builder';
export * from './implementation/nonleaf/nonleaf-tree';

@@ -18,0 +20,0 @@ export * from './builder/nonleaf/block-builder';

import { OptLazy, TraverseState, Update } from '@rimbu/common';
import type { BlockBuilder, BuilderBase, LeafBlockBuilder, LeafBuilder, LeafTree, ListContext, NonLeafBlockBuilder, NonLeafBuilder, NonLeafTree } from '../../list-custom';
import type { BlockBuilder, ListContext, NonLeafBuilder } from '../../list-custom';
export declare abstract class TreeBuilderBase<T, C> {

@@ -27,50 +27,1 @@ abstract get context(): ListContext;

}
export declare class LeafTreeBuilder<T> extends TreeBuilderBase<T, T> implements LeafBuilder<T> {
readonly context: ListContext;
source?: LeafTree<T> | undefined;
_left?: LeafBlockBuilder<T> | undefined;
_right?: LeafBlockBuilder<T> | undefined;
_middle?: NonLeafBuilder<T, LeafBlockBuilder<T>> | undefined;
length: number;
constructor(context: ListContext, source?: LeafTree<T> | undefined, _left?: LeafBlockBuilder<T> | undefined, _right?: LeafBlockBuilder<T> | undefined, _middle?: NonLeafBuilder<T, LeafBlockBuilder<T>> | undefined, length?: number);
prepareMutate(): void;
get level(): 0;
get left(): LeafBlockBuilder<T>;
set left(value: LeafBlockBuilder<T>);
get right(): LeafBlockBuilder<T>;
set right(value: LeafBlockBuilder<T>);
get middle(): NonLeafBuilder<T, LeafBlockBuilder<T>> | undefined;
set middle(value: NonLeafBuilder<T, LeafBlockBuilder<T>> | undefined);
getChildLength(): 1;
appendChildren(children: T[], from: number): void;
normalized(): LeafBuilder<T>;
get<O>(index: number, otherwise?: OptLazy<O>): T | O;
build(): LeafTree<T>;
buildMap<T2>(f: (value: T) => T2): LeafTree<T2>;
}
export declare class NonLeafTreeBuilder<T, C extends BlockBuilder<T>> extends TreeBuilderBase<T, C> implements BuilderBase<T, C> {
readonly context: ListContext;
readonly level: number;
source?: NonLeafTree<T, any> | undefined;
_left?: NonLeafBlockBuilder<T, C> | undefined;
_right?: NonLeafBlockBuilder<T, C> | undefined;
_middle?: NonLeafBuilder<T, NonLeafBlockBuilder<T, C>> | undefined;
length: number;
constructor(context: ListContext, level: number, source?: NonLeafTree<T, any> | undefined, _left?: NonLeafBlockBuilder<T, C> | undefined, _right?: NonLeafBlockBuilder<T, C> | undefined, _middle?: NonLeafBuilder<T, NonLeafBlockBuilder<T, C>> | undefined, length?: number);
prepareMutate(): void;
get left(): NonLeafBlockBuilder<T, C>;
set left(value: NonLeafBlockBuilder<T, C>);
get right(): NonLeafBlockBuilder<T, C>;
set right(value: NonLeafBlockBuilder<T, C>);
get middle(): NonLeafBuilder<T, NonLeafBlockBuilder<T, C>> | undefined;
set middle(value: NonLeafBuilder<T, NonLeafBlockBuilder<T, C>> | undefined);
getChildLength(child: C): number;
modifyFirstChild(f: (child: C) => number | undefined): number | undefined;
modifyLastChild(f: (child: C) => number | undefined): number | undefined;
normalized(): NonLeafBuilder<T, C>;
first(): C;
last(): C;
get<O>(index: number, otherwise?: OptLazy<O>): T | O;
build(): NonLeafTree<T, any>;
buildMap<T2>(f: (value: T) => T2): NonLeafTree<T2, any>;
}

@@ -15,4 +15,6 @@ export * from './implementation/block';

export * from './builder/tree/tree-builder';
export * from './builder/leaf/tree-builder';
export * from './builder/nonleaf/tree-builder';
export * from './implementation/nonleaf/nonleaf-tree';
export * from './builder/nonleaf/block-builder';
export * from './context';
{
"name": "@rimbu/list",
"version": "0.8.0",
"version": "0.8.1",
"description": "An efficient immutable ordered sequence of elements akin to a Vector",

@@ -62,6 +62,6 @@ "keywords": [

"dependencies": {
"@rimbu/base": "^0.7.0",
"@rimbu/collection-types": "^0.8.0",
"@rimbu/common": "^0.8.0",
"@rimbu/stream": "^0.8.0",
"@rimbu/base": "^0.7.1",
"@rimbu/collection-types": "^0.8.1",
"@rimbu/common": "^0.8.1",
"@rimbu/stream": "^0.8.1",
"tslib": "^2.3.1"

@@ -75,3 +75,3 @@ },

},
"gitHead": "c321aa32b1c5fd8ca8b7fb1c26bd4f7bbf3ef70d"
"gitHead": "d507e628ab82d501bc31351d69168e09bac5ae14"
}

@@ -160,6 +160,11 @@ import { RimbuError } from '@rimbu/base';

} else {
if (index === 0) return this.prepend(value);
if (index > this.length || -index > this.length + 1)
if (index === 0) {
return this.prepend(value);
}
if (index > this.length || -index > this.length + 1) {
return this.append(value);
if (index < 0) return this.insert(this.length + index, value);
}
if (index < 0) {
return this.insert(this.length + index, value);
}

@@ -166,0 +171,0 @@ this.builder.insert(index, value);

import { OptLazy, TraverseState, Update } from '@rimbu/common';
import type {
BlockBuilder,
BuilderBase,
LeafBlockBuilder,
LeafBuilder,
LeafTree,
ListContext,
NonLeafBlockBuilder,
NonLeafBuilder,
NonLeafTree,
} from '../../list-custom';
import { createFromBlock, createNonLeaf } from '../../list-custom';

@@ -245,3 +238,5 @@ export abstract class TreeBuilderBase<T, C> {

if (undefined !== delta) return;
if (undefined !== delta) {
return;
}
} else if (this.right.nrChildren < this.context.maxBlockSize) {

@@ -464,265 +459,1 @@ // try to shift to right

}
export class LeafTreeBuilder<T>
extends TreeBuilderBase<T, T>
implements LeafBuilder<T>
{
constructor(
readonly context: ListContext,
public source?: LeafTree<T>,
public _left?: LeafBlockBuilder<T>,
public _right?: LeafBlockBuilder<T>,
public _middle?: NonLeafBuilder<T, LeafBlockBuilder<T>>,
public length = source?.length ?? 0
) {
super();
}
prepareMutate(): void {
if (undefined !== this.source) {
this._left = this.context.leafBlockBuilderSource(this.source.left);
this._right = this.context.leafBlockBuilderSource(this.source.right);
this._middle =
null === this.source.middle
? undefined
: (createNonLeaf<T>(this.source.middle) as any);
this.source = undefined;
}
}
get level(): 0 {
return 0;
}
get left(): LeafBlockBuilder<T> {
this.prepareMutate();
return this._left!;
}
set left(value: LeafBlockBuilder<T>) {
this.prepareMutate();
this._left = value;
}
get right(): LeafBlockBuilder<T> {
this.prepareMutate();
return this._right!;
}
set right(value: LeafBlockBuilder<T>) {
this.prepareMutate();
this._right = value;
}
get middle(): NonLeafBuilder<T, LeafBlockBuilder<T>> | undefined {
this.prepareMutate();
return this._middle;
}
set middle(value: NonLeafBuilder<T, LeafBlockBuilder<T>> | undefined) {
this.prepareMutate();
this._middle = value;
}
getChildLength(): 1 {
return 1;
}
appendChildren(children: T[], from: number): void {
if (children.length === 0 || from >= children.length) return;
if (this.right.nrChildren < this.context.maxBlockSize) {
const items = children.slice(
from,
from + this.context.maxBlockSize - this.right.nrChildren
);
this.right.children = this.right.children.concat(items);
this.length += items.length;
this.appendChildren(children, from + items.length);
return;
}
const block = children.slice(from, from + this.context.maxBlockSize);
this.appendMiddle(this.right);
this.right = this.context.leafBlockBuilder(block);
this.length += block.length;
this.appendChildren(children, from + block.length);
}
normalized(): LeafBuilder<T> {
if (this.length <= this.context.maxBlockSize) {
this.left.concat(this.right);
return this.left;
}
if (undefined !== this.middle) {
if (this.middle.length + this.left.length <= this.context.maxBlockSize) {
this.left.concat(this.middle.first());
this.middle = undefined;
} else if (
this.middle.length + this.right.length <=
this.context.maxBlockSize
) {
const newRight = this.middle.last();
newRight.concat(this.right);
this.right = newRight;
this.middle = undefined;
}
}
return this;
}
get<O>(index: number, otherwise?: OptLazy<O>): T | O {
if (undefined !== this.source) return this.source.get(index, otherwise);
return super.get(index, otherwise);
}
build(): LeafTree<T> {
if (undefined !== this.source) return this.source;
return this.context.leafTree(
this.left.build(),
this.right.build(),
undefined === this.middle ? null : this.middle.build()
);
}
buildMap<T2>(f: (value: T) => T2): LeafTree<T2> {
if (undefined !== this.source) return this.source.map(f);
return this.context.leafTree(
this.left.buildMap(f),
this.right.buildMap(f),
undefined === this.middle ? null : (this.middle as any).buildMap(f)
);
}
}
export class NonLeafTreeBuilder<T, C extends BlockBuilder<T>>
extends TreeBuilderBase<T, C>
implements BuilderBase<T, C>
{
constructor(
readonly context: ListContext,
readonly level: number,
public source?: NonLeafTree<T, any>,
public _left?: NonLeafBlockBuilder<T, C>,
public _right?: NonLeafBlockBuilder<T, C>,
public _middle?: NonLeafBuilder<T, NonLeafBlockBuilder<T, C>>,
public length = source?.length ?? 0
) {
super();
}
prepareMutate(): void {
if (undefined !== this.source) {
this._left = createFromBlock(this.source.left) as any;
this._right = createFromBlock(this.source.right) as any;
this._middle =
null === this.source.middle
? undefined
: (createNonLeaf(this.source.middle) as any);
this.source = undefined;
}
}
get left(): NonLeafBlockBuilder<T, C> {
this.prepareMutate();
return this._left!;
}
set left(value: NonLeafBlockBuilder<T, C>) {
this.prepareMutate();
this._left = value;
}
get right(): NonLeafBlockBuilder<T, C> {
this.prepareMutate();
return this._right!;
}
set right(value: NonLeafBlockBuilder<T, C>) {
this.prepareMutate();
this._right = value;
}
get middle(): NonLeafBuilder<T, NonLeafBlockBuilder<T, C>> | undefined {
this.prepareMutate();
return this._middle;
}
set middle(value: NonLeafBuilder<T, NonLeafBlockBuilder<T, C>> | undefined) {
this.prepareMutate();
this._middle = value;
}
getChildLength(child: C): number {
return child.length;
}
modifyFirstChild(f: (child: C) => number | undefined): number | undefined {
const delta = this.left.modifyFirstChild(f);
if (undefined !== delta) this.length += delta;
return delta;
}
modifyLastChild(f: (child: C) => number | undefined): number | undefined {
const delta = this.right.modifyLastChild(f);
if (undefined !== delta) this.length += delta;
return delta;
}
normalized(): NonLeafBuilder<T, C> {
if (undefined === this.middle) {
if (
this.left.nrChildren + this.right.nrChildren <=
this.context.maxBlockSize
) {
this.left.concat(this.right);
return this.left;
}
} else {
this.middle = this.middle.normalized();
}
return this;
}
first(): C {
return this.left.first();
}
last(): C {
return this.right.last();
}
get<O>(index: number, otherwise?: OptLazy<O>): T | O {
if (undefined !== this.source) return this.source.get(index);
return super.get(index, otherwise);
}
build(): NonLeafTree<T, any> {
if (undefined !== this.source) return this.source;
return this.context.nonLeafTree(
this.left.build(),
this.right.build(),
undefined === this.middle ? null : this.middle.build(),
this.level
);
}
buildMap<T2>(f: (value: T) => T2): NonLeafTree<T2, any> {
if (undefined !== this.source) return this.source.map(f);
return this.context.nonLeafTree(
this.left.buildMap(f),
this.right.buildMap(f),
undefined === this.middle ? null : (this.middle as any).buildMap(f),
this.level
);
}
}

@@ -271,4 +271,4 @@ import { RimbuError } from '@rimbu/base';

): obj is NonLeafBlockBuilder<T, any> {
return obj instanceof LeafTreeBuilder;
return obj instanceof NonLeafBlockBuilder;
}
}

@@ -429,26 +429,2 @@ import type { CustomBase } from '@rimbu/collection-types';

toJSON(): ToJSON<T[], this['context']['typeTag']>;
/**
* Returns an array of Lists, where each list contains the values of the corresponding index of tuple T.
* @param length - the length of the tuples in type T
* @example
* const m = List.of([1, 'a'], [2, 'b'])
* m.unzip(2) // => [List.NonEmpty<number>, List.NonEmpty<string>]
*/
// unzip<L extends number, T2 extends T = T>(
// length: L
// ): T2 extends readonly [unknown, ...unknown[]] & { length: L }
// ? { [K in keyof T2]: List<T2[K]> }
// : never;
/**
* Returns, if T is a valid `StreamSource`, the result of concatenating all
* streamable elements of this List.
* @example
* const m = List.of([1, 2], [3, 4, 5])
* m.flatten().toArray() // => [1, 2, 3, 4, 5]
*/
// flatten<T2 = T>(): T2 extends StreamSource.NonEmpty<infer S>
// ? List<S>
// : T2 extends StreamSource<infer S>
// ? List<S>
// : never;
}

@@ -679,19 +655,2 @@

toArray(range?: IndexRange, reversed?: boolean): T[];
/**
* Returns an array of Lists, where each list contains the values of the corresponding index of tuple T.
* @param length - the length of the tuples in type T
* @example
* const m = List.of([1, 'a'], [2, 'b'])
* m.unzip(2) // => [List.NonEmpty<number>, List.NonEmpty<string>]
*/
// unzip<L extends number, T2 extends T = T>(
// length: L
// ): T2 extends readonly [unknown, ...unknown[]] & { length: L }
// ? { [K in keyof T2]: List.NonEmpty<T2[K]> }
// : never;
// flatten<T2 extends T = T>(): T2 extends StreamSource.NonEmpty<infer S>
// ? List.NonEmpty<S>
// : T2 extends StreamSource<infer S>
// ? List<S>
// : never;
}

@@ -698,0 +657,0 @@

@@ -18,2 +18,4 @@ export * from './implementation/block';

export * from './builder/tree/tree-builder';
export * from './builder/leaf/tree-builder';
export * from './builder/nonleaf/tree-builder';

@@ -20,0 +22,0 @@ export * from './implementation/nonleaf/nonleaf-tree';

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

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

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

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