list-toolkit 2.2.6 → 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 -37
- package/llms-full.txt +743 -0
- package/llms.txt +100 -0
- package/package.json +34 -29
- 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/queue.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.Queue = 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 Queue {
|
|
12
|
-
constructor(underlyingList = new _valueList.default()) {
|
|
13
|
-
this.list = underlyingList;
|
|
14
|
-
this.size = this.list.getLength();
|
|
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
|
-
add(value) {
|
|
26
|
-
this.list.pushBack(value);
|
|
27
|
-
++this.size;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
remove() {
|
|
31
|
-
if (!this.list.isEmpty) {
|
|
32
|
-
--this.size;
|
|
33
|
-
return this.list.popFront();
|
|
34
|
-
}
|
|
35
|
-
// return undefined;
|
|
36
|
-
}
|
|
37
|
-
addValues(values) {
|
|
38
|
-
(0, _listUtils.pushValuesBack)(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.Queue = Queue;
|
|
54
|
-
(0, _metaUtils.addAliases)(Queue.prototype, {
|
|
55
|
-
add: 'push, pushBack, enqueue',
|
|
56
|
-
remove: 'pop, popFront, dequeue'
|
|
57
|
-
});
|
|
58
|
-
var _default = exports.default = Queue;
|
package/cjs/slist/basics.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// useful low-level operations on singly linked lists
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.splice = exports.pop = exports.extract = exports.append = void 0;
|
|
8
|
-
const extract = ({
|
|
9
|
-
nextName
|
|
10
|
-
}, {
|
|
11
|
-
prevFrom,
|
|
12
|
-
to = prevFrom[nextName]
|
|
13
|
-
}) => {
|
|
14
|
-
const node = prevFrom[nextName],
|
|
15
|
-
next = to[nextName];
|
|
16
|
-
|
|
17
|
-
// exclude the range
|
|
18
|
-
prevFrom[nextName] = to[nextName];
|
|
19
|
-
|
|
20
|
-
// circle the range
|
|
21
|
-
to[nextName] = node;
|
|
22
|
-
return {
|
|
23
|
-
extracted: {
|
|
24
|
-
prevFrom: to,
|
|
25
|
-
to
|
|
26
|
-
},
|
|
27
|
-
rest: next === node ? null : next
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// pop(options, prev).node === extract(options, {prevFrom: prev}).prevFrom[options.nextName]
|
|
32
|
-
exports.extract = extract;
|
|
33
|
-
const pop = ({
|
|
34
|
-
nextName
|
|
35
|
-
}, prev) => {
|
|
36
|
-
const node = prev[nextName],
|
|
37
|
-
next = node[nextName];
|
|
38
|
-
|
|
39
|
-
// exclude the node
|
|
40
|
-
prev[nextName] = next;
|
|
41
|
-
|
|
42
|
-
// circle the node
|
|
43
|
-
node[nextName] = node;
|
|
44
|
-
return {
|
|
45
|
-
extracted: {
|
|
46
|
-
prevFrom: node,
|
|
47
|
-
to: node
|
|
48
|
-
},
|
|
49
|
-
rest: next === node ? null : next
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
exports.pop = pop;
|
|
53
|
-
const splice = ({
|
|
54
|
-
nextName
|
|
55
|
-
}, target, {
|
|
56
|
-
prevFrom,
|
|
57
|
-
to = prevFrom[nextName]
|
|
58
|
-
}) => {
|
|
59
|
-
// form the combined head
|
|
60
|
-
const next = target[nextName];
|
|
61
|
-
target[nextName] = prevFrom[nextName];
|
|
62
|
-
|
|
63
|
-
// finish the combined tail
|
|
64
|
-
prevFrom[nextName] = to[nextName];
|
|
65
|
-
to[nextName] = next;
|
|
66
|
-
return target;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// append(options, target, range) === splice(options, target, extract(options, range))
|
|
70
|
-
exports.splice = splice;
|
|
71
|
-
const append = exports.append = splice;
|
package/cjs/slist/core.js
DELETED
|
@@ -1,362 +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 _ptr.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
exports.default = exports.SList = void 0;
|
|
13
|
-
var _metaUtils = require("../meta-utils.js");
|
|
14
|
-
var _nodes = require("./nodes.js");
|
|
15
|
-
var _basics = require("./basics.js");
|
|
16
|
-
var _ptr = _interopRequireDefault(require("./ptr.js"));
|
|
17
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
class SList extends _nodes.HeadNode {
|
|
19
|
-
get frontPtr() {
|
|
20
|
-
return new _ptr.default(this);
|
|
21
|
-
}
|
|
22
|
-
get ptrRange() {
|
|
23
|
-
return this.isEmpty ? null : {
|
|
24
|
-
from: new _ptr.default(this),
|
|
25
|
-
to: this.last
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
makePtr(node) {
|
|
29
|
-
if (node && !this.isNodeLike(node)) throw new Error('"node" is not a compatible node');
|
|
30
|
-
return new _ptr.default(this, node);
|
|
31
|
-
}
|
|
32
|
-
makePtrFromPrev(prev) {
|
|
33
|
-
if (prev && !this.isNodeLike(prev)) throw new Error('"prev" is not a compatible node');
|
|
34
|
-
return new _ptr.default(this, null, prev || this);
|
|
35
|
-
}
|
|
36
|
-
popFrontNode() {
|
|
37
|
-
if (this[this.nextName] === this) return undefined;
|
|
38
|
-
const node = this[this.nextName];
|
|
39
|
-
this[this.nextName] = node[this.nextName];
|
|
40
|
-
if (this[this.nextName] === this) this.last = this;
|
|
41
|
-
return node[this.nextName] = node;
|
|
42
|
-
}
|
|
43
|
-
pushFront(value) {
|
|
44
|
-
const node = this.adoptValue(value);
|
|
45
|
-
node[this.nextName] = this[this.nextName];
|
|
46
|
-
this[this.nextName] = node;
|
|
47
|
-
if (node[this.nextName] === this) this.last = node;
|
|
48
|
-
return this.makePtr();
|
|
49
|
-
}
|
|
50
|
-
pushBack(value) {
|
|
51
|
-
const node = this.adoptValue(value);
|
|
52
|
-
node[this.nextName] = this;
|
|
53
|
-
const last = this.last;
|
|
54
|
-
this.last = last[this.nextName] = node;
|
|
55
|
-
return this.makePtrFromPrev(last);
|
|
56
|
-
}
|
|
57
|
-
pushFrontNode(nodeOrPtr) {
|
|
58
|
-
const node = this.adoptNode(nodeOrPtr);
|
|
59
|
-
node[this.nextName] = this[this.nextName];
|
|
60
|
-
this[this.nextName] = node;
|
|
61
|
-
if (node[this.nextName] === this) this.last = node;
|
|
62
|
-
return this.makePtr();
|
|
63
|
-
}
|
|
64
|
-
pushBackNode(nodeOrPtr) {
|
|
65
|
-
const node = this.adoptNode(nodeOrPtr);
|
|
66
|
-
node[this.nextName] = this;
|
|
67
|
-
const last = this.last;
|
|
68
|
-
this.last = last[this.nextName] = node;
|
|
69
|
-
return this.makePtrFromPrev(last);
|
|
70
|
-
}
|
|
71
|
-
appendFront(list) {
|
|
72
|
-
if (!this.isCompatible(list)) throw new Error('Incompatible lists');
|
|
73
|
-
if (list.isEmpty) return this;
|
|
74
|
-
list.last[this.nextName] = this[this.nextName];
|
|
75
|
-
this[this.nextName] = list[this.nextName];
|
|
76
|
-
if (list.last[this.nextName] === this) this.last = list.last;
|
|
77
|
-
list[this.nextName] = list.last = list; // clear the list
|
|
78
|
-
return this.makePtr();
|
|
79
|
-
}
|
|
80
|
-
appendBack(list) {
|
|
81
|
-
if (!this.isCompatible(list)) throw new Error('Incompatible lists');
|
|
82
|
-
if (list.isEmpty) return this;
|
|
83
|
-
this.last[this.nextName] = list[this.nextName];
|
|
84
|
-
list.last[this.nextName] = this;
|
|
85
|
-
const last = this.last;
|
|
86
|
-
this.last = list.last;
|
|
87
|
-
list[this.nextName] = list.last = list; // clear the list
|
|
88
|
-
return this.makePtrFromPrev(last);
|
|
89
|
-
}
|
|
90
|
-
moveToFront(ptr) {
|
|
91
|
-
if (!this.isCompatiblePtr(ptr)) throw new Error('Incompatible pointer');
|
|
92
|
-
ptr.list = this;
|
|
93
|
-
if (ptr.isHead) return this;
|
|
94
|
-
const node = ptr.removeCurrent();
|
|
95
|
-
ptr.prevNode = this;
|
|
96
|
-
return this.pushFrontNode(node);
|
|
97
|
-
}
|
|
98
|
-
moveToBack(ptr) {
|
|
99
|
-
if (!this.isCompatiblePtr(ptr)) throw new Error('Incompatible pointer');
|
|
100
|
-
ptr.list = this;
|
|
101
|
-
if (ptr.isHead) return this;
|
|
102
|
-
const node = ptr.removeCurrent();
|
|
103
|
-
ptr.prevNode = this.last;
|
|
104
|
-
return this.pushBackNode(node);
|
|
105
|
-
}
|
|
106
|
-
clear(drop) {
|
|
107
|
-
if (drop) {
|
|
108
|
-
let current = this;
|
|
109
|
-
do {
|
|
110
|
-
const next = current[this.nextName];
|
|
111
|
-
current[this.nextName] = current;
|
|
112
|
-
current = next;
|
|
113
|
-
} while (current !== this);
|
|
114
|
-
} else {
|
|
115
|
-
this[this.nextName] = this;
|
|
116
|
-
}
|
|
117
|
-
this.last = this;
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
removeNode(ptr) {
|
|
121
|
-
if (!ptr.isPrevNodeValid()) throw new Error('Cannot remove node: "prevNode" is invalid');
|
|
122
|
-
if (!this.isCompatiblePtr(ptr)) throw new Error('Incompatible pointer');
|
|
123
|
-
const node = ptr.prevNode[this.nextName];
|
|
124
|
-
if (node === this || node === ptr.prevNode) return null;
|
|
125
|
-
if (this.last === node) this.last = ptr.prevNode;
|
|
126
|
-
ptr.prevNode[this.nextName] = node[this.nextName];
|
|
127
|
-
ptr.list = this;
|
|
128
|
-
node[this.nextName] = node;
|
|
129
|
-
return node;
|
|
130
|
-
}
|
|
131
|
-
removeRange(ptrRange, drop) {
|
|
132
|
-
return this.extractRange(ptrRange).clear(drop);
|
|
133
|
-
}
|
|
134
|
-
extractRange(ptrRange = {}) {
|
|
135
|
-
const originalTo = ptrRange.to;
|
|
136
|
-
ptrRange = this.normalizePtrRange(ptrRange.from ? ptrRange : {
|
|
137
|
-
...ptrRange,
|
|
138
|
-
from: this.frontPtr
|
|
139
|
-
});
|
|
140
|
-
if (!ptrRange.from.isPrevNodeValid()) throw new Error('Cannot extract range: "prevNode" is invalid');
|
|
141
|
-
ptrRange.to ||= this.last;
|
|
142
|
-
const extracted = this.make();
|
|
143
|
-
(0, _basics.append)(this, extracted, {
|
|
144
|
-
prevFrom: ptrRange.from.prevNode,
|
|
145
|
-
to: ptrRange.to
|
|
146
|
-
});
|
|
147
|
-
extracted.last = ptrRange.to;
|
|
148
|
-
ptrRange.from.list = extracted;
|
|
149
|
-
if (originalTo instanceof _ptr.default) originalTo.list = extracted;
|
|
150
|
-
if (ptrRange.to === this.last) this.last = ptrRange.from.prevNode;
|
|
151
|
-
return extracted;
|
|
152
|
-
}
|
|
153
|
-
extractBy(condition) {
|
|
154
|
-
const extracted = this.make();
|
|
155
|
-
if (this.isEmpty) return extracted;
|
|
156
|
-
for (const ptr = this.frontPtr; !ptr.isHead;) {
|
|
157
|
-
if (condition(ptr.node)) {
|
|
158
|
-
extracted.pushBackNode(ptr.removeCurrent());
|
|
159
|
-
} else {
|
|
160
|
-
ptr.next();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return extracted;
|
|
164
|
-
}
|
|
165
|
-
reverse() {
|
|
166
|
-
if (this.isOneOrEmpty) return this;
|
|
167
|
-
this.last = this[this.nextName];
|
|
168
|
-
let prev = this,
|
|
169
|
-
current = prev[this.nextName];
|
|
170
|
-
do {
|
|
171
|
-
const next = current[this.nextName];
|
|
172
|
-
current[this.nextName] = prev;
|
|
173
|
-
prev = current;
|
|
174
|
-
current = next;
|
|
175
|
-
} while (current !== this);
|
|
176
|
-
this[this.nextName] = prev;
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
sort(lessFn) {
|
|
180
|
-
if (this.isOneOrEmpty) return this;
|
|
181
|
-
const left = this.make(),
|
|
182
|
-
right = this.make();
|
|
183
|
-
|
|
184
|
-
// split into two sublists
|
|
185
|
-
for (let isLeft = true; !this.isEmpty; isLeft = !isLeft) {
|
|
186
|
-
(isLeft ? left : right).pushBackNode(this.popFrontNode());
|
|
187
|
-
}
|
|
188
|
-
// the list is empty now
|
|
189
|
-
|
|
190
|
-
// sort sublists
|
|
191
|
-
left.sort(lessFn);
|
|
192
|
-
right.sort(lessFn);
|
|
193
|
-
|
|
194
|
-
// merge sublists
|
|
195
|
-
while (!left.isEmpty && !right.isEmpty) {
|
|
196
|
-
this.pushBackNode((lessFn(left.front, right.front) ? left : right).popFrontNode());
|
|
197
|
-
}
|
|
198
|
-
if (!left.isEmpty) this.appendBack(left);
|
|
199
|
-
if (!right.isEmpty) this.appendBack(right);
|
|
200
|
-
return this;
|
|
201
|
-
}
|
|
202
|
-
releaseAsPtrRange() {
|
|
203
|
-
if (this.isEmpty) return null;
|
|
204
|
-
const head = this[this.nextName],
|
|
205
|
-
tail = this.last;
|
|
206
|
-
this.clear();
|
|
207
|
-
tail[this.nextName] = head;
|
|
208
|
-
return {
|
|
209
|
-
from: new _ptr.default(this, null, tail),
|
|
210
|
-
to: tail
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
releaseRawList() {
|
|
214
|
-
if (this.isEmpty) return null;
|
|
215
|
-
const head = this[this.nextName],
|
|
216
|
-
tail = this.last;
|
|
217
|
-
this.clear();
|
|
218
|
-
tail[this.nextName] = head;
|
|
219
|
-
return head;
|
|
220
|
-
}
|
|
221
|
-
releaseNTList() {
|
|
222
|
-
if (this.isEmpty) return null;
|
|
223
|
-
const head = this[this.nextName],
|
|
224
|
-
tail = this.last;
|
|
225
|
-
this.clear();
|
|
226
|
-
tail[this.nextName] = null;
|
|
227
|
-
return {
|
|
228
|
-
head,
|
|
229
|
-
tail
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
validateRange(range = {}) {
|
|
233
|
-
range = this.normalizeRange(range);
|
|
234
|
-
let current = range.from;
|
|
235
|
-
do {
|
|
236
|
-
if (current === this) return false;
|
|
237
|
-
current = current[this.nextName];
|
|
238
|
-
} while (current !== range.to);
|
|
239
|
-
return true;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// iterators
|
|
243
|
-
|
|
244
|
-
[Symbol.iterator]() {
|
|
245
|
-
let current = this[this.nextName],
|
|
246
|
-
readyToStop = this.isEmpty;
|
|
247
|
-
return (0, _metaUtils.normalizeIterator)({
|
|
248
|
-
next: () => {
|
|
249
|
-
if (readyToStop && current === this) return {
|
|
250
|
-
done: true
|
|
251
|
-
};
|
|
252
|
-
readyToStop = true;
|
|
253
|
-
const value = current;
|
|
254
|
-
current = current[this.nextName];
|
|
255
|
-
return {
|
|
256
|
-
value
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
getNodeIterator(range = {}) {
|
|
262
|
-
range = this.normalizeRange(range);
|
|
263
|
-
const {
|
|
264
|
-
from,
|
|
265
|
-
to
|
|
266
|
-
} = range;
|
|
267
|
-
return {
|
|
268
|
-
[Symbol.iterator]: () => {
|
|
269
|
-
let current = from || this[this.nextName],
|
|
270
|
-
readyToStop = this.isEmpty;
|
|
271
|
-
const stop = to ? to[this.nextName] : this;
|
|
272
|
-
return (0, _metaUtils.normalizeIterator)({
|
|
273
|
-
next: () => {
|
|
274
|
-
if (readyToStop && current === stop) return {
|
|
275
|
-
done: true
|
|
276
|
-
};
|
|
277
|
-
readyToStop = true;
|
|
278
|
-
const value = current;
|
|
279
|
-
current = current[this.nextName];
|
|
280
|
-
return {
|
|
281
|
-
value
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
getPtrIterator(ptrRange = {}) {
|
|
289
|
-
if (!ptrRange.from) ptrRange = Object.assign({
|
|
290
|
-
from: this.frontPtr
|
|
291
|
-
}, ptrRange);
|
|
292
|
-
ptrRange = this.normalizePtrRange(ptrRange);
|
|
293
|
-
const {
|
|
294
|
-
from: fromPtr,
|
|
295
|
-
to
|
|
296
|
-
} = ptrRange;
|
|
297
|
-
return {
|
|
298
|
-
[Symbol.iterator]: () => {
|
|
299
|
-
let current = fromPtr.clone(),
|
|
300
|
-
readyToStop = this.isEmpty;
|
|
301
|
-
const stop = to ? to[this.nextName] : this;
|
|
302
|
-
return (0, _metaUtils.normalizeIterator)({
|
|
303
|
-
next: () => {
|
|
304
|
-
if (readyToStop && current.node === stop) return {
|
|
305
|
-
done: true
|
|
306
|
-
};
|
|
307
|
-
readyToStop = true;
|
|
308
|
-
const value = current.clone();
|
|
309
|
-
current = current.next();
|
|
310
|
-
return {
|
|
311
|
-
value
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// meta helpers
|
|
320
|
-
|
|
321
|
-
make() {
|
|
322
|
-
return new SList(this);
|
|
323
|
-
}
|
|
324
|
-
makeFrom(values) {
|
|
325
|
-
return SList.from(values, this);
|
|
326
|
-
}
|
|
327
|
-
makeFromRange(range) {
|
|
328
|
-
return SList.fromRange(range, this);
|
|
329
|
-
}
|
|
330
|
-
static from(values, options) {
|
|
331
|
-
const list = new SList(options);
|
|
332
|
-
for (const value of values) list.pushBack(value);
|
|
333
|
-
return list;
|
|
334
|
-
}
|
|
335
|
-
static fromPtrRange(ptrRange, options) {
|
|
336
|
-
const list = new SList(options);
|
|
337
|
-
if (!list.isCompatiblePtrRange(ptrRange)) throw new Error('"range" is not a compatible range');
|
|
338
|
-
if (ptrRange) (0, _basics.append)(list, list, ptrRange);
|
|
339
|
-
return list;
|
|
340
|
-
}
|
|
341
|
-
static fromExtList(extList) {
|
|
342
|
-
if (!(extList instanceof _nodes.ExtListBase)) throw new Error('Not a circular list');
|
|
343
|
-
const list = new SList(extList);
|
|
344
|
-
if (extList.isEmpty) return list;
|
|
345
|
-
const range = extList.range;
|
|
346
|
-
if (range) {
|
|
347
|
-
(0, _basics.append)(list, list, range);
|
|
348
|
-
extList.clear();
|
|
349
|
-
}
|
|
350
|
-
return list;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
exports.SList = SList;
|
|
354
|
-
SList.Ptr = _ptr.default;
|
|
355
|
-
(0, _metaUtils.addAliases)(SList.prototype, {
|
|
356
|
-
popFrontNode: 'popFront, pop',
|
|
357
|
-
popBackNode: 'popBack',
|
|
358
|
-
pushFront: 'push',
|
|
359
|
-
appendBack: 'append',
|
|
360
|
-
getNodeIterator: 'getIterator'
|
|
361
|
-
});
|
|
362
|
-
var _default = exports.default = SList;
|
package/cjs/slist/ext-value.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ExtValueSList = void 0;
|
|
7
|
-
Object.defineProperty(exports, "ValueNode", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _nodes.ValueNode;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
exports.default = void 0;
|
|
14
|
-
var _ext = _interopRequireWildcard(require("./ext.js"));
|
|
15
|
-
var _nodes = require("./nodes.js");
|
|
16
|
-
var _metaUtils = require("../meta-utils.js");
|
|
17
|
-
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); }
|
|
18
|
-
class ExtValueSList extends _ext.default {
|
|
19
|
-
adoptValue(value) {
|
|
20
|
-
if (value instanceof _ext.Ptr) {
|
|
21
|
-
if (!this.isCompatiblePtr(value)) throw new Error('Incompatible pointer');
|
|
22
|
-
if (value.node instanceof _nodes.ValueNode) {
|
|
23
|
-
value.list = this;
|
|
24
|
-
return super.adoptNode(value);
|
|
25
|
-
}
|
|
26
|
-
return new _nodes.ValueNode(value.node, this);
|
|
27
|
-
}
|
|
28
|
-
if (value instanceof _nodes.ValueNode) {
|
|
29
|
-
if (!this.isNodeLike(value)) throw new Error('Incompatible node');
|
|
30
|
-
return super.adoptNode(value);
|
|
31
|
-
}
|
|
32
|
-
return new _nodes.ValueNode(value, this);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// iterators
|
|
36
|
-
|
|
37
|
-
[Symbol.iterator]() {
|
|
38
|
-
let current = this.head,
|
|
39
|
-
readyToStop = this.isEmpty;
|
|
40
|
-
return (0, _metaUtils.normalizeIterator)({
|
|
41
|
-
next: () => {
|
|
42
|
-
if (readyToStop && current === this.head) return {
|
|
43
|
-
done: true
|
|
44
|
-
};
|
|
45
|
-
readyToStop = true;
|
|
46
|
-
const value = current.value;
|
|
47
|
-
current = current[this.nextName];
|
|
48
|
-
return {
|
|
49
|
-
value
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
getValueIterator(range) {
|
|
55
|
-
return (0, _metaUtils.mapIterator)(this.getNodeIterator(range), node => node.value);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// meta helpers
|
|
59
|
-
|
|
60
|
-
clone() {
|
|
61
|
-
return new ExtValueSList(this);
|
|
62
|
-
}
|
|
63
|
-
make(head = null) {
|
|
64
|
-
return new ExtValueSList(head, this);
|
|
65
|
-
}
|
|
66
|
-
makeFrom(values) {
|
|
67
|
-
return ExtValueSList.from(values, this);
|
|
68
|
-
}
|
|
69
|
-
static from(values, options) {
|
|
70
|
-
const list = new ExtValueSList(null, options);
|
|
71
|
-
for (const value of values) {
|
|
72
|
-
list.addAfter(value);
|
|
73
|
-
list.next();
|
|
74
|
-
}
|
|
75
|
-
return list.next();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.ExtValueSList = ExtValueSList;
|
|
79
|
-
ExtValueSList.Ptr = _ext.Ptr;
|
|
80
|
-
ExtValueSList.ValueNode = _nodes.ValueNode;
|
|
81
|
-
(0, _metaUtils.addAlias)(ExtValueSList.prototype, 'getIterator', 'getValueIterator');
|
|
82
|
-
var _default = exports.default = ExtValueSList;
|