data-structure-typed 1.54.3 → 2.0.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 (174) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/benchmark/report.html +26 -2
  3. package/benchmark/report.json +292 -42
  4. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +14 -40
  5. package/dist/cjs/data-structures/base/iterable-element-base.js +14 -11
  6. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  7. package/dist/cjs/data-structures/base/linear-base.d.ts +277 -0
  8. package/dist/cjs/data-structures/base/linear-base.js +553 -0
  9. package/dist/cjs/data-structures/base/linear-base.js.map +1 -0
  10. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +12 -8
  11. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +50 -37
  12. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +64 -0
  14. package/dist/cjs/data-structures/binary-tree/avl-tree.js +64 -0
  15. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +62 -0
  17. package/dist/cjs/data-structures/binary-tree/binary-tree.js +67 -5
  18. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  19. package/dist/cjs/data-structures/binary-tree/bst.d.ts +3 -3
  20. package/dist/cjs/data-structures/binary-tree/bst.js +14 -14
  21. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  22. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +1 -7
  23. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +1 -7
  24. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  25. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +175 -14
  26. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +210 -40
  27. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/abstract-graph.js +2 -2
  29. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  30. package/dist/cjs/data-structures/heap/heap.d.ts +3 -11
  31. package/dist/cjs/data-structures/heap/heap.js +0 -10
  32. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  33. package/dist/cjs/data-structures/heap/max-heap.d.ts +2 -2
  34. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  35. package/dist/cjs/data-structures/heap/min-heap.d.ts +2 -2
  36. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  37. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  38. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +131 -146
  39. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  40. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  41. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +217 -169
  42. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  43. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  44. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  45. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  46. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  47. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -2
  48. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  49. package/dist/cjs/data-structures/queue/deque.d.ts +130 -91
  50. package/dist/cjs/data-structures/queue/deque.js +269 -169
  51. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  52. package/dist/cjs/data-structures/queue/queue.d.ts +84 -40
  53. package/dist/cjs/data-structures/queue/queue.js +134 -50
  54. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  55. package/dist/cjs/data-structures/stack/stack.d.ts +3 -11
  56. package/dist/cjs/data-structures/stack/stack.js +0 -10
  57. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  58. package/dist/cjs/data-structures/trie/trie.d.ts +4 -3
  59. package/dist/cjs/data-structures/trie/trie.js +3 -0
  60. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  61. package/dist/cjs/types/data-structures/base/base.d.ts +9 -4
  62. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  63. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  64. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  65. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  66. package/dist/cjs/types/data-structures/queue/deque.d.ts +2 -3
  67. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -2
  68. package/dist/esm/data-structures/base/iterable-element-base.d.ts +14 -40
  69. package/dist/esm/data-structures/base/iterable-element-base.js +14 -11
  70. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  71. package/dist/esm/data-structures/base/linear-base.d.ts +277 -0
  72. package/dist/esm/data-structures/base/linear-base.js +549 -0
  73. package/dist/esm/data-structures/base/linear-base.js.map +1 -0
  74. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +12 -8
  75. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +50 -36
  76. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  77. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +64 -0
  78. package/dist/esm/data-structures/binary-tree/avl-tree.js +64 -0
  79. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  80. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +62 -0
  81. package/dist/esm/data-structures/binary-tree/binary-tree.js +67 -5
  82. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  83. package/dist/esm/data-structures/binary-tree/bst.d.ts +3 -3
  84. package/dist/esm/data-structures/binary-tree/bst.js +14 -12
  85. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  86. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +1 -7
  87. package/dist/esm/data-structures/binary-tree/red-black-tree.js +1 -7
  88. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  89. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +175 -14
  90. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +210 -39
  91. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  92. package/dist/esm/data-structures/graph/abstract-graph.js +2 -2
  93. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  94. package/dist/esm/data-structures/heap/heap.d.ts +3 -11
  95. package/dist/esm/data-structures/heap/heap.js +0 -10
  96. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  97. package/dist/esm/data-structures/heap/max-heap.d.ts +2 -2
  98. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  99. package/dist/esm/data-structures/heap/min-heap.d.ts +2 -2
  100. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  101. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  102. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +132 -148
  103. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  104. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  105. package/dist/esm/data-structures/linked-list/singly-linked-list.js +217 -170
  106. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  107. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  108. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  109. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  110. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  111. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -2
  112. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  113. package/dist/esm/data-structures/queue/deque.d.ts +130 -91
  114. package/dist/esm/data-structures/queue/deque.js +269 -169
  115. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  116. package/dist/esm/data-structures/queue/queue.d.ts +84 -40
  117. package/dist/esm/data-structures/queue/queue.js +135 -51
  118. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  119. package/dist/esm/data-structures/stack/stack.d.ts +3 -11
  120. package/dist/esm/data-structures/stack/stack.js +0 -10
  121. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  122. package/dist/esm/data-structures/trie/trie.d.ts +4 -3
  123. package/dist/esm/data-structures/trie/trie.js +3 -0
  124. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  125. package/dist/esm/types/data-structures/base/base.d.ts +9 -4
  126. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  127. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  128. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  129. package/dist/esm/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  130. package/dist/esm/types/data-structures/queue/deque.d.ts +2 -3
  131. package/dist/esm/types/data-structures/queue/queue.d.ts +2 -2
  132. package/dist/umd/data-structure-typed.js +1246 -635
  133. package/dist/umd/data-structure-typed.min.js +3 -3
  134. package/dist/umd/data-structure-typed.min.js.map +1 -1
  135. package/package.json +6 -6
  136. package/src/data-structures/base/iterable-element-base.ts +29 -20
  137. package/src/data-structures/base/linear-base.ts +649 -0
  138. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +51 -36
  139. package/src/data-structures/binary-tree/avl-tree.ts +64 -0
  140. package/src/data-structures/binary-tree/binary-tree.ts +5 -5
  141. package/src/data-structures/binary-tree/bst.ts +9 -9
  142. package/src/data-structures/binary-tree/tree-multi-map.ts +214 -40
  143. package/src/data-structures/graph/abstract-graph.ts +2 -2
  144. package/src/data-structures/heap/heap.ts +3 -14
  145. package/src/data-structures/heap/max-heap.ts +2 -2
  146. package/src/data-structures/heap/min-heap.ts +2 -2
  147. package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
  148. package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
  149. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
  150. package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
  151. package/src/data-structures/priority-queue/priority-queue.ts +2 -2
  152. package/src/data-structures/queue/deque.ts +286 -183
  153. package/src/data-structures/queue/queue.ts +149 -63
  154. package/src/data-structures/stack/stack.ts +3 -18
  155. package/src/data-structures/trie/trie.ts +7 -3
  156. package/src/types/data-structures/base/base.ts +17 -8
  157. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  158. package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
  159. package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
  160. package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
  161. package/src/types/data-structures/queue/deque.ts +2 -3
  162. package/src/types/data-structures/queue/queue.ts +2 -2
  163. package/test/integration/all-in-one.test.ts +1 -1
  164. package/test/integration/avl-tree.test.ts +1 -1
  165. package/test/integration/bst.test.ts +2 -2
  166. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +168 -0
  167. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +15 -14
  168. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +1 -1
  169. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +165 -7
  170. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +135 -27
  171. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +111 -11
  172. package/test/unit/data-structures/queue/deque.test.ts +241 -60
  173. package/test/unit/data-structures/queue/queue.test.ts +118 -19
  174. package/test/unit/unrestricted-interconversion.test.ts +1 -1
@@ -0,0 +1,549 @@
1
+ import { IterableElementBase } from './iterable-element-base';
2
+ export class LinkedListNode {
3
+ constructor(value) {
4
+ this._value = value;
5
+ this._next = undefined;
6
+ }
7
+ _value;
8
+ get value() {
9
+ return this._value;
10
+ }
11
+ set value(value) {
12
+ this._value = value;
13
+ }
14
+ _next;
15
+ get next() {
16
+ return this._next;
17
+ }
18
+ set next(value) {
19
+ this._next = value;
20
+ }
21
+ }
22
+ export class LinearBase extends IterableElementBase {
23
+ /**
24
+ * The constructor initializes the LinearBase class with optional options, setting the maximum length
25
+ * if provided.
26
+ * @param [options] - The `options` parameter is an optional object that can be passed to the
27
+ * constructor. It is of type `LinearBaseOptions<E, R>`. The constructor checks if the `options`
28
+ * object is provided and then extracts the `maxLen` property from it. If `maxLen` is a
29
+ */
30
+ constructor(options) {
31
+ super(options);
32
+ if (options) {
33
+ const { maxLen } = options;
34
+ if (typeof maxLen === 'number' && maxLen > 0 && maxLen % 1 === 0)
35
+ this._maxLen = maxLen;
36
+ }
37
+ }
38
+ _maxLen = -1;
39
+ get maxLen() {
40
+ return this._maxLen;
41
+ }
42
+ /**
43
+ * Time Complexity: O(n)
44
+ * Space Complexity: O(1)
45
+ *
46
+ * The function indexOf searches for a specified element starting from a given index in an array-like
47
+ * object and returns the index of the first occurrence, or -1 if not found.
48
+ * @param {E} searchElement - The `searchElement` parameter in the `indexOf` function represents the
49
+ * element that you want to find within the array. The function will search for this element starting
50
+ * from the `fromIndex` (if provided) up to the end of the array. If the `searchElement` is found
51
+ * within the
52
+ * @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` function represents the
53
+ * index at which to start searching for the `searchElement` within the array. If provided, the
54
+ * search will begin at this index and continue to the end of the array. If `fromIndex` is not
55
+ * specified, the default
56
+ * @returns The `indexOf` method is returning the index of the `searchElement` if it is found in the
57
+ * array starting from the `fromIndex`. If the `searchElement` is not found, it returns -1.
58
+ */
59
+ indexOf(searchElement, fromIndex = 0) {
60
+ // Boundary checks and adjustments
61
+ if (this.length === 0)
62
+ return -1;
63
+ if (fromIndex < 0)
64
+ fromIndex = this.length + fromIndex;
65
+ if (fromIndex < 0)
66
+ fromIndex = 0;
67
+ // Iterating from the specified index to the end
68
+ for (let i = fromIndex; i < this.length; i++) {
69
+ const element = this.at(i);
70
+ if (element === searchElement)
71
+ return i;
72
+ }
73
+ return -1; // Not found
74
+ }
75
+ /**
76
+ * Time Complexity: O(n)
77
+ * Space Complexity: O(1)
78
+ *
79
+ * The function `lastIndexOf` in TypeScript returns the index of the last occurrence of a specified
80
+ * element in an array.
81
+ * @param {E} searchElement - The `searchElement` parameter is the element that you want to find the
82
+ * last index of within the array. The `lastIndexOf` method will search the array starting from the
83
+ * `fromIndex` (or the end of the array if not specified) and return the index of the last occurrence
84
+ * of the
85
+ * @param {number} fromIndex - The `fromIndex` parameter in the `lastIndexOf` method specifies the
86
+ * index at which to start searching for the `searchElement` in the array. By default, it starts
87
+ * searching from the last element of the array (`this.length - 1`). If a specific `fromIndex` is
88
+ * provided
89
+ * @returns The last index of the `searchElement` in the array is being returned. If the
90
+ * `searchElement` is not found in the array, -1 is returned.
91
+ */
92
+ lastIndexOf(searchElement, fromIndex = this.length - 1) {
93
+ if (this.length === 0)
94
+ return -1;
95
+ if (fromIndex >= this.length)
96
+ fromIndex = this.length - 1;
97
+ if (fromIndex < 0)
98
+ fromIndex = this.length + fromIndex;
99
+ for (let i = fromIndex; i >= 0; i--) {
100
+ const element = this.at(i);
101
+ if (element === searchElement)
102
+ return i;
103
+ }
104
+ return -1;
105
+ }
106
+ /**
107
+ * Time Complexity: O(n)
108
+ * Space Complexity: O(1)
109
+ *
110
+ * The `findIndex` function iterates over an array and returns the index of the first element that
111
+ * satisfies the provided predicate function.
112
+ * @param predicate - The `predicate` parameter in the `findIndex` function is a callback function
113
+ * that takes three arguments: `item`, `index`, and the array `this`. It should return a boolean
114
+ * value indicating whether the current element satisfies the condition being checked for.
115
+ * @param {any} [thisArg] - The `thisArg` parameter in the `findIndex` function is an optional
116
+ * parameter that specifies the value to use as `this` when executing the `predicate` function. If
117
+ * provided, the `predicate` function will be called with `thisArg` as its `this` value. If `
118
+ * @returns The `findIndex` method is returning the index of the first element in the array that
119
+ * satisfies the provided predicate function. If no such element is found, it returns -1.
120
+ */
121
+ findIndex(predicate, thisArg) {
122
+ for (let i = 0; i < this.length; i++) {
123
+ const item = this.at(i);
124
+ if (item !== undefined && predicate.call(thisArg, item, i, this))
125
+ return i;
126
+ }
127
+ return -1;
128
+ }
129
+ /**
130
+ * Time Complexity: O(n + m)
131
+ * Space Complexity: O(n + m)
132
+ *
133
+ * The `concat` function in TypeScript concatenates multiple items into a new list, handling both
134
+ * individual elements and instances of `LinearBase`.
135
+ * @param {(E | this)[]} items - The `concat` method takes in an array of items, where
136
+ * each item can be either of type `E` or an instance of `LinearBase<E, R>`.
137
+ * @returns The `concat` method is returning a new instance of the class that it belongs to, with the
138
+ * items passed as arguments concatenated to it.
139
+ */
140
+ concat(...items) {
141
+ const newList = this.clone();
142
+ for (const item of items) {
143
+ if (item instanceof LinearBase) {
144
+ newList.pushMany(item);
145
+ }
146
+ else {
147
+ newList.push(item);
148
+ }
149
+ }
150
+ return newList;
151
+ }
152
+ /**
153
+ * Time Complexity: O(n log n)
154
+ * Space Complexity: O(n)
155
+ *
156
+ * The `sort` function in TypeScript sorts the elements of a collection using a specified comparison
157
+ * function.
158
+ * @param [compareFn] - The `compareFn` parameter is a function that defines the sort order. It takes
159
+ * two elements `a` and `b` as input and returns a number indicating their relative order. If the
160
+ * returned value is negative, `a` comes before `b`. If the returned value is positive, `
161
+ * @returns The `sort` method is returning the instance of the object on which it is called (this),
162
+ * after sorting the elements based on the provided comparison function (compareFn).
163
+ */
164
+ sort(compareFn) {
165
+ const arr = this.toArray();
166
+ arr.sort(compareFn);
167
+ this.clear();
168
+ for (const item of arr)
169
+ this.push(item);
170
+ return this;
171
+ }
172
+ /**
173
+ * Time Complexity: O(n + m)
174
+ * Space Complexity: O(m)
175
+ *
176
+ * The `splice` function in TypeScript removes elements from an array and optionally inserts new
177
+ * elements at the specified index.
178
+ * @param {number} start - The `start` parameter in the `splice` method indicates the index at which
179
+ * to start modifying the array. If `start` is a negative number, it will count from the end of the
180
+ * array.
181
+ * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
182
+ * number of elements to remove from the array starting at the specified `start` index. If
183
+ * `deleteCount` is not provided or is 0, no elements are removed, and only new elements are inserted
184
+ * at the `start`
185
+ * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
186
+ * will be inserted into the array at the specified `start` index. These elements can be of any type
187
+ * and you can pass multiple elements separated by commas. The `splice` method will insert these
188
+ * items into the array at the
189
+ * @returns The `splice` method returns a list of elements that were removed from the original list
190
+ * during the operation.
191
+ */
192
+ splice(start, deleteCount = 0, ...items) {
193
+ const removedList = this._createInstance();
194
+ // Handling negative indexes and bounds
195
+ start = start < 0 ? this.length + start : start;
196
+ start = Math.max(0, Math.min(start, this.length));
197
+ deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
198
+ // Delete elements
199
+ for (let i = 0; i < deleteCount; i++) {
200
+ const removed = this.deleteAt(start); // Always delete the start position
201
+ if (removed !== undefined) {
202
+ removedList.push(removed); // Add removed elements to the returned list
203
+ }
204
+ }
205
+ // Insert new element
206
+ for (let i = 0; i < items.length; i++) {
207
+ this.addAt(start + i, items[i]); // Insert new elements one by one at the current position
208
+ }
209
+ return removedList; // Returns a list of removed elements
210
+ }
211
+ /**
212
+ * Time Complexity: O(n)
213
+ * Space Complexity: O(1)
214
+ *
215
+ * The `join` function in TypeScript returns a string by joining the elements of an array with a
216
+ * specified separator.
217
+ * @param {string} [separator=,] - The `separator` parameter is a string that specifies the character
218
+ * or characters that will be used to separate each element when joining them into a single string.
219
+ * By default, the separator is set to a comma (`,`), but you can provide a different separator if
220
+ * needed.
221
+ * @returns The `join` method is being returned, which takes an optional `separator` parameter
222
+ * (defaulting to a comma) and returns a string created by joining all elements of the array after
223
+ * converting it to an array.
224
+ */
225
+ join(separator = ',') {
226
+ return this.toArray().join(separator);
227
+ }
228
+ /**
229
+ * Time Complexity: O(n)
230
+ * Space Complexity: O(n)
231
+ *
232
+ * The function `toReversedArray` takes an array and returns a new array with its elements in reverse
233
+ * order.
234
+ * @returns The `toReversedArray()` function returns an array of elements of type `E` in reverse
235
+ * order.
236
+ */
237
+ toReversedArray() {
238
+ const array = [];
239
+ for (let i = this.length - 1; i >= 0; i--) {
240
+ array.push(this.at(i));
241
+ }
242
+ return array;
243
+ }
244
+ /**
245
+ * Time Complexity: O(n)
246
+ * Space Complexity: O(1)
247
+ *
248
+ * The `reduceRight` function in TypeScript iterates over an array from right to left and applies a
249
+ * callback function to each element, accumulating a single result.
250
+ * @param callbackfn - The `callbackfn` parameter in the `reduceRight` method is a function that will
251
+ * be called on each element in the array from right to left. It takes four arguments:
252
+ * @param {U} [initialValue] - The `initialValue` parameter in the `reduceRight` method is an
253
+ * optional parameter that specifies the initial value of the accumulator. If provided, the
254
+ * `accumulator` will start with this initial value before iterating over the elements of the array.
255
+ * If `initialValue` is not provided, the accumulator will
256
+ * @returns The `reduceRight` method is returning the final accumulated value after applying the
257
+ * callback function to each element in the array from right to left.
258
+ */
259
+ reduceRight(callbackfn, initialValue) {
260
+ let accumulator = initialValue ?? 0;
261
+ for (let i = this.length - 1; i >= 0; i--) {
262
+ accumulator = callbackfn(accumulator, this.at(i), i, this);
263
+ }
264
+ return accumulator;
265
+ }
266
+ /**
267
+ * Time Complexity: O(m)
268
+ * Space Complexity: O(m)
269
+ *
270
+ * The `slice` function in TypeScript creates a new instance by extracting a portion of elements from
271
+ * the original instance based on the specified start and end indices.
272
+ * @param {number} [start=0] - The `start` parameter in the `slice` method represents the index at
273
+ * which to begin extracting elements from an array-like object. If no `start` parameter is provided,
274
+ * the default value is 0, meaning the extraction will start from the beginning of the array.
275
+ * @param {number} end - The `end` parameter in the `slice` method represents the index at which to
276
+ * end the slicing. By default, if no `end` parameter is provided, it will slice until the end of the
277
+ * array (i.e., `this.length`).
278
+ * @returns The `slice` method is returning a new instance of the object with elements sliced from
279
+ * the specified start index (default is 0) to the specified end index (default is the length of the
280
+ * object).
281
+ */
282
+ slice(start = 0, end = this.length) {
283
+ start = start < 0 ? this.length + start : start;
284
+ end = end < 0 ? this.length + end : end;
285
+ const newList = this._createInstance();
286
+ for (let i = start; i < end; i++) {
287
+ newList.push(this.at(i));
288
+ }
289
+ return newList;
290
+ }
291
+ /**
292
+ * Time Complexity: O(n)
293
+ * Space Complexity: O(1)
294
+ *
295
+ * The `fill` function in TypeScript fills a specified range in an array-like object with a given
296
+ * value.
297
+ * @param {E} value - The `value` parameter in the `fill` method represents the element that will be
298
+ * used to fill the specified range in the array.
299
+ * @param [start=0] - The `start` parameter specifies the index at which to start filling the array
300
+ * with the specified value. If not provided, it defaults to 0, indicating the beginning of the
301
+ * array.
302
+ * @param end - The `end` parameter in the `fill` function represents the index at which the filling
303
+ * of values should stop. It specifies the end of the range within the array where the `value` should
304
+ * be filled.
305
+ * @returns The `fill` method is returning the modified object (`this`) after filling the specified
306
+ * range with the provided value.
307
+ */
308
+ fill(value, start = 0, end = this.length) {
309
+ // Handling negative indexes
310
+ start = start < 0 ? this.length + start : start;
311
+ end = end < 0 ? this.length + end : end;
312
+ // Boundary processing
313
+ if (start < 0)
314
+ start = 0;
315
+ if (end > this.length)
316
+ end = this.length;
317
+ if (start >= end)
318
+ return this;
319
+ // Iterate through the specified range and fill in the values
320
+ for (let i = start; i < end; i++) {
321
+ this.setAt(i, value);
322
+ }
323
+ return this;
324
+ }
325
+ }
326
+ export class LinearLinkedBase extends LinearBase {
327
+ /**
328
+ * The constructor initializes the LinearBase class with optional options, setting the maximum length
329
+ * if provided and valid.
330
+ * @param [options] - The `options` parameter is an optional object that can be passed to the
331
+ * constructor. It is of type `LinearBaseOptions<E, R>`. This object may contain properties such as
332
+ * `maxLen`, which is a number representing the maximum length. If `maxLen` is a positive integer,
333
+ */
334
+ constructor(options) {
335
+ super(options);
336
+ if (options) {
337
+ const { maxLen } = options;
338
+ if (typeof maxLen === 'number' && maxLen > 0 && maxLen % 1 === 0)
339
+ this._maxLen = maxLen;
340
+ }
341
+ }
342
+ /**
343
+ * Time Complexity: O(n)
344
+ * Space Complexity: O(1)
345
+ *
346
+ * The function overrides the indexOf method to improve performance by searching for an element in a
347
+ * custom array implementation starting from a specified index.
348
+ * @param {E} searchElement - The `searchElement` parameter is the element that you are searching for
349
+ * within the array. The `indexOf` method will return the index of the first occurrence of this
350
+ * element within the array.
351
+ * @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` method specifies the
352
+ * index in the array at which to start the search for the `searchElement`. If provided, the search
353
+ * will begin at the specified index and continue to the end of the array. If not provided, the
354
+ * search will start at index
355
+ * @returns The `indexOf` method is returning the index of the `searchElement` if it is found in the
356
+ * array starting from the `fromIndex`. If the `searchElement` is not found, it returns -1.
357
+ */
358
+ indexOf(searchElement, fromIndex = 0) {
359
+ // In order to improve performance, it is best to override this method in the subclass of the array implementation
360
+ const iterator = this._getIterator();
361
+ let current = iterator.next();
362
+ let index = 0;
363
+ while (index < fromIndex) {
364
+ current = iterator.next();
365
+ index++;
366
+ }
367
+ while (!current.done) {
368
+ if (current.value === searchElement)
369
+ return index;
370
+ current = iterator.next();
371
+ index++;
372
+ }
373
+ return -1;
374
+ }
375
+ /**
376
+ * Time Complexity: O(n)
377
+ * Space Complexity: O(1)
378
+ *
379
+ * The function overrides the lastIndexOf method in TypeScript to improve performance by searching
380
+ * for an element in reverse order starting from a specified index.
381
+ * @param {E} searchElement - The `searchElement` parameter is the element that you want to find
382
+ * within the array. The `lastIndexOf` method searches the array for this element starting from the
383
+ * end of the array (or from the specified `fromIndex` if provided) and returns the index of the last
384
+ * occurrence of the element
385
+ * @param {number} fromIndex - The `fromIndex` parameter in the `lastIndexOf` method specifies the
386
+ * index at which to start searching for the `searchElement` in the array. If provided, the search
387
+ * will begin at this index and move towards the beginning of the array. If not provided, the search
388
+ * will start at the
389
+ * @returns The `lastIndexOf` method is being overridden to search for the `searchElement` starting
390
+ * from the specified `fromIndex` (defaulting to the end of the array). It iterates over the array in
391
+ * reverse order using a custom iterator `_getReverseIterator` and returns the index of the last
392
+ * occurrence of the `searchElement` if found, or -1 if not found.
393
+ */
394
+ lastIndexOf(searchElement, fromIndex = this.length - 1) {
395
+ // In order to improve performance, it is best to override this method in the subclass of the array implementation
396
+ const iterator = this._getReverseIterator();
397
+ let current = iterator.next();
398
+ let index = this.length - 1;
399
+ while (index > fromIndex) {
400
+ current = iterator.next();
401
+ index--;
402
+ }
403
+ while (!current.done) {
404
+ if (current.value === searchElement)
405
+ return index;
406
+ current = iterator.next();
407
+ index--;
408
+ }
409
+ return -1;
410
+ }
411
+ /**
412
+ * Time Complexity: O(n + m)
413
+ * Space Complexity: O(n + m)
414
+ *
415
+ * The `concat` function in TypeScript overrides the default behavior to concatenate items into a new
416
+ * list, handling both individual elements and instances of `LinearBase`.
417
+ * @param {(E | LinearBase<E, R>)[]} items - The `concat` method you provided takes in a variable
418
+ * number of arguments of type `E` or `LinearBase<E, R>`. The method concatenates these items to the
419
+ * current list and returns a new list with the concatenated items.
420
+ * @returns The `concat` method is returning a new instance of the class that it belongs to, with the
421
+ * items passed as arguments concatenated to it.
422
+ */
423
+ concat(...items) {
424
+ const newList = this.clone();
425
+ for (const item of items) {
426
+ if (item instanceof LinearBase) {
427
+ newList.pushMany(item);
428
+ }
429
+ else {
430
+ newList.push(item);
431
+ }
432
+ }
433
+ return newList;
434
+ }
435
+ /**
436
+ * Time Complexity: O(m)
437
+ * Space Complexity: O(m)
438
+ *
439
+ * The `slice` method is overridden to improve performance by creating a new instance and iterating
440
+ * through the array to extract a subset based on the specified start and end indices.
441
+ * @param {number} [start=0] - The `start` parameter in the `slice` method specifies the index at
442
+ * which to begin extracting elements from the array. If no `start` parameter is provided, the
443
+ * default value is 0, indicating that extraction should start from the beginning of the array.
444
+ * @param {number} end - The `end` parameter in the `slice` method represents the index at which to
445
+ * end the slicing of the array. If not provided, it defaults to the length of the array.
446
+ * @returns The `slice` method is returning a new instance of the array implementation with elements
447
+ * sliced from the original array based on the `start` and `end` parameters.
448
+ */
449
+ slice(start = 0, end = this.length) {
450
+ // In order to improve performance, it is best to override this method in the subclass of the array implementation
451
+ start = start < 0 ? this.length + start : start;
452
+ end = end < 0 ? this.length + end : end;
453
+ const newList = this._createInstance();
454
+ const iterator = this._getIterator();
455
+ let current = iterator.next();
456
+ let c = 0;
457
+ while (c < start) {
458
+ current = iterator.next();
459
+ c++;
460
+ }
461
+ for (let i = start; i < end; i++) {
462
+ newList.push(current.value);
463
+ current = iterator.next();
464
+ }
465
+ return newList;
466
+ }
467
+ /**
468
+ * Time Complexity: O(n + m)
469
+ * Space Complexity: O(m)
470
+ *
471
+ * The function overrides the splice method to handle deletion and insertion of elements in a data
472
+ * structure while returning the removed elements.
473
+ * @param {number} start - The `start` parameter in the `splice` method indicates the index at which
474
+ * to start modifying the array.
475
+ * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
476
+ * number of elements to remove from the array starting at the specified `start` index. If
477
+ * `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
478
+ * elements can still be inserted at
479
+ * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
480
+ * will be inserted into the array at the specified `start` index. These elements can be of any type
481
+ * and there can be multiple elements passed as arguments to be inserted into the array.
482
+ * @returns The `splice` method is returning a new instance of the data structure that was modified
483
+ * by removing elements specified by the `start` and `deleteCount` parameters, and inserting new
484
+ * elements provided in the `items` array.
485
+ */
486
+ splice(start, deleteCount = 0, ...items) {
487
+ const removedList = this._createInstance(); // Used to store deleted elements
488
+ // Handling negative indexes
489
+ start = start < 0 ? this.length + start : start;
490
+ start = Math.max(0, Math.min(start, this.length)); // Correct start range
491
+ deleteCount = Math.max(0, deleteCount); // Make sure deleteCount is non-negative
492
+ let currentIndex = 0;
493
+ let currentNode = undefined;
494
+ let previousNode = undefined;
495
+ // Find the starting point using an iterator
496
+ const iterator = this._getNodeIterator();
497
+ for (const node of iterator) {
498
+ if (currentIndex === start) {
499
+ currentNode = node; // Find the starting node
500
+ break;
501
+ }
502
+ previousNode = node; // Update the previous node
503
+ currentIndex++;
504
+ }
505
+ // Delete nodes
506
+ for (let i = 0; i < deleteCount && currentNode; i++) {
507
+ removedList.push(currentNode.value); // Store the deleted value in removedList
508
+ const nextNode = currentNode.next; // Save next node
509
+ this.delete(currentNode); // Delete current node
510
+ currentNode = nextNode;
511
+ }
512
+ // Insert new value
513
+ for (let i = 0; i < items.length; i++) {
514
+ if (previousNode) {
515
+ this.addAfter(previousNode, items[i]); // Insert after previousNode
516
+ previousNode = previousNode.next; // Move to newly inserted node
517
+ }
518
+ else {
519
+ this.addAt(0, items[i]); // Insert at the head of the linked list
520
+ previousNode = this._getNodeIterator().next().value; // Update the head node to be the first inserted node
521
+ }
522
+ }
523
+ return removedList;
524
+ }
525
+ /**
526
+ * Time Complexity: O(n)
527
+ * Space Complexity: O(1)
528
+ *
529
+ * The function `reduceRight` iterates over an array in reverse order and applies a callback function
530
+ * to each element, accumulating a single result.
531
+ * @param callbackfn - The `callbackfn` parameter is a function that will be called on each element
532
+ * of the array from right to left. It takes four arguments:
533
+ * @param {U} [initialValue] - The `initialValue` parameter is an optional value that is used as the
534
+ * initial accumulator value in the reduce operation. If provided, the reduce operation starts with
535
+ * this initial value and iterates over the elements of the array, applying the callback function to
536
+ * each element and the current accumulator value. If `initial
537
+ * @returns The `reduceRight` method is returning the final accumulated value after applying the
538
+ * callback function to each element in the array from right to left.
539
+ */
540
+ reduceRight(callbackfn, initialValue) {
541
+ let accumulator = initialValue ?? 0;
542
+ let index = this.length - 1;
543
+ for (const item of this._getReverseIterator()) {
544
+ accumulator = callbackfn(accumulator, item, index--, this);
545
+ }
546
+ return accumulator;
547
+ }
548
+ }
549
+ //# sourceMappingURL=linear-base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linear-base.js","sourceRoot":"","sources":["../../../../src/data-structures/base/linear-base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAA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,CAAC,CAAC,CAAC,4BAA4B;gBACnE,YAAY,GAAG,YAAY,CAAC,IAAY,CAAC,CAAC,8BAA8B;YAC1E,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,wCAAwC;gBACjE,YAAY,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,qDAAqD;YAC5G,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAQD;;;;;;;;;;;;;;OAcG;IACM,WAAW,CAAI,UAAsC,EAAE,YAAgB;QAC9E,IAAI,WAAW,GAAG,YAAY,IAAK,CAAO,CAAC;QAC3C,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAC5B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,mBAAmB,EAAE,EAAE,CAAC;YAC9C,WAAW,GAAG,UAAU,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CAeF"}
@@ -60,15 +60,19 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = object, MK = any, MV
60
60
  * Time Complexity: O(1)
61
61
  * Space Complexity: O(1)
62
62
  *
63
- * The function `createNode` overrides the method to create a new AVLTreeMultiMapNode with a
64
- * specified key and an empty array of values.
65
- * @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
66
- * that will be created in the AVLTreeMultiMap.
67
- * @returns An AVLTreeMultiMapNode object is being returned, initialized with the provided key and an
68
- * empty array.
63
+ * The `createNode` function in TypeScript overrides the default implementation to create a new
64
+ * AVLTreeMultiMapNode with a specified key and value array.
65
+ * @param {K} key - The `key` parameter represents the key of the node being created in the
66
+ * AVLTreeMultiMap.
67
+ * @param {V[]} value - The `value` parameter in the `createNode` method represents an array of
68
+ * values associated with a specific key in the AVLTreeMultiMapNode. If no value is provided when
69
+ * calling the method, an empty array `[]` is used as the default value.
70
+ * @returns An AVLTreeMultiMapNode object is being returned, with the specified key and value. If the
71
+ * AVLTreeMultiMap is in map mode, an empty array is used as the value, otherwise the provided value
72
+ * array is used.
69
73
  */
70
- createNode(key: K): AVLTreeMultiMapNode<K, V>;
71
- add(node: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
74
+ createNode(key: K, value?: V[]): AVLTreeMultiMapNode<K, V>;
75
+ add(keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
72
76
  add(key: K, value: V): boolean;
73
77
  /**
74
78
  * Time Complexity: O(log n)