linked-list-typed 2.0.4 → 2.1.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 (102) hide show
  1. package/README.md +14 -14
  2. package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
  3. package/dist/data-structures/base/iterable-element-base.js +149 -107
  4. package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
  5. package/dist/data-structures/base/iterable-entry-base.js +59 -116
  6. package/dist/data-structures/base/linear-base.d.ts +250 -192
  7. package/dist/data-structures/base/linear-base.js +137 -274
  8. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  9. package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
  10. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  11. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  12. package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
  13. package/dist/data-structures/binary-tree/avl-tree.js +208 -195
  14. package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
  15. package/dist/data-structures/binary-tree/binary-tree.js +612 -879
  16. package/dist/data-structures/binary-tree/bst.d.ts +258 -306
  17. package/dist/data-structures/binary-tree/bst.js +505 -481
  18. package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  19. package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
  20. package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
  21. package/dist/data-structures/binary-tree/tree-counter.js +172 -203
  22. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  23. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
  24. package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
  25. package/dist/data-structures/graph/abstract-graph.js +267 -237
  26. package/dist/data-structures/graph/directed-graph.d.ts +108 -224
  27. package/dist/data-structures/graph/directed-graph.js +146 -233
  28. package/dist/data-structures/graph/map-graph.d.ts +49 -55
  29. package/dist/data-structures/graph/map-graph.js +56 -59
  30. package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
  31. package/dist/data-structures/graph/undirected-graph.js +129 -149
  32. package/dist/data-structures/hash/hash-map.d.ts +164 -338
  33. package/dist/data-structures/hash/hash-map.js +270 -457
  34. package/dist/data-structures/heap/heap.d.ts +214 -289
  35. package/dist/data-structures/heap/heap.js +340 -349
  36. package/dist/data-structures/heap/max-heap.d.ts +11 -47
  37. package/dist/data-structures/heap/max-heap.js +11 -66
  38. package/dist/data-structures/heap/min-heap.d.ts +12 -47
  39. package/dist/data-structures/heap/min-heap.js +11 -66
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  43. package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
  44. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  45. package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
  50. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
  51. package/dist/data-structures/priority-queue/priority-queue.js +8 -83
  52. package/dist/data-structures/queue/deque.d.ts +227 -254
  53. package/dist/data-structures/queue/deque.js +309 -348
  54. package/dist/data-structures/queue/queue.d.ts +180 -201
  55. package/dist/data-structures/queue/queue.js +265 -248
  56. package/dist/data-structures/stack/stack.d.ts +124 -102
  57. package/dist/data-structures/stack/stack.js +181 -125
  58. package/dist/data-structures/trie/trie.d.ts +164 -165
  59. package/dist/data-structures/trie/trie.js +189 -172
  60. package/dist/interfaces/binary-tree.d.ts +56 -6
  61. package/dist/interfaces/graph.d.ts +16 -0
  62. package/dist/types/data-structures/base/base.d.ts +1 -1
  63. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
  64. package/dist/types/utils/utils.d.ts +6 -6
  65. package/dist/utils/utils.d.ts +110 -49
  66. package/dist/utils/utils.js +148 -73
  67. package/package.json +2 -2
  68. package/src/data-structures/base/iterable-element-base.ts +238 -115
  69. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  70. package/src/data-structures/base/linear-base.ts +271 -277
  71. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  72. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  73. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  74. package/src/data-structures/binary-tree/binary-tree.ts +681 -905
  75. package/src/data-structures/binary-tree/bst.ts +568 -570
  76. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  77. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  78. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  79. package/src/data-structures/graph/abstract-graph.ts +339 -264
  80. package/src/data-structures/graph/directed-graph.ts +146 -236
  81. package/src/data-structures/graph/map-graph.ts +63 -60
  82. package/src/data-structures/graph/undirected-graph.ts +129 -152
  83. package/src/data-structures/hash/hash-map.ts +274 -496
  84. package/src/data-structures/heap/heap.ts +389 -402
  85. package/src/data-structures/heap/max-heap.ts +12 -76
  86. package/src/data-structures/heap/min-heap.ts +13 -76
  87. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  88. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  89. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  90. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  91. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  92. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  93. package/src/data-structures/queue/deque.ts +381 -357
  94. package/src/data-structures/queue/queue.ts +310 -264
  95. package/src/data-structures/stack/stack.ts +217 -131
  96. package/src/data-structures/trie/trie.ts +240 -175
  97. package/src/interfaces/binary-tree.ts +240 -6
  98. package/src/interfaces/graph.ts +37 -0
  99. package/src/types/data-structures/base/base.ts +5 -5
  100. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  101. package/src/types/utils/utils.ts +9 -5
  102. package/src/utils/utils.ts +152 -86
@@ -1,11 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IterableElementBase = void 0;
4
+ /**
5
+ * Base class that makes a data structure iterable and provides common
6
+ * element-wise utilities (e.g., map/filter/reduce/find).
7
+ *
8
+ * @template E The public element type yielded by the structure.
9
+ * @template R The underlying "raw" element type used internally or by converters.
10
+ *
11
+ * @remarks
12
+ * This class implements the JavaScript iteration protocol (via `Symbol.iterator`)
13
+ * and offers array-like helpers with predictable time/space complexity.
14
+ */
4
15
  class IterableElementBase {
5
16
  /**
6
- * The protected constructor initializes the options for the IterableElementBase class, including the
7
- * toElementFn function.
8
- * @param [options] - An optional object that contains the following properties:
17
+ * Create a new iterable base.
18
+ *
19
+ * @param options Optional behavior overrides. When provided, a `toElementFn`
20
+ * is used to convert a raw element (`R`) into a public element (`E`).
21
+ *
22
+ * @remarks
23
+ * Time O(1), Space O(1).
9
24
  */
10
25
  constructor(options) {
11
26
  if (options) {
@@ -16,183 +31,210 @@ class IterableElementBase {
16
31
  throw new TypeError('toElementFn must be a function type');
17
32
  }
18
33
  }
34
+ /**
35
+ * Exposes the current `toElementFn`, if configured.
36
+ *
37
+ * @returns The converter function or `undefined` when not set.
38
+ * @remarks
39
+ * Time O(1), Space O(1).
40
+ */
19
41
  get toElementFn() {
20
42
  return this._toElementFn;
21
43
  }
22
44
  /**
23
- * Time Complexity: O(n)
24
- * Space Complexity: O(1)
45
+ * Returns an iterator over the structure's elements.
25
46
  *
26
- * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
27
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
28
- * allows the function to accept any number of arguments as an array. In this case, the `args`
29
- * parameter is used to pass any number of arguments to the `_getIterator` method.
47
+ * @param args Optional iterator arguments forwarded to the internal iterator.
48
+ * @returns An `IterableIterator<E>` that yields the elements in traversal order.
49
+ *
50
+ * @remarks
51
+ * Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
30
52
  */
31
53
  *[Symbol.iterator](...args) {
32
54
  yield* this._getIterator(...args);
33
55
  }
34
56
  /**
35
- * Time Complexity: O(n)
36
- * Space Complexity: O(n)
57
+ * Returns an iterator over the values (alias of the default iterator).
37
58
  *
38
- * The function returns an iterator that yields all the values in the object.
59
+ * @returns An `IterableIterator<E>` over all elements.
60
+ * @remarks
61
+ * Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
39
62
  */
40
63
  *values() {
41
- for (const item of this) {
64
+ for (const item of this)
42
65
  yield item;
43
- }
44
66
  }
45
67
  /**
46
- * Time Complexity: O(n)
47
- * Space Complexity: O(1)
48
- *
49
- * The `every` function checks if every element in the array satisfies a given predicate.
50
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
51
- * the current element being processed, its index, and the array it belongs to. It should return a
52
- * boolean value indicating whether the element satisfies a certain condition or not.
53
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
54
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
55
- * passed as the `this` value to the `predicate` function. If `thisArg` is
56
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
57
- * the array satisfies the provided predicate function, and `false` otherwise.
68
+ * Tests whether all elements satisfy the predicate.
69
+ *
70
+ * @template TReturn
71
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
72
+ * @param thisArg Optional `this` binding for the predicate.
73
+ * @returns `true` if every element passes; otherwise `false`.
74
+ *
75
+ * @remarks
76
+ * Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
58
77
  */
59
78
  every(predicate, thisArg) {
60
79
  let index = 0;
61
80
  for (const item of this) {
62
- if (!predicate.call(thisArg, item, index++, this)) {
63
- return false;
81
+ if (thisArg === undefined) {
82
+ if (!predicate(item, index++, this))
83
+ return false;
84
+ }
85
+ else {
86
+ const fn = predicate;
87
+ if (!fn.call(thisArg, item, index++, this))
88
+ return false;
64
89
  }
65
90
  }
66
91
  return true;
67
92
  }
68
93
  /**
69
- * Time Complexity: O(n)
70
- * Space Complexity: O(1)
71
- *
72
- * The "some" function checks if at least one element in a collection satisfies a given predicate.
73
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
74
- * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
75
- * element satisfies the condition.
76
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
77
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
78
- * it will be passed as the `this` value to the `predicate` function. If `thisArg
79
- * @returns a boolean value. It returns true if the predicate function returns true for any element
80
- * in the collection, and false otherwise.
94
+ * Tests whether at least one element satisfies the predicate.
95
+ *
96
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
97
+ * @param thisArg Optional `this` binding for the predicate.
98
+ * @returns `true` if any element passes; otherwise `false`.
99
+ *
100
+ * @remarks
101
+ * Time O(n) in the worst case; may exit early on first success. Space O(1).
81
102
  */
82
103
  some(predicate, thisArg) {
83
104
  let index = 0;
84
105
  for (const item of this) {
85
- if (predicate.call(thisArg, item, index++, this)) {
86
- return true;
106
+ if (thisArg === undefined) {
107
+ if (predicate(item, index++, this))
108
+ return true;
109
+ }
110
+ else {
111
+ const fn = predicate;
112
+ if (fn.call(thisArg, item, index++, this))
113
+ return true;
87
114
  }
88
115
  }
89
116
  return false;
90
117
  }
91
118
  /**
92
- * Time Complexity: O(n)
93
- * Space Complexity: O(1)
94
- *
95
- * The `forEach` function iterates over each element in an array-like object and calls a callback
96
- * function for each element.
97
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
98
- * the array. It takes three arguments: the current element being processed, the index of the current
99
- * element, and the array that forEach was called upon.
100
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
101
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
102
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
119
+ * Invokes a callback for each element in iteration order.
120
+ *
121
+ * @param callbackfn Function invoked per element with signature `(value, index, self)`.
122
+ * @param thisArg Optional `this` binding for the callback.
123
+ * @returns `void`.
124
+ *
125
+ * @remarks
126
+ * Time O(n), Space O(1).
103
127
  */
104
128
  forEach(callbackfn, thisArg) {
105
129
  let index = 0;
106
130
  for (const item of this) {
107
- callbackfn.call(thisArg, item, index++, this);
131
+ if (thisArg === undefined) {
132
+ callbackfn(item, index++, this);
133
+ }
134
+ else {
135
+ const fn = callbackfn;
136
+ fn.call(thisArg, item, index++, this);
137
+ }
108
138
  }
109
139
  }
110
- /**
111
- * Time Complexity: O(n)
112
- * Space Complexity: O(1)
113
- *
114
- * The `find` function iterates over the elements of an array-like object and returns the first
115
- * element that satisfies the provided callback function.
116
- * @param predicate - The predicate parameter is a function that will be called for each element in
117
- * the array. It takes three arguments: the current element being processed, the index of the current
118
- * element, and the array itself. The function should return a boolean value indicating whether the
119
- * current element matches the desired condition.
120
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
121
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
122
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
123
- * @returns The `find` method returns the first element in the array that satisfies the provided
124
- * callback function. If no element satisfies the callback function, `undefined` is returned.
125
- */
140
+ // Implementation signature
126
141
  find(predicate, thisArg) {
127
142
  let index = 0;
128
143
  for (const item of this) {
129
- if (predicate.call(thisArg, item, index++, this))
130
- return item;
144
+ if (thisArg === undefined) {
145
+ if (predicate(item, index++, this))
146
+ return item;
147
+ }
148
+ else {
149
+ const fn = predicate;
150
+ if (fn.call(thisArg, item, index++, this))
151
+ return item;
152
+ }
131
153
  }
132
154
  return;
133
155
  }
134
156
  /**
135
- * Time Complexity: O(n)
136
- * Space Complexity: O(1)
137
- *
138
- * The function checks if a given element exists in a collection.
139
- * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
140
- * represents the element that we want to check for existence in the collection.
141
- * @returns a boolean value. It returns true if the element is found in the collection, and false
142
- * otherwise.
157
+ * Checks whether a strictly-equal element exists in the structure.
158
+ *
159
+ * @param element The element to test with `===` equality.
160
+ * @returns `true` if an equal element is found; otherwise `false`.
161
+ *
162
+ * @remarks
163
+ * Time O(n) in the worst case. Space O(1).
143
164
  */
144
165
  has(element) {
145
- for (const ele of this) {
166
+ for (const ele of this)
146
167
  if (ele === element)
147
168
  return true;
148
- }
149
169
  return false;
150
170
  }
151
171
  /**
152
- * Time Complexity: O(n)
153
- * Space Complexity: O(1)
154
- *
155
- * The `reduce` function iterates over the elements of an array-like object and applies a callback
156
- * function to reduce them into a single value.
157
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
158
- * the array. It takes four arguments:
159
- * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
160
- * is the value that the accumulator starts with before the reduction operation begins.
161
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
162
- * all the elements in the array and applying the callback function to each element.
172
+ * Reduces all elements to a single accumulated value.
173
+ *
174
+ * @overload
175
+ * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`. The first element is used as the initial accumulator.
176
+ * @returns The final accumulated value typed as `E`.
177
+ *
178
+ * @overload
179
+ * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`.
180
+ * @param initialValue The initial accumulator value of type `E`.
181
+ * @returns The final accumulated value typed as `E`.
182
+ *
183
+ * @overload
184
+ * @template U The accumulator type when it differs from `E`.
185
+ * @param callbackfn Reducer of signature `(acc: U, value, index, self) => U`.
186
+ * @param initialValue The initial accumulator value of type `U`.
187
+ * @returns The final accumulated value typed as `U`.
188
+ *
189
+ * @remarks
190
+ * Time O(n), Space O(1). Throws if called on an empty structure without `initialValue`.
163
191
  */
164
192
  reduce(callbackfn, initialValue) {
165
- let accumulator = initialValue !== null && initialValue !== void 0 ? initialValue : 0;
166
193
  let index = 0;
167
- for (const item of this) {
168
- accumulator = callbackfn(accumulator, item, index++, this);
194
+ const iter = this[Symbol.iterator]();
195
+ let acc;
196
+ if (arguments.length >= 2) {
197
+ acc = initialValue;
198
+ }
199
+ else {
200
+ const first = iter.next();
201
+ if (first.done)
202
+ throw new TypeError('Reduce of empty structure with no initial value');
203
+ acc = first.value;
204
+ index = 1;
205
+ }
206
+ for (const value of iter) {
207
+ acc = callbackfn(acc, value, index++, this);
169
208
  }
170
- return accumulator;
209
+ return acc;
171
210
  }
172
211
  /**
173
- * Time Complexity: O(n)
174
- * Space Complexity: O(n)
212
+ * Materializes the elements into a new array.
175
213
  *
176
- * The `toArray` function converts a linked list into an array.
177
- * @returns The `toArray()` method is returning an array of type `E[]`.
214
+ * @returns A shallow array copy of the iteration order.
215
+ * @remarks
216
+ * Time O(n), Space O(n).
178
217
  */
179
218
  toArray() {
180
219
  return [...this];
181
220
  }
182
221
  /**
183
- * Time Complexity: O(n)
184
- * Space Complexity: O(n)
222
+ * Returns a representation of the structure suitable for quick visualization.
223
+ * Defaults to an array of elements; subclasses may override to provide richer visuals.
185
224
  *
186
- * The print function logs the elements of an array to the console.
225
+ * @returns A visual representation (array by default).
226
+ * @remarks
227
+ * Time O(n), Space O(n).
187
228
  */
188
229
  toVisual() {
189
230
  return [...this];
190
231
  }
191
232
  /**
192
- * Time Complexity: O(n)
193
- * Space Complexity: O(n)
233
+ * Prints `toVisual()` to the console. Intended for quick debugging.
194
234
  *
195
- * The print function logs the elements of an array to the console.
235
+ * @returns `void`.
236
+ * @remarks
237
+ * Time O(n) due to materialization, Space O(n) for the intermediate representation.
196
238
  */
197
239
  print() {
198
240
  console.log(this.toVisual());
@@ -1,168 +1,144 @@
1
- import { EntryCallback, ReduceEntryCallback } from '../../types';
1
+ import type { EntryCallback, ReduceEntryCallback } from '../../types';
2
+ /**
3
+ * Iterable view over key-value entries.
4
+ * @template K - Key type.
5
+ * @template V - Value type.
6
+ * @remarks Time O(1), Space O(1)
7
+ */
2
8
  export declare abstract class IterableEntryBase<K = any, V = any> {
9
+ /**
10
+ * Total number of entries.
11
+ * @returns Entry count.
12
+ * @remarks Time O(1), Space O(1)
13
+ */
3
14
  abstract get size(): number;
4
15
  /**
5
- * Time Complexity: O(n)
6
- * Space Complexity: O(1)
7
- *
8
- * The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
9
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
10
- * allows the function to accept any number of arguments as an array. In this case, the `args`
11
- * parameter is used to pass any additional arguments to the `_getIterator` method.
16
+ * Default iterator yielding `[key, value]` entries.
17
+ * @returns Iterator of `[K, V]`.
18
+ * @remarks Time O(n) to iterate, Space O(1)
12
19
  */
13
20
  [Symbol.iterator](...args: any[]): IterableIterator<[K, V]>;
14
21
  /**
15
- * Time Complexity: O(n)
16
- * Space Complexity: O(n)
17
- *
18
- * The function returns an iterator that yields key-value pairs from the object, where the value can
19
- * be undefined.
22
+ * Iterate over `[key, value]` pairs (may yield `undefined` values).
23
+ * @returns Iterator of `[K, V | undefined]`.
24
+ * @remarks Time O(n), Space O(1)
20
25
  */
21
26
  entries(): IterableIterator<[K, V | undefined]>;
22
27
  /**
23
- * Time Complexity: O(n)
24
- * Space Complexity: O(n)
25
- *
26
- * The function returns an iterator that yields the keys of a data structure.
28
+ * Iterate over keys only.
29
+ * @returns Iterator of keys.
30
+ * @remarks Time O(n), Space O(1)
27
31
  */
28
32
  keys(): IterableIterator<K>;
29
33
  /**
30
- * Time Complexity: O(n)
31
- * Space Complexity: O(n)
32
- *
33
- * The function returns an iterator that yields the values of a collection.
34
+ * Iterate over values only.
35
+ * @returns Iterator of values.
36
+ * @remarks Time O(n), Space O(1)
34
37
  */
35
38
  values(): IterableIterator<V>;
36
39
  /**
37
- * Time Complexity: O(n)
38
- * Space Complexity: O(1)
39
- *
40
- * The `every` function checks if every element in a collection satisfies a given condition.
41
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
42
- * `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
43
- * met for the current element in the iteration.
44
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
45
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
46
- * passed as the first argument to the `predicate` function. If `thisArg` is not provided
47
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
48
- * the collection satisfies the provided predicate function, and `false` otherwise.
40
+ * Test whether all entries satisfy the predicate.
41
+ * @param predicate - `(key, value, index, self) => boolean`.
42
+ * @param thisArg - Optional `this` for callback.
43
+ * @returns `true` if all pass; otherwise `false`.
44
+ * @remarks Time O(n), Space O(1)
49
45
  */
50
46
  every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean;
51
47
  /**
52
- * Time Complexity: O(n)
53
- * Space Complexity: O(1)
54
- *
55
- * The "some" function iterates over a collection and returns true if at least one element satisfies
56
- * a given predicate.
57
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
58
- * `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
59
- * met for the current element in the iteration.
60
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
61
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
62
- * it will be passed as the first argument to the `predicate` function. If `thisArg` is
63
- * @returns a boolean value. It returns true if the predicate function returns true for any pair in
64
- * the collection, and false otherwise.
48
+ * Test whether any entry satisfies the predicate.
49
+ * @param predicate - `(key, value, index, self) => boolean`.
50
+ * @param thisArg - Optional `this` for callback.
51
+ * @returns `true` if any passes; otherwise `false`.
52
+ * @remarks Time O(n), Space O(1)
65
53
  */
66
54
  some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean;
67
55
  /**
68
- * Time Complexity: O(n)
69
- * Space Complexity: O(1)
70
- *
71
- * The `forEach` function iterates over each key-value pair in a collection and executes a callback
72
- * function for each pair.
73
- * @param callbackfn - The callback function that will be called for each element in the collection.
74
- * It takes four parameters: the value of the current element, the key of the current element, the
75
- * index of the current element, and the collection itself.
76
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
77
- * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
78
- * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
56
+ * Visit each entry, left-to-right.
57
+ * @param callbackfn - `(key, value, index, self) => void`.
58
+ * @param thisArg - Optional `this` for callback.
59
+ * @remarks Time O(n), Space O(1)
79
60
  */
80
61
  forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: any): void;
81
62
  /**
82
- * Time Complexity: O(n)
83
- * Space Complexity: O(1)
84
- *
85
- * The `find` function iterates over the entries of a collection and returns the first value for
86
- * which the callback function returns true.
87
- * @param callbackfn - The callback function that will be called for each entry in the collection. It
88
- * takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
89
- * the collection. It should return a boolean value indicating whether the current entry matches the
90
- * desired condition.
91
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
92
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
93
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
94
- * @returns The method `find` returns the value of the first element in the iterable that satisfies
95
- * the provided callback function. If no element satisfies the callback function, `undefined` is
96
- * returned.
63
+ * Find the first entry that matches a predicate.
64
+ * @param callbackfn - `(key, value, index, self) => boolean`.
65
+ * @param thisArg - Optional `this` for callback.
66
+ * @returns Matching `[key, value]` or `undefined`.
67
+ * @remarks Time O(n), Space O(1)
97
68
  */
98
69
  find(callbackfn: EntryCallback<K, V, boolean>, thisArg?: any): [K, V] | undefined;
99
70
  /**
100
- * Time Complexity: O(n)
101
- * Space Complexity: O(1)
102
- *
103
- * The function checks if a given key exists in a collection.
104
- * @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
105
- * the key that we want to check for existence in the data structure.
106
- * @returns a boolean value. It returns true if the key is found in the collection, and false
107
- * otherwise.
71
+ * Whether the given key exists.
72
+ * @param key - Key to test.
73
+ * @returns `true` if found; otherwise `false`.
74
+ * @remarks Time O(n) generic, Space O(1)
108
75
  */
109
76
  has(key: K): boolean;
110
77
  /**
111
- * Time Complexity: O(n)
112
- * Space Complexity: O(1)
113
- *
114
- * The function checks if a given value exists in a collection.
115
- * @param {V} value - The parameter "value" is the value that we want to check if it exists in the
116
- * collection.
117
- * @returns a boolean value, either true or false.
78
+ * Whether there exists an entry with the given value.
79
+ * @param value - Value to test.
80
+ * @returns `true` if found; otherwise `false`.
81
+ * @remarks Time O(n), Space O(1)
118
82
  */
119
83
  hasValue(value: V): boolean;
120
84
  /**
121
- * Time Complexity: O(n)
122
- * Space Complexity: O(1)
123
- *
124
- * The `get` function retrieves the value associated with a given key from a collection.
125
- * @param {K} key - K (the type of the key) - This parameter represents the key that is being
126
- * searched for in the collection.
127
- * @returns The `get` method returns the value associated with the specified key if it exists in the
128
- * collection, otherwise it returns `undefined`.
85
+ * Get the value under a key.
86
+ * @param key - Key to look up.
87
+ * @returns Value or `undefined`.
88
+ * @remarks Time O(n) generic, Space O(1)
129
89
  */
130
90
  get(key: K): V | undefined;
131
91
  /**
132
- * Time Complexity: O(n)
133
- * Space Complexity: O(1)
134
- *
135
- * The `reduce` function iterates over key-value pairs and applies a callback function to each pair,
136
- * accumulating a single value.
137
- * @param callbackfn - The callback function that will be called for each element in the collection.
138
- * It takes four arguments: the current accumulator value, the current value of the element, the key
139
- * of the element, and the index of the element in the collection. It should return the updated
140
- * accumulator value.
141
- * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
142
- * is the value that will be used as the first argument to the `callbackfn` function when reducing
143
- * the elements of the collection.
144
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
145
- * all the elements in the collection.
92
+ * Reduce entries into a single accumulator.
93
+ * @param callbackfn - `(acc, value, key, index, self) => acc`.
94
+ * @param initialValue - Initial accumulator.
95
+ * @returns Final accumulator.
96
+ * @remarks Time O(n), Space O(1)
146
97
  */
147
98
  reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
148
99
  /**
149
- * Time Complexity: O(n)
150
- * Space Complexity: O(n)
151
- *
152
- * The print function logs the elements of an array to the console.
100
+ * Visualize the iterable as an array of `[key, value]` pairs (or a custom string).
101
+ * @returns Array of entries (default) or a string.
102
+ * @remarks Time O(n), Space O(n)
153
103
  */
154
104
  toVisual(): [K, V][] | string;
155
105
  /**
156
- * Time Complexity: O(n)
157
- * Space Complexity: O(n)
158
- *
159
- * The print function logs the elements of an array to the console.
106
+ * Print a human-friendly representation to the console.
107
+ * @remarks Time O(n), Space O(n)
160
108
  */
161
109
  print(): void;
110
+ /**
111
+ * Whether there are no entries.
112
+ * @returns `true` if empty; `false` otherwise.
113
+ * @remarks Time O(1) typical, Space O(1)
114
+ */
162
115
  abstract isEmpty(): boolean;
116
+ /**
117
+ * Remove all entries.
118
+ * @remarks Time O(n) typical, Space O(1)
119
+ */
163
120
  abstract clear(): void;
164
- abstract clone(): any;
121
+ /**
122
+ * Deep clone preserving the concrete subtype.
123
+ * @returns A new instance of the same concrete class (`this` type).
124
+ * @remarks Time O(n) typical, Space O(n)
125
+ */
126
+ abstract clone(): this;
127
+ /**
128
+ * Map entries using an implementation-specific strategy.
129
+ * @remarks Time O(n), Space O(n)
130
+ */
165
131
  abstract map(...args: any[]): any;
166
- abstract filter(...args: any[]): any;
132
+ /**
133
+ * Filter entries and return the same-species structure.
134
+ * @returns A new instance of the same concrete class (`this` type).
135
+ * @remarks Time O(n), Space O(n)
136
+ */
137
+ abstract filter(...args: any[]): this;
138
+ /**
139
+ * Underlying iterator for the default iteration protocol.
140
+ * @returns Iterator of `[K, V]`.
141
+ * @remarks Time O(n), Space O(1)
142
+ */
167
143
  protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
168
144
  }