min-heap-typed 2.0.5 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/data-structures/base/iterable-element-base.js +149 -107
- package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/data-structures/base/linear-base.d.ts +250 -192
- package/dist/data-structures/base/linear-base.js +137 -274
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/data-structures/binary-tree/binary-tree.js +602 -873
- package/dist/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/data-structures/binary-tree/bst.js +505 -481
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/data-structures/graph/abstract-graph.js +267 -237
- package/dist/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/data-structures/graph/directed-graph.js +146 -233
- package/dist/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/data-structures/graph/map-graph.js +56 -59
- package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/data-structures/graph/undirected-graph.js +129 -149
- package/dist/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/data-structures/hash/hash-map.js +270 -457
- package/dist/data-structures/heap/heap.d.ts +214 -289
- package/dist/data-structures/heap/heap.js +340 -349
- package/dist/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/data-structures/heap/max-heap.js +11 -66
- package/dist/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/data-structures/heap/min-heap.js +11 -66
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/data-structures/queue/deque.d.ts +227 -254
- package/dist/data-structures/queue/deque.js +309 -348
- package/dist/data-structures/queue/queue.d.ts +180 -201
- package/dist/data-structures/queue/queue.js +265 -248
- package/dist/data-structures/stack/stack.d.ts +124 -102
- package/dist/data-structures/stack/stack.js +181 -125
- package/dist/data-structures/trie/trie.d.ts +164 -165
- package/dist/data-structures/trie/trie.js +189 -172
- package/dist/interfaces/binary-tree.d.ts +56 -6
- package/dist/interfaces/graph.d.ts +16 -0
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +2 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
- package/src/data-structures/binary-tree/avl-tree.ts +237 -206
- package/src/data-structures/binary-tree/binary-tree.ts +665 -896
- package/src/data-structures/binary-tree/bst.ts +565 -572
- package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
- package/src/data-structures/binary-tree/tree-counter.ts +195 -219
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { DequeOptions, ElementCallback, IterableWithSizeOrLength } from '../../types';
|
|
8
|
+
import type { DequeOptions, ElementCallback, IterableElementBaseOptions, IterableWithSizeOrLength, LinearBaseOptions } from '../../types';
|
|
9
9
|
import { LinearBase } from '../base/linear-base';
|
|
10
10
|
/**
|
|
11
|
+
* Deque implemented with circular buckets allowing O(1) amortized push/pop at both ends.
|
|
12
|
+
* @remarks Time O(1), Space O(1)
|
|
13
|
+
* @template E
|
|
14
|
+
* @template R
|
|
11
15
|
* 1. Operations at Both Ends: Supports adding and removing elements at both the front and back of the queue. This allows it to be used as a stack (last in, first out) and a queue (first in, first out).
|
|
12
16
|
* 2. Efficient Random Access: Being based on an array, it offers fast random access capability, allowing constant time access to any element.
|
|
13
17
|
* 3. Continuous Memory Allocation: Since it is based on an array, all elements are stored contiguously in memory, which can bring cache friendliness and efficient memory access.
|
|
@@ -103,356 +107,325 @@ import { LinearBase } from '../base/linear-base';
|
|
|
103
107
|
* console.log(maxSlidingWindow(nums, k)); // [3, 3, 5, 5, 6, 7]
|
|
104
108
|
*/
|
|
105
109
|
export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
110
|
+
protected _equals: (a: E, b: E) => boolean;
|
|
106
111
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @
|
|
109
|
-
* elements
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @param {DequeOptions} [options] - The `options` parameter is an optional object that can contain
|
|
113
|
-
* configuration options for the deque. In this code, it is used to set the `bucketSize` option,
|
|
114
|
-
* which determines the size of each bucket in the deque. If the `bucketSize` option is not provided
|
|
115
|
-
* or is not a number
|
|
112
|
+
* Create a Deque and optionally bulk-insert elements.
|
|
113
|
+
* @remarks Time O(N), Space O(N)
|
|
114
|
+
* @param [elements] - Iterable (or iterable-like) of elements/records to insert.
|
|
115
|
+
* @param [options] - Options such as bucketSize, toElementFn, and maxLen.
|
|
116
|
+
* @returns New Deque instance.
|
|
116
117
|
*/
|
|
117
118
|
constructor(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>, options?: DequeOptions<E, R>);
|
|
118
119
|
protected _bucketSize: number;
|
|
120
|
+
/**
|
|
121
|
+
* Get the current bucket size.
|
|
122
|
+
* @remarks Time O(1), Space O(1)
|
|
123
|
+
* @returns Bucket capacity per bucket.
|
|
124
|
+
*/
|
|
119
125
|
get bucketSize(): number;
|
|
120
126
|
protected _bucketFirst: number;
|
|
127
|
+
/**
|
|
128
|
+
* Get the index of the first bucket in use.
|
|
129
|
+
* @remarks Time O(1), Space O(1)
|
|
130
|
+
* @returns Zero-based bucket index.
|
|
131
|
+
*/
|
|
121
132
|
get bucketFirst(): number;
|
|
122
133
|
protected _firstInBucket: number;
|
|
134
|
+
/**
|
|
135
|
+
* Get the index inside the first bucket.
|
|
136
|
+
* @remarks Time O(1), Space O(1)
|
|
137
|
+
* @returns Zero-based index within the first bucket.
|
|
138
|
+
*/
|
|
123
139
|
get firstInBucket(): number;
|
|
124
140
|
protected _bucketLast: number;
|
|
141
|
+
/**
|
|
142
|
+
* Get the index of the last bucket in use.
|
|
143
|
+
* @remarks Time O(1), Space O(1)
|
|
144
|
+
* @returns Zero-based bucket index.
|
|
145
|
+
*/
|
|
125
146
|
get bucketLast(): number;
|
|
126
147
|
protected _lastInBucket: number;
|
|
148
|
+
/**
|
|
149
|
+
* Get the index inside the last bucket.
|
|
150
|
+
* @remarks Time O(1), Space O(1)
|
|
151
|
+
* @returns Zero-based index within the last bucket.
|
|
152
|
+
*/
|
|
127
153
|
get lastInBucket(): number;
|
|
128
154
|
protected _bucketCount: number;
|
|
155
|
+
/**
|
|
156
|
+
* Get the number of buckets allocated.
|
|
157
|
+
* @remarks Time O(1), Space O(1)
|
|
158
|
+
* @returns Bucket count.
|
|
159
|
+
*/
|
|
129
160
|
get bucketCount(): number;
|
|
130
161
|
protected _buckets: E[][];
|
|
162
|
+
/**
|
|
163
|
+
* Get the internal buckets array.
|
|
164
|
+
* @remarks Time O(1), Space O(1)
|
|
165
|
+
* @returns Array of buckets storing values.
|
|
166
|
+
*/
|
|
131
167
|
get buckets(): E[][];
|
|
132
168
|
protected _length: number;
|
|
169
|
+
/**
|
|
170
|
+
* Get the number of elements in the deque.
|
|
171
|
+
* @remarks Time O(1), Space O(1)
|
|
172
|
+
* @returns Current length.
|
|
173
|
+
*/
|
|
133
174
|
get length(): number;
|
|
134
175
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* @returns
|
|
176
|
+
* Get the first element without removing it.
|
|
177
|
+
* @remarks Time O(1), Space O(1)
|
|
178
|
+
* @returns First element or undefined.
|
|
138
179
|
*/
|
|
139
180
|
get first(): E | undefined;
|
|
140
181
|
/**
|
|
141
|
-
*
|
|
142
|
-
* @
|
|
182
|
+
* Get the last element without removing it.
|
|
183
|
+
* @remarks Time O(1), Space O(1)
|
|
184
|
+
* @returns Last element or undefined.
|
|
143
185
|
*/
|
|
144
186
|
get last(): E | undefined;
|
|
145
187
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @param
|
|
151
|
-
*
|
|
152
|
-
* @
|
|
188
|
+
* Create a Deque from an array of elements.
|
|
189
|
+
* @remarks Time O(N), Space O(N)
|
|
190
|
+
* @template E
|
|
191
|
+
* @template R
|
|
192
|
+
* @param this - Constructor (subclass) to instantiate.
|
|
193
|
+
* @param data - Array of elements to insert in order.
|
|
194
|
+
* @param [options] - Options forwarded to the constructor.
|
|
195
|
+
* @returns A new Deque populated from the array.
|
|
196
|
+
*/
|
|
197
|
+
static fromArray<E, R = any>(this: new (elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>, options?: DequeOptions<E, R>) => any, data: E[], options?: DequeOptions<E, R>): any;
|
|
198
|
+
/**
|
|
199
|
+
* Append one element at the back.
|
|
200
|
+
* @remarks Time O(1) amortized, Space O(1)
|
|
201
|
+
* @param element - Element to append.
|
|
202
|
+
* @returns True when appended.
|
|
153
203
|
*/
|
|
154
204
|
push(element: E): boolean;
|
|
155
205
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* The `pop()` function removes and returns the last element from a data structure, updating the
|
|
160
|
-
* internal state variables accordingly.
|
|
161
|
-
* @returns The element that was removed from the data structure is being returned.
|
|
206
|
+
* Remove and return the last element.
|
|
207
|
+
* @remarks Time O(1), Space O(1)
|
|
208
|
+
* @returns Removed element or undefined.
|
|
162
209
|
*/
|
|
163
210
|
pop(): E | undefined;
|
|
164
211
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* The `shift()` function removes and returns the first element from a data structure, updating the
|
|
169
|
-
* internal state variables accordingly.
|
|
170
|
-
* @returns The element that is being removed from the beginning of the data structure is being
|
|
171
|
-
* returned.
|
|
212
|
+
* Remove and return the first element.
|
|
213
|
+
* @remarks Time O(1) amortized, Space O(1)
|
|
214
|
+
* @returns Removed element or undefined.
|
|
172
215
|
*/
|
|
173
216
|
shift(): E | undefined;
|
|
174
217
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* returns the new size of the structure.
|
|
180
|
-
* @param {E} element - The `element` parameter represents the element that you want to add to the
|
|
181
|
-
* beginning of the data structure.
|
|
182
|
-
* @returns The size of the data structure after the element has been added.
|
|
218
|
+
* Prepend one element at the front.
|
|
219
|
+
* @remarks Time O(1) amortized, Space O(1)
|
|
220
|
+
* @param element - Element to prepend.
|
|
221
|
+
* @returns True when prepended.
|
|
183
222
|
*/
|
|
184
223
|
unshift(element: E): boolean;
|
|
185
224
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* transformation function if provided.
|
|
191
|
-
* @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
|
|
192
|
-
* parameter in the `pushMany` function is expected to be an iterable containing elements of type `E`
|
|
193
|
-
* or `R`. It can be either an `IterableWithSizeOrLength<E>` or an `IterableWithSizeOrLength<R>`. The
|
|
194
|
-
* function iterates over each element
|
|
195
|
-
* @returns The `pushMany` function is returning an array of boolean values, where each value
|
|
196
|
-
* represents the result of calling the `push` method on the current object instance with the
|
|
197
|
-
* corresponding element from the input `elements` iterable.
|
|
225
|
+
* Append a sequence of elements.
|
|
226
|
+
* @remarks Time O(N), Space O(1)
|
|
227
|
+
* @param elements - Iterable (or iterable-like) of elements/records.
|
|
228
|
+
* @returns Array of per-element success flags.
|
|
198
229
|
*/
|
|
199
230
|
pushMany(elements: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
|
|
200
231
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* an array, optionally converting them using a provided function.
|
|
206
|
-
* @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
|
|
207
|
-
* parameter in the `unshiftMany` function is an iterable containing elements of type `E` or `R`. It
|
|
208
|
-
* can be an array or any other iterable data structure that has a known size or length. The function
|
|
209
|
-
* iterates over each element in the `elements` iterable and
|
|
210
|
-
* @returns The `unshiftMany` function returns an array of boolean values indicating whether each
|
|
211
|
-
* element was successfully added to the beginning of the array.
|
|
232
|
+
* Prepend a sequence of elements.
|
|
233
|
+
* @remarks Time O(N), Space O(1)
|
|
234
|
+
* @param [elements] - Iterable (or iterable-like) of elements/records.
|
|
235
|
+
* @returns Array of per-element success flags.
|
|
212
236
|
*/
|
|
213
237
|
unshiftMany(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
|
|
214
238
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
219
|
-
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
239
|
+
* Check whether the deque is empty.
|
|
240
|
+
* @remarks Time O(1), Space O(1)
|
|
241
|
+
* @returns True if length is 0.
|
|
220
242
|
*/
|
|
221
243
|
isEmpty(): boolean;
|
|
222
244
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* The clear() function resets the state of the object by initializing all variables to their default
|
|
227
|
-
* values.
|
|
245
|
+
* Remove all elements and reset structure.
|
|
246
|
+
* @remarks Time O(1), Space O(1)
|
|
247
|
+
* @returns void
|
|
228
248
|
*/
|
|
229
249
|
clear(): void;
|
|
230
250
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
*
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
*
|
|
243
|
-
* Space Complexity: O(1)
|
|
244
|
-
*
|
|
245
|
-
* The `setAt` function sets an element at a specific position in an array-like data structure.
|
|
246
|
-
* @param {number} pos - The `pos` parameter represents the position at which the element needs to be
|
|
247
|
-
* set. It is of type `number`.
|
|
248
|
-
* @param {E} element - The `element` parameter is the value that you want to set at the specified
|
|
249
|
-
* position in the data structure.
|
|
251
|
+
* Get the element at a given position.
|
|
252
|
+
* @remarks Time O(1), Space O(1)
|
|
253
|
+
* @param pos - Zero-based position from the front.
|
|
254
|
+
* @returns Element or undefined.
|
|
255
|
+
*/
|
|
256
|
+
at(pos: number): E | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Replace the element at a given position.
|
|
259
|
+
* @remarks Time O(1), Space O(1)
|
|
260
|
+
* @param pos - Zero-based position from the front.
|
|
261
|
+
* @param element - New element value.
|
|
262
|
+
* @returns True if updated.
|
|
250
263
|
*/
|
|
251
264
|
setAt(pos: number, element: E): boolean;
|
|
252
265
|
/**
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* @
|
|
259
|
-
* be inserted. It is of type `number`.
|
|
260
|
-
* @param {E} element - The `element` parameter represents the element that you want to insert into
|
|
261
|
-
* the array at the specified position.
|
|
262
|
-
* @param [num=1] - The `num` parameter represents the number of times the `element` should be
|
|
263
|
-
* inserted at the specified position (`pos`). By default, it is set to 1, meaning that the `element`
|
|
264
|
-
* will be inserted once. However, you can provide a different value for `num` if you want
|
|
265
|
-
* @returns The size of the array after the insertion is being returned.
|
|
266
|
+
* Insert repeated copies of an element at a position.
|
|
267
|
+
* @remarks Time O(N), Space O(1)
|
|
268
|
+
* @param pos - Zero-based position from the front.
|
|
269
|
+
* @param element - Element to insert.
|
|
270
|
+
* @param [num] - Number of times to insert (default 1).
|
|
271
|
+
* @returns True if inserted.
|
|
266
272
|
*/
|
|
267
273
|
addAt(pos: number, element: E, num?: number): boolean;
|
|
268
274
|
/**
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* @param {number} pos - The `pos` parameter represents the position at which the string should be
|
|
275
|
-
* cut. It is a number that indicates the index of the character where the cut should be made.
|
|
276
|
-
* @param {boolean} isCutSelf - If true, the original deque will not be cut, and return a new deque
|
|
277
|
-
* @returns The method is returning the updated size of the data structure.
|
|
275
|
+
* Cut the deque to keep items up to index; optionally mutate in-place.
|
|
276
|
+
* @remarks Time O(N), Space O(1)
|
|
277
|
+
* @param pos - Last index to keep.
|
|
278
|
+
* @param [isCutSelf] - When true, mutate this deque; otherwise return a new deque.
|
|
279
|
+
* @returns This deque if in-place; otherwise a new deque of the prefix.
|
|
278
280
|
*/
|
|
279
281
|
cut(pos: number, isCutSelf?: boolean): Deque<E>;
|
|
280
282
|
/**
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* @
|
|
287
|
-
* to start changing the array. Items will be removed or added starting from this index.
|
|
288
|
-
* @param {number} deleteCount - The `deleteCount` parameter in the `splice` method represents the
|
|
289
|
-
* number of elements to remove from the array starting at the specified `start` index. If
|
|
290
|
-
* `deleteCount` is not provided, it defaults to the number of elements from the `start` index to the
|
|
291
|
-
* end of the array (`
|
|
292
|
-
* @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
|
|
293
|
-
* will be inserted into the deque at the specified `start` index. These elements will be inserted in
|
|
294
|
-
* place of the elements that are removed based on the `start` and `deleteCount` parameters.
|
|
295
|
-
* @returns The `splice` method is returning the array `deletedElements` which contains the elements
|
|
296
|
-
* that were removed from the Deque during the splice operation.
|
|
283
|
+
* Remove and/or insert elements at a position (array-like behavior).
|
|
284
|
+
* @remarks Time O(N + M), Space O(M)
|
|
285
|
+
* @param start - Start index (clamped to [0, length]).
|
|
286
|
+
* @param [deleteCount] - Number of elements to remove (default: length - start).
|
|
287
|
+
* @param [items] - Elements to insert after `start`.
|
|
288
|
+
* @returns A new deque containing the removed elements (typed as `this`).
|
|
297
289
|
*/
|
|
298
290
|
splice(start: number, deleteCount?: number, ...items: E[]): this;
|
|
299
291
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* deque
|
|
305
|
-
* @param {number} pos - The `pos` parameter represents the position from which to cut the Deque. It
|
|
306
|
-
* is a number that indicates the index of the element in the Deque where the cut should start.
|
|
307
|
-
* @param [isCutSelf=false] - isCutSelf is a boolean parameter that determines whether the original
|
|
308
|
-
* Deque should be modified or a new Deque should be created. If isCutSelf is true, the original
|
|
309
|
-
* Deque will be modified by cutting off elements starting from the specified position. If isCutSelf
|
|
310
|
-
* is false, a new De
|
|
311
|
-
* @returns The function `cutRest` returns either the modified original deque (`this`) or a new deque
|
|
312
|
-
* (`newDeque`) depending on the value of the `isCutSelf` parameter.
|
|
292
|
+
* Cut the deque to keep items from index onward; optionally mutate in-place.
|
|
293
|
+
* @remarks Time O(N), Space O(1)
|
|
294
|
+
* @param pos - First index to keep.
|
|
295
|
+
* @param [isCutSelf] - When true, mutate this deque; otherwise return a new deque.
|
|
296
|
+
* @returns This deque if in-place; otherwise a new deque of the suffix.
|
|
313
297
|
*/
|
|
314
298
|
cutRest(pos: number, isCutSelf?: boolean): Deque<E>;
|
|
315
299
|
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* structure.
|
|
321
|
-
* @param {number} pos - The `pos` parameter in the `deleteAt` function represents the position at
|
|
322
|
-
* which an element needs to be deleted from the data structure. It is of type `number` and indicates
|
|
323
|
-
* the index of the element to be deleted.
|
|
324
|
-
* @returns The size of the data structure after the deletion operation is performed.
|
|
300
|
+
* Delete the element at a given position.
|
|
301
|
+
* @remarks Time O(N), Space O(1)
|
|
302
|
+
* @param pos - Zero-based position from the front.
|
|
303
|
+
* @returns Removed element or undefined.
|
|
325
304
|
*/
|
|
326
305
|
deleteAt(pos: number): E | undefined;
|
|
327
306
|
/**
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* structure.
|
|
333
|
-
* @param {E} element - The `element` parameter represents the element that you want to delete from
|
|
334
|
-
* the data structure.
|
|
335
|
-
* @returns The size of the data structure after the element has been deleted.
|
|
307
|
+
* Delete the first occurrence of a value.
|
|
308
|
+
* @remarks Time O(N), Space O(1)
|
|
309
|
+
* @param element - Element to remove (using the configured equality).
|
|
310
|
+
* @returns True if an element was removed.
|
|
336
311
|
*/
|
|
337
312
|
delete(element: E): boolean;
|
|
338
313
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
314
|
+
* Delete the first element matching a predicate.
|
|
315
|
+
* @remarks Time O(N), Space O(1)
|
|
316
|
+
* @param predicate - Function (value, index, deque) → boolean.
|
|
317
|
+
* @returns True if a match was removed.
|
|
318
|
+
*/
|
|
319
|
+
deleteWhere(predicate: (value: E, index: number, deque: this) => boolean): boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Set the equality comparator used by delete operations.
|
|
322
|
+
* @remarks Time O(1), Space O(1)
|
|
323
|
+
* @param equals - Equality predicate (a, b) → boolean.
|
|
324
|
+
* @returns This deque.
|
|
325
|
+
*/
|
|
326
|
+
setEquality(equals: (a: E, b: E) => boolean): this;
|
|
327
|
+
/**
|
|
328
|
+
* Reverse the deque by reversing buckets and pointers.
|
|
329
|
+
* @remarks Time O(N), Space O(N)
|
|
330
|
+
* @returns This deque.
|
|
346
331
|
*/
|
|
347
332
|
reverse(): this;
|
|
348
333
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* The `unique()` function removes duplicate elements from an array-like data structure and returns
|
|
353
|
-
* the number of unique elements.
|
|
354
|
-
* @returns The size of the modified array is being returned.
|
|
334
|
+
* Deduplicate consecutive equal elements in-place.
|
|
335
|
+
* @remarks Time O(N), Space O(1)
|
|
336
|
+
* @returns This deque.
|
|
355
337
|
*/
|
|
356
338
|
unique(): this;
|
|
357
339
|
/**
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
|
|
362
|
-
* memory usage.
|
|
363
|
-
* @returns Nothing is being returned. The function is using the `return` statement to exit early if
|
|
364
|
-
* `this._length` is 0, but it does not return any value.
|
|
340
|
+
* Trim unused buckets to fit exactly the active range.
|
|
341
|
+
* @remarks Time O(N), Space O(1)
|
|
342
|
+
* @returns void
|
|
365
343
|
*/
|
|
366
344
|
shrinkToFit(): void;
|
|
367
345
|
/**
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* The `clone()` function returns a new instance of the `Deque` class with the same elements and
|
|
372
|
-
* bucket size as the original instance.
|
|
373
|
-
* @returns The `clone()` method is returning a new instance of the `Deque` class with the same
|
|
374
|
-
* elements as the original deque (`this`) and the same bucket size.
|
|
346
|
+
* Deep clone this deque, preserving options.
|
|
347
|
+
* @remarks Time O(N), Space O(N)
|
|
348
|
+
* @returns A new deque with the same content and options.
|
|
375
349
|
*/
|
|
376
350
|
clone(): this;
|
|
377
351
|
/**
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
* deque
|
|
387
|
-
* @
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
* @returns
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
* Time
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* @param
|
|
401
|
-
*
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
*
|
|
406
|
-
* @
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
*
|
|
415
|
-
* Space Complexity: O(1)
|
|
416
|
-
*
|
|
417
|
-
* The above function is an implementation of the iterator protocol in TypeScript, allowing the
|
|
418
|
-
* object to be iterated over using a for...of loop.
|
|
352
|
+
* Filter elements into a new deque of the same class.
|
|
353
|
+
* @remarks Time O(N), Space O(N)
|
|
354
|
+
* @param predicate - Predicate (value, index, deque) → boolean to keep element.
|
|
355
|
+
* @param [thisArg] - Value for `this` inside the predicate.
|
|
356
|
+
* @returns A new deque with kept elements.
|
|
357
|
+
*/
|
|
358
|
+
filter(predicate: ElementCallback<E, R, boolean>, thisArg?: any): this;
|
|
359
|
+
/**
|
|
360
|
+
* Map elements into a new deque of the same element type.
|
|
361
|
+
* @remarks Time O(N), Space O(N)
|
|
362
|
+
* @param callback - Mapping function (value, index, deque) → newValue.
|
|
363
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
364
|
+
* @returns A new deque with mapped values.
|
|
365
|
+
*/
|
|
366
|
+
mapSame(callback: ElementCallback<E, R, E>, thisArg?: any): this;
|
|
367
|
+
/**
|
|
368
|
+
* Map elements into a new deque (possibly different element type).
|
|
369
|
+
* @remarks Time O(N), Space O(N)
|
|
370
|
+
* @template EM
|
|
371
|
+
* @template RM
|
|
372
|
+
* @param callback - Mapping function (value, index, deque) → newElement.
|
|
373
|
+
* @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
|
|
374
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
375
|
+
* @returns A new Deque with mapped elements.
|
|
376
|
+
*/
|
|
377
|
+
map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: IterableElementBaseOptions<EM, RM>, thisArg?: any): Deque<EM, RM>;
|
|
378
|
+
/**
|
|
379
|
+
* (Protected) Set the internal bucket size.
|
|
380
|
+
* @remarks Time O(1), Space O(1)
|
|
381
|
+
* @param size - Bucket capacity to assign.
|
|
382
|
+
* @returns void
|
|
383
|
+
*/
|
|
384
|
+
protected _setBucketSize(size: number): void;
|
|
385
|
+
/**
|
|
386
|
+
* (Protected) Iterate elements from front to back.
|
|
387
|
+
* @remarks Time O(N), Space O(1)
|
|
388
|
+
* @returns Iterator of elements.
|
|
419
389
|
*/
|
|
420
390
|
protected _getIterator(): IterableIterator<E>;
|
|
421
391
|
/**
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
* @param {number} [needBucketNum] - The `needBucketNum` parameter is an optional number that
|
|
427
|
-
* specifies the number of new buckets needed. If not provided, it will default to half of the
|
|
428
|
-
* current bucket count (`this._bucketCount >> 1`) or 1 if the current bucket count is less than 2.
|
|
392
|
+
* (Protected) Reallocate buckets to make room near the ends.
|
|
393
|
+
* @remarks Time O(N), Space O(N)
|
|
394
|
+
* @param [needBucketNum] - How many extra buckets to add; defaults to half of current.
|
|
395
|
+
* @returns void
|
|
429
396
|
*/
|
|
430
397
|
protected _reallocate(needBucketNum?: number): void;
|
|
431
398
|
/**
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* @param {number} pos - The `pos` parameter represents the position within the data structure. It is
|
|
437
|
-
* a number that indicates the index or position of an element within the structure.
|
|
438
|
-
* @returns an object with two properties: "bucketIndex" and "indexInBucket".
|
|
399
|
+
* (Protected) Translate a logical position to bucket/offset.
|
|
400
|
+
* @remarks Time O(1), Space O(1)
|
|
401
|
+
* @param pos - Zero-based position.
|
|
402
|
+
* @returns An object containing bucketIndex and indexInBucket.
|
|
439
403
|
*/
|
|
440
404
|
protected _getBucketAndPosition(pos: number): {
|
|
441
405
|
bucketIndex: number;
|
|
442
406
|
indexInBucket: number;
|
|
443
407
|
};
|
|
444
408
|
/**
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
* @param [options] -
|
|
448
|
-
*
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
409
|
+
* (Protected) Create an empty instance of the same concrete class.
|
|
410
|
+
* @remarks Time O(1), Space O(1)
|
|
411
|
+
* @param [options] - Options forwarded to the constructor.
|
|
412
|
+
* @returns An empty like-kind deque instance.
|
|
413
|
+
*/
|
|
414
|
+
protected _createInstance(options?: LinearBaseOptions<E, R>): this;
|
|
415
|
+
/**
|
|
416
|
+
* (Protected) Create a like-kind deque seeded by elements.
|
|
417
|
+
* @remarks Time O(N), Space O(N)
|
|
418
|
+
* @template T
|
|
419
|
+
* @template RR
|
|
420
|
+
* @param [elements] - Iterable used to seed the new deque.
|
|
421
|
+
* @param [options] - Options forwarded to the constructor.
|
|
422
|
+
* @returns A like-kind Deque instance.
|
|
452
423
|
*/
|
|
453
|
-
protected
|
|
424
|
+
protected _createLike<T = E, RR = R>(elements?: IterableWithSizeOrLength<T> | IterableWithSizeOrLength<RR>, options?: DequeOptions<T, RR>): any;
|
|
454
425
|
/**
|
|
455
|
-
*
|
|
426
|
+
* (Protected) Iterate elements from back to front.
|
|
427
|
+
* @remarks Time O(N), Space O(1)
|
|
428
|
+
* @returns Iterator of elements.
|
|
456
429
|
*/
|
|
457
430
|
protected _getReverseIterator(): IterableIterator<E>;
|
|
458
431
|
}
|