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.
Files changed (125) hide show
  1. package/README.md +40 -36
  2. package/llms-full.txt +743 -0
  3. package/llms.txt +100 -0
  4. package/package.json +40 -32
  5. package/src/cache/cache-fifo.d.ts +6 -0
  6. package/src/cache/cache-fifo.js +7 -4
  7. package/src/cache/cache-lfu.d.ts +18 -0
  8. package/src/cache/cache-lfu.js +18 -6
  9. package/src/cache/cache-lru.d.ts +74 -0
  10. package/src/cache/cache-lru.js +60 -5
  11. package/src/cache/cache-random.d.ts +20 -0
  12. package/src/cache/cache-random.js +17 -6
  13. package/src/cache/decorator.d.ts +46 -0
  14. package/src/cache/decorator.js +26 -2
  15. package/src/cache.d.ts +13 -0
  16. package/src/cache.js +7 -2
  17. package/src/ext-list.d.ts +3 -0
  18. package/src/ext-list.js +0 -2
  19. package/src/ext-slist.d.ts +3 -0
  20. package/src/ext-slist.js +0 -2
  21. package/src/ext-value-list.d.ts +3 -0
  22. package/src/ext-value-list.js +0 -2
  23. package/src/ext-value-slist.d.ts +3 -0
  24. package/src/ext-value-slist.js +0 -2
  25. package/src/heap/basics.d.ts +89 -0
  26. package/src/heap/basics.js +42 -5
  27. package/src/heap/leftist-heap.d.ts +107 -0
  28. package/src/heap/leftist-heap.js +54 -2
  29. package/src/heap/min-heap.d.ts +270 -0
  30. package/src/heap/min-heap.js +186 -2
  31. package/src/heap/skew-heap.d.ts +105 -0
  32. package/src/heap/skew-heap.js +54 -2
  33. package/src/heap.d.ts +3 -0
  34. package/src/heap.js +0 -2
  35. package/src/list/basics.d.ts +43 -0
  36. package/src/list/basics.js +26 -8
  37. package/src/list/core.d.ts +271 -0
  38. package/src/list/core.js +162 -7
  39. package/src/list/ext-value.d.ts +253 -0
  40. package/src/list/ext-value.js +40 -6
  41. package/src/list/ext.d.ts +242 -0
  42. package/src/list/ext.js +148 -10
  43. package/src/list/nodes.d.ts +336 -0
  44. package/src/list/nodes.js +141 -3
  45. package/src/list/ptr.d.ts +72 -0
  46. package/src/list/ptr.js +44 -2
  47. package/src/list/value.d.ts +292 -0
  48. package/src/list/value.js +47 -6
  49. package/src/list-helpers.d.ts +44 -0
  50. package/src/list-helpers.js +36 -3
  51. package/src/list-utils.d.ts +141 -0
  52. package/src/list-utils.js +89 -3
  53. package/src/list.d.ts +3 -0
  54. package/src/list.js +0 -2
  55. package/src/meta-utils.d.ts +212 -0
  56. package/src/meta-utils.js +152 -1
  57. package/src/nt-utils.d.ts +91 -0
  58. package/src/nt-utils.js +65 -4
  59. package/src/queue.d.ts +74 -0
  60. package/src/queue.js +28 -2
  61. package/src/slist/basics.d.ts +47 -0
  62. package/src/slist/basics.js +23 -8
  63. package/src/slist/core.d.ts +251 -0
  64. package/src/slist/core.js +151 -6
  65. package/src/slist/ext-value.d.ts +188 -0
  66. package/src/slist/ext-value.js +35 -6
  67. package/src/slist/ext.d.ts +182 -0
  68. package/src/slist/ext.js +114 -12
  69. package/src/slist/nodes.d.ts +361 -0
  70. package/src/slist/nodes.js +156 -3
  71. package/src/slist/ptr.d.ts +73 -0
  72. package/src/slist/ptr.js +45 -2
  73. package/src/slist/value.d.ts +246 -0
  74. package/src/slist/value.js +38 -6
  75. package/src/slist.d.ts +3 -0
  76. package/src/slist.js +0 -2
  77. package/src/stack.d.ts +59 -0
  78. package/src/stack.js +29 -3
  79. package/src/tree/splay-tree.d.ts +151 -0
  80. package/src/tree/splay-tree.js +94 -3
  81. package/src/value-list.d.ts +3 -0
  82. package/src/value-list.js +0 -2
  83. package/src/value-slist.d.ts +3 -0
  84. package/src/value-slist.js +0 -2
  85. package/cjs/cache/cache-fifo.js +0 -37
  86. package/cjs/cache/cache-lfu.js +0 -76
  87. package/cjs/cache/cache-lru.js +0 -100
  88. package/cjs/cache/cache-random.js +0 -77
  89. package/cjs/cache/decorator.js +0 -47
  90. package/cjs/cache.js +0 -27
  91. package/cjs/ext-list.js +0 -21
  92. package/cjs/ext-slist.js +0 -21
  93. package/cjs/ext-value-list.js +0 -21
  94. package/cjs/ext-value-slist.js +0 -21
  95. package/cjs/heap/basics.js +0 -63
  96. package/cjs/heap/leftist-heap.js +0 -124
  97. package/cjs/heap/min-heap.js +0 -294
  98. package/cjs/heap/skew-heap.js +0 -114
  99. package/cjs/heap.js +0 -21
  100. package/cjs/list/basics.js +0 -88
  101. package/cjs/list/core.js +0 -305
  102. package/cjs/list/ext-value.js +0 -88
  103. package/cjs/list/ext.js +0 -356
  104. package/cjs/list/nodes.js +0 -240
  105. package/cjs/list/ptr.js +0 -61
  106. package/cjs/list/value.js +0 -99
  107. package/cjs/list-helpers.js +0 -91
  108. package/cjs/list-utils.js +0 -141
  109. package/cjs/list.js +0 -21
  110. package/cjs/meta-utils.js +0 -171
  111. package/cjs/nt-utils.js +0 -132
  112. package/cjs/package.json +0 -1
  113. package/cjs/queue.js +0 -58
  114. package/cjs/slist/basics.js +0 -71
  115. package/cjs/slist/core.js +0 -362
  116. package/cjs/slist/ext-value.js +0 -82
  117. package/cjs/slist/ext.js +0 -336
  118. package/cjs/slist/nodes.js +0 -276
  119. package/cjs/slist/ptr.js +0 -87
  120. package/cjs/slist/value.js +0 -90
  121. package/cjs/slist.js +0 -21
  122. package/cjs/stack.js +0 -55
  123. package/cjs/tree/splay-tree.js +0 -362
  124. package/cjs/value-list.js +0 -21
  125. package/cjs/value-slist.js +0 -21
package/cjs/list/ext.js DELETED
@@ -1,356 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.Ptr = exports.ExtList = void 0;
7
- var _nodes = require("./nodes.js");
8
- var _basics = require("./basics.js");
9
- var _metaUtils = require("../meta-utils.js");
10
- class Ptr extends _nodes.PtrBase {
11
- constructor(list, node) {
12
- super(list, node, ExtList);
13
- this.node ||= this.list.head;
14
- }
15
- clone() {
16
- return new Ptr(this);
17
- }
18
- }
19
- exports.Ptr = Ptr;
20
- class ExtList extends _nodes.ExtListBase {
21
- makePtr(node) {
22
- if (node && !this.isNodeLike(node)) throw new Error('"node" is not a compatible node');
23
- node ||= this.head;
24
- return node ? new Ptr(this, node) : null;
25
- }
26
- makePtrFromPrev(prev) {
27
- if (prev && !this.isNodeLike(prev)) throw new Error('"prev" is not a compatible node');
28
- return new Ptr(this, prev ? prev[this.nextName] : this.front);
29
- }
30
-
31
- // Ptr API
32
-
33
- removeCurrent() {
34
- if (!this.head) return null;
35
- if (this.head[this.nextName] === this.head) {
36
- const node = this.head;
37
- this.head = null;
38
- return node;
39
- }
40
- const result = (0, _basics.pop)(this, this.head);
41
- this.head = result.rest;
42
- return result.extracted;
43
- }
44
- removeNodeBefore() {
45
- return this.head ? this.removeNode(this.head[this.prevName]) : null;
46
- }
47
- removeNodeAfter() {
48
- return this.head ? this.removeNode(this.head[this.nextName]) : null;
49
- }
50
- addBefore(value) {
51
- const node = this.adoptValue(value);
52
- if (this.head) {
53
- (0, _basics.splice)(this, this.head[this.prevName], node);
54
- } else {
55
- this.head = node;
56
- }
57
- return this.makePtr(node);
58
- }
59
- addAfter(value) {
60
- const node = this.adoptValue(value);
61
- if (this.head) {
62
- (0, _basics.splice)(this, this.head, node);
63
- } else {
64
- this.head = node;
65
- }
66
- return this.makePtr(node);
67
- }
68
- addNodeBefore(nodeOrPtr) {
69
- const node = this.adoptNode(nodeOrPtr);
70
- if (this.head) {
71
- (0, _basics.splice)(this, this.head[this.prevName], node);
72
- } else {
73
- this.head = node;
74
- }
75
- return this.makePtr(node);
76
- }
77
- addNodeAfter(nodeOrPtr) {
78
- const node = this.adoptNode(nodeOrPtr);
79
- if (this.head) {
80
- (0, _basics.splice)(this, this.head, node);
81
- } else {
82
- this.head = node;
83
- }
84
- return this.makePtr(node);
85
- }
86
- insertBefore(extList) {
87
- if (!this.isCompatible(extList)) throw new Error('Incompatible lists');
88
- const head = extList.head;
89
- if (head) {
90
- (0, _basics.splice)(this, this.head[this.prevName], head);
91
- extList.head = null;
92
- }
93
- return this.makePtr(head);
94
- }
95
- insertAfter(extList) {
96
- if (!this.isCompatible(extList)) throw new Error('Incompatible lists');
97
- const head = extList.head;
98
- if (head) {
99
- (0, _basics.splice)(this, this.head, head);
100
- extList.head = null;
101
- }
102
- return this.makePtr(head);
103
- }
104
- moveBefore(nodeOrPtr) {
105
- const node = this.normalizeNode(nodeOrPtr);
106
- if (this.head === node) {
107
- this.head = this.head[this.nextName];
108
- return this;
109
- }
110
- if (this.head) {
111
- (0, _basics.append)(this, this.head[this.prevName], {
112
- from: node
113
- });
114
- } else {
115
- (0, _basics.pop)(this, node);
116
- this.head = node;
117
- }
118
- return this.makePtr(node);
119
- }
120
- moveAfter(nodeOrPtr) {
121
- const node = this.normalizeNode(nodeOrPtr);
122
- if (this.head === node) {
123
- this.head = this.head[this.prevName];
124
- return this;
125
- }
126
- if (this.head) {
127
- (0, _basics.append)(this, this.head, {
128
- from: node
129
- });
130
- } else {
131
- (0, _basics.pop)(this, node);
132
- this.head = node;
133
- }
134
- return this.makePtr(node);
135
- }
136
-
137
- // List API
138
-
139
- clear(drop) {
140
- if (drop) {
141
- for (const current of this.getNodeIterator()) {
142
- current[this.nextName] = current[this.prevName] = current; // make stand-alone
143
- }
144
- }
145
- this.head = null;
146
- return this;
147
- }
148
- removeNode(nodeOrPtr) {
149
- if (!this.head) return null;
150
- const node = this.normalizeNode(nodeOrPtr);
151
- if (this.head === node) {
152
- // remove head
153
- if (this.head[this.nextName] === this.head) {
154
- // single node
155
- this.head = null;
156
- return node;
157
- }
158
- this.head = this.head[this.nextName];
159
- }
160
- return (0, _basics.pop)(this, node).extracted;
161
- }
162
- removeRange(range, drop) {
163
- return this.extractRange(range).clear(drop);
164
- }
165
- extractRange(range = {}) {
166
- range = this.normalizeRange(range);
167
- const {
168
- from = this.head,
169
- to = from
170
- } = range;
171
- const extracted = this.make();
172
- if (!this.head) return extracted;
173
- if (this.head === from || this.head === to) this.head = to[this.nextName];
174
- if (this.head === from) this.head = null;
175
- extracted.head = (0, _basics.extract)(this, {
176
- from,
177
- to
178
- }).extracted;
179
- return extracted;
180
- }
181
- extractBy(condition) {
182
- const extracted = this.make();
183
- if (this.isEmpty) return extracted;
184
- const rest = this.make();
185
- for (const current of this.getNodeIterator()) {
186
- current[this.nextName] = current[this.prevName] = current; // make stand-alone
187
- (condition(current) ? extracted : rest).addBefore(current);
188
- }
189
- this.head = rest.head;
190
- return extracted;
191
- }
192
- reverse() {
193
- if (this.isOneOrEmpty) return this;
194
- let current = this.head;
195
- do {
196
- const next = current[this.nextName];
197
- current[this.nextName] = current[this.prevName];
198
- current[this.prevName] = next;
199
- current = next;
200
- } while (current !== this.head);
201
- this.head = this.head[this.nextName];
202
- return this;
203
- }
204
- sort(lessFn) {
205
- if (this.isOneOrEmpty) return this;
206
- const left = this.make(),
207
- right = this.make();
208
-
209
- // split into two sublists
210
- let isLeft = true;
211
- for (const current of this.getNodeIterator()) {
212
- current[this.nextName] = current[this.prevName] = current; // make stand-alone
213
- if (isLeft) {
214
- left.addNodeAfter(current);
215
- left.next();
216
- } else {
217
- right.addNodeAfter(current);
218
- right.next();
219
- }
220
- isLeft = !isLeft;
221
- }
222
- this.clear();
223
- // the list is empty now
224
-
225
- // sort sublists
226
- left.next().sort(lessFn);
227
- right.next().sort(lessFn);
228
-
229
- // merge sublists
230
- while (!left.isEmpty && !right.isEmpty) {
231
- this.addNodeAfter((lessFn(left.head, right.head) ? left : right).removeCurrent());
232
- this.next();
233
- }
234
- if (!left.isEmpty) {
235
- const last = left.head[left.prevName];
236
- this.insertAfter(left);
237
- this.head = last;
238
- }
239
- if (!right.isEmpty) {
240
- const last = right.head[right.prevName];
241
- this.insertAfter(right);
242
- this.head = last;
243
- }
244
- return this.next();
245
- }
246
-
247
- // iterators
248
-
249
- [Symbol.iterator]() {
250
- let current = this.head,
251
- readyToStop = this.isEmpty;
252
- return (0, _metaUtils.normalizeIterator)({
253
- next: () => {
254
- if (readyToStop && current === this.head) return {
255
- done: true
256
- };
257
- readyToStop = true;
258
- const value = current;
259
- current = current[this.nextName];
260
- return {
261
- value
262
- };
263
- }
264
- });
265
- }
266
- getNodeIterator(range = {}) {
267
- range = this.normalizeRange(range);
268
- const {
269
- from,
270
- to
271
- } = range;
272
- return {
273
- [Symbol.iterator]: () => {
274
- let readyToStop = this.isEmpty,
275
- current = readyToStop ? null : from || this.head;
276
- const stop = readyToStop ? null : to ? to[this.nextName] : this.head;
277
- return (0, _metaUtils.normalizeIterator)({
278
- next: () => {
279
- if (readyToStop && current === stop) return {
280
- done: true
281
- };
282
- readyToStop = true;
283
- const value = current;
284
- current = current[this.nextName];
285
- return {
286
- value
287
- };
288
- }
289
- });
290
- }
291
- };
292
- }
293
- getPtrIterator(range) {
294
- return mapIterator(this.getNodeIterator(range), node => new Ptr(this, node));
295
- }
296
- getReverseNodeIterator(range = {}) {
297
- range = this.normalizeRange(range);
298
- const {
299
- from,
300
- to
301
- } = range;
302
- return {
303
- [Symbol.iterator]: () => {
304
- let readyToStop = this.isEmpty,
305
- current = readyToStop ? null : to || this.head[this.prevName];
306
- const stop = readyToStop ? null : from ? from[this.prevName] : this.head[this.prevName];
307
- return (0, _metaUtils.normalizeIterator)({
308
- next: () => {
309
- if (readyToStop && current === stop) return {
310
- done: true
311
- };
312
- readyToStop = true;
313
- const value = current;
314
- current = current[this.prevName];
315
- return {
316
- value
317
- };
318
- }
319
- });
320
- }
321
- };
322
- }
323
- getReversePtrIterator(range) {
324
- return mapIterator(this.getReverseNodeIterator(range), node => new Ptr(this, node));
325
- }
326
-
327
- // meta helpers
328
-
329
- clone() {
330
- return new ExtList(this);
331
- }
332
- make(head = null) {
333
- return new ExtList(head, this);
334
- }
335
- makeFrom(values) {
336
- return ExtList.from(values, this);
337
- }
338
- static from(values, options) {
339
- const list = new ExtList(null, options);
340
- for (const value of values) {
341
- list.addNodeAfter(value);
342
- list.next();
343
- }
344
- return list.next();
345
- }
346
- }
347
- exports.ExtList = ExtList;
348
- ExtList.Ptr = Ptr;
349
- (0, _metaUtils.addAliases)(ExtList.prototype, {
350
- addAfter: 'add',
351
- removeNodeBefore: 'removeBefore',
352
- removeNodeAfter: 'removeAfter',
353
- getNodeIterator: 'getIterator',
354
- getReverseNodeIterator: 'getReverseIterator'
355
- });
356
- var _default = exports.default = ExtList;
package/cjs/list/nodes.js DELETED
@@ -1,240 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isStandAlone = exports.isNodeLike = exports.isCompatible = exports.ValueNode = exports.PtrBase = exports.Node = exports.HeadNode = exports.ExtListBase = void 0;
7
- var _listHelpers = require("../list-helpers.js");
8
- var _metaUtils = require("../meta-utils.js");
9
- const isNodeLike = ({
10
- nextName,
11
- prevName
12
- }, node) => node && node[prevName] && node[nextName];
13
- exports.isNodeLike = isNodeLike;
14
- const isStandAlone = ({
15
- nextName,
16
- prevName
17
- }, node) => node && node[prevName] === node && node[nextName] === node;
18
- exports.isStandAlone = isStandAlone;
19
- const isCompatible = (options1, options2) => options1.nextName === options2.nextName && options1.prevName === options2.prevName;
20
- exports.isCompatible = isCompatible;
21
- class Node {
22
- constructor({
23
- nextName = 'next',
24
- prevName = 'prev'
25
- } = {}) {
26
- this.nextName = nextName;
27
- this.prevName = prevName;
28
- this[nextName] = this[prevName] = this;
29
- }
30
- get isStandAlone() {
31
- return this[this.nextName] === this;
32
- }
33
- }
34
- exports.Node = Node;
35
- class HeadNode extends Node {
36
- isNodeLike(node) {
37
- if (!node) return false;
38
- const next = node[this.nextName];
39
- if (!next || _metaUtils.canHaveProps[typeof next] !== 1) return false;
40
- const prev = node[this.prevName];
41
- return prev && _metaUtils.canHaveProps[typeof prev] === 1;
42
- }
43
- isCompatibleNames({
44
- nextName,
45
- prevName
46
- }) {
47
- return this.nextName === nextName && this.prevName === prevName;
48
- }
49
- isCompatible(list) {
50
- return list === this || list instanceof HeadNode && this.nextName === list.nextName && this.prevName === list.prevName;
51
- }
52
- isCompatiblePtr(ptr) {
53
- return ptr instanceof PtrBase && (ptr.list === this || ptr.list instanceof HeadNode && this.nextName === ptr.list.nextName && this.prevName === ptr.list.prevName);
54
- }
55
- isCompatibleRange(range) {
56
- return (0, _listHelpers.isRangeLike)(this, range);
57
- }
58
- get isEmpty() {
59
- return this[this.nextName] === this;
60
- }
61
- get isOne() {
62
- return this[this.nextName] !== this && this[this.nextName][this.nextName] === this;
63
- }
64
- get isOneOrEmpty() {
65
- return this[this.nextName][this.nextName] === this;
66
- }
67
- get head() {
68
- return this;
69
- }
70
- get front() {
71
- return this[this.nextName];
72
- }
73
- get back() {
74
- return this[this.prevName];
75
- }
76
- get range() {
77
- return this[this.nextName] === this ? null : {
78
- from: this[this.nextName],
79
- to: this[this.prevName],
80
- list: this
81
- };
82
- }
83
- getLength() {
84
- let n = 0;
85
- const nextName = this.nextName;
86
- for (let p = this[nextName]; p !== this; ++n, p = p[nextName]);
87
- return n;
88
- }
89
- adoptNode(nodeOrPtr) {
90
- const node = nodeOrPtr instanceof PtrBase ? nodeOrPtr.node : nodeOrPtr;
91
- if (node[this.nextName] || node[this.prevName]) {
92
- if (node[this.nextName] === node && node[this.prevName] === node) return node;
93
- throw new Error('node is already a part of a list, or there is a name clash');
94
- }
95
- node[this.nextName] = node[this.prevName] = node;
96
- if (nodeOrPtr instanceof PtrBase) nodeOrPtr.list = this;
97
- return node;
98
- }
99
- normalizeNode(nodeOrPtr) {
100
- const node = (0, _listHelpers.normalizeNode)(this, nodeOrPtr, PtrBase);
101
- if (nodeOrPtr instanceof PtrBase) nodeOrPtr.list = this;
102
- return node;
103
- }
104
- normalizeRange(range) {
105
- return (0, _listHelpers.normalizeRange)(this, range, PtrBase);
106
- }
107
- }
108
- exports.HeadNode = HeadNode;
109
- (0, _metaUtils.addAlias)(HeadNode.prototype, 'adoptNode', 'adoptValue');
110
- class ValueNode extends Node {
111
- constructor(value, options) {
112
- super(options);
113
- this.value = value;
114
- }
115
- }
116
- exports.ValueNode = ValueNode;
117
- class PtrBase {
118
- constructor(list, node, ListClass) {
119
- if (list instanceof PtrBase) {
120
- this.list = list.list;
121
- this.node = list.node;
122
- return;
123
- }
124
- if (!(list instanceof ListClass)) throw new Error('"list" is not a compatible list');
125
- if (node instanceof PtrBase) {
126
- if (list !== node.list) throw new Error('Node specified by a pointer must belong to the same list');
127
- this.list = list;
128
- this.node = node.node;
129
- } else {
130
- this.list = list;
131
- this.node = node;
132
- }
133
- if (this.node && !isNodeLike(this.list, this.node)) throw new Error('"node" is not a compatible node');
134
- if (!this.node) this.node = this.list.front;
135
- }
136
- get nextNode() {
137
- return this.node[this.list.nextName];
138
- }
139
- get prevNode() {
140
- return this.node[this.list.prevName];
141
- }
142
- isPrevNodeValid() {
143
- return true;
144
- }
145
- next() {
146
- this.node = this.node[this.list.nextName];
147
- return this;
148
- }
149
- prev() {
150
- this.node = this.node[this.list.prevName];
151
- return this;
152
- }
153
- }
154
- exports.PtrBase = PtrBase;
155
- class ExtListBase {
156
- constructor(head = null, {
157
- nextName = 'next',
158
- prevName = 'prev'
159
- } = {}) {
160
- if (head instanceof ExtListBase) {
161
- this.nextName = head.nextName;
162
- this.prevName = head.prevName;
163
- this.attach(head.head);
164
- return;
165
- }
166
- if (head instanceof PtrBase) {
167
- this.nextName = head.list.nextName;
168
- this.prevName = head.list.prevName;
169
- this.attach(head.node);
170
- return;
171
- }
172
- this.nextName = nextName;
173
- this.prevName = prevName;
174
- this.attach(head);
175
- }
176
- isCompatible(list) {
177
- return list === this || list instanceof ExtListBase && this.nextName === list.nextName && this.prevName === list.prevName;
178
- }
179
- isCompatiblePtr(ptr) {
180
- return ptr instanceof PtrBase && (ptr.list === this || ptr.list instanceof ExtListBase && this.nextName === ptr.list.nextName && this.prevName === ptr.list.prevName);
181
- }
182
- get isEmpty() {
183
- return !this.head;
184
- }
185
- get isOne() {
186
- return this.head && this.head[this.nextName] === this.head;
187
- }
188
- get isOneOrEmpty() {
189
- return !this.head || this.head[this.nextName] === this.head;
190
- }
191
- get front() {
192
- return this.head;
193
- }
194
- get back() {
195
- return this.head?.[this.prevName];
196
- }
197
- get range() {
198
- return this.head ? {
199
- from: this.head,
200
- to: this.head[this.prevName],
201
- list: this.head
202
- } : null;
203
- }
204
- getLength() {
205
- if (!this.head) return 0;
206
- let n = 0,
207
- current = this.head;
208
- do {
209
- current = current[this.nextName];
210
- ++n;
211
- } while (current !== this.head);
212
- return n;
213
- }
214
- attach(head = null) {
215
- const oldHead = this.head;
216
- if (head instanceof PtrBase) {
217
- if (!this.isCompatible(head.list)) throw new Error('Incompatible lists');
218
- this.head = head.node;
219
- } else {
220
- if (head && !this.isNodeLike(head)) throw new Error('"head" is not a compatible node');
221
- this.head = head;
222
- }
223
- return oldHead;
224
- }
225
- detach() {
226
- const oldHead = this.head;
227
- this.head = null;
228
- return oldHead;
229
- }
230
- next() {
231
- if (this.head) this.head = this.head[this.nextName];
232
- return this;
233
- }
234
- prev() {
235
- if (this.head) this.head = this.head[this.prevName];
236
- return this;
237
- }
238
- }
239
- exports.ExtListBase = ExtListBase;
240
- (0, _metaUtils.copyDescriptors)(ExtListBase.prototype, HeadNode.prototype, ['isNodeLike', 'isCompatibleNames', 'isCompatibleRange', 'normalizeNode', 'normalizeRange', 'adoptNode', 'adoptValue']);
package/cjs/list/ptr.js DELETED
@@ -1,61 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.Ptr = void 0;
7
- var _nodes = require("./nodes.js");
8
- var _basics = require("./basics.js");
9
- class Ptr extends _nodes.PtrBase {
10
- constructor(list, node) {
11
- super(list, node, _nodes.HeadNode);
12
- }
13
- get isHead() {
14
- return this.node === this.list;
15
- }
16
- clone() {
17
- return new Ptr(this);
18
- }
19
- removeCurrent() {
20
- if (this.node === this.list) return null;
21
- const node = this.node;
22
- this.node = node[this.list.nextName];
23
- return (0, _basics.pop)(this.list, node).extracted;
24
- }
25
- addBefore(value) {
26
- const node = this.list.adoptValue(value);
27
- (0, _basics.splice)(this.list, this.node[this.list.prevName], node);
28
- return this.list.makePtr(node);
29
- }
30
- addNodeBefore(node) {
31
- node = this.list.adoptNode(node);
32
- (0, _basics.splice)(this.list, this.node[this.list.prevName], node);
33
- return this.list.makePtr(node);
34
- }
35
- addAfter(value) {
36
- const node = this.list.adoptValue(value);
37
- (0, _basics.splice)(this.list, this.node, node);
38
- return this.list.makePtr(node);
39
- }
40
- addNodeAfter(node) {
41
- node = this.list.adoptNode(node);
42
- (0, _basics.splice)(this.list, this.node, node);
43
- return this.list.makePtr(node);
44
- }
45
- insertBefore(list) {
46
- if (!this.list.isCompatible(list)) throw new Error('Incompatible lists');
47
- if (list.isEmpty) return null;
48
- const head = (0, _basics.pop)(list, list).rest;
49
- (0, _basics.splice)(this.list, this.node[this.list.prevName], head);
50
- return this.list.makePtr(head);
51
- }
52
- insertAfter(list) {
53
- if (!this.list.isCompatible(list)) throw new Error('Incompatible lists');
54
- if (list.isEmpty) return null;
55
- const head = (0, _basics.pop)(list, list).rest;
56
- (0, _basics.splice)(this.list, this.node, head);
57
- return this.list.makePtr(head);
58
- }
59
- }
60
- exports.Ptr = Ptr;
61
- var _default = exports.default = Ptr;