max-priority-queue-typed 2.4.4 → 2.5.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 +63 -0
- package/dist/cjs/index.cjs +403 -98
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +402 -97
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +403 -99
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +402 -98
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +23 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +439 -78
- package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +217 -31
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +220 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +218 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
- package/dist/types/data-structures/heap/heap.d.ts +287 -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 +286 -44
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +331 -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 +313 -66
- package/dist/types/data-structures/queue/queue.d.ts +211 -42
- package/dist/types/data-structures/stack/stack.d.ts +174 -32
- package/dist/types/data-structures/trie/trie.d.ts +213 -43
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/queue/deque.d.ts +6 -0
- package/dist/umd/max-priority-queue-typed.js +400 -95
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +60 -0
- package/src/common/index.ts +2 -0
- package/src/data-structures/base/iterable-element-base.ts +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +134 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +303 -247
- package/src/data-structures/binary-tree/binary-tree.ts +542 -121
- package/src/data-structures/binary-tree/bst.ts +346 -37
- package/src/data-structures/binary-tree/red-black-tree.ts +309 -96
- package/src/data-structures/binary-tree/segment-tree.ts +372 -248
- package/src/data-structures/binary-tree/tree-map.ts +1292 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +1098 -215
- package/src/data-structures/binary-tree/tree-multi-set.ts +863 -69
- package/src/data-structures/binary-tree/tree-set.ts +1143 -15
- package/src/data-structures/graph/abstract-graph.ts +106 -1
- package/src/data-structures/graph/directed-graph.ts +223 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +299 -59
- package/src/data-structures/hash/hash-map.ts +243 -79
- package/src/data-structures/heap/heap.ts +291 -102
- package/src/data-structures/heap/max-heap.ts +48 -3
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
- package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
- package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
- package/src/data-structures/matrix/matrix.ts +425 -22
- package/src/data-structures/priority-queue/max-priority-queue.ts +59 -3
- 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 +343 -68
- package/src/data-structures/queue/queue.ts +211 -42
- package/src/data-structures/stack/stack.ts +174 -32
- package/src/data-structures/trie/trie.ts +215 -44
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/queue/deque.ts +7 -0
- package/src/utils/utils.ts +4 -2
|
@@ -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,86 @@ 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
|
+
* @example
|
|
200
|
+
* // basic DoublyLinkedList creation and push operation
|
|
201
|
+
* // Create a simple DoublyLinkedList with initial values
|
|
202
|
+
* const list = new DoublyLinkedList([1, 2, 3, 4, 5]);
|
|
203
|
+
*
|
|
204
|
+
* // Verify the list maintains insertion order
|
|
205
|
+
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
206
|
+
*
|
|
207
|
+
* // Check length
|
|
208
|
+
* console.log(list.length); // 5;
|
|
209
|
+
*
|
|
210
|
+
* // Push a new element to the end
|
|
211
|
+
* list.push(6);
|
|
212
|
+
* console.log(list.length); // 6;
|
|
213
|
+
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
222
214
|
*/
|
|
223
215
|
push(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
224
216
|
/**
|
|
225
217
|
* Remove and return the tail element.
|
|
226
218
|
* @remarks Time O(1), Space O(1)
|
|
227
219
|
* @returns Removed element or undefined.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
* @example
|
|
232
|
+
* // DoublyLinkedList pop and shift operations
|
|
233
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
234
|
+
*
|
|
235
|
+
* // Pop removes from the end
|
|
236
|
+
* const last = list.pop();
|
|
237
|
+
* console.log(last); // 50;
|
|
238
|
+
*
|
|
239
|
+
* // Shift removes from the beginning
|
|
240
|
+
* const first = list.shift();
|
|
241
|
+
* console.log(first); // 10;
|
|
242
|
+
*
|
|
243
|
+
* // Verify remaining elements
|
|
244
|
+
* console.log([...list]); // [20, 30, 40];
|
|
245
|
+
* console.log(list.length); // 3;
|
|
228
246
|
*/
|
|
229
247
|
pop(): E | undefined;
|
|
230
248
|
/**
|
|
231
249
|
* Remove and return the head element.
|
|
232
250
|
* @remarks Time O(1), Space O(1)
|
|
233
251
|
* @returns Removed element or undefined.
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
* @example
|
|
264
|
+
* // Remove from the front
|
|
265
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30]);
|
|
266
|
+
* console.log(list.shift()); // 10;
|
|
267
|
+
* console.log(list.first); // 20;
|
|
234
268
|
*/
|
|
235
269
|
shift(): E | undefined;
|
|
236
270
|
/**
|
|
@@ -238,6 +272,22 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
238
272
|
* @remarks Time O(1), Space O(1)
|
|
239
273
|
* @param elementOrNode - Element or node to prepend.
|
|
240
274
|
* @returns True when prepended.
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
* @example
|
|
287
|
+
* // Add to the front
|
|
288
|
+
* const list = new DoublyLinkedList<number>([2, 3]);
|
|
289
|
+
* list.unshift(1);
|
|
290
|
+
* console.log([...list]); // [1, 2, 3];
|
|
241
291
|
*/
|
|
242
292
|
unshift(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
243
293
|
/**
|
|
@@ -259,6 +309,22 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
259
309
|
* @remarks Time O(N), Space O(1)
|
|
260
310
|
* @param index - Zero-based index.
|
|
261
311
|
* @returns Element or undefined.
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
* @example
|
|
324
|
+
* // Access by index
|
|
325
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
326
|
+
* console.log(list.at(1)); // 'b';
|
|
327
|
+
* console.log(list.at(2)); // 'c';
|
|
262
328
|
*/
|
|
263
329
|
at(index: number): E | undefined;
|
|
264
330
|
/**
|
|
@@ -266,6 +332,18 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
266
332
|
* @remarks Time O(N), Space O(1)
|
|
267
333
|
* @param index - Zero-based index.
|
|
268
334
|
* @returns Node or undefined.
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
* @example
|
|
344
|
+
* // Get node at index
|
|
345
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
346
|
+
* console.log(list.getNodeAt(1)?.value); // 'b';
|
|
269
347
|
*/
|
|
270
348
|
getNodeAt(index: number): DoublyLinkedListNode<E> | undefined;
|
|
271
349
|
/**
|
|
@@ -281,6 +359,19 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
281
359
|
* @param index - Zero-based index.
|
|
282
360
|
* @param newElementOrNode - Element or node to insert.
|
|
283
361
|
* @returns True if inserted.
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
* @example
|
|
371
|
+
* // Insert at position
|
|
372
|
+
* const list = new DoublyLinkedList<number>([1, 3]);
|
|
373
|
+
* list.addAt(1, 2);
|
|
374
|
+
* console.log(list.toArray()); // [1, 2, 3];
|
|
284
375
|
*/
|
|
285
376
|
addAt(index: number, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
286
377
|
/**
|
|
@@ -312,6 +403,19 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
312
403
|
* @remarks Time O(N), Space O(1)
|
|
313
404
|
* @param index - Zero-based index.
|
|
314
405
|
* @returns Removed element or undefined.
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
* @example
|
|
415
|
+
* // Remove by index
|
|
416
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
417
|
+
* list.deleteAt(1);
|
|
418
|
+
* console.log(list.toArray()); // ['a', 'c'];
|
|
315
419
|
*/
|
|
316
420
|
deleteAt(index: number): E | undefined;
|
|
317
421
|
/**
|
|
@@ -319,18 +423,57 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
319
423
|
* @remarks Time O(N), Space O(1)
|
|
320
424
|
* @param [elementOrNode] - Element or node to remove.
|
|
321
425
|
* @returns True if removed.
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
* @example
|
|
435
|
+
* // Remove first occurrence
|
|
436
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 2]);
|
|
437
|
+
* list.delete(2);
|
|
438
|
+
* console.log(list.toArray()); // [1, 3, 2];
|
|
322
439
|
*/
|
|
323
440
|
delete(elementOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
324
441
|
/**
|
|
325
442
|
* Check whether the list is empty.
|
|
326
443
|
* @remarks Time O(1), Space O(1)
|
|
327
444
|
* @returns True if length is 0.
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
* @example
|
|
455
|
+
* // Check empty
|
|
456
|
+
* console.log(new DoublyLinkedList().isEmpty()); // true;
|
|
328
457
|
*/
|
|
329
458
|
isEmpty(): boolean;
|
|
330
459
|
/**
|
|
331
460
|
* Remove all nodes and reset length.
|
|
332
461
|
* @remarks Time O(N), Space O(1)
|
|
333
462
|
* @returns void
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
* @example
|
|
473
|
+
* // Remove all
|
|
474
|
+
* const list = new DoublyLinkedList<number>([1, 2]);
|
|
475
|
+
* list.clear();
|
|
476
|
+
* console.log(list.isEmpty()); // true;
|
|
334
477
|
*/
|
|
335
478
|
clear(): void;
|
|
336
479
|
/**
|
|
@@ -338,6 +481,19 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
338
481
|
* @remarks Time O(N), Space O(1)
|
|
339
482
|
* @param elementNodeOrPredicate - Element, node, or predicate to match.
|
|
340
483
|
* @returns Matched value or undefined.
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
* @example
|
|
493
|
+
* // Search with predicate
|
|
494
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30]);
|
|
495
|
+
* const found = list.search(node => node.value > 15);
|
|
496
|
+
* console.log(found); // 20;
|
|
341
497
|
*/
|
|
342
498
|
search(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
|
|
343
499
|
/**
|
|
@@ -345,12 +501,42 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
345
501
|
* @remarks Time O(N), Space O(1)
|
|
346
502
|
* @param elementNodeOrPredicate - Element, node, or predicate to match.
|
|
347
503
|
* @returns Matched value or undefined.
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
* @example
|
|
513
|
+
* // Find value scanning from tail
|
|
514
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
|
|
515
|
+
* // getBackward scans from tail to head, returns first match
|
|
516
|
+
* const found = list.getBackward(node => node.value < 4);
|
|
517
|
+
* console.log(found); // 3;
|
|
348
518
|
*/
|
|
349
519
|
getBackward(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
|
|
350
520
|
/**
|
|
351
521
|
* Reverse the list in place.
|
|
352
522
|
* @remarks Time O(N), Space O(1)
|
|
353
523
|
* @returns This list.
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
* @example
|
|
536
|
+
* // Reverse in-place
|
|
537
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
538
|
+
* list.reverse();
|
|
539
|
+
* console.log([...list]); // [3, 2, 1];
|
|
354
540
|
*/
|
|
355
541
|
reverse(): this;
|
|
356
542
|
/**
|
|
@@ -364,6 +550,21 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
364
550
|
* Deep clone this list (values are copied by reference).
|
|
365
551
|
* @remarks Time O(N), Space O(N)
|
|
366
552
|
* @returns A new list with the same element sequence.
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
* @example
|
|
563
|
+
* // Deep copy
|
|
564
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
565
|
+
* const copy = list.clone();
|
|
566
|
+
* copy.pop();
|
|
567
|
+
* console.log(list.length); // 3;
|
|
367
568
|
*/
|
|
368
569
|
clone(): this;
|
|
369
570
|
/**
|
|
@@ -372,6 +573,22 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
372
573
|
* @param callback - Predicate (value, index, list) → boolean to keep value.
|
|
373
574
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
374
575
|
* @returns A new list with kept values.
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
* @example
|
|
588
|
+
* // Filter elements
|
|
589
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
590
|
+
* const evens = list.filter(n => n % 2 === 0);
|
|
591
|
+
* console.log([...evens]); // [2, 4];
|
|
375
592
|
*/
|
|
376
593
|
filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): this;
|
|
377
594
|
/**
|
|
@@ -391,6 +608,31 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
391
608
|
* @param [options] - Options for the output list (e.g., maxLen, toElementFn).
|
|
392
609
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
393
610
|
* @returns A new DoublyLinkedList with mapped values.
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
* @example
|
|
623
|
+
* // DoublyLinkedList for...of iteration and map operation
|
|
624
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
625
|
+
*
|
|
626
|
+
* // Iterate through list
|
|
627
|
+
* const doubled = list.map(value => value * 2);
|
|
628
|
+
* console.log(doubled.length); // 5;
|
|
629
|
+
*
|
|
630
|
+
* // Use for...of loop
|
|
631
|
+
* const result: number[] = [];
|
|
632
|
+
* for (const item of list) {
|
|
633
|
+
* result.push(item);
|
|
634
|
+
* }
|
|
635
|
+
* console.log(result); // [1, 2, 3, 4, 5];
|
|
394
636
|
*/
|
|
395
637
|
map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: DoublyLinkedListOptions<EM, RM>, thisArg?: any): DoublyLinkedList<EM, RM>;
|
|
396
638
|
/**
|