max-priority-queue-typed 2.4.5 → 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.
Files changed (76) hide show
  1. package/README.md +63 -0
  2. package/dist/cjs/index.cjs +400 -119
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +399 -118
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +400 -119
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +399 -118
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +429 -78
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +212 -32
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +219 -47
  22. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  23. package/dist/types/data-structures/graph/undirected-graph.d.ts +204 -59
  24. package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
  25. package/dist/types/data-structures/heap/heap.d.ts +287 -99
  26. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  27. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  28. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
  29. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
  30. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
  31. package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
  32. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  33. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  34. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  35. package/dist/types/data-structures/queue/deque.d.ts +272 -65
  36. package/dist/types/data-structures/queue/queue.d.ts +211 -42
  37. package/dist/types/data-structures/stack/stack.d.ts +174 -32
  38. package/dist/types/data-structures/trie/trie.d.ts +213 -43
  39. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  40. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  41. package/dist/umd/max-priority-queue-typed.js +397 -116
  42. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  43. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  44. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  45. package/package.json +2 -2
  46. package/src/data-structures/base/iterable-element-base.ts +4 -5
  47. package/src/data-structures/binary-tree/avl-tree.ts +134 -51
  48. package/src/data-structures/binary-tree/binary-indexed-tree.ts +302 -247
  49. package/src/data-structures/binary-tree/binary-tree.ts +429 -79
  50. package/src/data-structures/binary-tree/bst.ts +335 -34
  51. package/src/data-structures/binary-tree/red-black-tree.ts +290 -97
  52. package/src/data-structures/binary-tree/segment-tree.ts +372 -248
  53. package/src/data-structures/binary-tree/tree-map.ts +1284 -6
  54. package/src/data-structures/binary-tree/tree-multi-map.ts +1094 -211
  55. package/src/data-structures/binary-tree/tree-multi-set.ts +858 -65
  56. package/src/data-structures/binary-tree/tree-set.ts +1136 -9
  57. package/src/data-structures/graph/directed-graph.ts +219 -47
  58. package/src/data-structures/graph/map-graph.ts +59 -1
  59. package/src/data-structures/graph/undirected-graph.ts +204 -59
  60. package/src/data-structures/hash/hash-map.ts +230 -77
  61. package/src/data-structures/heap/heap.ts +287 -99
  62. package/src/data-structures/heap/max-heap.ts +46 -0
  63. package/src/data-structures/heap/min-heap.ts +59 -0
  64. package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
  65. package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
  66. package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
  67. package/src/data-structures/matrix/matrix.ts +416 -12
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  70. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  71. package/src/data-structures/queue/deque.ts +272 -65
  72. package/src/data-structures/queue/queue.ts +211 -42
  73. package/src/data-structures/stack/stack.ts +174 -32
  74. package/src/data-structures/trie/trie.ts +213 -43
  75. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  76. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
@@ -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
  /**