red-black-tree-typed 1.53.6 → 1.54.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.
Files changed (121) hide show
  1. package/README.md +52 -0
  2. package/dist/common/index.d.ts +12 -0
  3. package/dist/common/index.js +28 -0
  4. package/dist/data-structures/base/iterable-entry-base.js +4 -4
  5. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
  6. package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -170
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -331
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
  10. package/dist/data-structures/binary-tree/avl-tree.js +131 -71
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +309 -208
  14. package/dist/data-structures/binary-tree/binary-tree.js +382 -300
  15. package/dist/data-structures/binary-tree/bst.d.ts +245 -127
  16. package/dist/data-structures/binary-tree/bst.js +366 -163
  17. package/dist/data-structures/binary-tree/index.d.ts +3 -1
  18. package/dist/data-structures/binary-tree/index.js +3 -1
  19. package/dist/data-structures/binary-tree/red-black-tree.d.ts +286 -0
  20. package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +181 -108
  21. package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
  22. package/dist/data-structures/binary-tree/tree-counter.js +444 -0
  23. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -170
  24. package/dist/data-structures/binary-tree/tree-multi-map.js +145 -367
  25. package/dist/data-structures/graph/abstract-graph.js +2 -2
  26. package/dist/data-structures/graph/directed-graph.d.ts +3 -0
  27. package/dist/data-structures/graph/directed-graph.js +3 -0
  28. package/dist/data-structures/graph/map-graph.d.ts +3 -0
  29. package/dist/data-structures/graph/map-graph.js +3 -0
  30. package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
  31. package/dist/data-structures/graph/undirected-graph.js +3 -0
  32. package/dist/data-structures/hash/hash-map.d.ts +31 -1
  33. package/dist/data-structures/hash/hash-map.js +35 -5
  34. package/dist/data-structures/heap/heap.d.ts +26 -9
  35. package/dist/data-structures/heap/heap.js +37 -17
  36. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +64 -19
  37. package/dist/data-structures/linked-list/doubly-linked-list.js +92 -31
  38. package/dist/data-structures/linked-list/singly-linked-list.d.ts +48 -12
  39. package/dist/data-structures/linked-list/singly-linked-list.js +74 -27
  40. package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
  41. package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
  42. package/dist/data-structures/matrix/matrix.d.ts +3 -0
  43. package/dist/data-structures/matrix/matrix.js +3 -0
  44. package/dist/data-structures/matrix/navigator.d.ts +3 -0
  45. package/dist/data-structures/matrix/navigator.js +3 -0
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
  50. package/dist/data-structures/queue/deque.d.ts +37 -8
  51. package/dist/data-structures/queue/deque.js +73 -29
  52. package/dist/data-structures/queue/queue.d.ts +41 -1
  53. package/dist/data-structures/queue/queue.js +51 -9
  54. package/dist/data-structures/stack/stack.d.ts +27 -10
  55. package/dist/data-structures/stack/stack.js +39 -20
  56. package/dist/data-structures/trie/trie.d.ts +111 -10
  57. package/dist/data-structures/trie/trie.js +123 -18
  58. package/dist/index.d.ts +2 -1
  59. package/dist/index.js +2 -1
  60. package/dist/interfaces/binary-tree.d.ts +8 -8
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  63. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
  64. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
  65. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
  66. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -4
  67. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
  68. package/dist/types/data-structures/binary-tree/index.d.ts +2 -0
  69. package/dist/types/data-structures/binary-tree/index.js +2 -0
  70. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -5
  71. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  72. package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
  73. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
  74. package/dist/types/utils/utils.d.ts +10 -6
  75. package/dist/utils/utils.js +4 -2
  76. package/package.json +2 -2
  77. package/src/common/index.ts +25 -0
  78. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  79. package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
  80. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +152 -373
  81. package/src/data-structures/binary-tree/avl-tree.ts +164 -106
  82. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
  83. package/src/data-structures/binary-tree/binary-tree.ts +563 -447
  84. package/src/data-structures/binary-tree/bst.ts +433 -237
  85. package/src/data-structures/binary-tree/index.ts +3 -1
  86. package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +224 -146
  87. package/src/data-structures/binary-tree/tree-counter.ts +504 -0
  88. package/src/data-structures/binary-tree/tree-multi-map.ts +159 -401
  89. package/src/data-structures/graph/abstract-graph.ts +2 -2
  90. package/src/data-structures/graph/directed-graph.ts +3 -0
  91. package/src/data-structures/graph/map-graph.ts +3 -0
  92. package/src/data-structures/graph/undirected-graph.ts +3 -0
  93. package/src/data-structures/hash/hash-map.ts +37 -7
  94. package/src/data-structures/heap/heap.ts +72 -49
  95. package/src/data-structures/linked-list/doubly-linked-list.ts +186 -118
  96. package/src/data-structures/linked-list/singly-linked-list.ts +81 -28
  97. package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  98. package/src/data-structures/matrix/matrix.ts +3 -0
  99. package/src/data-structures/matrix/navigator.ts +3 -0
  100. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
  101. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
  102. package/src/data-structures/queue/deque.ts +72 -28
  103. package/src/data-structures/queue/queue.ts +50 -7
  104. package/src/data-structures/stack/stack.ts +39 -20
  105. package/src/data-structures/trie/trie.ts +123 -17
  106. package/src/index.ts +4 -3
  107. package/src/interfaces/binary-tree.ts +10 -21
  108. package/src/types/data-structures/base/base.ts +1 -1
  109. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  110. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
  111. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
  112. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -6
  113. package/src/types/data-structures/binary-tree/bst.ts +8 -7
  114. package/src/types/data-structures/binary-tree/index.ts +3 -1
  115. package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
  116. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  117. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
  118. package/src/types/utils/utils.ts +16 -10
  119. package/src/utils/utils.ts +4 -2
  120. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -205
  121. package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
@@ -64,13 +64,13 @@ class DoublyLinkedListNode {
64
64
  }
65
65
  exports.DoublyLinkedListNode = DoublyLinkedListNode;
66
66
  /**
67
- * 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
67
+ *1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
68
68
  * 2. Bidirectional Traversal: Unlike singly linked lists, doubly linked lists can be easily traversed forwards or backwards. This makes insertions and deletions in the list more flexible and efficient.
69
69
  * 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
70
70
  * 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.
71
71
  * @example
72
72
  * // text editor operation history
73
- * const actions = [
73
+ * const actions = [
74
74
  * { type: 'insert', content: 'first line of text' },
75
75
  * { type: 'insert', content: 'second line of text' },
76
76
  * { type: 'delete', content: 'delete the first line' }
@@ -82,7 +82,7 @@ exports.DoublyLinkedListNode = DoublyLinkedListNode;
82
82
  * console.log(editorHistory.last?.type); // 'insert'
83
83
  * @example
84
84
  * // Browser history
85
- * const browserHistory = new DoublyLinkedList<string>();
85
+ * const browserHistory = new DoublyLinkedList<string>();
86
86
  *
87
87
  * browserHistory.push('home page');
88
88
  * browserHistory.push('search page');
@@ -93,7 +93,7 @@ exports.DoublyLinkedListNode = DoublyLinkedListNode;
93
93
  * console.log(browserHistory.last); // 'search page'
94
94
  * @example
95
95
  * // Use DoublyLinkedList to implement music player
96
- * // Define the Song interface
96
+ * // Define the Song interface
97
97
  * interface Song {
98
98
  * title: string;
99
99
  * artist: string;
@@ -218,7 +218,7 @@ exports.DoublyLinkedListNode = DoublyLinkedListNode;
218
218
  * // ]
219
219
  * @example
220
220
  * // Use DoublyLinkedList to implement LRU cache
221
- * interface CacheEntry<K, V> {
221
+ * interface CacheEntry<K, V> {
222
222
  * key: K;
223
223
  * value: V;
224
224
  * }
@@ -380,7 +380,7 @@ exports.DoublyLinkedListNode = DoublyLinkedListNode;
380
380
  * console.log(cache.isEmpty); // true
381
381
  * @example
382
382
  * // finding lyrics by timestamp in Coldplay's "Fix You"
383
- * // Create a DoublyLinkedList to store song lyrics with timestamps
383
+ * // Create a DoublyLinkedList to store song lyrics with timestamps
384
384
  * const lyricsList = new DoublyLinkedList<{ time: number; text: string }>();
385
385
  *
386
386
  * // Detailed lyrics with precise timestamps (in milliseconds)
@@ -420,7 +420,7 @@ exports.DoublyLinkedListNode = DoublyLinkedListNode;
420
420
  * console.log(lateTimeLyric?.text); // 'And I will try to fix you'
421
421
  * @example
422
422
  * // cpu process schedules
423
- * class Process {
423
+ * class Process {
424
424
  * constructor(
425
425
  * public id: number,
426
426
  * public priority: number
@@ -496,20 +496,22 @@ exports.DoublyLinkedListNode = DoublyLinkedListNode;
496
496
  * console.log(scheduler.listProcesses()); // []
497
497
  */
498
498
  class DoublyLinkedList extends base_1.IterableElementBase {
499
+ /**
500
+ * This TypeScript constructor initializes a DoublyLinkedList with optional elements and options.
501
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the constructor is an
502
+ * iterable collection of elements of type `E` or `R`. It is used to initialize the DoublyLinkedList
503
+ * with the elements provided in the iterable. If no elements are provided, the default value is an
504
+ * empty iterable.
505
+ * @param [options] - The `options` parameter in the constructor is of type
506
+ * `DoublyLinkedListOptions<E, R>`. It is an optional parameter that allows you to pass additional
507
+ * configuration options to customize the behavior of the DoublyLinkedList.
508
+ */
499
509
  constructor(elements = [], options) {
500
510
  super(options);
501
511
  this._head = undefined;
502
512
  this._tail = undefined;
503
513
  this._size = 0;
504
- if (elements) {
505
- for (const el of elements) {
506
- if (this.toElementFn) {
507
- this.push(this.toElementFn(el));
508
- }
509
- else
510
- this.push(el);
511
- }
512
- }
514
+ this.pushMany(elements);
513
515
  }
514
516
  /**
515
517
  * The `head` function returns the first node of a doubly linked list.
@@ -555,6 +557,18 @@ class DoublyLinkedList extends base_1.IterableElementBase {
555
557
  var _a;
556
558
  return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
557
559
  }
560
+ /**
561
+ * Time Complexity: O(n)
562
+ * Space Complexity: O(n)
563
+ *
564
+ * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
565
+ * given array.
566
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
567
+ * @returns The `fromArray` function returns a DoublyLinkedList object.
568
+ */
569
+ static fromArray(data) {
570
+ return new DoublyLinkedList(data);
571
+ }
558
572
  /**
559
573
  * Time Complexity: O(1)
560
574
  * Space Complexity: O(1)
@@ -663,6 +677,55 @@ class DoublyLinkedList extends base_1.IterableElementBase {
663
677
  this._size++;
664
678
  return true;
665
679
  }
680
+ /**
681
+ * Time Complexity: O(k)
682
+ * Space Complexity: O(k)
683
+ *
684
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
685
+ * transformation function if provided.
686
+ * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
687
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
688
+ * or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and pushes
689
+ * it onto the linked list. If a transformation function `to
690
+ * @returns The `pushMany` function is returning an array of boolean values (`ans`) which indicate
691
+ * the success or failure of pushing each element into the data structure.
692
+ */
693
+ pushMany(elements) {
694
+ const ans = [];
695
+ for (const el of elements) {
696
+ if (this.toElementFn) {
697
+ ans.push(this.push(this.toElementFn(el)));
698
+ continue;
699
+ }
700
+ ans.push(this.push(el));
701
+ }
702
+ return ans;
703
+ }
704
+ /**
705
+ * Time Complexity: O(k)
706
+ * Space Complexity: O(k)
707
+ *
708
+ * The function `unshiftMany` iterates through a collection of elements and adds them to the
709
+ * beginning of a Doubly Linked List, returning an array of boolean values indicating the success of
710
+ * each insertion.
711
+ * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
712
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
713
+ * `R`, or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and
714
+ * performs an `unshift` operation on the doubly linked list
715
+ * @returns The `unshiftMany` function returns an array of boolean values indicating the success of
716
+ * each unshift operation performed on the elements passed as input.
717
+ */
718
+ unshiftMany(elements) {
719
+ const ans = [];
720
+ for (const el of elements) {
721
+ if (this.toElementFn) {
722
+ ans.push(this.unshift(this.toElementFn(el)));
723
+ continue;
724
+ }
725
+ ans.push(this.unshift(el));
726
+ }
727
+ return ans;
728
+ }
666
729
  /**
667
730
  * Time Complexity: O(n)
668
731
  * Space Complexity: O(1)
@@ -784,7 +847,9 @@ class DoublyLinkedList extends base_1.IterableElementBase {
784
847
  * node was not found.
785
848
  */
786
849
  addBefore(existingElementOrNode, newElementOrNode) {
787
- const existingNode = this.getNode(existingElementOrNode);
850
+ const existingNode = this.isNode(existingElementOrNode)
851
+ ? existingElementOrNode
852
+ : this.getNode(existingElementOrNode);
788
853
  if (existingNode) {
789
854
  const newNode = this._ensureNode(newElementOrNode);
790
855
  newNode.prev = existingNode.prev;
@@ -818,7 +883,9 @@ class DoublyLinkedList extends base_1.IterableElementBase {
818
883
  * was not found in the linked list.
819
884
  */
820
885
  addAfter(existingElementOrNode, newElementOrNode) {
821
- const existingNode = this.getNode(existingElementOrNode);
886
+ const existingNode = this.isNode(existingElementOrNode)
887
+ ? existingElementOrNode
888
+ : this.getNode(existingElementOrNode);
822
889
  if (existingNode) {
823
890
  const newNode = this._ensureNode(newElementOrNode);
824
891
  newNode.next = existingNode.next;
@@ -956,7 +1023,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
956
1023
  * @returns The `get` method returns the value of the first node in the doubly linked list that
957
1024
  * satisfies the provided predicate function. If no such node is found, it returns `undefined`.
958
1025
  */
959
- get(elementNodeOrPredicate) {
1026
+ search(elementNodeOrPredicate) {
960
1027
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
961
1028
  let current = this.head;
962
1029
  while (current) {
@@ -1110,6 +1177,12 @@ class DoublyLinkedList extends base_1.IterableElementBase {
1110
1177
  * Time Complexity: O(n)
1111
1178
  * Space Complexity: O(1)
1112
1179
  *
1180
+ * The function `countOccurrences` iterates through a doubly linked list and counts the occurrences
1181
+ * of a specified element or nodes that satisfy a given predicate.
1182
+ * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementOrNode
1183
+ * - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
1184
+ * @returns The `countOccurrences` method returns the number of occurrences of the specified element,
1185
+ * node, or predicate function in the doubly linked list.
1113
1186
  */
1114
1187
  countOccurrences(elementOrNode) {
1115
1188
  const predicate = this._ensurePredicate(elementOrNode);
@@ -1123,18 +1196,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
1123
1196
  }
1124
1197
  return count;
1125
1198
  }
1126
- /**
1127
- * Time Complexity: O(n)
1128
- * Space Complexity: O(n)
1129
- *
1130
- * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
1131
- * given array.
1132
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
1133
- * @returns The `fromArray` function returns a DoublyLinkedList object.
1134
- */
1135
- static fromArray(data) {
1136
- return new DoublyLinkedList(data);
1137
- }
1138
1199
  /**
1139
1200
  * The function returns an iterator that iterates over the values of a linked list.
1140
1201
  */
@@ -40,8 +40,11 @@ export declare class SinglyLinkedListNode<E = any> {
40
40
  */
41
41
  set next(value: SinglyLinkedListNode<E> | undefined);
42
42
  }
43
+ /**
44
+ *
45
+ */
43
46
  export declare class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R, SinglyLinkedList<E, R>> {
44
- constructor(elements?: Iterable<E> | Iterable<R>, options?: SinglyLinkedListOptions<E, R>);
47
+ constructor(elements?: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>, options?: SinglyLinkedListOptions<E, R>);
45
48
  protected _head: SinglyLinkedListNode<E> | undefined;
46
49
  /**
47
50
  * The `head` function returns the first node of a singly linked list.
@@ -72,6 +75,16 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
72
75
  * @returns The size of the object, which is a number.
73
76
  */
74
77
  get size(): number;
78
+ /**
79
+ * Time Complexity: O(n)
80
+ * Space Complexity: O(n)
81
+ *
82
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
83
+ * array.
84
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
85
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
86
+ */
87
+ static fromArray<E>(data: E[]): SinglyLinkedList<E, any>;
75
88
  /**
76
89
  * Time Complexity: O(1)
77
90
  * Space Complexity: O(1)
@@ -111,6 +124,33 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
111
124
  * @returns The `unshift` method is returning a boolean value, specifically `true`.
112
125
  */
113
126
  unshift(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
127
+ /**
128
+ * Time Complexity: O(k)
129
+ * Space Complexity: O(k)
130
+ *
131
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
132
+ * transformation function if provided.
133
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
134
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
135
+ * or `SinglyLinkedListNode<E>`.
136
+ * @returns The `pushMany` function returns an array of boolean values indicating whether each
137
+ * element was successfully pushed into the data structure.
138
+ */
139
+ pushMany(elements: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>): boolean[];
140
+ /**
141
+ * Time Complexity: O(k)
142
+ * Space Complexity: O(k)
143
+ *
144
+ * The function `unshiftMany` iterates over elements and adds them to a data structure, optionally
145
+ * converting them using a provided function.
146
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
147
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
148
+ * `R`, or `SinglyLinkedListNode<E>`. The function iterates over each element in the iterable and
149
+ * performs an `unshift` operation on the linked list for each
150
+ * @returns The `unshiftMany` function is returning an array of boolean values, where each value
151
+ * represents the result of calling the `unshift` method on the current instance of the class.
152
+ */
153
+ unshiftMany(elements: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>): boolean[];
114
154
  /**
115
155
  * Time Complexity: O(n)
116
156
  * Space Complexity: O(1)
@@ -123,7 +163,7 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
123
163
  * @returns The `get` method returns the value of the first node in the singly linked list that
124
164
  * satisfies the provided predicate function. If no such node is found, it returns `undefined`.
125
165
  */
126
- get(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): E | undefined;
166
+ search(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): E | undefined;
127
167
  /**
128
168
  * Time Complexity: O(n)
129
169
  * Space Complexity: O(1)
@@ -199,12 +239,18 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
199
239
  */
200
240
  addAt(index: number, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
201
241
  /**
242
+ * Time Complexity: O(1)
243
+ * Space Complexity: O(1)
244
+ *
202
245
  * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
203
246
  * whether it is empty or not.
204
247
  * @returns A boolean value indicating whether the length of the object is equal to 0.
205
248
  */
206
249
  isEmpty(): boolean;
207
250
  /**
251
+ * Time Complexity: O(1)
252
+ * Space Complexity: O(1)
253
+ *
208
254
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
209
255
  */
210
256
  clear(): void;
@@ -351,16 +397,6 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
351
397
  * The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
352
398
  */
353
399
  protected _getIterator(): IterableIterator<E>;
354
- /**
355
- * Time Complexity: O(n)
356
- * Space Complexity: O(n)
357
- *
358
- * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
359
- * array.
360
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
361
- * @returns The `fromArray` function returns a `SinglyLinkedList` object.
362
- */
363
- static fromArray<E>(data: E[]): SinglyLinkedList<E, any>;
364
400
  /**
365
401
  * The _isPredicate function in TypeScript checks if the input is a function that takes a
366
402
  * SinglyLinkedListNode as an argument and returns a boolean.
@@ -45,20 +45,14 @@ class SinglyLinkedListNode {
45
45
  }
46
46
  }
47
47
  exports.SinglyLinkedListNode = SinglyLinkedListNode;
48
+ /**
49
+ *
50
+ */
48
51
  class SinglyLinkedList extends base_1.IterableElementBase {
49
52
  constructor(elements = [], options) {
50
53
  super(options);
51
54
  this._size = 0;
52
- if (elements) {
53
- for (const el of elements) {
54
- if (this.toElementFn) {
55
- this.push(this.toElementFn(el));
56
- }
57
- else {
58
- this.push(el);
59
- }
60
- }
61
- }
55
+ this.pushMany(elements);
62
56
  }
63
57
  /**
64
58
  * The `head` function returns the first node of a singly linked list.
@@ -99,6 +93,22 @@ class SinglyLinkedList extends base_1.IterableElementBase {
99
93
  get size() {
100
94
  return this._size;
101
95
  }
96
+ /**
97
+ * Time Complexity: O(n)
98
+ * Space Complexity: O(n)
99
+ *
100
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
101
+ * array.
102
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
103
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
104
+ */
105
+ static fromArray(data) {
106
+ const singlyLinkedList = new SinglyLinkedList();
107
+ for (const item of data) {
108
+ singlyLinkedList.push(item);
109
+ }
110
+ return singlyLinkedList;
111
+ }
102
112
  /**
103
113
  * Time Complexity: O(1)
104
114
  * Space Complexity: O(1)
@@ -188,6 +198,53 @@ class SinglyLinkedList extends base_1.IterableElementBase {
188
198
  this._size++;
189
199
  return true;
190
200
  }
201
+ /**
202
+ * Time Complexity: O(k)
203
+ * Space Complexity: O(k)
204
+ *
205
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
206
+ * transformation function if provided.
207
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
208
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
209
+ * or `SinglyLinkedListNode<E>`.
210
+ * @returns The `pushMany` function returns an array of boolean values indicating whether each
211
+ * element was successfully pushed into the data structure.
212
+ */
213
+ pushMany(elements) {
214
+ const ans = [];
215
+ for (const el of elements) {
216
+ if (this.toElementFn) {
217
+ ans.push(this.push(this.toElementFn(el)));
218
+ continue;
219
+ }
220
+ ans.push(this.push(el));
221
+ }
222
+ return ans;
223
+ }
224
+ /**
225
+ * Time Complexity: O(k)
226
+ * Space Complexity: O(k)
227
+ *
228
+ * The function `unshiftMany` iterates over elements and adds them to a data structure, optionally
229
+ * converting them using a provided function.
230
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
231
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
232
+ * `R`, or `SinglyLinkedListNode<E>`. The function iterates over each element in the iterable and
233
+ * performs an `unshift` operation on the linked list for each
234
+ * @returns The `unshiftMany` function is returning an array of boolean values, where each value
235
+ * represents the result of calling the `unshift` method on the current instance of the class.
236
+ */
237
+ unshiftMany(elements) {
238
+ const ans = [];
239
+ for (const el of elements) {
240
+ if (this.toElementFn) {
241
+ ans.push(this.unshift(this.toElementFn(el)));
242
+ continue;
243
+ }
244
+ ans.push(this.unshift(el));
245
+ }
246
+ return ans;
247
+ }
191
248
  /**
192
249
  * Time Complexity: O(n)
193
250
  * Space Complexity: O(1)
@@ -200,7 +257,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
200
257
  * @returns The `get` method returns the value of the first node in the singly linked list that
201
258
  * satisfies the provided predicate function. If no such node is found, it returns `undefined`.
202
259
  */
203
- get(elementNodeOrPredicate) {
260
+ search(elementNodeOrPredicate) {
204
261
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
205
262
  let current = this.head;
206
263
  while (current) {
@@ -366,6 +423,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
366
423
  return true;
367
424
  }
368
425
  /**
426
+ * Time Complexity: O(1)
427
+ * Space Complexity: O(1)
428
+ *
369
429
  * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
370
430
  * whether it is empty or not.
371
431
  * @returns A boolean value indicating whether the length of the object is equal to 0.
@@ -374,6 +434,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
374
434
  return this._size === 0;
375
435
  }
376
436
  /**
437
+ * Time Complexity: O(1)
438
+ * Space Complexity: O(1)
439
+ *
377
440
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
378
441
  */
379
442
  clear() {
@@ -646,22 +709,6 @@ class SinglyLinkedList extends base_1.IterableElementBase {
646
709
  current = current.next;
647
710
  }
648
711
  }
649
- /**
650
- * Time Complexity: O(n)
651
- * Space Complexity: O(n)
652
- *
653
- * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
654
- * array.
655
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
656
- * @returns The `fromArray` function returns a `SinglyLinkedList` object.
657
- */
658
- static fromArray(data) {
659
- const singlyLinkedList = new SinglyLinkedList();
660
- for (const item of data) {
661
- singlyLinkedList.push(item);
662
- }
663
- return singlyLinkedList;
664
- }
665
712
  /**
666
713
  * The _isPredicate function in TypeScript checks if the input is a function that takes a
667
714
  * SinglyLinkedListNode as an argument and returns a boolean.
@@ -12,6 +12,9 @@ export declare class SkipListNode<K, V> {
12
12
  forward: SkipListNode<K, V>[];
13
13
  constructor(key: K, value: V, level: number);
14
14
  }
15
+ /**
16
+ *
17
+ */
15
18
  export declare class SkipList<K, V> {
16
19
  /**
17
20
  * The constructor function initializes a SkipLinkedList object with optional options and elements.
@@ -9,6 +9,9 @@ class SkipListNode {
9
9
  }
10
10
  }
11
11
  exports.SkipListNode = SkipListNode;
12
+ /**
13
+ *
14
+ */
12
15
  class SkipList {
13
16
  /**
14
17
  * The constructor function initializes a SkipLinkedList object with optional options and elements.
@@ -6,6 +6,9 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type { MatrixOptions } from '../../types';
9
+ /**
10
+ *
11
+ */
9
12
  export declare class Matrix {
10
13
  /**
11
14
  * The constructor function initializes a matrix object with the provided data and options, or with
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Matrix = void 0;
4
+ /**
5
+ *
6
+ */
4
7
  class Matrix {
5
8
  /**
6
9
  * The constructor function initializes a matrix object with the provided data and options, or with
@@ -19,6 +19,9 @@ export declare class Character {
19
19
  */
20
20
  constructor(direction: Direction, turning: Turning);
21
21
  }
22
+ /**
23
+ *
24
+ */
22
25
  export declare class Navigator<T = number> {
23
26
  onMove: (cur: [number, number]) => void;
24
27
  protected readonly _matrix: T[][];
@@ -16,6 +16,9 @@ class Character {
16
16
  }
17
17
  }
18
18
  exports.Character = Character;
19
+ /**
20
+ *
21
+ */
19
22
  class Navigator {
20
23
  /**
21
24
  * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
@@ -7,6 +7,9 @@
7
7
  */
8
8
  import type { Comparator, ElementCallback, PriorityQueueOptions } from '../../types';
9
9
  import { PriorityQueue } from './priority-queue';
10
+ /**
11
+ *
12
+ */
10
13
  export declare class MaxPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
11
14
  /**
12
15
  * The constructor initializes a PriorityQueue with optional elements and options, including a
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MaxPriorityQueue = void 0;
4
4
  const priority_queue_1 = require("./priority-queue");
5
+ /**
6
+ *
7
+ */
5
8
  class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
6
9
  /**
7
10
  * The constructor initializes a PriorityQueue with optional elements and options, including a
@@ -7,6 +7,9 @@
7
7
  */
8
8
  import type { Comparator, ElementCallback, PriorityQueueOptions } from '../../types';
9
9
  import { PriorityQueue } from './priority-queue';
10
+ /**
11
+ *
12
+ */
10
13
  export declare class MinPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
11
14
  /**
12
15
  * The constructor initializes a PriorityQueue with optional elements and options, including a
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MinPriorityQueue = void 0;
4
4
  const priority_queue_1 = require("./priority-queue");
5
+ /**
6
+ *
7
+ */
5
8
  class MinPriorityQueue extends priority_queue_1.PriorityQueue {
6
9
  /**
7
10
  * The constructor initializes a PriorityQueue with optional elements and options, including a
@@ -115,6 +115,16 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
115
115
  * @returns The element that was removed from the data structure is being returned.
116
116
  */
117
117
  pop(): E | undefined;
118
+ /**
119
+ * Time Complexity: O(1)
120
+ * Space Complexity: O(1)
121
+ *
122
+ * The `shift()` function removes and returns the first element from a data structure, updating the
123
+ * internal state variables accordingly.
124
+ * @returns The element that is being removed from the beginning of the data structure is being
125
+ * returned.
126
+ */
127
+ shift(): E | undefined;
118
128
  /**
119
129
  * Time Complexity: Amortized O(1)
120
130
  * Space Complexity: O(n)
@@ -127,15 +137,34 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
127
137
  */
128
138
  unshift(element: E): boolean;
129
139
  /**
130
- * Time Complexity: O(1)
131
- * Space Complexity: O(1)
140
+ * Time Complexity: O(k)
141
+ * Space Complexity: O(k)
132
142
  *
133
- * The `shift()` function removes and returns the first element from a data structure, updating the
134
- * internal state variables accordingly.
135
- * @returns The element that is being removed from the beginning of the data structure is being
136
- * returned.
137
- */
138
- shift(): E | undefined;
143
+ * The function `pushMany` iterates over elements and pushes them into an array after applying a
144
+ * transformation function if provided.
145
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
146
+ * parameter in the `pushMany` function is expected to be an iterable containing elements of type `E`
147
+ * or `R`. It can be either an `IterableWithSizeOrLength<E>` or an `IterableWithSizeOrLength<R>`. The
148
+ * function iterates over each element
149
+ * @returns The `pushMany` function is returning an array of boolean values, where each value
150
+ * represents the result of calling the `push` method on the current object instance with the
151
+ * corresponding element from the input `elements` iterable.
152
+ */
153
+ pushMany(elements: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
154
+ /**
155
+ * Time Complexity: O(k)
156
+ * Space Complexity: O(k)
157
+ *
158
+ * The `unshiftMany` function in TypeScript iterates over elements and adds them to the beginning of
159
+ * an array, optionally converting them using a provided function.
160
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
161
+ * parameter in the `unshiftMany` function is an iterable containing elements of type `E` or `R`. It
162
+ * can be an array or any other iterable data structure that has a known size or length. The function
163
+ * iterates over each element in the `elements` iterable and
164
+ * @returns The `unshiftMany` function returns an array of boolean values indicating whether each
165
+ * element was successfully added to the beginning of the array.
166
+ */
167
+ unshiftMany(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
139
168
  /**
140
169
  * Time Complexity: O(1)
141
170
  * Space Complexity: O(1)