binary-tree-typed 2.4.5 → 2.5.1
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 +0 -84
- package/dist/cjs/index.cjs +1476 -404
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1473 -401
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1476 -404
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1473 -401
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
- package/dist/types/data-structures/heap/heap.d.ts +581 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +646 -47
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +499 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +593 -71
- package/dist/types/data-structures/queue/queue.d.ts +463 -42
- package/dist/types/data-structures/stack/stack.d.ts +384 -32
- package/dist/types/data-structures/trie/trie.d.ts +470 -48
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/binary-tree-typed.js +1469 -397
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +386 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
- package/src/data-structures/binary-tree/binary-tree.ts +956 -81
- package/src/data-structures/binary-tree/bst.ts +840 -35
- package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
- package/src/data-structures/binary-tree/segment-tree.ts +498 -249
- package/src/data-structures/binary-tree/tree-map.ts +3784 -7
- package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
- package/src/data-structures/binary-tree/tree-set.ts +3531 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +429 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +393 -59
- package/src/data-structures/hash/hash-map.ts +476 -92
- package/src/data-structures/heap/heap.ts +581 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
- package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
- package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
- package/src/data-structures/matrix/matrix.ts +584 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +592 -70
- package/src/data-structures/queue/queue.ts +463 -42
- package/src/data-structures/stack/stack.ts +384 -32
- package/src/data-structures/trie/trie.ts +470 -48
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -60,50 +60,6 @@ export declare class DoublyLinkedListNode<E = any> extends LinkedListNode<E> {
|
|
|
60
60
|
* 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
|
|
61
61
|
* Caution: Although our linked list classes provide methods such as at, setAt, addAt, and indexOf that are based on array indices, their time complexity, like that of the native Array.lastIndexOf, is 𝑂(𝑛). If you need to use these methods frequently, you might want to consider other data structures, such as Deque or Queue (designed for random access). Similarly, since the native Array.shift method has a time complexity of 𝑂(𝑛), using an array to simulate a queue can be inefficient. In such cases, you should use Queue or Deque, as these data structures leverage deferred array rearrangement, effectively reducing the average time complexity to 𝑂(1).
|
|
62
62
|
* @example
|
|
63
|
-
* // basic DoublyLinkedList creation and push operation
|
|
64
|
-
* // Create a simple DoublyLinkedList with initial values
|
|
65
|
-
* const list = new DoublyLinkedList([1, 2, 3, 4, 5]);
|
|
66
|
-
*
|
|
67
|
-
* // Verify the list maintains insertion order
|
|
68
|
-
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
69
|
-
*
|
|
70
|
-
* // Check length
|
|
71
|
-
* console.log(list.length); // 5;
|
|
72
|
-
*
|
|
73
|
-
* // Push a new element to the end
|
|
74
|
-
* list.push(6);
|
|
75
|
-
* console.log(list.length); // 6;
|
|
76
|
-
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
77
|
-
* @example
|
|
78
|
-
* // DoublyLinkedList pop and shift operations
|
|
79
|
-
* const list = new DoublyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
80
|
-
*
|
|
81
|
-
* // Pop removes from the end
|
|
82
|
-
* const last = list.pop();
|
|
83
|
-
* console.log(last); // 50;
|
|
84
|
-
*
|
|
85
|
-
* // Shift removes from the beginning
|
|
86
|
-
* const first = list.shift();
|
|
87
|
-
* console.log(first); // 10;
|
|
88
|
-
*
|
|
89
|
-
* // Verify remaining elements
|
|
90
|
-
* console.log([...list]); // [20, 30, 40];
|
|
91
|
-
* console.log(list.length); // 3;
|
|
92
|
-
* @example
|
|
93
|
-
* // DoublyLinkedList for...of iteration and map operation
|
|
94
|
-
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
95
|
-
*
|
|
96
|
-
* // Iterate through list
|
|
97
|
-
* const doubled = list.map(value => value * 2);
|
|
98
|
-
* console.log(doubled.length); // 5;
|
|
99
|
-
*
|
|
100
|
-
* // Use for...of loop
|
|
101
|
-
* const result: number[] = [];
|
|
102
|
-
* for (const item of list) {
|
|
103
|
-
* result.push(item);
|
|
104
|
-
* }
|
|
105
|
-
* console.log(result); // [1, 2, 3, 4, 5];
|
|
106
|
-
* @example
|
|
107
63
|
* // Browser history
|
|
108
64
|
* const browserHistory = new DoublyLinkedList<string>();
|
|
109
65
|
*
|
|
@@ -153,6 +109,16 @@ export declare class DoublyLinkedListNode<E = any> extends LinkedListNode<E> {
|
|
|
153
109
|
* // Access entry (in real LRU, this would move it to end)
|
|
154
110
|
* const foundEntry = [...cacheList].find(entry => entry.key === 'user:2');
|
|
155
111
|
* console.log(foundEntry?.value); // 'Bob';
|
|
112
|
+
* @example
|
|
113
|
+
* // Find first matching element
|
|
114
|
+
* const list = new DoublyLinkedList<number>([5, 10, 15, 20]);
|
|
115
|
+
* console.log(list.find(n => n >= 12)); // 15;
|
|
116
|
+
* @example
|
|
117
|
+
* // Iterate over elements
|
|
118
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
119
|
+
* const sum: number[] = [];
|
|
120
|
+
* list.forEach(n => sum.push(n));
|
|
121
|
+
* console.log(sum); // [1, 2, 3];
|
|
156
122
|
*/
|
|
157
123
|
export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, DoublyLinkedListNode<E>> {
|
|
158
124
|
protected _equals: (a: E, b: E) => boolean;
|
|
@@ -219,18 +185,149 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
219
185
|
* @remarks Time O(1), Space O(1)
|
|
220
186
|
* @param elementOrNode - Element or node to append.
|
|
221
187
|
* @returns True when appended.
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
* @example
|
|
221
|
+
* // basic DoublyLinkedList creation and push operation
|
|
222
|
+
* // Create a simple DoublyLinkedList with initial values
|
|
223
|
+
* const list = new DoublyLinkedList([1, 2, 3, 4, 5]);
|
|
224
|
+
*
|
|
225
|
+
* // Verify the list maintains insertion order
|
|
226
|
+
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
227
|
+
*
|
|
228
|
+
* // Check length
|
|
229
|
+
* console.log(list.length); // 5;
|
|
230
|
+
*
|
|
231
|
+
* // Push a new element to the end
|
|
232
|
+
* list.push(6);
|
|
233
|
+
* console.log(list.length); // 6;
|
|
234
|
+
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
222
235
|
*/
|
|
223
236
|
push(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
224
237
|
/**
|
|
225
238
|
* Remove and return the tail element.
|
|
226
239
|
* @remarks Time O(1), Space O(1)
|
|
227
240
|
* @returns Removed element or undefined.
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
* @example
|
|
274
|
+
* // DoublyLinkedList pop and shift operations
|
|
275
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
276
|
+
*
|
|
277
|
+
* // Pop removes from the end
|
|
278
|
+
* const last = list.pop();
|
|
279
|
+
* console.log(last); // 50;
|
|
280
|
+
*
|
|
281
|
+
* // Shift removes from the beginning
|
|
282
|
+
* const first = list.shift();
|
|
283
|
+
* console.log(first); // 10;
|
|
284
|
+
*
|
|
285
|
+
* // Verify remaining elements
|
|
286
|
+
* console.log([...list]); // [20, 30, 40];
|
|
287
|
+
* console.log(list.length); // 3;
|
|
228
288
|
*/
|
|
229
289
|
pop(): E | undefined;
|
|
230
290
|
/**
|
|
231
291
|
* Remove and return the head element.
|
|
232
292
|
* @remarks Time O(1), Space O(1)
|
|
233
293
|
* @returns Removed element or undefined.
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
* @example
|
|
327
|
+
* // Remove from the front
|
|
328
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30]);
|
|
329
|
+
* console.log(list.shift()); // 10;
|
|
330
|
+
* console.log(list.first); // 20;
|
|
234
331
|
*/
|
|
235
332
|
shift(): E | undefined;
|
|
236
333
|
/**
|
|
@@ -238,6 +335,43 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
238
335
|
* @remarks Time O(1), Space O(1)
|
|
239
336
|
* @param elementOrNode - Element or node to prepend.
|
|
240
337
|
* @returns True when prepended.
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
* @example
|
|
371
|
+
* // Add to the front
|
|
372
|
+
* const list = new DoublyLinkedList<number>([2, 3]);
|
|
373
|
+
* list.unshift(1);
|
|
374
|
+
* console.log([...list]); // [1, 2, 3];
|
|
241
375
|
*/
|
|
242
376
|
unshift(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
243
377
|
/**
|
|
@@ -259,6 +393,43 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
259
393
|
* @remarks Time O(N), Space O(1)
|
|
260
394
|
* @param index - Zero-based index.
|
|
261
395
|
* @returns Element or undefined.
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
* @example
|
|
429
|
+
* // Access by index
|
|
430
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
431
|
+
* console.log(list.at(1)); // 'b';
|
|
432
|
+
* console.log(list.at(2)); // 'c';
|
|
262
433
|
*/
|
|
263
434
|
at(index: number): E | undefined;
|
|
264
435
|
/**
|
|
@@ -266,6 +437,39 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
266
437
|
* @remarks Time O(N), Space O(1)
|
|
267
438
|
* @param index - Zero-based index.
|
|
268
439
|
* @returns Node or undefined.
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
* @example
|
|
470
|
+
* // Get node at index
|
|
471
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
472
|
+
* console.log(list.getNodeAt(1)?.value); // 'b';
|
|
269
473
|
*/
|
|
270
474
|
getNodeAt(index: number): DoublyLinkedListNode<E> | undefined;
|
|
271
475
|
/**
|
|
@@ -281,6 +485,40 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
281
485
|
* @param index - Zero-based index.
|
|
282
486
|
* @param newElementOrNode - Element or node to insert.
|
|
283
487
|
* @returns True if inserted.
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
* @example
|
|
518
|
+
* // Insert at position
|
|
519
|
+
* const list = new DoublyLinkedList<number>([1, 3]);
|
|
520
|
+
* list.addAt(1, 2);
|
|
521
|
+
* console.log(list.toArray()); // [1, 2, 3];
|
|
284
522
|
*/
|
|
285
523
|
addAt(index: number, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
286
524
|
/**
|
|
@@ -312,6 +550,40 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
312
550
|
* @remarks Time O(N), Space O(1)
|
|
313
551
|
* @param index - Zero-based index.
|
|
314
552
|
* @returns Removed element or undefined.
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
* @example
|
|
583
|
+
* // Remove by index
|
|
584
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
585
|
+
* list.deleteAt(1);
|
|
586
|
+
* console.log(list.toArray()); // ['a', 'c'];
|
|
315
587
|
*/
|
|
316
588
|
deleteAt(index: number): E | undefined;
|
|
317
589
|
/**
|
|
@@ -319,18 +591,120 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
319
591
|
* @remarks Time O(N), Space O(1)
|
|
320
592
|
* @param [elementOrNode] - Element or node to remove.
|
|
321
593
|
* @returns True if removed.
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
* @example
|
|
624
|
+
* // Remove first occurrence
|
|
625
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 2]);
|
|
626
|
+
* list.delete(2);
|
|
627
|
+
* console.log(list.toArray()); // [1, 3, 2];
|
|
322
628
|
*/
|
|
323
629
|
delete(elementOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
324
630
|
/**
|
|
325
631
|
* Check whether the list is empty.
|
|
326
632
|
* @remarks Time O(1), Space O(1)
|
|
327
633
|
* @returns True if length is 0.
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
* @example
|
|
665
|
+
* // Check empty
|
|
666
|
+
* console.log(new DoublyLinkedList().isEmpty()); // true;
|
|
328
667
|
*/
|
|
329
668
|
isEmpty(): boolean;
|
|
330
669
|
/**
|
|
331
670
|
* Remove all nodes and reset length.
|
|
332
671
|
* @remarks Time O(N), Space O(1)
|
|
333
672
|
* @returns void
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
* @example
|
|
704
|
+
* // Remove all
|
|
705
|
+
* const list = new DoublyLinkedList<number>([1, 2]);
|
|
706
|
+
* list.clear();
|
|
707
|
+
* console.log(list.isEmpty()); // true;
|
|
334
708
|
*/
|
|
335
709
|
clear(): void;
|
|
336
710
|
/**
|
|
@@ -338,6 +712,40 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
338
712
|
* @remarks Time O(N), Space O(1)
|
|
339
713
|
* @param elementNodeOrPredicate - Element, node, or predicate to match.
|
|
340
714
|
* @returns Matched value or undefined.
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
* @example
|
|
745
|
+
* // Search with predicate
|
|
746
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30]);
|
|
747
|
+
* const found = list.search(node => node.value > 15);
|
|
748
|
+
* console.log(found); // 20;
|
|
341
749
|
*/
|
|
342
750
|
search(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
|
|
343
751
|
/**
|
|
@@ -345,12 +753,84 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
345
753
|
* @remarks Time O(N), Space O(1)
|
|
346
754
|
* @param elementNodeOrPredicate - Element, node, or predicate to match.
|
|
347
755
|
* @returns Matched value or undefined.
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
* @example
|
|
786
|
+
* // Find value scanning from tail
|
|
787
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
|
|
788
|
+
* // getBackward scans from tail to head, returns first match
|
|
789
|
+
* const found = list.getBackward(node => node.value < 4);
|
|
790
|
+
* console.log(found); // 3;
|
|
348
791
|
*/
|
|
349
792
|
getBackward(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
|
|
350
793
|
/**
|
|
351
794
|
* Reverse the list in place.
|
|
352
795
|
* @remarks Time O(N), Space O(1)
|
|
353
796
|
* @returns This list.
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
* @example
|
|
830
|
+
* // Reverse in-place
|
|
831
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
832
|
+
* list.reverse();
|
|
833
|
+
* console.log([...list]); // [3, 2, 1];
|
|
354
834
|
*/
|
|
355
835
|
reverse(): this;
|
|
356
836
|
/**
|
|
@@ -364,6 +844,42 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
364
844
|
* Deep clone this list (values are copied by reference).
|
|
365
845
|
* @remarks Time O(N), Space O(N)
|
|
366
846
|
* @returns A new list with the same element sequence.
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
* @example
|
|
878
|
+
* // Deep copy
|
|
879
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
880
|
+
* const copy = list.clone();
|
|
881
|
+
* copy.pop();
|
|
882
|
+
* console.log(list.length); // 3;
|
|
367
883
|
*/
|
|
368
884
|
clone(): this;
|
|
369
885
|
/**
|
|
@@ -372,8 +888,45 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
372
888
|
* @param callback - Predicate (value, index, list) → boolean to keep value.
|
|
373
889
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
374
890
|
* @returns A new list with kept values.
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
* @example
|
|
924
|
+
* // Filter elements
|
|
925
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
926
|
+
* const evens = list.filter(n => n % 2 === 0);
|
|
927
|
+
* console.log([...evens]); // [2, 4];
|
|
375
928
|
*/
|
|
376
|
-
filter(callback: ElementCallback<E, R, boolean>, thisArg?:
|
|
929
|
+
filter(callback: ElementCallback<E, R, boolean>, thisArg?: unknown): this;
|
|
377
930
|
/**
|
|
378
931
|
* Map values into a new list of the same class.
|
|
379
932
|
* @remarks Time O(N), Space O(N)
|
|
@@ -381,7 +934,7 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
381
934
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
382
935
|
* @returns A new list with mapped values.
|
|
383
936
|
*/
|
|
384
|
-
mapSame(callback: ElementCallback<E, R, E>, thisArg?:
|
|
937
|
+
mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this;
|
|
385
938
|
/**
|
|
386
939
|
* Map values into a new list (possibly different element type).
|
|
387
940
|
* @remarks Time O(N), Space O(N)
|
|
@@ -391,8 +944,54 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
391
944
|
* @param [options] - Options for the output list (e.g., maxLen, toElementFn).
|
|
392
945
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
393
946
|
* @returns A new DoublyLinkedList with mapped values.
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
* @example
|
|
980
|
+
* // DoublyLinkedList for...of iteration and map operation
|
|
981
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
982
|
+
*
|
|
983
|
+
* // Iterate through list
|
|
984
|
+
* const doubled = list.map(value => value * 2);
|
|
985
|
+
* console.log(doubled.length); // 5;
|
|
986
|
+
*
|
|
987
|
+
* // Use for...of loop
|
|
988
|
+
* const result: number[] = [];
|
|
989
|
+
* for (const item of list) {
|
|
990
|
+
* result.push(item);
|
|
991
|
+
* }
|
|
992
|
+
* console.log(result); // [1, 2, 3, 4, 5];
|
|
394
993
|
*/
|
|
395
|
-
map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: DoublyLinkedListOptions<EM, RM>, thisArg?:
|
|
994
|
+
map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: DoublyLinkedListOptions<EM, RM>, thisArg?: unknown): DoublyLinkedList<EM, RM>;
|
|
396
995
|
/**
|
|
397
996
|
* (Protected) Create or return a node for the given input (node or raw element).
|
|
398
997
|
* @remarks Time O(1), Space O(1)
|