data-structure-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/CHANGELOG.md +22 -1
- package/README.md +34 -1
- package/dist/cjs/index.cjs +10639 -2151
- package/dist/cjs-legacy/index.cjs +10694 -2195
- package/dist/esm/index.mjs +10639 -2150
- package/dist/esm-legacy/index.mjs +10694 -2194
- 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/data-structure-typed.js +10725 -2221
- package/dist/umd/data-structure-typed.min.js +4 -2
- package/package.json +5 -4
- 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 +146 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +317 -247
- package/src/data-structures/binary-tree/binary-tree.ts +567 -121
- package/src/data-structures/binary-tree/bst.ts +370 -37
- package/src/data-structures/binary-tree/red-black-tree.ts +328 -96
- package/src/data-structures/binary-tree/segment-tree.ts +378 -248
- package/src/data-structures/binary-tree/tree-map.ts +1411 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +1218 -215
- package/src/data-structures/binary-tree/tree-multi-set.ts +959 -69
- package/src/data-structures/binary-tree/tree-set.ts +1257 -15
- package/src/data-structures/graph/abstract-graph.ts +106 -1
- package/src/data-structures/graph/directed-graph.ts +233 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +308 -59
- package/src/data-structures/hash/hash-map.ts +254 -79
- package/src/data-structures/heap/heap.ts +305 -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 +303 -44
- package/src/data-structures/linked-list/singly-linked-list.ts +293 -65
- package/src/data-structures/linked-list/skip-linked-list.ts +707 -90
- package/src/data-structures/matrix/matrix.ts +433 -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 +358 -68
- package/src/data-structures/queue/queue.ts +223 -42
- package/src/data-structures/stack/stack.ts +184 -32
- package/src/data-structures/trie/trie.ts +227 -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
|
@@ -46,71 +46,6 @@ export declare class SinglyLinkedListNode<E = any> extends LinkedListNode<E> {
|
|
|
46
46
|
* 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.
|
|
47
47
|
* 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).
|
|
48
48
|
* @example
|
|
49
|
-
* // basic SinglyLinkedList creation and push operation
|
|
50
|
-
* // Create a simple SinglyLinkedList with initial values
|
|
51
|
-
* const list = new SinglyLinkedList([1, 2, 3, 4, 5]);
|
|
52
|
-
*
|
|
53
|
-
* // Verify the list maintains insertion order
|
|
54
|
-
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
55
|
-
*
|
|
56
|
-
* // Check length
|
|
57
|
-
* console.log(list.length); // 5;
|
|
58
|
-
*
|
|
59
|
-
* // Push a new element to the end
|
|
60
|
-
* list.push(6);
|
|
61
|
-
* console.log(list.length); // 6;
|
|
62
|
-
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
63
|
-
* @example
|
|
64
|
-
* // SinglyLinkedList pop and shift operations
|
|
65
|
-
* const list = new SinglyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
66
|
-
*
|
|
67
|
-
* // Pop removes from the end
|
|
68
|
-
* const last = list.pop();
|
|
69
|
-
* console.log(last); // 50;
|
|
70
|
-
*
|
|
71
|
-
* // Shift removes from the beginning
|
|
72
|
-
* const first = list.shift();
|
|
73
|
-
* console.log(first); // 10;
|
|
74
|
-
*
|
|
75
|
-
* // Verify remaining elements
|
|
76
|
-
* console.log([...list]); // [20, 30, 40];
|
|
77
|
-
* console.log(list.length); // 3;
|
|
78
|
-
* @example
|
|
79
|
-
* // SinglyLinkedList unshift and forward traversal
|
|
80
|
-
* const list = new SinglyLinkedList<number>([20, 30, 40]);
|
|
81
|
-
*
|
|
82
|
-
* // Unshift adds to the beginning
|
|
83
|
-
* list.unshift(10);
|
|
84
|
-
* console.log([...list]); // [10, 20, 30, 40];
|
|
85
|
-
*
|
|
86
|
-
* // Access elements (forward traversal only for singly linked)
|
|
87
|
-
* const second = list.at(1);
|
|
88
|
-
* console.log(second); // 20;
|
|
89
|
-
*
|
|
90
|
-
* // SinglyLinkedList allows forward iteration only
|
|
91
|
-
* const elements: number[] = [];
|
|
92
|
-
* for (const item of list) {
|
|
93
|
-
* elements.push(item);
|
|
94
|
-
* }
|
|
95
|
-
* console.log(elements); // [10, 20, 30, 40];
|
|
96
|
-
*
|
|
97
|
-
* console.log(list.length); // 4;
|
|
98
|
-
* @example
|
|
99
|
-
* // SinglyLinkedList filter and map operations
|
|
100
|
-
* const list = new SinglyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
101
|
-
*
|
|
102
|
-
* // Filter even numbers
|
|
103
|
-
* const filtered = list.filter(value => value % 2 === 0);
|
|
104
|
-
* console.log(filtered.length); // 2;
|
|
105
|
-
*
|
|
106
|
-
* // Map to double values
|
|
107
|
-
* const doubled = list.map(value => value * 2);
|
|
108
|
-
* console.log(doubled.length); // 5;
|
|
109
|
-
*
|
|
110
|
-
* // Use reduce to sum
|
|
111
|
-
* const sum = list.reduce((acc, value) => acc + value, 0);
|
|
112
|
-
* console.log(sum); // 15;
|
|
113
|
-
* @example
|
|
114
49
|
* // SinglyLinkedList for sequentially processed data stream
|
|
115
50
|
* interface LogEntry {
|
|
116
51
|
* timestamp: number;
|
|
@@ -227,6 +162,17 @@ export declare class SinglyLinkedListNode<E = any> extends LinkedListNode<E> {
|
|
|
227
162
|
* editor.moveCursor(1);
|
|
228
163
|
* editor.insert('a');
|
|
229
164
|
* console.log(editor.getText()); // 'Haello';
|
|
165
|
+
* @example
|
|
166
|
+
* // Find first matching element
|
|
167
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
168
|
+
* console.log(list.find(n => n > 3)); // 4;
|
|
169
|
+
* console.log(list.find(n => n > 10)); // undefined;
|
|
170
|
+
* @example
|
|
171
|
+
* // Iterate over elements
|
|
172
|
+
* const list = new SinglyLinkedList<number>([10, 20, 30]);
|
|
173
|
+
* const result: number[] = [];
|
|
174
|
+
* list.forEach(n => result.push(n));
|
|
175
|
+
* console.log(result); // [10, 20, 30];
|
|
230
176
|
*/
|
|
231
177
|
export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, SinglyLinkedListNode<E>> {
|
|
232
178
|
protected _equals: (a: E, b: E) => boolean;
|
|
@@ -288,18 +234,86 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
288
234
|
* @remarks Time O(1), Space O(1)
|
|
289
235
|
* @param elementOrNode - Element or node to append.
|
|
290
236
|
* @returns True when appended.
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
* @example
|
|
249
|
+
* // basic SinglyLinkedList creation and push operation
|
|
250
|
+
* // Create a simple SinglyLinkedList with initial values
|
|
251
|
+
* const list = new SinglyLinkedList([1, 2, 3, 4, 5]);
|
|
252
|
+
*
|
|
253
|
+
* // Verify the list maintains insertion order
|
|
254
|
+
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
255
|
+
*
|
|
256
|
+
* // Check length
|
|
257
|
+
* console.log(list.length); // 5;
|
|
258
|
+
*
|
|
259
|
+
* // Push a new element to the end
|
|
260
|
+
* list.push(6);
|
|
261
|
+
* console.log(list.length); // 6;
|
|
262
|
+
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
291
263
|
*/
|
|
292
264
|
push(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
|
|
293
265
|
/**
|
|
294
266
|
* Remove and return the tail element.
|
|
295
267
|
* @remarks Time O(N), Space O(1)
|
|
296
268
|
* @returns Removed element or undefined.
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
* @example
|
|
281
|
+
* // SinglyLinkedList pop and shift operations
|
|
282
|
+
* const list = new SinglyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
283
|
+
*
|
|
284
|
+
* // Pop removes from the end
|
|
285
|
+
* const last = list.pop();
|
|
286
|
+
* console.log(last); // 50;
|
|
287
|
+
*
|
|
288
|
+
* // Shift removes from the beginning
|
|
289
|
+
* const first = list.shift();
|
|
290
|
+
* console.log(first); // 10;
|
|
291
|
+
*
|
|
292
|
+
* // Verify remaining elements
|
|
293
|
+
* console.log([...list]); // [20, 30, 40];
|
|
294
|
+
* console.log(list.length); // 3;
|
|
297
295
|
*/
|
|
298
296
|
pop(): E | undefined;
|
|
299
297
|
/**
|
|
300
298
|
* Remove and return the head element.
|
|
301
299
|
* @remarks Time O(1), Space O(1)
|
|
302
300
|
* @returns Removed element or undefined.
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
* @example
|
|
313
|
+
* // Remove from the front
|
|
314
|
+
* const list = new SinglyLinkedList<number>([10, 20, 30]);
|
|
315
|
+
* console.log(list.shift()); // 10;
|
|
316
|
+
* console.log(list.length); // 2;
|
|
303
317
|
*/
|
|
304
318
|
shift(): E | undefined;
|
|
305
319
|
/**
|
|
@@ -307,6 +321,37 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
307
321
|
* @remarks Time O(1), Space O(1)
|
|
308
322
|
* @param elementOrNode - Element or node to prepend.
|
|
309
323
|
* @returns True when prepended.
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
* @example
|
|
336
|
+
* // SinglyLinkedList unshift and forward traversal
|
|
337
|
+
* const list = new SinglyLinkedList<number>([20, 30, 40]);
|
|
338
|
+
*
|
|
339
|
+
* // Unshift adds to the beginning
|
|
340
|
+
* list.unshift(10);
|
|
341
|
+
* console.log([...list]); // [10, 20, 30, 40];
|
|
342
|
+
*
|
|
343
|
+
* // Access elements (forward traversal only for singly linked)
|
|
344
|
+
* const second = list.at(1);
|
|
345
|
+
* console.log(second); // 20;
|
|
346
|
+
*
|
|
347
|
+
* // SinglyLinkedList allows forward iteration only
|
|
348
|
+
* const elements: number[] = [];
|
|
349
|
+
* for (const item of list) {
|
|
350
|
+
* elements.push(item);
|
|
351
|
+
* }
|
|
352
|
+
* console.log(elements); // [10, 20, 30, 40];
|
|
353
|
+
*
|
|
354
|
+
* console.log(list.length); // 4;
|
|
310
355
|
*/
|
|
311
356
|
unshift(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
|
|
312
357
|
/**
|
|
@@ -335,6 +380,23 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
335
380
|
* @remarks Time O(N), Space O(1)
|
|
336
381
|
* @param index - Zero-based index.
|
|
337
382
|
* @returns Element or undefined.
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
* @example
|
|
395
|
+
* // Access element by index
|
|
396
|
+
* const list = new SinglyLinkedList<string>(['a', 'b', 'c', 'd']);
|
|
397
|
+
* console.log(list.at(0)); // 'a';
|
|
398
|
+
* console.log(list.at(2)); // 'c';
|
|
399
|
+
* console.log(list.at(3)); // 'd';
|
|
338
400
|
*/
|
|
339
401
|
at(index: number): E | undefined;
|
|
340
402
|
/**
|
|
@@ -349,6 +411,18 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
349
411
|
* @remarks Time O(N), Space O(1)
|
|
350
412
|
* @param index - Zero-based index.
|
|
351
413
|
* @returns Node or undefined.
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
* @example
|
|
423
|
+
* // Get node at index
|
|
424
|
+
* const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
|
|
425
|
+
* console.log(list.getNodeAt(1)?.value); // 'b';
|
|
352
426
|
*/
|
|
353
427
|
getNodeAt(index: number): SinglyLinkedListNode<E> | undefined;
|
|
354
428
|
/**
|
|
@@ -356,6 +430,19 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
356
430
|
* @remarks Time O(N), Space O(1)
|
|
357
431
|
* @param index - Zero-based index.
|
|
358
432
|
* @returns Removed element or undefined.
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
* @example
|
|
442
|
+
* // Remove by index
|
|
443
|
+
* const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
|
|
444
|
+
* list.deleteAt(1);
|
|
445
|
+
* console.log(list.toArray()); // ['a', 'c'];
|
|
359
446
|
*/
|
|
360
447
|
deleteAt(index: number): E | undefined;
|
|
361
448
|
/**
|
|
@@ -363,6 +450,19 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
363
450
|
* @remarks Time O(N), Space O(1)
|
|
364
451
|
* @param [elementOrNode] - Element or node to remove; if omitted/undefined, nothing happens.
|
|
365
452
|
* @returns True if removed.
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
* @example
|
|
462
|
+
* // Remove first occurrence
|
|
463
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3, 2]);
|
|
464
|
+
* list.delete(2);
|
|
465
|
+
* console.log(list.toArray()); // [1, 3, 2];
|
|
366
466
|
*/
|
|
367
467
|
delete(elementOrNode: E | SinglyLinkedListNode<E> | undefined): boolean;
|
|
368
468
|
/**
|
|
@@ -371,6 +471,19 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
371
471
|
* @param index - Zero-based index.
|
|
372
472
|
* @param newElementOrNode - Element or node to insert.
|
|
373
473
|
* @returns True if inserted.
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
* @example
|
|
483
|
+
* // Insert at index
|
|
484
|
+
* const list = new SinglyLinkedList<number>([1, 3]);
|
|
485
|
+
* list.addAt(1, 2);
|
|
486
|
+
* console.log(list.toArray()); // [1, 2, 3];
|
|
374
487
|
*/
|
|
375
488
|
addAt(index: number, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
|
|
376
489
|
/**
|
|
@@ -385,18 +498,60 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
385
498
|
* Check whether the list is empty.
|
|
386
499
|
* @remarks Time O(1), Space O(1)
|
|
387
500
|
* @returns True if length is 0.
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
* @example
|
|
511
|
+
* // Check empty
|
|
512
|
+
* console.log(new SinglyLinkedList().isEmpty()); // true;
|
|
388
513
|
*/
|
|
389
514
|
isEmpty(): boolean;
|
|
390
515
|
/**
|
|
391
516
|
* Remove all nodes and reset length.
|
|
392
517
|
* @remarks Time O(N), Space O(1)
|
|
393
518
|
* @returns void
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
* @example
|
|
529
|
+
* // Remove all
|
|
530
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
531
|
+
* list.clear();
|
|
532
|
+
* console.log(list.isEmpty()); // true;
|
|
394
533
|
*/
|
|
395
534
|
clear(): void;
|
|
396
535
|
/**
|
|
397
536
|
* Reverse the list in place.
|
|
398
537
|
* @remarks Time O(N), Space O(1)
|
|
399
538
|
* @returns This list.
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
* @example
|
|
551
|
+
* // Reverse the list in-place
|
|
552
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3, 4]);
|
|
553
|
+
* list.reverse();
|
|
554
|
+
* console.log([...list]); // [4, 3, 2, 1];
|
|
400
555
|
*/
|
|
401
556
|
reverse(): this;
|
|
402
557
|
/**
|
|
@@ -456,6 +611,22 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
456
611
|
* Deep clone this list (values are copied by reference).
|
|
457
612
|
* @remarks Time O(N), Space O(N)
|
|
458
613
|
* @returns A new list with the same element sequence.
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
* @example
|
|
624
|
+
* // Deep copy
|
|
625
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
626
|
+
* const copy = list.clone();
|
|
627
|
+
* copy.pop();
|
|
628
|
+
* console.log(list.length); // 3;
|
|
629
|
+
* console.log(copy.length); // 2;
|
|
459
630
|
*/
|
|
460
631
|
clone(): this;
|
|
461
632
|
/**
|
|
@@ -464,6 +635,32 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
464
635
|
* @param callback - Predicate (value, index, list) → boolean to keep value.
|
|
465
636
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
466
637
|
* @returns A new list with kept values.
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
* @example
|
|
650
|
+
* // SinglyLinkedList filter and map operations
|
|
651
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
652
|
+
*
|
|
653
|
+
* // Filter even numbers
|
|
654
|
+
* const filtered = list.filter(value => value % 2 === 0);
|
|
655
|
+
* console.log(filtered.length); // 2;
|
|
656
|
+
*
|
|
657
|
+
* // Map to double values
|
|
658
|
+
* const doubled = list.map(value => value * 2);
|
|
659
|
+
* console.log(doubled.length); // 5;
|
|
660
|
+
*
|
|
661
|
+
* // Use reduce to sum
|
|
662
|
+
* const sum = list.reduce((acc, value) => acc + value, 0);
|
|
663
|
+
* console.log(sum); // 15;
|
|
467
664
|
*/
|
|
468
665
|
filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): this;
|
|
469
666
|
/**
|
|
@@ -483,6 +680,22 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
|
|
|
483
680
|
* @param [options] - Options for the output list (e.g., maxLen, toElementFn).
|
|
484
681
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
485
682
|
* @returns A new SinglyLinkedList with mapped values.
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
* @example
|
|
695
|
+
* // Transform elements
|
|
696
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
697
|
+
* const doubled = list.map(n => n * 2);
|
|
698
|
+
* console.log([...doubled]); // [2, 4, 6];
|
|
486
699
|
*/
|
|
487
700
|
map<EM, RM = any>(callback: ElementCallback<E, R, EM>, options?: SinglyLinkedListOptions<EM, RM>, thisArg?: any): SinglyLinkedList<EM, RM>;
|
|
488
701
|
/**
|