data-structure-typed 2.6.0 → 2.6.2
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/.github/workflows/ci.yml +7 -2
- package/.github/workflows/release-package.yml +9 -2
- package/CHANGELOG.md +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +253 -101
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +244 -114
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +84 -14
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +138 -34
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +149 -41
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +172 -92
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +120 -70
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +125 -75
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/Queue.md +158 -74
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +172 -94
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +112 -50
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +90 -121
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +298 -107
- package/docs-site-docusaurus/docs/api/classes/Trie.md +116 -58
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- package/package.json +45 -46
- package/src/common/error.ts +15 -32
- package/src/common/index.ts +0 -3
- package/src/data-structures/base/iterable-element-base.ts +0 -3
- package/src/data-structures/base/linear-base.ts +2 -36
- package/src/data-structures/binary-tree/avl-tree.ts +31 -529
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -572
- package/src/data-structures/binary-tree/binary-tree.ts +326 -1311
- package/src/data-structures/binary-tree/bst.ts +158 -1082
- package/src/data-structures/binary-tree/red-black-tree.ts +451 -1290
- package/src/data-structures/binary-tree/segment-tree.ts +73 -351
- package/src/data-structures/binary-tree/tree-map.ts +462 -5124
- package/src/data-structures/binary-tree/tree-multi-map.ts +302 -4914
- package/src/data-structures/binary-tree/tree-multi-set.ts +299 -3983
- package/src/data-structures/binary-tree/tree-set.ts +338 -4836
- package/src/data-structures/graph/abstract-graph.ts +98 -167
- package/src/data-structures/graph/directed-graph.ts +137 -562
- package/src/data-structures/graph/map-graph.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +132 -511
- package/src/data-structures/hash/hash-map.ts +154 -582
- package/src/data-structures/heap/heap.ts +200 -795
- package/src/data-structures/linked-list/doubly-linked-list.ts +121 -865
- package/src/data-structures/linked-list/singly-linked-list.ts +122 -794
- package/src/data-structures/linked-list/skip-linked-list.ts +211 -918
- package/src/data-structures/matrix/matrix.ts +179 -518
- package/src/data-structures/matrix/navigator.ts +0 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
- package/src/data-structures/priority-queue/priority-queue.ts +1 -2
- package/src/data-structures/queue/deque.ts +214 -882
- package/src/data-structures/queue/queue.ts +102 -625
- package/src/data-structures/stack/stack.ts +76 -505
- package/src/data-structures/trie/trie.ts +98 -628
- package/src/types/common.ts +0 -10
- package/src/types/data-structures/binary-tree/bst.ts +0 -7
- package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
- package/src/types/data-structures/graph/abstract-graph.ts +0 -2
- package/src/types/data-structures/hash/hash-map.ts +0 -3
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/matrix/navigator.ts +0 -2
- package/src/types/utils/utils.ts +0 -7
- package/src/types/utils/validate-type.ts +0 -7
- package/src/utils/number.ts +0 -2
- package/src/utils/utils.ts +0 -5
|
@@ -165,57 +165,15 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
165
165
|
* Get the number of elements.
|
|
166
166
|
* @remarks Time O(1), Space O(1)
|
|
167
167
|
* @returns Heap size.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
* @example
|
|
211
|
-
* // Track heap capacity
|
|
212
|
-
* const heap = new Heap<number>();
|
|
213
|
-
* console.log(heap.size); // 0;
|
|
214
|
-
* heap.add(10);
|
|
215
|
-
* heap.add(20);
|
|
216
|
-
* console.log(heap.size); // 2;
|
|
217
|
-
* heap.poll();
|
|
218
|
-
* console.log(heap.size); // 1;
|
|
168
|
+
* @example
|
|
169
|
+
* // Track heap capacity
|
|
170
|
+
* const heap = new Heap<number>();
|
|
171
|
+
* console.log(heap.size); // 0;
|
|
172
|
+
* heap.add(10);
|
|
173
|
+
* heap.add(20);
|
|
174
|
+
* console.log(heap.size); // 2;
|
|
175
|
+
* heap.poll();
|
|
176
|
+
* console.log(heap.size); // 1;
|
|
219
177
|
*/
|
|
220
178
|
get size(): number;
|
|
221
179
|
/**
|
|
@@ -224,6 +182,12 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
224
182
|
* @returns Last element or undefined.
|
|
225
183
|
*/
|
|
226
184
|
get leaf(): E | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* Get the comparator used to order elements.
|
|
187
|
+
* @remarks Time O(1), Space O(1)
|
|
188
|
+
* @returns Comparator function.
|
|
189
|
+
*/
|
|
190
|
+
get comparator(): Comparator<E>;
|
|
227
191
|
/**
|
|
228
192
|
* Create a heap of the same class from an iterable.
|
|
229
193
|
* @remarks Time O(N), Space O(N)
|
|
@@ -250,63 +214,21 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
250
214
|
* @remarks Time O(log N) amortized, Space O(1)
|
|
251
215
|
* @param element - Element to insert.
|
|
252
216
|
* @returns True.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
* @example
|
|
296
|
-
* // basic Heap creation and add operation
|
|
297
|
-
* // Create a min heap (default)
|
|
298
|
-
* const minHeap = new Heap([5, 3, 7, 1, 9, 2]);
|
|
299
|
-
*
|
|
300
|
-
* // Verify size
|
|
301
|
-
* console.log(minHeap.size); // 6;
|
|
302
|
-
*
|
|
303
|
-
* // Add new element
|
|
304
|
-
* minHeap.add(4);
|
|
305
|
-
* console.log(minHeap.size); // 7;
|
|
306
|
-
*
|
|
307
|
-
* // Min heap property: smallest element at root
|
|
308
|
-
* const min = minHeap.peek();
|
|
309
|
-
* console.log(min); // 1;
|
|
217
|
+
* @example
|
|
218
|
+
* // basic Heap creation and add operation
|
|
219
|
+
* // Create a min heap (default)
|
|
220
|
+
* const minHeap = new Heap([5, 3, 7, 1, 9, 2]);
|
|
221
|
+
*
|
|
222
|
+
* // Verify size
|
|
223
|
+
* console.log(minHeap.size); // 6;
|
|
224
|
+
*
|
|
225
|
+
* // Add new element
|
|
226
|
+
* minHeap.add(4);
|
|
227
|
+
* console.log(minHeap.size); // 7;
|
|
228
|
+
*
|
|
229
|
+
* // Min heap property: smallest element at root
|
|
230
|
+
* const min = minHeap.peek();
|
|
231
|
+
* console.log(min); // 1;
|
|
310
232
|
*/
|
|
311
233
|
add(element: E): boolean;
|
|
312
234
|
/**
|
|
@@ -314,151 +236,71 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
314
236
|
* @remarks Time O(N log N), Space O(1)
|
|
315
237
|
* @param elements - Iterable of elements or raw values.
|
|
316
238
|
* @returns Array of per-element success flags.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
* @example
|
|
357
|
-
* // Add multiple elements
|
|
358
|
-
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
359
|
-
* heap.addMany([5, 3, 7, 1]);
|
|
360
|
-
* console.log(heap.peek()); // 1;
|
|
361
|
-
* console.log(heap.size); // 4;
|
|
239
|
+
* @example
|
|
240
|
+
* // Add multiple elements
|
|
241
|
+
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
242
|
+
* heap.addMany([5, 3, 7, 1]);
|
|
243
|
+
* console.log(heap.peek()); // 1;
|
|
244
|
+
* console.log(heap.size); // 4;
|
|
362
245
|
*/
|
|
363
246
|
addMany(elements: Iterable<E | R>): boolean[];
|
|
364
247
|
/**
|
|
365
248
|
* Remove and return the top element.
|
|
366
249
|
* @remarks Time O(log N), Space O(1)
|
|
367
250
|
* @returns Top element or undefined.
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
* @example
|
|
407
|
-
* // Heap with custom comparator (MaxHeap behavior)
|
|
408
|
-
* interface Task {
|
|
409
|
-
* id: number;
|
|
410
|
-
* priority: number;
|
|
411
|
-
* name: string;
|
|
412
|
-
* }
|
|
413
|
-
*
|
|
414
|
-
* // Custom comparator for max heap behavior (higher priority first)
|
|
415
|
-
* const tasks: Task[] = [
|
|
416
|
-
* { id: 1, priority: 5, name: 'Email' },
|
|
417
|
-
* { id: 2, priority: 3, name: 'Chat' },
|
|
418
|
-
* { id: 3, priority: 8, name: 'Alert' }
|
|
419
|
-
* ];
|
|
420
|
-
*
|
|
421
|
-
* const maxHeap = new Heap(tasks, {
|
|
422
|
-
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
423
|
-
* });
|
|
424
|
-
*
|
|
425
|
-
* console.log(maxHeap.size); // 3;
|
|
426
|
-
*
|
|
427
|
-
* // Peek returns highest priority task
|
|
428
|
-
* const topTask = maxHeap.peek();
|
|
429
|
-
* console.log(topTask?.priority); // 8;
|
|
430
|
-
* console.log(topTask?.name); // 'Alert';
|
|
251
|
+
* @example
|
|
252
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
253
|
+
* interface Task {
|
|
254
|
+
* id: number;
|
|
255
|
+
* priority: number;
|
|
256
|
+
* name: string;
|
|
257
|
+
* }
|
|
258
|
+
*
|
|
259
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
260
|
+
* const tasks: Task[] = [
|
|
261
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
262
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
263
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
264
|
+
* ];
|
|
265
|
+
*
|
|
266
|
+
* const maxHeap = new Heap(tasks, {
|
|
267
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
268
|
+
* });
|
|
269
|
+
*
|
|
270
|
+
* console.log(maxHeap.size); // 3;
|
|
271
|
+
*
|
|
272
|
+
* // Peek returns highest priority task
|
|
273
|
+
* const topTask = maxHeap.peek();
|
|
274
|
+
* console.log(topTask?.priority); // 8;
|
|
275
|
+
* console.log(topTask?.name); // 'Alert';
|
|
431
276
|
*/
|
|
432
277
|
/**
|
|
433
278
|
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
* const topTask = maxHeap.peek();
|
|
460
|
-
* console.log(topTask?.priority); // 8;
|
|
461
|
-
* console.log(topTask?.name); // 'Alert';
|
|
279
|
+
* @example
|
|
280
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
281
|
+
* interface Task {
|
|
282
|
+
* id: number;
|
|
283
|
+
* priority: number;
|
|
284
|
+
* name: string;
|
|
285
|
+
* }
|
|
286
|
+
*
|
|
287
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
288
|
+
* const tasks: Task[] = [
|
|
289
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
290
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
291
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
292
|
+
* ];
|
|
293
|
+
*
|
|
294
|
+
* const maxHeap = new Heap(tasks, {
|
|
295
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
296
|
+
* });
|
|
297
|
+
*
|
|
298
|
+
* console.log(maxHeap.size); // 3;
|
|
299
|
+
*
|
|
300
|
+
* // Peek returns highest priority task
|
|
301
|
+
* const topTask = maxHeap.peek();
|
|
302
|
+
* console.log(topTask?.priority); // 8;
|
|
303
|
+
* console.log(topTask?.name); // 'Alert';
|
|
462
304
|
*/
|
|
463
305
|
poll(): E | undefined;
|
|
464
306
|
/**
|
|
@@ -471,210 +313,88 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
471
313
|
* Get the current top element without removing it.
|
|
472
314
|
* @remarks Time O(1), Space O(1)
|
|
473
315
|
* @returns Top element or undefined.
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
* }
|
|
534
|
-
* });
|
|
535
|
-
*
|
|
536
|
-
* // Add events in random order
|
|
537
|
-
* eventHeap.add({ id: 1, type: 'info', timestamp: 100, message: 'User logged in' });
|
|
538
|
-
* eventHeap.add({ id: 2, type: 'critical', timestamp: 101, message: 'Server down' });
|
|
539
|
-
* eventHeap.add({ id: 3, type: 'warning', timestamp: 102, message: 'High memory' });
|
|
540
|
-
* eventHeap.add({ id: 4, type: 'info', timestamp: 103, message: 'Cache cleared' });
|
|
541
|
-
* eventHeap.add({ id: 5, type: 'critical', timestamp: 104, message: 'Database error' });
|
|
542
|
-
*
|
|
543
|
-
* console.log(eventHeap.size); // 5;
|
|
544
|
-
*
|
|
545
|
-
* // Process events by priority (critical first)
|
|
546
|
-
* const processedOrder: Event[] = [];
|
|
547
|
-
* while (eventHeap.size > 0) {
|
|
548
|
-
* const event = eventHeap.poll();
|
|
549
|
-
* if (event) {
|
|
550
|
-
* processedOrder.push(event);
|
|
551
|
-
* }
|
|
552
|
-
* }
|
|
553
|
-
*
|
|
554
|
-
* // Verify critical events came first
|
|
555
|
-
* console.log(processedOrder[0].type); // 'critical';
|
|
556
|
-
* console.log(processedOrder[1].type); // 'critical';
|
|
557
|
-
* console.log(processedOrder[2].type); // 'warning';
|
|
558
|
-
* console.log(processedOrder[3].type); // 'info';
|
|
559
|
-
* console.log(processedOrder[4].type); // 'info';
|
|
560
|
-
*
|
|
561
|
-
* // Verify O(log n) operations
|
|
562
|
-
* const newHeap = new Heap<number>([5, 3, 7, 1]);
|
|
563
|
-
*
|
|
564
|
-
* // Add - O(log n)
|
|
565
|
-
* newHeap.add(2);
|
|
566
|
-
* console.log(newHeap.size); // 5;
|
|
567
|
-
*
|
|
568
|
-
* // Poll - O(log n)
|
|
569
|
-
* const removed = newHeap.poll();
|
|
570
|
-
* console.log(removed); // 1;
|
|
571
|
-
*
|
|
572
|
-
* // Peek - O(1)
|
|
573
|
-
* const top = newHeap.peek();
|
|
574
|
-
* console.log(top); // 2;
|
|
316
|
+
* @example
|
|
317
|
+
* // Heap for event processing with priority
|
|
318
|
+
* interface Event {
|
|
319
|
+
* id: number;
|
|
320
|
+
* type: 'critical' | 'warning' | 'info';
|
|
321
|
+
* timestamp: number;
|
|
322
|
+
* message: string;
|
|
323
|
+
* }
|
|
324
|
+
*
|
|
325
|
+
* // Custom priority: critical > warning > info
|
|
326
|
+
* const priorityMap = { critical: 3, warning: 2, info: 1 };
|
|
327
|
+
*
|
|
328
|
+
* const eventHeap = new Heap<Event>([], {
|
|
329
|
+
* comparator: (a: Event, b: Event) => {
|
|
330
|
+
* const priorityA = priorityMap[a.type];
|
|
331
|
+
* const priorityB = priorityMap[b.type];
|
|
332
|
+
* return priorityB - priorityA; // Higher priority first
|
|
333
|
+
* }
|
|
334
|
+
* });
|
|
335
|
+
*
|
|
336
|
+
* // Add events in random order
|
|
337
|
+
* eventHeap.add({ id: 1, type: 'info', timestamp: 100, message: 'User logged in' });
|
|
338
|
+
* eventHeap.add({ id: 2, type: 'critical', timestamp: 101, message: 'Server down' });
|
|
339
|
+
* eventHeap.add({ id: 3, type: 'warning', timestamp: 102, message: 'High memory' });
|
|
340
|
+
* eventHeap.add({ id: 4, type: 'info', timestamp: 103, message: 'Cache cleared' });
|
|
341
|
+
* eventHeap.add({ id: 5, type: 'critical', timestamp: 104, message: 'Database error' });
|
|
342
|
+
*
|
|
343
|
+
* console.log(eventHeap.size); // 5;
|
|
344
|
+
*
|
|
345
|
+
* // Process events by priority (critical first)
|
|
346
|
+
* const processedOrder: Event[] = [];
|
|
347
|
+
* while (eventHeap.size > 0) {
|
|
348
|
+
* const event = eventHeap.poll();
|
|
349
|
+
* if (event) {
|
|
350
|
+
* processedOrder.push(event);
|
|
351
|
+
* }
|
|
352
|
+
* }
|
|
353
|
+
*
|
|
354
|
+
* // Verify critical events came first
|
|
355
|
+
* console.log(processedOrder[0].type); // 'critical';
|
|
356
|
+
* console.log(processedOrder[1].type); // 'critical';
|
|
357
|
+
* console.log(processedOrder[2].type); // 'warning';
|
|
358
|
+
* console.log(processedOrder[3].type); // 'info';
|
|
359
|
+
* console.log(processedOrder[4].type); // 'info';
|
|
360
|
+
*
|
|
361
|
+
* // Verify O(log n) operations
|
|
362
|
+
* const newHeap = new Heap<number>([5, 3, 7, 1]);
|
|
363
|
+
*
|
|
364
|
+
* // Add - O(log n)
|
|
365
|
+
* newHeap.add(2);
|
|
366
|
+
* console.log(newHeap.size); // 5;
|
|
367
|
+
*
|
|
368
|
+
* // Poll - O(log n)
|
|
369
|
+
* const removed = newHeap.poll();
|
|
370
|
+
* console.log(removed); // 1;
|
|
371
|
+
*
|
|
372
|
+
* // Peek - O(1)
|
|
373
|
+
* const top = newHeap.peek();
|
|
374
|
+
* console.log(top); // 2;
|
|
575
375
|
*/
|
|
576
376
|
peek(): E | undefined;
|
|
577
377
|
/**
|
|
578
378
|
* Check whether the heap is empty.
|
|
579
379
|
* @remarks Time O(1), Space O(1)
|
|
580
380
|
* @returns True if size is 0.
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
* @example
|
|
622
|
-
* // Check if heap is empty
|
|
623
|
-
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
624
|
-
* console.log(heap.isEmpty()); // true;
|
|
625
|
-
* heap.add(1);
|
|
626
|
-
* console.log(heap.isEmpty()); // false;
|
|
381
|
+
* @example
|
|
382
|
+
* // Check if heap is empty
|
|
383
|
+
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
384
|
+
* console.log(heap.isEmpty()); // true;
|
|
385
|
+
* heap.add(1);
|
|
386
|
+
* console.log(heap.isEmpty()); // false;
|
|
627
387
|
*/
|
|
628
388
|
isEmpty(): boolean;
|
|
629
389
|
/**
|
|
630
390
|
* Remove all elements.
|
|
631
391
|
* @remarks Time O(1), Space O(1)
|
|
632
392
|
* @returns void
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
* @example
|
|
674
|
-
* // Remove all elements
|
|
675
|
-
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
676
|
-
* heap.clear();
|
|
677
|
-
* console.log(heap.isEmpty()); // true;
|
|
393
|
+
* @example
|
|
394
|
+
* // Remove all elements
|
|
395
|
+
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
396
|
+
* heap.clear();
|
|
397
|
+
* console.log(heap.isEmpty()); // true;
|
|
678
398
|
*/
|
|
679
399
|
clear(): void;
|
|
680
400
|
/**
|
|
@@ -682,44 +402,11 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
682
402
|
* @remarks Time O(N), Space O(1)
|
|
683
403
|
* @param element - Element to search for.
|
|
684
404
|
* @returns True if found.
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
* @example
|
|
719
|
-
* // Check element existence
|
|
720
|
-
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
721
|
-
* console.log(heap.has(1)); // true;
|
|
722
|
-
* console.log(heap.has(99)); // false;
|
|
405
|
+
* @example
|
|
406
|
+
* // Check element existence
|
|
407
|
+
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
408
|
+
* console.log(heap.has(1)); // true;
|
|
409
|
+
* console.log(heap.has(99)); // false;
|
|
723
410
|
*/
|
|
724
411
|
has(element: E): boolean;
|
|
725
412
|
/**
|
|
@@ -727,50 +414,11 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
727
414
|
* @remarks Time O(N), Space O(1)
|
|
728
415
|
* @param element - Element to delete.
|
|
729
416
|
* @returns True if an element was removed.
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
* @example
|
|
770
|
-
* // Remove specific element
|
|
771
|
-
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
772
|
-
* heap.delete(4);
|
|
773
|
-
* console.log(heap.toArray().includes(4)); // false;
|
|
417
|
+
* @example
|
|
418
|
+
* // Remove specific element
|
|
419
|
+
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
420
|
+
* heap.delete(4);
|
|
421
|
+
* console.log(heap.toArray().includes(4)); // false;
|
|
774
422
|
*/
|
|
775
423
|
delete(element: E): boolean;
|
|
776
424
|
/**
|
|
@@ -796,44 +444,11 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
796
444
|
* @remarks Time O(N), Space O(H)
|
|
797
445
|
* @param [order] - Traversal order: 'PRE' | 'IN' | 'POST'.
|
|
798
446
|
* @returns Array of visited elements.
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
* @example
|
|
833
|
-
* // Depth-first traversal
|
|
834
|
-
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
835
|
-
* const result = heap.dfs('IN');
|
|
836
|
-
* console.log(result.length); // 3;
|
|
447
|
+
* @example
|
|
448
|
+
* // Depth-first traversal
|
|
449
|
+
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
450
|
+
* const result = heap.dfs('IN');
|
|
451
|
+
* console.log(result.length); // 3;
|
|
837
452
|
*/
|
|
838
453
|
dfs(order?: DFSOrderPattern): E[];
|
|
839
454
|
/**
|
|
@@ -846,106 +461,24 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
846
461
|
* Return all elements in ascending order by repeatedly polling.
|
|
847
462
|
* @remarks Time O(N log N), Space O(N)
|
|
848
463
|
* @returns Sorted array of elements.
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
* @example
|
|
892
|
-
* // Sort elements using heap
|
|
893
|
-
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
894
|
-
* const sorted = heap.sort();
|
|
895
|
-
* console.log(sorted); // [1, 2, 3, 4, 5];
|
|
464
|
+
* @example
|
|
465
|
+
* // Sort elements using heap
|
|
466
|
+
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
467
|
+
* const sorted = heap.sort();
|
|
468
|
+
* console.log(sorted); // [1, 2, 3, 4, 5];
|
|
896
469
|
*/
|
|
897
470
|
sort(): E[];
|
|
898
471
|
/**
|
|
899
472
|
* Deep clone this heap.
|
|
900
473
|
* @remarks Time O(N), Space O(N)
|
|
901
474
|
* @returns A new heap with the same elements.
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
* @example
|
|
943
|
-
* // Create independent copy
|
|
944
|
-
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
945
|
-
* const copy = heap.clone();
|
|
946
|
-
* copy.poll();
|
|
947
|
-
* console.log(heap.size); // 3;
|
|
948
|
-
* console.log(copy.size); // 2;
|
|
475
|
+
* @example
|
|
476
|
+
* // Create independent copy
|
|
477
|
+
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
478
|
+
* const copy = heap.clone();
|
|
479
|
+
* copy.poll();
|
|
480
|
+
* console.log(heap.size); // 3;
|
|
481
|
+
* console.log(copy.size); // 2;
|
|
949
482
|
*/
|
|
950
483
|
clone(): this;
|
|
951
484
|
/**
|
|
@@ -954,51 +487,11 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
954
487
|
* @param callback - Predicate (element, index, heap) → boolean to keep element.
|
|
955
488
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
956
489
|
* @returns A new heap with the kept elements.
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
* @example
|
|
998
|
-
* // Filter elements
|
|
999
|
-
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
1000
|
-
* const evens = heap.filter(x => x % 2 === 0);
|
|
1001
|
-
* console.log(evens.size); // 2;
|
|
490
|
+
* @example
|
|
491
|
+
* // Filter elements
|
|
492
|
+
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
493
|
+
* const evens = heap.filter(x => x % 2 === 0);
|
|
494
|
+
* console.log(evens.size); // 2;
|
|
1002
495
|
*/
|
|
1003
496
|
filter(callback: ElementCallback<E, R, boolean>, thisArg?: unknown): this;
|
|
1004
497
|
/**
|
|
@@ -1010,50 +503,11 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
1010
503
|
* @param options - Options for the output heap, including comparator for EM.
|
|
1011
504
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
1012
505
|
* @returns A new heap with mapped elements.
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
* @example
|
|
1053
|
-
* // Transform elements
|
|
1054
|
-
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
1055
|
-
* const doubled = heap.map(x => x * 2, { comparator: (a, b) => a - b });
|
|
1056
|
-
* console.log(doubled.peek()); // 2;
|
|
506
|
+
* @example
|
|
507
|
+
* // Transform elements
|
|
508
|
+
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
509
|
+
* const doubled = heap.map(x => x * 2, { comparator: (a, b) => a - b });
|
|
510
|
+
* console.log(doubled.peek()); // 2;
|
|
1057
511
|
*/
|
|
1058
512
|
map<EM, RM>(callback: ElementCallback<E, R, EM>, options: HeapOptions<EM, RM> & {
|
|
1059
513
|
comparator: Comparator<EM>;
|
|
@@ -1068,12 +522,6 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
1068
522
|
mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this;
|
|
1069
523
|
protected readonly _DEFAULT_COMPARATOR: Comparator<E>;
|
|
1070
524
|
protected readonly _comparator: Comparator<E>;
|
|
1071
|
-
/**
|
|
1072
|
-
* Get the comparator used to order elements.
|
|
1073
|
-
* @remarks Time O(1), Space O(1)
|
|
1074
|
-
* @returns Comparator function.
|
|
1075
|
-
*/
|
|
1076
|
-
get comparator(): Comparator<E>;
|
|
1077
525
|
protected _getIterator(): IterableIterator<E>;
|
|
1078
526
|
protected _bubbleUp(index: number): boolean;
|
|
1079
527
|
protected _sinkDown(index: number, halfLength: number): boolean;
|
|
@@ -1126,6 +574,7 @@ export declare class FibonacciHeapNode<E> {
|
|
|
1126
574
|
* @example examples will be generated by unit test
|
|
1127
575
|
*/
|
|
1128
576
|
export declare class FibonacciHeap<E> {
|
|
577
|
+
protected readonly _comparator: Comparator<E>;
|
|
1129
578
|
/**
|
|
1130
579
|
* Create a FibonacciHeap.
|
|
1131
580
|
* @remarks Time O(1), Space O(1)
|
|
@@ -1149,7 +598,6 @@ export declare class FibonacciHeap<E> {
|
|
|
1149
598
|
* @returns Min node or undefined.
|
|
1150
599
|
*/
|
|
1151
600
|
get min(): FibonacciHeapNode<E> | undefined;
|
|
1152
|
-
protected readonly _comparator: Comparator<E>;
|
|
1153
601
|
get comparator(): Comparator<E>;
|
|
1154
602
|
clear(): void;
|
|
1155
603
|
add(element: E): boolean;
|