list-toolkit 2.2.5 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -36
- package/llms-full.txt +743 -0
- package/llms.txt +100 -0
- package/package.json +40 -32
- package/src/cache/cache-fifo.d.ts +6 -0
- package/src/cache/cache-fifo.js +7 -4
- package/src/cache/cache-lfu.d.ts +18 -0
- package/src/cache/cache-lfu.js +18 -6
- package/src/cache/cache-lru.d.ts +74 -0
- package/src/cache/cache-lru.js +60 -5
- package/src/cache/cache-random.d.ts +20 -0
- package/src/cache/cache-random.js +17 -6
- package/src/cache/decorator.d.ts +46 -0
- package/src/cache/decorator.js +26 -2
- package/src/cache.d.ts +13 -0
- package/src/cache.js +7 -2
- package/src/ext-list.d.ts +3 -0
- package/src/ext-list.js +0 -2
- package/src/ext-slist.d.ts +3 -0
- package/src/ext-slist.js +0 -2
- package/src/ext-value-list.d.ts +3 -0
- package/src/ext-value-list.js +0 -2
- package/src/ext-value-slist.d.ts +3 -0
- package/src/ext-value-slist.js +0 -2
- package/src/heap/basics.d.ts +89 -0
- package/src/heap/basics.js +42 -5
- package/src/heap/leftist-heap.d.ts +107 -0
- package/src/heap/leftist-heap.js +54 -2
- package/src/heap/min-heap.d.ts +270 -0
- package/src/heap/min-heap.js +186 -2
- package/src/heap/skew-heap.d.ts +105 -0
- package/src/heap/skew-heap.js +54 -2
- package/src/heap.d.ts +3 -0
- package/src/heap.js +0 -2
- package/src/list/basics.d.ts +43 -0
- package/src/list/basics.js +26 -8
- package/src/list/core.d.ts +271 -0
- package/src/list/core.js +162 -7
- package/src/list/ext-value.d.ts +253 -0
- package/src/list/ext-value.js +40 -6
- package/src/list/ext.d.ts +242 -0
- package/src/list/ext.js +148 -10
- package/src/list/nodes.d.ts +336 -0
- package/src/list/nodes.js +141 -3
- package/src/list/ptr.d.ts +72 -0
- package/src/list/ptr.js +44 -2
- package/src/list/value.d.ts +292 -0
- package/src/list/value.js +47 -6
- package/src/list-helpers.d.ts +44 -0
- package/src/list-helpers.js +36 -3
- package/src/list-utils.d.ts +141 -0
- package/src/list-utils.js +89 -3
- package/src/list.d.ts +3 -0
- package/src/list.js +0 -2
- package/src/meta-utils.d.ts +212 -0
- package/src/meta-utils.js +152 -1
- package/src/nt-utils.d.ts +91 -0
- package/src/nt-utils.js +65 -4
- package/src/queue.d.ts +74 -0
- package/src/queue.js +28 -2
- package/src/slist/basics.d.ts +47 -0
- package/src/slist/basics.js +23 -8
- package/src/slist/core.d.ts +251 -0
- package/src/slist/core.js +151 -6
- package/src/slist/ext-value.d.ts +188 -0
- package/src/slist/ext-value.js +35 -6
- package/src/slist/ext.d.ts +182 -0
- package/src/slist/ext.js +114 -12
- package/src/slist/nodes.d.ts +361 -0
- package/src/slist/nodes.js +156 -3
- package/src/slist/ptr.d.ts +73 -0
- package/src/slist/ptr.js +45 -2
- package/src/slist/value.d.ts +246 -0
- package/src/slist/value.js +38 -6
- package/src/slist.d.ts +3 -0
- package/src/slist.js +0 -2
- package/src/stack.d.ts +59 -0
- package/src/stack.js +29 -3
- package/src/tree/splay-tree.d.ts +151 -0
- package/src/tree/splay-tree.js +94 -3
- package/src/value-list.d.ts +3 -0
- package/src/value-list.js +0 -2
- package/src/value-slist.d.ts +3 -0
- package/src/value-slist.js +0 -2
- package/cjs/cache/cache-fifo.js +0 -37
- package/cjs/cache/cache-lfu.js +0 -76
- package/cjs/cache/cache-lru.js +0 -100
- package/cjs/cache/cache-random.js +0 -77
- package/cjs/cache/decorator.js +0 -47
- package/cjs/cache.js +0 -27
- package/cjs/ext-list.js +0 -21
- package/cjs/ext-slist.js +0 -21
- package/cjs/ext-value-list.js +0 -21
- package/cjs/ext-value-slist.js +0 -21
- package/cjs/heap/basics.js +0 -63
- package/cjs/heap/leftist-heap.js +0 -124
- package/cjs/heap/min-heap.js +0 -294
- package/cjs/heap/skew-heap.js +0 -114
- package/cjs/heap.js +0 -21
- package/cjs/list/basics.js +0 -88
- package/cjs/list/core.js +0 -305
- package/cjs/list/ext-value.js +0 -88
- package/cjs/list/ext.js +0 -356
- package/cjs/list/nodes.js +0 -240
- package/cjs/list/ptr.js +0 -61
- package/cjs/list/value.js +0 -99
- package/cjs/list-helpers.js +0 -91
- package/cjs/list-utils.js +0 -141
- package/cjs/list.js +0 -21
- package/cjs/meta-utils.js +0 -171
- package/cjs/nt-utils.js +0 -132
- package/cjs/package.json +0 -1
- package/cjs/queue.js +0 -58
- package/cjs/slist/basics.js +0 -71
- package/cjs/slist/core.js +0 -362
- package/cjs/slist/ext-value.js +0 -82
- package/cjs/slist/ext.js +0 -336
- package/cjs/slist/nodes.js +0 -276
- package/cjs/slist/ptr.js +0 -87
- package/cjs/slist/value.js +0 -90
- package/cjs/slist.js +0 -21
- package/cjs/stack.js +0 -55
- package/cjs/tree/splay-tree.js +0 -362
- package/cjs/value-list.js +0 -21
- package/cjs/value-slist.js +0 -21
package/cjs/slist/value.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "Ptr", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _core.Ptr;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "ValueNode", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _nodes.ValueNode;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
exports.default = exports.ValueSList = void 0;
|
|
19
|
-
var _core = _interopRequireWildcard(require("./core.js"));
|
|
20
|
-
var _nodes = require("./nodes.js");
|
|
21
|
-
var _metaUtils = require("../meta-utils.js");
|
|
22
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
23
|
-
class ValueSList extends _core.default {
|
|
24
|
-
popFront() {
|
|
25
|
-
return this.popFrontNode()?.value;
|
|
26
|
-
}
|
|
27
|
-
adoptValue(value) {
|
|
28
|
-
if (value instanceof _core.Ptr) {
|
|
29
|
-
if (!this.isCompatiblePtr(value)) throw new Error('Incompatible pointer');
|
|
30
|
-
if (value.node instanceof _nodes.ValueNode) {
|
|
31
|
-
value.list = this;
|
|
32
|
-
return super.adoptNode(value);
|
|
33
|
-
}
|
|
34
|
-
return new _nodes.ValueNode(value.node, this);
|
|
35
|
-
}
|
|
36
|
-
if (value instanceof _nodes.ValueNode) {
|
|
37
|
-
if (!this.isNodeLike(value)) throw new Error('Incompatible node');
|
|
38
|
-
return super.adoptNode(value);
|
|
39
|
-
}
|
|
40
|
-
return new _nodes.ValueNode(value, this);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// iterators
|
|
44
|
-
|
|
45
|
-
[Symbol.iterator]() {
|
|
46
|
-
let current = this[this.nextName],
|
|
47
|
-
readyToStop = this.isEmpty;
|
|
48
|
-
return (0, _metaUtils.normalizeIterator)({
|
|
49
|
-
next: () => {
|
|
50
|
-
if (readyToStop && current === this) return {
|
|
51
|
-
done: true
|
|
52
|
-
};
|
|
53
|
-
readyToStop = true;
|
|
54
|
-
const value = current.value;
|
|
55
|
-
current = current[this.nextName];
|
|
56
|
-
return {
|
|
57
|
-
value
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
getValueIterator(range) {
|
|
63
|
-
return (0, _metaUtils.mapIterator)(this.getNodeIterator(range), node => node.value);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// meta helpers
|
|
67
|
-
|
|
68
|
-
clone() {
|
|
69
|
-
return ValueSList.from(this, this);
|
|
70
|
-
}
|
|
71
|
-
make() {
|
|
72
|
-
return new ValueSList(this);
|
|
73
|
-
}
|
|
74
|
-
makeFrom(values) {
|
|
75
|
-
return ValueSList.from(values, this);
|
|
76
|
-
}
|
|
77
|
-
static from(values, options) {
|
|
78
|
-
const list = new ValueSList(options);
|
|
79
|
-
for (const value of values) list.pushBack(value);
|
|
80
|
-
return list;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.ValueSList = ValueSList;
|
|
84
|
-
ValueSList.Ptr = _core.Ptr;
|
|
85
|
-
ValueSList.ValueNode = _nodes.ValueNode;
|
|
86
|
-
(0, _metaUtils.addAliases)(ValueSList.prototype, {
|
|
87
|
-
popFront: 'pop',
|
|
88
|
-
getValueIterator: 'getIterator'
|
|
89
|
-
}, true);
|
|
90
|
-
var _default = exports.default = ValueSList;
|
package/cjs/slist.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {};
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _core = _interopRequireWildcard(require("./slist/core.js"));
|
|
9
|
-
Object.keys(_core).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
12
|
-
if (key in exports && exports[key] === _core[key]) return;
|
|
13
|
-
Object.defineProperty(exports, key, {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _core[key];
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
21
|
-
var _default = exports.default = _core.default;
|
package/cjs/stack.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.Stack = void 0;
|
|
7
|
-
var _valueList = _interopRequireDefault(require("./value-list.js"));
|
|
8
|
-
var _metaUtils = require("./meta-utils.js");
|
|
9
|
-
var _listUtils = require("./list-utils.js");
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
class Stack {
|
|
12
|
-
constructor(UnderlyingList = _valueList.default) {
|
|
13
|
-
this.size = 0;
|
|
14
|
-
this.list = new UnderlyingList();
|
|
15
|
-
}
|
|
16
|
-
get isEmpty() {
|
|
17
|
-
return this.list.isEmpty;
|
|
18
|
-
}
|
|
19
|
-
get top() {
|
|
20
|
-
return this.list.isEmpty ? undefined : this.list.front.value;
|
|
21
|
-
}
|
|
22
|
-
peek() {
|
|
23
|
-
return this.list.isEmpty ? undefined : this.list.front.value;
|
|
24
|
-
}
|
|
25
|
-
push(value) {
|
|
26
|
-
this.list.pushFront(value);
|
|
27
|
-
++this.size;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
pop() {
|
|
31
|
-
if (!this.list.isEmpty) {
|
|
32
|
-
--this.size;
|
|
33
|
-
return this.list.popFront().value;
|
|
34
|
-
}
|
|
35
|
-
// return undefined;
|
|
36
|
-
}
|
|
37
|
-
pushValues(values) {
|
|
38
|
-
(0, _listUtils.pushValuesFront)(this, values);
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
clear() {
|
|
42
|
-
this.list.clear();
|
|
43
|
-
this.size = 0;
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
[Symbol.iterator]() {
|
|
47
|
-
return this.list[Symbol.iterator]();
|
|
48
|
-
}
|
|
49
|
-
getReverseIterator() {
|
|
50
|
-
return this.list.getReverseIterator?.();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.Stack = Stack;
|
|
54
|
-
(0, _metaUtils.addAlias)(Stack.prototype, 'push', 'pushFront');
|
|
55
|
-
var _default = exports.default = Stack;
|
package/cjs/tree/splay-tree.js
DELETED
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.SplayTreeNode = exports.SplayTree = void 0;
|
|
7
|
-
var _metaUtils = require("../meta-utils.js");
|
|
8
|
-
const defaultLess = (a, b) => a < b;
|
|
9
|
-
const zig = tree => {
|
|
10
|
-
const newTree = tree.left,
|
|
11
|
-
parent = newTree.parent = tree.parent;
|
|
12
|
-
if (parent) {
|
|
13
|
-
if (parent.left === tree) parent.left = newTree;else parent.right = newTree;
|
|
14
|
-
}
|
|
15
|
-
tree.parent = newTree;
|
|
16
|
-
const child = tree.left = newTree.right;
|
|
17
|
-
if (child) child.parent = tree;
|
|
18
|
-
newTree.right = tree;
|
|
19
|
-
return newTree;
|
|
20
|
-
};
|
|
21
|
-
const zag = tree => {
|
|
22
|
-
const newTree = tree.right,
|
|
23
|
-
parent = newTree.parent = tree.parent;
|
|
24
|
-
if (parent) {
|
|
25
|
-
if (parent.left === tree) parent.left = newTree;else parent.right = newTree;
|
|
26
|
-
}
|
|
27
|
-
tree.parent = newTree;
|
|
28
|
-
const child = tree.right = newTree.left;
|
|
29
|
-
if (child) child.parent = tree;
|
|
30
|
-
newTree.left = tree;
|
|
31
|
-
return newTree;
|
|
32
|
-
};
|
|
33
|
-
const splay = node => {
|
|
34
|
-
while (node.parent) {
|
|
35
|
-
if (!node.parent.parent) {
|
|
36
|
-
node.parent.left === node ? zig(node.parent) : zag(node.parent);
|
|
37
|
-
} else if (node.parent.left === node && node.parent.parent.left === node.parent) {
|
|
38
|
-
zig(node.parent.parent);
|
|
39
|
-
zig(node.parent);
|
|
40
|
-
} else if (node.parent.right === node && node.parent.parent.right === node.parent) {
|
|
41
|
-
zag(node.parent.parent);
|
|
42
|
-
zag(node.parent);
|
|
43
|
-
} else if (node.parent.left === node && node.parent.parent.right === node.parent) {
|
|
44
|
-
zig(node.parent);
|
|
45
|
-
zag(node.parent);
|
|
46
|
-
} else {
|
|
47
|
-
zag(node.parent);
|
|
48
|
-
zig(node.parent);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return node;
|
|
52
|
-
};
|
|
53
|
-
const count = tree => tree ? count(tree.left) + count(tree.right) + 1 : 0;
|
|
54
|
-
class SplayTreeNode {
|
|
55
|
-
constructor(value) {
|
|
56
|
-
this.left = this.right = this.parent = null;
|
|
57
|
-
this.value = value;
|
|
58
|
-
}
|
|
59
|
-
getMin() {
|
|
60
|
-
let z = this;
|
|
61
|
-
while (z.left) z = z.left;
|
|
62
|
-
return z;
|
|
63
|
-
}
|
|
64
|
-
getMax() {
|
|
65
|
-
let z = this;
|
|
66
|
-
while (z.right) z = z.right;
|
|
67
|
-
return z;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.SplayTreeNode = SplayTreeNode;
|
|
71
|
-
class SplayTree {
|
|
72
|
-
constructor(options) {
|
|
73
|
-
(0, _metaUtils.copyOptions)(this, SplayTree.defaults, options);
|
|
74
|
-
if (typeof this.compare == 'function') {
|
|
75
|
-
this.less = (a, b) => this.compare(a, b) < 0;
|
|
76
|
-
this.find = this.findWithCompare;
|
|
77
|
-
this.insert = this.insertWithCompare;
|
|
78
|
-
this.splitMaxTree = this.splitMaxTreeWithCompare;
|
|
79
|
-
}
|
|
80
|
-
this.root = null;
|
|
81
|
-
this.size = 0;
|
|
82
|
-
}
|
|
83
|
-
get isEmpty() {
|
|
84
|
-
return !this.root;
|
|
85
|
-
}
|
|
86
|
-
get length() {
|
|
87
|
-
return this.size;
|
|
88
|
-
}
|
|
89
|
-
getMin() {
|
|
90
|
-
return this.root.getMin();
|
|
91
|
-
}
|
|
92
|
-
getMax() {
|
|
93
|
-
return this.root.getMax();
|
|
94
|
-
}
|
|
95
|
-
find(value) {
|
|
96
|
-
for (let z = this.root; z;) {
|
|
97
|
-
if (this.less(z.value, value)) z = z.right;else if (this.less(value, z.value)) z = z.left;else return z;
|
|
98
|
-
}
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
findWithCompare(value) {
|
|
102
|
-
for (let z = this.root; z;) {
|
|
103
|
-
const cmp = this.compare(value, z.value);
|
|
104
|
-
if (cmp < 0) z = z.left;else if (cmp > 0) z = z.right;else return z;
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
promote(value) {
|
|
109
|
-
const z = this.find(value);
|
|
110
|
-
if (z) {
|
|
111
|
-
this.root = splay(z);
|
|
112
|
-
}
|
|
113
|
-
return z;
|
|
114
|
-
}
|
|
115
|
-
splay(node) {
|
|
116
|
-
this.root = splay(node);
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
insert(value) {
|
|
120
|
-
let z = this.root,
|
|
121
|
-
parent = null;
|
|
122
|
-
while (z) {
|
|
123
|
-
parent = z;
|
|
124
|
-
if (this.less(z.value, value)) z = z.right;else if (this.less(value, z.value)) z = z.left;else break;
|
|
125
|
-
}
|
|
126
|
-
if (!z) {
|
|
127
|
-
z = new SplayTreeNode(value);
|
|
128
|
-
z.parent = parent;
|
|
129
|
-
if (parent) {
|
|
130
|
-
if (this.less(parent.value, value)) parent.right = z;else parent.left = z;
|
|
131
|
-
}
|
|
132
|
-
++this.size;
|
|
133
|
-
}
|
|
134
|
-
this.root = splay(z);
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
insertWithCompare(value) {
|
|
138
|
-
let z = this.root,
|
|
139
|
-
parent = null;
|
|
140
|
-
while (z) {
|
|
141
|
-
parent = z;
|
|
142
|
-
const cmp = this.compare(value, z.value);
|
|
143
|
-
if (cmp < 0) z = z.left;else if (cmp > 0) z = z.right;else break;
|
|
144
|
-
}
|
|
145
|
-
if (!z) {
|
|
146
|
-
z = new SplayTreeNode(value);
|
|
147
|
-
z.parent = parent;
|
|
148
|
-
if (parent) {
|
|
149
|
-
if (this.compare(parent.value, value) < 0) parent.right = z;else parent.left = z;
|
|
150
|
-
}
|
|
151
|
-
++this.size;
|
|
152
|
-
}
|
|
153
|
-
this.root = splay(z);
|
|
154
|
-
return this;
|
|
155
|
-
}
|
|
156
|
-
remove(value) {
|
|
157
|
-
const z = this.find(value);
|
|
158
|
-
if (!z) return this;
|
|
159
|
-
splay(z);
|
|
160
|
-
this.root = null;
|
|
161
|
-
let maxNode = null;
|
|
162
|
-
if (z.left) {
|
|
163
|
-
z.left.parent = null;
|
|
164
|
-
maxNode = z.left.getMax();
|
|
165
|
-
this.root = splay(maxNode);
|
|
166
|
-
}
|
|
167
|
-
if (z.right) {
|
|
168
|
-
if (maxNode) maxNode.right = z.right;else this.root = z.right;
|
|
169
|
-
z.right.parent = maxNode;
|
|
170
|
-
}
|
|
171
|
-
--this.size;
|
|
172
|
-
return this;
|
|
173
|
-
}
|
|
174
|
-
clear() {
|
|
175
|
-
this.root = null;
|
|
176
|
-
this.size = 0;
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
splitMaxTree(value) {
|
|
180
|
-
if (!this.root) return new SplayTree(this);
|
|
181
|
-
let z = this.root,
|
|
182
|
-
parent = null,
|
|
183
|
-
right;
|
|
184
|
-
while (z) {
|
|
185
|
-
parent = z;
|
|
186
|
-
if (this.less(z.value, value)) {
|
|
187
|
-
z = z.right;
|
|
188
|
-
right = true;
|
|
189
|
-
} else if (this.less(value, z.value)) {
|
|
190
|
-
z = z.left;
|
|
191
|
-
right = false;
|
|
192
|
-
} else break;
|
|
193
|
-
}
|
|
194
|
-
this.root = splay(z || parent);
|
|
195
|
-
const newTree = new SplayTree(this);
|
|
196
|
-
if (z || right) {
|
|
197
|
-
newTree.root = this.root.right;
|
|
198
|
-
if (newTree.root) {
|
|
199
|
-
newTree.root.parent = null;
|
|
200
|
-
newTree.size = count(newTree.root);
|
|
201
|
-
this.root.right = null;
|
|
202
|
-
this.size -= newTree.size;
|
|
203
|
-
}
|
|
204
|
-
} else {
|
|
205
|
-
newTree.root = this.root;
|
|
206
|
-
newTree.size = this.size;
|
|
207
|
-
this.root = this.root.left;
|
|
208
|
-
if (this.root) {
|
|
209
|
-
this.root.parent = null;
|
|
210
|
-
this.size = count(this.root);
|
|
211
|
-
newTree.root.left = null;
|
|
212
|
-
newTree.size -= this.size;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return newTree;
|
|
216
|
-
}
|
|
217
|
-
splitMaxTreeWithCompare(value) {
|
|
218
|
-
if (!this.root) return new SplayTree(this);
|
|
219
|
-
let z = this.root,
|
|
220
|
-
parent = null,
|
|
221
|
-
right;
|
|
222
|
-
while (z) {
|
|
223
|
-
parent = z;
|
|
224
|
-
const cmp = this.compare(value, z.value);
|
|
225
|
-
if (cmp < 0) {
|
|
226
|
-
z = z.left;
|
|
227
|
-
right = false;
|
|
228
|
-
} else if (cmp > 0) {
|
|
229
|
-
z = z.right;
|
|
230
|
-
right = true;
|
|
231
|
-
} else break;
|
|
232
|
-
}
|
|
233
|
-
this.root = splay(z || parent);
|
|
234
|
-
const newTree = new SplayTree(this);
|
|
235
|
-
if (z || right) {
|
|
236
|
-
newTree.root = this.root.right;
|
|
237
|
-
if (newTree.root) {
|
|
238
|
-
newTree.root.parent = null;
|
|
239
|
-
newTree.size = count(newTree.root);
|
|
240
|
-
this.root.right = null;
|
|
241
|
-
this.size -= newTree.size;
|
|
242
|
-
}
|
|
243
|
-
} else {
|
|
244
|
-
newTree.root = this.root;
|
|
245
|
-
newTree.size = this.size;
|
|
246
|
-
this.root = this.root.left;
|
|
247
|
-
if (this.root) {
|
|
248
|
-
this.root.parent = null;
|
|
249
|
-
this.size = count(this.root);
|
|
250
|
-
newTree.root.left = null;
|
|
251
|
-
newTree.size -= this.size;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return newTree;
|
|
255
|
-
}
|
|
256
|
-
joinMaxTreeUnsafe(tree) {
|
|
257
|
-
if (this.root.right) {
|
|
258
|
-
this.splay(this.getMax());
|
|
259
|
-
}
|
|
260
|
-
this.root.right = tree.root;
|
|
261
|
-
tree.root.parent = this.root;
|
|
262
|
-
this.size += tree.size;
|
|
263
|
-
tree.clear();
|
|
264
|
-
return this;
|
|
265
|
-
}
|
|
266
|
-
join(tree) {
|
|
267
|
-
if (!tree.root) return this;
|
|
268
|
-
if (!this.root) {
|
|
269
|
-
this.root = tree.root;
|
|
270
|
-
this.size = tree.size;
|
|
271
|
-
tree.clear();
|
|
272
|
-
return this;
|
|
273
|
-
}
|
|
274
|
-
const leftMax = this.getMax(),
|
|
275
|
-
rightMin = tree.getMin();
|
|
276
|
-
if (this.less(leftMax.value, rightMin.value)) {
|
|
277
|
-
return this.splay(leftMax).joinMaxTreeUnsafe(tree);
|
|
278
|
-
}
|
|
279
|
-
for (const value of tree) {
|
|
280
|
-
this.insert(value);
|
|
281
|
-
}
|
|
282
|
-
tree.clear();
|
|
283
|
-
return this;
|
|
284
|
-
}
|
|
285
|
-
[Symbol.iterator]() {
|
|
286
|
-
let current = this.root ? this.root.getMin() : null;
|
|
287
|
-
return {
|
|
288
|
-
next: () => {
|
|
289
|
-
if (!current) return {
|
|
290
|
-
done: true
|
|
291
|
-
};
|
|
292
|
-
const last = current;
|
|
293
|
-
if (current.right) {
|
|
294
|
-
current = current.right.getMin();
|
|
295
|
-
} else {
|
|
296
|
-
for (;;) {
|
|
297
|
-
const parent = current.parent;
|
|
298
|
-
if (!parent) {
|
|
299
|
-
current = null;
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
302
|
-
if (parent.left === current) {
|
|
303
|
-
current = parent;
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
current = parent;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return {
|
|
310
|
-
value: last.value
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
getReverseIterator() {
|
|
316
|
-
return {
|
|
317
|
-
[Symbol.iterator]: () => {
|
|
318
|
-
let current = this.root ? this.root.getMax() : null;
|
|
319
|
-
return {
|
|
320
|
-
next: () => {
|
|
321
|
-
if (!current) return {
|
|
322
|
-
done: true
|
|
323
|
-
};
|
|
324
|
-
const last = current;
|
|
325
|
-
if (current.left) {
|
|
326
|
-
current = current.left.getMax();
|
|
327
|
-
} else {
|
|
328
|
-
for (;;) {
|
|
329
|
-
const parent = current.parent;
|
|
330
|
-
if (!parent) {
|
|
331
|
-
current = null;
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
if (parent.right === current) {
|
|
335
|
-
current = parent;
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
current = parent;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
value: last.value
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
static from(values, options) {
|
|
350
|
-
const tree = new SplayTree(options);
|
|
351
|
-
for (const value of values) {
|
|
352
|
-
tree.insert(value);
|
|
353
|
-
}
|
|
354
|
-
return tree;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
exports.SplayTree = SplayTree;
|
|
358
|
-
SplayTree.defaults = {
|
|
359
|
-
less: defaultLess,
|
|
360
|
-
compare: null
|
|
361
|
-
};
|
|
362
|
-
var _default = exports.default = SplayTree;
|
package/cjs/value-list.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {};
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _value = _interopRequireWildcard(require("./list/value.js"));
|
|
9
|
-
Object.keys(_value).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
12
|
-
if (key in exports && exports[key] === _value[key]) return;
|
|
13
|
-
Object.defineProperty(exports, key, {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _value[key];
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
21
|
-
var _default = exports.default = _value.default;
|
package/cjs/value-slist.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {};
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _value = _interopRequireWildcard(require("./slist/value.js"));
|
|
9
|
-
Object.keys(_value).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
12
|
-
if (key in exports && exports[key] === _value[key]) return;
|
|
13
|
-
Object.defineProperty(exports, key, {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _value[key];
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
21
|
-
var _default = exports.default = _value.default;
|