min-heap-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 (101) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
  2. package/dist/data-structures/base/iterable-element-base.js +149 -107
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
  4. package/dist/data-structures/base/iterable-entry-base.js +59 -116
  5. package/dist/data-structures/base/linear-base.d.ts +250 -192
  6. package/dist/data-structures/base/linear-base.js +137 -274
  7. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  8. package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
  9. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  10. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  11. package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
  12. package/dist/data-structures/binary-tree/avl-tree.js +208 -195
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
  14. package/dist/data-structures/binary-tree/binary-tree.js +612 -879
  15. package/dist/data-structures/binary-tree/bst.d.ts +258 -306
  16. package/dist/data-structures/binary-tree/bst.js +505 -481
  17. package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  18. package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
  19. package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
  20. package/dist/data-structures/binary-tree/tree-counter.js +172 -203
  21. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  22. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
  23. package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
  24. package/dist/data-structures/graph/abstract-graph.js +267 -237
  25. package/dist/data-structures/graph/directed-graph.d.ts +108 -224
  26. package/dist/data-structures/graph/directed-graph.js +146 -233
  27. package/dist/data-structures/graph/map-graph.d.ts +49 -55
  28. package/dist/data-structures/graph/map-graph.js +56 -59
  29. package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
  30. package/dist/data-structures/graph/undirected-graph.js +129 -149
  31. package/dist/data-structures/hash/hash-map.d.ts +164 -338
  32. package/dist/data-structures/hash/hash-map.js +270 -457
  33. package/dist/data-structures/heap/heap.d.ts +214 -289
  34. package/dist/data-structures/heap/heap.js +340 -349
  35. package/dist/data-structures/heap/max-heap.d.ts +11 -47
  36. package/dist/data-structures/heap/max-heap.js +11 -66
  37. package/dist/data-structures/heap/min-heap.d.ts +12 -47
  38. package/dist/data-structures/heap/min-heap.js +11 -66
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  42. package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
  43. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  44. package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
  45. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  46. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
  47. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  48. package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
  49. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
  50. package/dist/data-structures/priority-queue/priority-queue.js +8 -83
  51. package/dist/data-structures/queue/deque.d.ts +227 -254
  52. package/dist/data-structures/queue/deque.js +309 -348
  53. package/dist/data-structures/queue/queue.d.ts +180 -201
  54. package/dist/data-structures/queue/queue.js +265 -248
  55. package/dist/data-structures/stack/stack.d.ts +124 -102
  56. package/dist/data-structures/stack/stack.js +181 -125
  57. package/dist/data-structures/trie/trie.d.ts +164 -165
  58. package/dist/data-structures/trie/trie.js +189 -172
  59. package/dist/interfaces/binary-tree.d.ts +56 -6
  60. package/dist/interfaces/graph.d.ts +16 -0
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
  63. package/dist/types/utils/utils.d.ts +6 -6
  64. package/dist/utils/utils.d.ts +110 -49
  65. package/dist/utils/utils.js +148 -73
  66. package/package.json +2 -2
  67. package/src/data-structures/base/iterable-element-base.ts +238 -115
  68. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  69. package/src/data-structures/base/linear-base.ts +271 -277
  70. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  71. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  72. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  73. package/src/data-structures/binary-tree/binary-tree.ts +681 -905
  74. package/src/data-structures/binary-tree/bst.ts +568 -570
  75. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  76. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  77. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  78. package/src/data-structures/graph/abstract-graph.ts +339 -264
  79. package/src/data-structures/graph/directed-graph.ts +146 -236
  80. package/src/data-structures/graph/map-graph.ts +63 -60
  81. package/src/data-structures/graph/undirected-graph.ts +129 -152
  82. package/src/data-structures/hash/hash-map.ts +274 -496
  83. package/src/data-structures/heap/heap.ts +389 -402
  84. package/src/data-structures/heap/max-heap.ts +12 -76
  85. package/src/data-structures/heap/min-heap.ts +13 -76
  86. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  87. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  88. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  89. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  90. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  91. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  92. package/src/data-structures/queue/deque.ts +381 -357
  93. package/src/data-structures/queue/queue.ts +310 -264
  94. package/src/data-structures/stack/stack.ts +217 -131
  95. package/src/data-structures/trie/trie.ts +240 -175
  96. package/src/interfaces/binary-tree.ts +240 -6
  97. package/src/interfaces/graph.ts +37 -0
  98. package/src/types/data-structures/base/base.ts +5 -5
  99. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  100. package/src/types/utils/utils.ts +9 -5
  101. package/src/utils/utils.ts +152 -86
@@ -1,12 +1,18 @@
1
1
  /**
2
- * @license MIT
3
- * @copyright Pablo Zeng <zrwusa@gmail.com>
4
- * @class
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
5
7
  */
6
- import type { ElementCallback, QueueOptions } from '../../types';
8
+ import type { ElementCallback, LinearBaseOptions, QueueOptions } from '../../types';
7
9
  import { SinglyLinkedList } from '../linked-list';
8
10
  import { LinearBase } from '../base/linear-base';
9
11
  /**
12
+ * Array-backed queue with amortized O(1) enqueue/dequeue via an offset pointer and optional auto-compaction.
13
+ * @remarks Time O(1), Space O(1)
14
+ * @template E
15
+ * @template R
10
16
  * 1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
11
17
  * 2. Operations: The main operations include enqueue (adding an element to the end of the queue) and dequeue (removing and returning the element at the front of the queue). Typically, there is also a peek operation (looking at the front element without removing it).
12
18
  * 3. Uses: Queues are commonly used to manage a series of tasks or elements that need to be processed in order. For example, managing task queues in a multi-threaded environment, or in algorithms for data structures like trees and graphs for breadth-first search.
@@ -23,7 +29,7 @@ import { LinearBase } from '../base/linear-base';
23
29
  * let maxSum = 0;
24
30
  * let currentSum = 0;
25
31
  *
26
- * nums.forEach((num) => {
32
+ * nums.forEach(num => {
27
33
  * queue.push(num);
28
34
  * currentSum += num;
29
35
  *
@@ -63,267 +69,240 @@ import { LinearBase } from '../base/linear-base';
63
69
  * console.log(visited); // [1, 2, 3, 4, 5]
64
70
  */
65
71
  export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
72
+ /**
73
+ * Create a Queue and optionally bulk-insert elements.
74
+ * @remarks Time O(N), Space O(N)
75
+ * @param [elements] - Iterable of elements (or raw records if toElementFn is set).
76
+ * @param [options] - Options such as toElementFn, maxLen, and autoCompactRatio.
77
+ * @returns New Queue instance.
78
+ */
66
79
  constructor(elements?: Iterable<E> | Iterable<R>, options?: QueueOptions<E, R>);
67
80
  protected _elements: E[];
81
+ /**
82
+ * Get the underlying array buffer.
83
+ * @remarks Time O(1), Space O(1)
84
+ * @returns Backing array of elements.
85
+ */
68
86
  get elements(): E[];
69
87
  protected _offset: number;
88
+ /**
89
+ * Get the current start offset into the array.
90
+ * @remarks Time O(1), Space O(1)
91
+ * @returns Zero-based offset.
92
+ */
70
93
  get offset(): number;
71
- get length(): number;
72
94
  protected _autoCompactRatio: number;
95
+ /**
96
+ * Get the compaction threshold (offset/size).
97
+ * @remarks Time O(1), Space O(1)
98
+ * @returns Auto-compaction ratio in (0,1].
99
+ */
73
100
  get autoCompactRatio(): number;
74
- set autoCompactRatio(v: number);
75
101
  /**
76
- * Time Complexity: O(1)
77
- * Space Complexity: O(1)
78
- *
79
- * The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
80
- * @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
81
- * the `_offset` index. If the data structure is empty (length is 0), it returns `undefined`.
102
+ * Set the compaction threshold.
103
+ * @remarks Time O(1), Space O(1)
104
+ * @param value - New ratio; compacts when offset/size exceeds this value.
105
+ * @returns void
106
+ */
107
+ set autoCompactRatio(value: number);
108
+ /**
109
+ * Get the number of elements currently in the queue.
110
+ * @remarks Time O(1), Space O(1)
111
+ * @returns Current length.
112
+ */
113
+ get length(): number;
114
+ /**
115
+ * Get the first element (front) without removing it.
116
+ * @remarks Time O(1), Space O(1)
117
+ * @returns Front element or undefined.
82
118
  */
83
119
  get first(): E | undefined;
84
120
  /**
85
- * Time Complexity: O(1)
86
- * Space Complexity: O(1)
87
- *
88
- * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
89
- * @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
90
- * array is empty, it returns `undefined`.
121
+ * Get the last element (back) without removing it.
122
+ * @remarks Time O(1), Space O(1)
123
+ * @returns Back element or undefined.
91
124
  */
92
125
  get last(): E | undefined;
93
126
  /**
94
- * Time Complexity: O(n)
95
- * Space Complexity: O(n)
96
- *
97
- * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
98
- * @public
99
- * @param {E[]} elements - The "elements" parameter is an array of elements of type E.
100
- * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
101
- * array.
127
+ * Create a queue from an array of elements.
128
+ * @remarks Time O(N), Space O(N)
129
+ * @template E
130
+ * @param elements - Array of elements to enqueue in order.
131
+ * @returns A new queue populated from the array.
102
132
  */
103
133
  static fromArray<E>(elements: E[]): Queue<E>;
104
134
  /**
105
- * Time Complexity: O(1)
106
- * Space Complexity: O(1)
107
- *
108
- * The push function adds an element to the end of the queue and returns true. Adds an element at the back of the queue.
109
- * @param {E} element - The `element` parameter represents the element that you want to add to the queue.
110
- * @returns Always returns true, indicating the element was successfully added.
135
+ * Check whether the queue is empty.
136
+ * @remarks Time O(1), Space O(1)
137
+ * @returns True if length is 0.
138
+ */
139
+ isEmpty(): boolean;
140
+ /**
141
+ * Enqueue one element at the back.
142
+ * @remarks Time O(1), Space O(1)
143
+ * @param element - Element to enqueue.
144
+ * @returns True on success.
111
145
  */
112
146
  push(element: E): boolean;
113
147
  /**
114
- * Time Complexity: O(k)
115
- * Space Complexity: O(k)
116
- *
117
- * The `pushMany` function iterates over elements and pushes them into an array after applying a
118
- * transformation function if provided.
119
- * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
120
- * is an iterable containing elements of type `E` or `R`.
121
- * @returns The `pushMany` function is returning an array of boolean values indicating whether each
122
- * element was successfully pushed into the data structure.
148
+ * Enqueue many elements from an iterable.
149
+ * @remarks Time O(N), Space O(1)
150
+ * @param elements - Iterable of elements (or raw records if toElementFn is set).
151
+ * @returns Array of per-element success flags.
123
152
  */
124
153
  pushMany(elements: Iterable<E> | Iterable<R>): boolean[];
125
154
  /**
126
- * Time Complexity: O(1)
127
- * Space Complexity: O(1)
128
- *
129
- * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
130
- * necessary to optimize performance.
131
- * @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
155
+ * Dequeue one element from the front (amortized via offset).
156
+ * @remarks Time O(1) amortized, Space O(1)
157
+ * @returns Removed element or undefined.
132
158
  */
133
159
  shift(): E | undefined;
134
160
  /**
135
- * Time Complexity: O(n)
136
- * Space Complexity: O(1)
137
- *
138
- * The delete function removes an element from the list.
139
- * @param {E} element - Specify the element to be deleted
140
- * @return A boolean value indicating whether the element was successfully deleted or not
161
+ * Delete the first occurrence of a specific element.
162
+ * @remarks Time O(N), Space O(1)
163
+ * @param element - Element to remove (strict equality via Object.is).
164
+ * @returns True if an element was removed.
141
165
  */
142
166
  delete(element: E): boolean;
143
167
  /**
144
- * Time Complexity: O(n)
145
- * Space Complexity: O(1)
146
- *
147
- * The deleteAt function deletes the element at a given index.
148
- * @param {number} index - Determine the index of the element to be deleted
149
- * @return A boolean value
150
- */
151
- deleteAt(index: number): E | undefined;
152
- /**
153
- * Time Complexity: O(1)
154
- * Space Complexity: O(1)
155
- *
156
- * The `at` function returns the element at a specified index adjusted by an offset, or `undefined`
157
- * if the index is out of bounds.
158
- * @param {number} index - The `index` parameter represents the position of the element you want to
159
- * retrieve from the data structure.
160
- * @returns The `at` method is returning the element at the specified index adjusted by the offset
161
- * `_offset`.
168
+ * Get the element at a given logical index.
169
+ * @remarks Time O(1), Space O(1)
170
+ * @param index - Zero-based index from the front.
171
+ * @returns Element or undefined.
162
172
  */
163
173
  at(index: number): E | undefined;
164
174
  /**
165
- * Time Complexity: O(n)
166
- * Space Complexity: O(1)
167
- *
168
- * The `reverse` function in TypeScript reverses the elements of an array starting from a specified
169
- * offset.
170
- * @returns The `reverse()` method is returning the modified object itself (`this`) after reversing
171
- * the elements in the array and resetting the offset to 0.
175
+ * Delete the element at a given index.
176
+ * @remarks Time O(N), Space O(1)
177
+ * @param index - Zero-based index from the front.
178
+ * @returns Removed element or undefined.
172
179
  */
173
- reverse(): this;
180
+ deleteAt(index: number): E | undefined;
174
181
  /**
175
- * Time Complexity: O(n)
176
- * Space Complexity: O(1)
177
- *
178
- * The function `addAt` inserts a new element at a specified index in an array, returning true if
179
- * successful and false if the index is out of bounds.
180
- * @param {number} index - The `index` parameter represents the position at which the `newElement`
181
- * should be added in the array.
182
- * @param {E} newElement - The `newElement` parameter represents the element that you want to insert
183
- * into the array at the specified index.
184
- * @returns The `addAt` method returns a boolean value - `true` if the new element was successfully
185
- * added at the specified index, and `false` if the index is out of bounds (less than 0 or greater
186
- * than the length of the array).
182
+ * Insert a new element at a given index.
183
+ * @remarks Time O(N), Space O(1)
184
+ * @param index - Zero-based index from the front.
185
+ * @param newElement - Element to insert.
186
+ * @returns True if inserted.
187
187
  */
188
188
  addAt(index: number, newElement: E): boolean;
189
189
  /**
190
- * Time Complexity: O(1)
191
- * Space Complexity: O(1)
192
- *
193
- * The function `setAt` updates an element at a specified index in an array-like data structure.
194
- * @param {number} index - The `index` parameter is a number that represents the position in the
195
- * array where the new element will be set.
196
- * @param {E} newElement - The `newElement` parameter represents the new value that you want to set
197
- * at the specified index in the array.
198
- * @returns The `setAt` method returns a boolean value - `true` if the element was successfully set
199
- * at the specified index, and `false` if the index is out of bounds (less than 0 or greater than the
200
- * length of the array).
190
+ * Replace the element at a given index.
191
+ * @remarks Time O(1), Space O(1)
192
+ * @param index - Zero-based index from the front.
193
+ * @param newElement - New element to set.
194
+ * @returns True if updated.
201
195
  */
202
196
  setAt(index: number, newElement: E): boolean;
203
197
  /**
204
- * Time Complexity: O(1)
205
- * Space Complexity: O(1)
206
- *
207
- * The function checks if a data structure is empty by comparing its length to zero.
208
- * @returns {boolean} A boolean value indicating whether the length of the object is 0 or not.
198
+ * Reverse the queue in-place by compacting then reversing.
199
+ * @remarks Time O(N), Space O(N)
200
+ * @returns This queue.
209
201
  */
210
- isEmpty(): boolean;
202
+ reverse(): this;
211
203
  /**
212
- * Time Complexity: O(1)
213
- * Space Complexity: O(1)
214
- *
215
- * The clear function resets the elements array and offset to their initial values.
204
+ * Remove all elements and reset offset.
205
+ * @remarks Time O(1), Space O(1)
206
+ * @returns void
216
207
  */
217
208
  clear(): void;
218
209
  /**
219
- * Time Complexity: O(n)
220
- * Space Complexity: O(1)
221
- *
222
- * The `compact` function in TypeScript slices the elements array based on the offset and resets the
223
- * offset to zero.
224
- * @returns The `compact()` method is returning a boolean value of `true`.
210
+ * Compact storage by discarding consumed head elements.
211
+ * @remarks Time O(N), Space O(N)
212
+ * @returns True when compaction performed.
225
213
  */
226
214
  compact(): boolean;
227
215
  /**
228
- * Time Complexity: O(n)
229
- * Space Complexity: O(n)
230
- *
231
- * The function overrides the splice method to remove and insert elements in a queue-like data
232
- * structure.
233
- * @param {number} start - The `start` parameter in the `splice` method specifies the index at which
234
- * to start changing the array. Items will be added or removed starting from this index.
235
- * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
236
- * number of elements to remove from the array starting at the specified `start` index. If
237
- * `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
238
- * elements can still be inserted at
239
- * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
240
- * will be added to the array at the specified `start` index. These elements will replace the
241
- * existing elements starting from the `start` index for the `deleteCount` number of elements.
242
- * @returns The `splice` method is returning the `removedQueue`, which is an instance of the same
243
- * class as the original object.
216
+ * Remove and/or insert elements at a position (array-like).
217
+ * @remarks Time O(N + M), Space O(M)
218
+ * @param start - Start index (clamped to [0, length]).
219
+ * @param [deleteCount] - Number of elements to remove (default 0).
220
+ * @param [items] - Elements to insert after `start`.
221
+ * @returns A new queue containing the removed elements (typed as `this`).
244
222
  */
245
223
  splice(start: number, deleteCount?: number, ...items: E[]): this;
246
224
  /**
247
- * Time Complexity: O(n)
248
- * Space Complexity: O(n)
249
- *
250
- * The `clone()` function returns a new Queue object with the same elements as the original Queue.
251
- * @returns The `clone()` method is returning a new instance of the `Queue` class.
225
+ * Deep clone this queue and its parameters.
226
+ * @remarks Time O(N), Space O(N)
227
+ * @returns A new queue with the same content and options.
252
228
  */
253
229
  clone(): this;
254
230
  /**
255
- * Time Complexity: O(n)
256
- * Space Complexity: O(n)
257
- *
258
- * The `filter` function creates a new `Queue` object containing elements from the original `Queue`
259
- * that satisfy a given predicate function.
260
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
261
- * the current element being iterated over, the index of the current element, and the queue itself.
262
- * It should return a boolean value indicating whether the element should be included in the filtered
263
- * queue or not.
264
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
265
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
266
- * passed as the `this` value to the `predicate` function. If `thisArg` is
267
- * @returns The `filter` method is returning a new `Queue` object that contains the elements that
268
- * satisfy the given predicate function.
269
- */
270
- filter(predicate: ElementCallback<E, R, boolean>, thisArg?: any): Queue<E, R>;
271
- /**
272
- * Time Complexity: O(n)
273
- * Space Complexity: O(n)
274
- *
275
- * The `map` function in TypeScript creates a new Queue by applying a callback function to each
276
- * element in the original Queue.
277
- * @param callback - The `callback` parameter is a function that will be applied to each element in
278
- * the queue. It takes the current element, its index, and the queue itself as arguments, and returns
279
- * a new element.
280
- * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be provided to
281
- * convert a raw element of type `RM` to a new element of type `EM`. This function is used within the
282
- * `map` method to transform each raw element before passing it to the `callback` function. If
283
- * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is used to specify the
284
- * value of `this` when executing the `callback` function. It allows you to set the context (the
285
- * value of `this`) within the callback function. If `thisArg` is provided, it will be
286
- * @returns A new Queue object containing elements of type EM, which are the result of applying the
287
- * callback function to each element in the original Queue object.
288
- */
289
- map<EM, RM>(callback: ElementCallback<E, R, EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): Queue<EM, RM>;
290
- /**
291
- * Time Complexity: O(n)
292
- * Space Complexity: O(n)
293
- *
294
- * The function `_getIterator` returns an iterable iterator for the elements in the class.
231
+ * Filter elements into a new queue of the same class.
232
+ * @remarks Time O(N), Space O(N)
233
+ * @param predicate - Predicate (element, index, queue) → boolean to keep element.
234
+ * @param [thisArg] - Value for `this` inside the predicate.
235
+ * @returns A new queue with kept elements.
295
236
  */
296
- protected _getIterator(): IterableIterator<E>;
237
+ filter(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): this;
238
+ /**
239
+ * Map each element to a new element in a possibly different-typed queue.
240
+ * @remarks Time O(N), Space O(N)
241
+ * @template EM
242
+ * @template RM
243
+ * @param callback - Mapping function (element, index, queue) → newElement.
244
+ * @param [options] - Options for the output queue (e.g., toElementFn, maxLen, autoCompactRatio).
245
+ * @param [thisArg] - Value for `this` inside the callback.
246
+ * @returns A new Queue with mapped elements.
247
+ */
248
+ map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: QueueOptions<EM, RM>, thisArg?: unknown): Queue<EM, RM>;
297
249
  /**
298
- * The function `_createInstance` returns a new instance of the `Queue` class with the specified
299
- * options.
300
- * @param [options] - The `options` parameter in the `_createInstance` method is of type
301
- * `QueueOptions<E, R>`, which is used to configure the behavior of the queue being created. It
302
- * allows you to specify settings or properties that can influence how the queue operates.
303
- * @returns An instance of the `Queue` class with an empty array and the provided options is being
304
- * returned.
250
+ * Map each element to a new value of the same type.
251
+ * @remarks Time O(N), Space O(N)
252
+ * @param callback - Mapping function (element, index, queue) element.
253
+ * @param [thisArg] - Value for `this` inside the callback.
254
+ * @returns A new queue with mapped elements (same element type).
305
255
  */
306
- protected _createInstance(options?: QueueOptions<E, R>): this;
256
+ mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this;
307
257
  /**
308
- * The function `_getReverseIterator` returns an iterator that iterates over elements in reverse
309
- * order.
258
+ * (Protected) Set the internal auto-compaction ratio.
259
+ * @remarks Time O(1), Space O(1)
260
+ * @param value - New ratio to assign.
261
+ * @returns void
262
+ */
263
+ protected _setAutoCompactRatio(value: number): void;
264
+ /**
265
+ * (Protected) Iterate elements from front to back.
266
+ * @remarks Time O(N), Space O(1)
267
+ * @returns Iterator of E.
268
+ */
269
+ protected _getIterator(): IterableIterator<E>;
270
+ /**
271
+ * (Protected) Iterate elements from back to front.
272
+ * @remarks Time O(N), Space O(1)
273
+ * @returns Iterator of E.
310
274
  */
311
275
  protected _getReverseIterator(): IterableIterator<E>;
276
+ /**
277
+ * (Protected) Create an empty instance of the same concrete class.
278
+ * @remarks Time O(1), Space O(1)
279
+ * @param [options] - Options forwarded to the constructor.
280
+ * @returns An empty like-kind queue instance.
281
+ */
282
+ protected _createInstance(options?: LinearBaseOptions<E, R>): this;
283
+ /**
284
+ * (Protected) Create a like-kind queue and seed it from an iterable.
285
+ * @remarks Time O(N), Space O(N)
286
+ * @template EM
287
+ * @template RM
288
+ * @param [elements] - Iterable used to seed the new queue.
289
+ * @param [options] - Options forwarded to the constructor.
290
+ * @returns A like-kind Queue instance.
291
+ */
292
+ protected _createLike<EM = E, RM = R>(elements?: Iterable<EM> | Iterable<RM>, options?: QueueOptions<EM, RM>): Queue<EM, RM>;
312
293
  }
313
294
  /**
314
- * 1. First In, First Out (FIFO) Strategy: Like other queue implementations, LinkedListQueue follows the first in, first out principle, meaning the element that is added to the queue first will be the first to be removed.
315
- * 2. Based on Linked List: LinkedListQueue uses a linked list to store elements. Each node in the linked list contains data and a pointer to the next node.
316
- * 3. Memory Usage: Since each element requires additional space to store a pointer to the next element, linked lists may use more memory compared to arrays.
317
- * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
295
+ * Queue implemented over a singly linked list; preserves head/tail operations with linear scans for queries.
296
+ * @remarks Time O(1), Space O(1)
297
+ * @template E
298
+ * @template R
299
+ * @example examples will be generated by unit test
318
300
  */
319
301
  export declare class LinkedListQueue<E = any, R = any> extends SinglyLinkedList<E, R> {
320
302
  /**
321
- * Time Complexity: O(n)
322
- * Space Complexity: O(n)
323
- * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
324
- * the current instance.
325
- * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
326
- * values as the original `LinkedListQueue`.
303
+ * Deep clone this linked-list-based queue.
304
+ * @remarks Time O(N), Space O(N)
305
+ * @returns A new queue with the same sequence of elements.
327
306
  */
328
307
  clone(): this;
329
308
  }