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
@@ -113,32 +113,6 @@ export class TrieNode {
113
113
  * 10. IP Routing: Used in certain types of IP routing algorithms.
114
114
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
115
115
  * @example
116
- * // basic Trie creation and add words
117
- * // Create a simple Trie with initial words
118
- * const trie = new Trie(['apple', 'app', 'apply']);
119
- *
120
- * // Verify size
121
- * console.log(trie.size); // 3;
122
- *
123
- * // Check if words exist
124
- * console.log(trie.has('apple')); // true;
125
- * console.log(trie.has('app')); // true;
126
- *
127
- * // Add a new word
128
- * trie.add('application');
129
- * console.log(trie.size); // 4;
130
- * @example
131
- * // Trie getWords and prefix search
132
- * const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
133
- *
134
- * // Get all words with prefix 'app'
135
- * const appWords = trie.getWords('app');
136
- * console.log(appWords); // contains 'app';
137
- * console.log(appWords); // contains 'apple';
138
- * console.log(appWords); // contains 'apply';
139
- * console.log(appWords); // contains 'application';
140
- * expect(appWords).not.toContain('apricot');
141
- * @example
142
116
  * // Trie isPrefix and isAbsolutePrefix checks
143
117
  * const trie = new Trie(['tree', 'trial', 'trick', 'trip', 'trie']);
144
118
  *
@@ -154,23 +128,6 @@ export class TrieNode {
154
128
  * // Verify size
155
129
  * console.log(trie.size); // 5;
156
130
  * @example
157
- * // Trie delete and iteration
158
- * const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
159
- *
160
- * // Delete a word
161
- * trie.delete('card');
162
- * console.log(trie.has('card')); // false;
163
- *
164
- * // Word with same prefix still exists
165
- * console.log(trie.has('care')); // true;
166
- *
167
- * // Size decreased
168
- * console.log(trie.size); // 5;
169
- *
170
- * // Iterate through all words
171
- * const allWords = [...trie];
172
- * console.log(allWords.length); // 5;
173
- * @example
174
131
  * // Trie for autocomplete search index
175
132
  * // Trie is perfect for autocomplete: O(m + k) where m is prefix length, k is results
176
133
  * const searchIndex = new Trie(['typescript', 'javascript', 'python', 'java', 'rust', 'ruby', 'golang', 'kotlin']);
@@ -327,6 +284,32 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
327
284
  * @remarks Time O(L), Space O(L)
328
285
  * @param word - Word to insert.
329
286
  * @returns True if the word was newly added.
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+ * @example
299
+ * // basic Trie creation and add words
300
+ * // Create a simple Trie with initial words
301
+ * const trie = new Trie(['apple', 'app', 'apply']);
302
+ *
303
+ * // Verify size
304
+ * console.log(trie.size); // 3;
305
+ *
306
+ * // Check if words exist
307
+ * console.log(trie.has('apple')); // true;
308
+ * console.log(trie.has('app')); // true;
309
+ *
310
+ * // Add a new word
311
+ * trie.add('application');
312
+ * console.log(trie.size); // 4;
330
313
  */
331
314
 
332
315
  add(word: string): boolean {
@@ -354,6 +337,21 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
354
337
  * @remarks Time O(ΣL), Space O(ΣL)
355
338
  * @param words - Iterable of strings (or raw records if toElementFn is provided).
356
339
  * @returns Array of per-word 'added' flags.
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+ * @example
349
+ * // Add multiple words
350
+ * const trie = new Trie();
351
+ * trie.addMany(['cat', 'car', 'card']);
352
+ * console.log(trie.has('cat')); // true;
353
+ * console.log(trie.has('car')); // true;
354
+ * console.log(trie.size); // 3;
357
355
  */
358
356
 
359
357
  addMany(words: Iterable<string> | Iterable<R>): boolean[] {
@@ -373,6 +371,24 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
373
371
  * @remarks Time O(L), Space O(1)
374
372
  * @param word - Word to search for.
375
373
  * @returns True if present.
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+ * @example
386
+ * // Check if a word exists
387
+ * const dict = new Trie(['apple', 'app', 'application']);
388
+ *
389
+ * console.log(dict.has('app')); // true;
390
+ * console.log(dict.has('apple')); // true;
391
+ * console.log(dict.has('ap')); // false;
376
392
  */
377
393
 
378
394
  override has(word: string): boolean {
@@ -390,6 +406,20 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
390
406
  * Check whether the trie is empty.
391
407
  * @remarks Time O(1), Space O(1)
392
408
  * @returns True if size is 0.
409
+
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+ * @example
418
+ * // Check if empty
419
+ * const trie = new Trie();
420
+ * console.log(trie.isEmpty()); // true;
421
+ * trie.add('word');
422
+ * console.log(trie.isEmpty()); // false;
393
423
  */
394
424
 
395
425
  isEmpty(): boolean {
@@ -400,6 +430,19 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
400
430
  * Remove all words and reset to a fresh root.
401
431
  * @remarks Time O(1), Space O(1)
402
432
  * @returns void
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+ * @example
442
+ * // Remove all words
443
+ * const trie = new Trie(['a', 'b', 'c']);
444
+ * trie.clear();
445
+ * console.log(trie.isEmpty()); // true;
403
446
  */
404
447
 
405
448
  clear(): void {
@@ -412,6 +455,34 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
412
455
  * @remarks Time O(L), Space O(1)
413
456
  * @param word - Word to delete.
414
457
  * @returns True if a word was removed.
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+ * @example
470
+ * // Trie delete and iteration
471
+ * const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
472
+ *
473
+ * // Delete a word
474
+ * trie.delete('card');
475
+ * console.log(trie.has('card')); // false;
476
+ *
477
+ * // Word with same prefix still exists
478
+ * console.log(trie.has('care')); // true;
479
+ *
480
+ * // Size decreased
481
+ * console.log(trie.size); // 5;
482
+ *
483
+ * // Iterate through all words
484
+ * const allWords = [...trie];
485
+ * console.log(allWords.length); // 5;
415
486
  */
416
487
 
417
488
  delete(word: string): boolean {
@@ -499,6 +570,24 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
499
570
  * @remarks Time O(L), Space O(1)
500
571
  * @param input - String to test as prefix.
501
572
  * @returns True if input matches a path from root.
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+ * @example
585
+ * // Check if a prefix exists
586
+ * const trie = new Trie(['hello', 'help', 'world']);
587
+ *
588
+ * console.log(trie.hasPrefix('hel')); // true;
589
+ * console.log(trie.hasPrefix('wor')); // true;
590
+ * console.log(trie.hasPrefix('xyz')); // false;
502
591
  */
503
592
 
504
593
  hasPrefix(input: string): boolean {
@@ -537,6 +626,22 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
537
626
  * Return the longest common prefix among all words.
538
627
  * @remarks Time O(H), Space O(1)
539
628
  * @returns The longest common prefix string.
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+ * @example
641
+ * // Find shared prefix
642
+ * const trie = new Trie(['flower', 'flow', 'flight']);
643
+ *
644
+ * console.log(trie.getLongestCommonPrefix()); // 'fl';
540
645
  */
541
646
 
542
647
  getLongestCommonPrefix(): string {
@@ -558,6 +663,28 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
558
663
  * @param [max] - Maximum number of words to return; default is Number.MAX_SAFE_INTEGER.
559
664
  * @param [isAllWhenEmptyPrefix] - When true, collect from root even if prefix is empty.
560
665
  * @returns Array of collected words (at most max).
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+ * @example
678
+ * // Trie getWords and prefix search
679
+ * const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
680
+ *
681
+ * // Get all words with prefix 'app'
682
+ * const appWords = trie.getWords('app');
683
+ * console.log(appWords); // contains 'app';
684
+ * console.log(appWords); // contains 'apple';
685
+ * console.log(appWords); // contains 'apply';
686
+ * console.log(appWords); // contains 'application';
687
+ * expect(appWords).not.toContain('apricot');
561
688
  */
562
689
 
563
690
  getWords(prefix = '', max = Number.MAX_SAFE_INTEGER, isAllWhenEmptyPrefix = false): string[] {
@@ -599,6 +726,20 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
599
726
  * Deep clone this trie by iterating and inserting all words.
600
727
  * @remarks Time O(ΣL), Space O(ΣL)
601
728
  * @returns A new trie with the same words and options.
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+ * @example
738
+ * // Create independent copy
739
+ * const trie = new Trie(['hello', 'world']);
740
+ * const copy = trie.clone();
741
+ * copy.delete('hello');
742
+ * console.log(trie.has('hello')); // true;
602
743
  */
603
744
 
604
745
  clone(): this {
@@ -613,6 +754,19 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
613
754
  * @param predicate - Predicate (word, index, trie) → boolean to keep word.
614
755
  * @param [thisArg] - Value for `this` inside the predicate.
615
756
  * @returns A new trie containing words that satisfy the predicate.
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+ * @example
766
+ * // Filter words
767
+ * const trie = new Trie(['cat', 'car', 'dog', 'card']);
768
+ * const result = trie.filter(w => w.startsWith('ca'));
769
+ * console.log(result.size); // 3;
616
770
  */
617
771
 
618
772
  filter(predicate: ElementCallback<string, R, boolean>, thisArg?: any): this {
@@ -627,6 +781,22 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
627
781
  return results;
628
782
  }
629
783
 
784
+ /**
785
+ * Transform words
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+ * @example
795
+ * // Transform words
796
+ * const trie = new Trie(['hello', 'world']);
797
+ * const upper = trie.map(w => w.toUpperCase());
798
+ * console.log(upper.has('HELLO')); // true;
799
+ */
630
800
  map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: any): Trie<RM>;
631
801
 
632
802
  /**
@@ -1 +1 @@
1
- export type SegmentTreeNodeVal = number;
1
+ export {};
@@ -1 +1,2 @@
1
- export type SkipLinkedListOptions = { maxLevel?: number; probability?: number };
1
+ // SkipList types are co-located with the implementation in src/data-structures/linked-list/skip-linked-list.ts
2
+ export {};