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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: MinPriorityQueue\<E, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/priority-queue/min-priority-queue.ts:
|
|
9
|
+
Defined in: [data-structures/priority-queue/min-priority-queue.ts:74](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/priority-queue/min-priority-queue.ts#L74)
|
|
10
10
|
|
|
11
11
|
Min-oriented priority queue (min-heap) built on [PriorityQueue](PriorityQueue.md).
|
|
12
12
|
The queue removes the smallest element first under the provided comparator.
|
|
@@ -18,10 +18,10 @@ Provide a custom comparator if you store non-primitive objects.
|
|
|
18
18
|
// Shortest job first scheduling
|
|
19
19
|
const jobs = new MinPriorityQueue<number>();
|
|
20
20
|
|
|
21
|
-
jobs.add(8);
|
|
22
|
-
jobs.add(2);
|
|
23
|
-
jobs.add(5);
|
|
24
|
-
jobs.add(1);
|
|
21
|
+
jobs.add(8); // 8 seconds
|
|
22
|
+
jobs.add(2); // 2 seconds
|
|
23
|
+
jobs.add(5); // 5 seconds
|
|
24
|
+
jobs.add(1); // 1 second
|
|
25
25
|
|
|
26
26
|
// Shortest job first
|
|
27
27
|
console.log(jobs.poll()); // 1;
|
|
@@ -50,12 +50,7 @@ Provide a custom comparator if you store non-primitive objects.
|
|
|
50
50
|
while (timeline.size > 0) {
|
|
51
51
|
order.push(timeline.poll()!.action);
|
|
52
52
|
}
|
|
53
|
-
console.log(order); // [
|
|
54
|
-
// 'Request received',
|
|
55
|
-
// 'Cache hit',
|
|
56
|
-
// 'Processing done',
|
|
57
|
-
// 'Timeout'
|
|
58
|
-
// ];
|
|
53
|
+
console.log(order); // ['Request received', 'Cache hit', 'Processing done', 'Timeout'];
|
|
59
54
|
```
|
|
60
55
|
|
|
61
56
|
```ts
|
|
@@ -73,7 +68,7 @@ Provide a custom comparator if you store non-primitive objects.
|
|
|
73
68
|
// Always pick two lowest frequencies
|
|
74
69
|
const first = freq.poll()!;
|
|
75
70
|
const second = freq.poll()!;
|
|
76
|
-
console.log(first[1]); // 'd';
|
|
71
|
+
console.log(first[1]); // 'd'; // freq 2
|
|
77
72
|
console.log(second[1]); // 'a'; // freq 5
|
|
78
73
|
|
|
79
74
|
// Combined node goes back
|
|
@@ -107,7 +102,7 @@ Extra record/metadata associated with each element.
|
|
|
107
102
|
new MinPriorityQueue<E, R>(elements?, options?): MinPriorityQueue<E, R>;
|
|
108
103
|
```
|
|
109
104
|
|
|
110
|
-
Defined in: [data-structures/priority-queue/min-priority-queue.ts:
|
|
105
|
+
Defined in: [data-structures/priority-queue/min-priority-queue.ts:81](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/priority-queue/min-priority-queue.ts#L81)
|
|
111
106
|
|
|
112
107
|
Creates a min-priority queue.
|
|
113
108
|
|
|
@@ -149,7 +144,7 @@ PriorityQueue<E, R>.constructor
|
|
|
149
144
|
get comparator(): Comparator<E>;
|
|
150
145
|
```
|
|
151
146
|
|
|
152
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
147
|
+
Defined in: [data-structures/heap/heap.ts:211](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L211)
|
|
153
148
|
|
|
154
149
|
Get the comparator used to order elements.
|
|
155
150
|
|
|
@@ -177,7 +172,7 @@ Comparator function.
|
|
|
177
172
|
get elements(): E[];
|
|
178
173
|
```
|
|
179
174
|
|
|
180
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
175
|
+
Defined in: [data-structures/heap/heap.ts:175](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L175)
|
|
181
176
|
|
|
182
177
|
Get the backing array of the heap.
|
|
183
178
|
|
|
@@ -205,7 +200,7 @@ Internal elements array.
|
|
|
205
200
|
get leaf(): E | undefined;
|
|
206
201
|
```
|
|
207
202
|
|
|
208
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
203
|
+
Defined in: [data-structures/heap/heap.ts:202](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L202)
|
|
209
204
|
|
|
210
205
|
Get the last leaf element.
|
|
211
206
|
|
|
@@ -233,7 +228,7 @@ Last element or undefined.
|
|
|
233
228
|
get size(): number;
|
|
234
229
|
```
|
|
235
230
|
|
|
236
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
231
|
+
Defined in: [data-structures/heap/heap.ts:193](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L193)
|
|
237
232
|
|
|
238
233
|
Get the number of elements.
|
|
239
234
|
|
|
@@ -260,8 +255,6 @@ Time O(1), Space O(1)
|
|
|
260
255
|
|
|
261
256
|
Heap size.
|
|
262
257
|
|
|
263
|
-
*
|
|
264
|
-
|
|
265
258
|
#### Inherited from
|
|
266
259
|
|
|
267
260
|
[`PriorityQueue`](PriorityQueue.md).[`size`](PriorityQueue.md#size)
|
|
@@ -336,7 +329,7 @@ Producing the iterator is O(1); consuming the entire iterator is Time O(n) with
|
|
|
336
329
|
add(element): boolean;
|
|
337
330
|
```
|
|
338
331
|
|
|
339
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
332
|
+
Defined in: [data-structures/heap/heap.ts:267](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L267)
|
|
340
333
|
|
|
341
334
|
Insert an element.
|
|
342
335
|
|
|
@@ -354,8 +347,6 @@ Element to insert.
|
|
|
354
347
|
|
|
355
348
|
True.
|
|
356
349
|
|
|
357
|
-
*
|
|
358
|
-
|
|
359
350
|
#### Remarks
|
|
360
351
|
|
|
361
352
|
Time O(log N) amortized, Space O(1)
|
|
@@ -391,7 +382,7 @@ Time O(log N) amortized, Space O(1)
|
|
|
391
382
|
addMany(elements): boolean[];
|
|
392
383
|
```
|
|
393
384
|
|
|
394
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
385
|
+
Defined in: [data-structures/heap/heap.ts:284](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L284)
|
|
395
386
|
|
|
396
387
|
Insert many elements from an iterable.
|
|
397
388
|
|
|
@@ -409,8 +400,6 @@ Iterable of elements or raw values.
|
|
|
409
400
|
|
|
410
401
|
Array of per-element success flags.
|
|
411
402
|
|
|
412
|
-
*
|
|
413
|
-
|
|
414
403
|
#### Remarks
|
|
415
404
|
|
|
416
405
|
Time O(N log N), Space O(1)
|
|
@@ -437,7 +426,7 @@ Time O(N log N), Space O(1)
|
|
|
437
426
|
clear(): void;
|
|
438
427
|
```
|
|
439
428
|
|
|
440
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
429
|
+
Defined in: [data-structures/heap/heap.ts:469](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L469)
|
|
441
430
|
|
|
442
431
|
Remove all elements.
|
|
443
432
|
|
|
@@ -447,8 +436,6 @@ Remove all elements.
|
|
|
447
436
|
|
|
448
437
|
void
|
|
449
438
|
|
|
450
|
-
*
|
|
451
|
-
|
|
452
439
|
#### Remarks
|
|
453
440
|
|
|
454
441
|
Time O(1), Space O(1)
|
|
@@ -474,7 +461,7 @@ Time O(1), Space O(1)
|
|
|
474
461
|
clone(): this;
|
|
475
462
|
```
|
|
476
463
|
|
|
477
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
464
|
+
Defined in: [data-structures/heap/heap.ts:648](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L648)
|
|
478
465
|
|
|
479
466
|
Deep clone this heap.
|
|
480
467
|
|
|
@@ -484,8 +471,6 @@ Deep clone this heap.
|
|
|
484
471
|
|
|
485
472
|
A new heap with the same elements.
|
|
486
473
|
|
|
487
|
-
*
|
|
488
|
-
|
|
489
474
|
#### Remarks
|
|
490
475
|
|
|
491
476
|
Time O(N), Space O(N)
|
|
@@ -513,7 +498,7 @@ Time O(N), Space O(N)
|
|
|
513
498
|
delete(element): boolean;
|
|
514
499
|
```
|
|
515
500
|
|
|
516
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
501
|
+
Defined in: [data-structures/heap/heap.ts:500](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L500)
|
|
517
502
|
|
|
518
503
|
Delete one occurrence of an element.
|
|
519
504
|
|
|
@@ -531,8 +516,6 @@ Element to delete.
|
|
|
531
516
|
|
|
532
517
|
True if an element was removed.
|
|
533
518
|
|
|
534
|
-
*
|
|
535
|
-
|
|
536
519
|
#### Remarks
|
|
537
520
|
|
|
538
521
|
Time O(N), Space O(1)
|
|
@@ -558,7 +541,7 @@ Time O(N), Space O(1)
|
|
|
558
541
|
deleteBy(predicate): boolean;
|
|
559
542
|
```
|
|
560
543
|
|
|
561
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
544
|
+
Defined in: [data-structures/heap/heap.ts:524](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L524)
|
|
562
545
|
|
|
563
546
|
#### Parameters
|
|
564
547
|
|
|
@@ -586,7 +569,7 @@ Use `deleteWhere` instead. Will be removed in a future major version.
|
|
|
586
569
|
deleteWhere(predicate): boolean;
|
|
587
570
|
```
|
|
588
571
|
|
|
589
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
572
|
+
Defined in: [data-structures/heap/heap.ts:534](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L534)
|
|
590
573
|
|
|
591
574
|
Delete the first element that matches a predicate.
|
|
592
575
|
|
|
@@ -620,7 +603,7 @@ Time O(N), Space O(1)
|
|
|
620
603
|
dfs(order?): E[];
|
|
621
604
|
```
|
|
622
605
|
|
|
623
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
606
|
+
Defined in: [data-structures/heap/heap.ts:577](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L577)
|
|
624
607
|
|
|
625
608
|
Traverse the binary heap as a complete binary tree and collect elements.
|
|
626
609
|
|
|
@@ -638,8 +621,6 @@ Traversal order: 'PRE' | 'IN' | 'POST'.
|
|
|
638
621
|
|
|
639
622
|
Array of visited elements.
|
|
640
623
|
|
|
641
|
-
*
|
|
642
|
-
|
|
643
624
|
#### Remarks
|
|
644
625
|
|
|
645
626
|
Time O(N), Space O(H)
|
|
@@ -659,6 +640,30 @@ Time O(N), Space O(H)
|
|
|
659
640
|
|
|
660
641
|
***
|
|
661
642
|
|
|
643
|
+
### entries()
|
|
644
|
+
|
|
645
|
+
```ts
|
|
646
|
+
entries(): IterableIterator<[number, E]>;
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
Defined in: [data-structures/base/iterable-element-base.ts:207](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L207)
|
|
650
|
+
|
|
651
|
+
Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
652
|
+
|
|
653
|
+
#### Returns
|
|
654
|
+
|
|
655
|
+
`IterableIterator`\<\[`number`, `E`\]\>
|
|
656
|
+
|
|
657
|
+
#### Remarks
|
|
658
|
+
|
|
659
|
+
Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
660
|
+
|
|
661
|
+
#### Inherited from
|
|
662
|
+
|
|
663
|
+
[`PriorityQueue`](PriorityQueue.md).[`entries`](PriorityQueue.md#entries)
|
|
664
|
+
|
|
665
|
+
***
|
|
666
|
+
|
|
662
667
|
### every()
|
|
663
668
|
|
|
664
669
|
```ts
|
|
@@ -705,7 +710,7 @@ Time O(n) in the worst case; may exit early when the first failure is found. Spa
|
|
|
705
710
|
filter(callback, thisArg?): this;
|
|
706
711
|
```
|
|
707
712
|
|
|
708
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
713
|
+
Defined in: [data-structures/heap/heap.ts:666](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L666)
|
|
709
714
|
|
|
710
715
|
Filter elements into a new heap of the same class.
|
|
711
716
|
|
|
@@ -729,8 +734,6 @@ Value for `this` inside the callback.
|
|
|
729
734
|
|
|
730
735
|
A new heap with the kept elements.
|
|
731
736
|
|
|
732
|
-
*
|
|
733
|
-
|
|
734
737
|
#### Remarks
|
|
735
738
|
|
|
736
739
|
Time O(N log N), Space O(N)
|
|
@@ -846,7 +849,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
846
849
|
fix(): boolean[];
|
|
847
850
|
```
|
|
848
851
|
|
|
849
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
852
|
+
Defined in: [data-structures/heap/heap.ts:607](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L607)
|
|
850
853
|
|
|
851
854
|
Restore heap order bottom-up (heapify in-place).
|
|
852
855
|
|
|
@@ -912,7 +915,7 @@ Time O(n), Space O(1).
|
|
|
912
915
|
has(element): boolean;
|
|
913
916
|
```
|
|
914
917
|
|
|
915
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
918
|
+
Defined in: [data-structures/heap/heap.ts:484](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L484)
|
|
916
919
|
|
|
917
920
|
Check if an equal element exists in the heap.
|
|
918
921
|
|
|
@@ -930,8 +933,6 @@ Element to search for.
|
|
|
930
933
|
|
|
931
934
|
True if found.
|
|
932
935
|
|
|
933
|
-
*
|
|
934
|
-
|
|
935
936
|
#### Remarks
|
|
936
937
|
|
|
937
938
|
Time O(N), Space O(1)
|
|
@@ -951,13 +952,47 @@ Time O(N), Space O(1)
|
|
|
951
952
|
|
|
952
953
|
***
|
|
953
954
|
|
|
955
|
+
### includes()
|
|
956
|
+
|
|
957
|
+
```ts
|
|
958
|
+
includes(element): boolean;
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
Defined in: [data-structures/base/iterable-element-base.ts:199](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L199)
|
|
962
|
+
|
|
963
|
+
Check whether a value exists (Array-compatible alias for `has`).
|
|
964
|
+
|
|
965
|
+
#### Parameters
|
|
966
|
+
|
|
967
|
+
##### element
|
|
968
|
+
|
|
969
|
+
`E`
|
|
970
|
+
|
|
971
|
+
Element to search for (uses `===`).
|
|
972
|
+
|
|
973
|
+
#### Returns
|
|
974
|
+
|
|
975
|
+
`boolean`
|
|
976
|
+
|
|
977
|
+
`true` if found.
|
|
978
|
+
|
|
979
|
+
#### Remarks
|
|
980
|
+
|
|
981
|
+
Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
982
|
+
|
|
983
|
+
#### Inherited from
|
|
984
|
+
|
|
985
|
+
[`PriorityQueue`](PriorityQueue.md).[`includes`](PriorityQueue.md#includes)
|
|
986
|
+
|
|
987
|
+
***
|
|
988
|
+
|
|
954
989
|
### isEmpty()
|
|
955
990
|
|
|
956
991
|
```ts
|
|
957
992
|
isEmpty(): boolean;
|
|
958
993
|
```
|
|
959
994
|
|
|
960
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
995
|
+
Defined in: [data-structures/heap/heap.ts:455](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L455)
|
|
961
996
|
|
|
962
997
|
Check whether the heap is empty.
|
|
963
998
|
|
|
@@ -967,8 +1002,6 @@ Check whether the heap is empty.
|
|
|
967
1002
|
|
|
968
1003
|
True if size is 0.
|
|
969
1004
|
|
|
970
|
-
*
|
|
971
|
-
|
|
972
1005
|
#### Remarks
|
|
973
1006
|
|
|
974
1007
|
Time O(1), Space O(1)
|
|
@@ -989,6 +1022,30 @@ Time O(1), Space O(1)
|
|
|
989
1022
|
|
|
990
1023
|
***
|
|
991
1024
|
|
|
1025
|
+
### keys()
|
|
1026
|
+
|
|
1027
|
+
```ts
|
|
1028
|
+
keys(): IterableIterator<number>;
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
Defined in: [data-structures/base/iterable-element-base.ts:218](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L218)
|
|
1032
|
+
|
|
1033
|
+
Return an iterator of numeric indices (Array-compatible).
|
|
1034
|
+
|
|
1035
|
+
#### Returns
|
|
1036
|
+
|
|
1037
|
+
`IterableIterator`\<`number`\>
|
|
1038
|
+
|
|
1039
|
+
#### Remarks
|
|
1040
|
+
|
|
1041
|
+
Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
1042
|
+
|
|
1043
|
+
#### Inherited from
|
|
1044
|
+
|
|
1045
|
+
[`PriorityQueue`](PriorityQueue.md).[`keys`](PriorityQueue.md#keys)
|
|
1046
|
+
|
|
1047
|
+
***
|
|
1048
|
+
|
|
992
1049
|
### map()
|
|
993
1050
|
|
|
994
1051
|
```ts
|
|
@@ -998,7 +1055,7 @@ map<EM, RM>(
|
|
|
998
1055
|
thisArg?): Heap<EM, RM>;
|
|
999
1056
|
```
|
|
1000
1057
|
|
|
1001
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1058
|
+
Defined in: [data-structures/heap/heap.ts:694](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L694)
|
|
1002
1059
|
|
|
1003
1060
|
Map elements into a new heap of possibly different element type.
|
|
1004
1061
|
|
|
@@ -1038,8 +1095,6 @@ Value for `this` inside the callback.
|
|
|
1038
1095
|
|
|
1039
1096
|
A new heap with mapped elements.
|
|
1040
1097
|
|
|
1041
|
-
*
|
|
1042
|
-
|
|
1043
1098
|
#### Remarks
|
|
1044
1099
|
|
|
1045
1100
|
Time O(N log N), Space O(N)
|
|
@@ -1065,7 +1120,7 @@ Time O(N log N), Space O(N)
|
|
|
1065
1120
|
mapSame(callback, thisArg?): this;
|
|
1066
1121
|
```
|
|
1067
1122
|
|
|
1068
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1123
|
+
Defined in: [data-structures/heap/heap.ts:717](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L717)
|
|
1069
1124
|
|
|
1070
1125
|
Map elements into a new heap of the same element type.
|
|
1071
1126
|
|
|
@@ -1105,7 +1160,7 @@ Time O(N log N), Space O(N)
|
|
|
1105
1160
|
peek(): E | undefined;
|
|
1106
1161
|
```
|
|
1107
1162
|
|
|
1108
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1163
|
+
Defined in: [data-structures/heap/heap.ts:440](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L440)
|
|
1109
1164
|
|
|
1110
1165
|
Get the current top element without removing it.
|
|
1111
1166
|
|
|
@@ -1115,8 +1170,6 @@ Get the current top element without removing it.
|
|
|
1115
1170
|
|
|
1116
1171
|
Top element or undefined.
|
|
1117
1172
|
|
|
1118
|
-
*
|
|
1119
|
-
|
|
1120
1173
|
#### Remarks
|
|
1121
1174
|
|
|
1122
1175
|
Time O(1), Space O(1)
|
|
@@ -1196,7 +1249,7 @@ Time O(1), Space O(1)
|
|
|
1196
1249
|
poll(): E | undefined;
|
|
1197
1250
|
```
|
|
1198
1251
|
|
|
1199
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1252
|
+
Defined in: [data-structures/heap/heap.ts:356](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L356)
|
|
1200
1253
|
|
|
1201
1254
|
#### Returns
|
|
1202
1255
|
|
|
@@ -1205,7 +1258,6 @@ Defined in: [data-structures/heap/heap.ts:511](https://github.com/zrwusa/data-st
|
|
|
1205
1258
|
#### Deprecated
|
|
1206
1259
|
|
|
1207
1260
|
Use `pop` instead. Will be removed in a future major version.
|
|
1208
|
-
*
|
|
1209
1261
|
|
|
1210
1262
|
#### Example
|
|
1211
1263
|
|
|
@@ -1248,7 +1300,7 @@ Use `pop` instead. Will be removed in a future major version.
|
|
|
1248
1300
|
pop(): E | undefined;
|
|
1249
1301
|
```
|
|
1250
1302
|
|
|
1251
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1303
|
+
Defined in: [data-structures/heap/heap.ts:365](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L365)
|
|
1252
1304
|
|
|
1253
1305
|
Remove and return the top element (min or max depending on comparator).
|
|
1254
1306
|
|
|
@@ -1274,7 +1326,7 @@ Time O(log N) amortized, Space O(1)
|
|
|
1274
1326
|
print(): void;
|
|
1275
1327
|
```
|
|
1276
1328
|
|
|
1277
|
-
Defined in: [data-structures/base/iterable-element-base.ts:
|
|
1329
|
+
Defined in: [data-structures/base/iterable-element-base.ts:298](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L298)
|
|
1278
1330
|
|
|
1279
1331
|
Prints `toVisual()` to the console. Intended for quick debugging.
|
|
1280
1332
|
|
|
@@ -1332,7 +1384,7 @@ Time O(n), Space O(1). Throws if called on an empty structure without `initialVa
|
|
|
1332
1384
|
reduce(callbackfn): E;
|
|
1333
1385
|
```
|
|
1334
1386
|
|
|
1335
|
-
Defined in: [data-structures/base/iterable-element-base.ts:
|
|
1387
|
+
Defined in: [data-structures/base/iterable-element-base.ts:225](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L225)
|
|
1336
1388
|
|
|
1337
1389
|
##### Parameters
|
|
1338
1390
|
|
|
@@ -1354,7 +1406,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.c
|
|
|
1354
1406
|
reduce(callbackfn, initialValue): E;
|
|
1355
1407
|
```
|
|
1356
1408
|
|
|
1357
|
-
Defined in: [data-structures/base/iterable-element-base.ts:
|
|
1409
|
+
Defined in: [data-structures/base/iterable-element-base.ts:226](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L226)
|
|
1358
1410
|
|
|
1359
1411
|
##### Parameters
|
|
1360
1412
|
|
|
@@ -1380,7 +1432,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.c
|
|
|
1380
1432
|
reduce<U>(callbackfn, initialValue): U;
|
|
1381
1433
|
```
|
|
1382
1434
|
|
|
1383
|
-
Defined in: [data-structures/base/iterable-element-base.ts:
|
|
1435
|
+
Defined in: [data-structures/base/iterable-element-base.ts:227](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L227)
|
|
1384
1436
|
|
|
1385
1437
|
##### Type Parameters
|
|
1386
1438
|
|
|
@@ -1414,7 +1466,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.c
|
|
|
1414
1466
|
setEquality(equals): this;
|
|
1415
1467
|
```
|
|
1416
1468
|
|
|
1417
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1469
|
+
Defined in: [data-structures/heap/heap.ts:561](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L561)
|
|
1418
1470
|
|
|
1419
1471
|
Set the equality comparator used by has/delete operations.
|
|
1420
1472
|
|
|
@@ -1488,7 +1540,7 @@ Time O(n) in the worst case; may exit early on first success. Space O(1).
|
|
|
1488
1540
|
sort(): E[];
|
|
1489
1541
|
```
|
|
1490
1542
|
|
|
1491
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1543
|
+
Defined in: [data-structures/heap/heap.ts:625](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L625)
|
|
1492
1544
|
|
|
1493
1545
|
Return all elements in ascending order by repeatedly polling.
|
|
1494
1546
|
|
|
@@ -1498,8 +1550,6 @@ Return all elements in ascending order by repeatedly polling.
|
|
|
1498
1550
|
|
|
1499
1551
|
Sorted array of elements.
|
|
1500
1552
|
|
|
1501
|
-
*
|
|
1502
|
-
|
|
1503
1553
|
#### Remarks
|
|
1504
1554
|
|
|
1505
1555
|
Time O(N log N), Space O(N)
|
|
@@ -1525,7 +1575,7 @@ Time O(N log N), Space O(N)
|
|
|
1525
1575
|
toArray(): E[];
|
|
1526
1576
|
```
|
|
1527
1577
|
|
|
1528
|
-
Defined in: [data-structures/base/iterable-element-base.ts:
|
|
1578
|
+
Defined in: [data-structures/base/iterable-element-base.ts:275](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L275)
|
|
1529
1579
|
|
|
1530
1580
|
Materializes the elements into a new array.
|
|
1531
1581
|
|
|
@@ -1551,7 +1601,7 @@ Time O(n), Space O(n).
|
|
|
1551
1601
|
toVisual(): E[];
|
|
1552
1602
|
```
|
|
1553
1603
|
|
|
1554
|
-
Defined in: [data-structures/base/iterable-element-base.ts:
|
|
1604
|
+
Defined in: [data-structures/base/iterable-element-base.ts:287](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L287)
|
|
1555
1605
|
|
|
1556
1606
|
Returns a representation of the structure suitable for quick visualization.
|
|
1557
1607
|
Defaults to an array of elements; subclasses may override to provide richer visuals.
|
|
@@ -1607,7 +1657,7 @@ static from<T, R, S>(
|
|
|
1607
1657
|
options?): S;
|
|
1608
1658
|
```
|
|
1609
1659
|
|
|
1610
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1660
|
+
Defined in: [data-structures/heap/heap.ts:225](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L225)
|
|
1611
1661
|
|
|
1612
1662
|
Create a heap of the same class from an iterable.
|
|
1613
1663
|
|
|
@@ -1665,7 +1715,7 @@ Time O(N), Space O(N)
|
|
|
1665
1715
|
static heapify<EE, RR>(elements, options): Heap<EE, RR>;
|
|
1666
1716
|
```
|
|
1667
1717
|
|
|
1668
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1718
|
+
Defined in: [data-structures/heap/heap.ts:242](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L242)
|
|
1669
1719
|
|
|
1670
1720
|
Build a Heap from an iterable in linear time given a comparator.
|
|
1671
1721
|
|
|
@@ -1748,7 +1798,7 @@ Time O(1), Space O(1).
|
|
|
1748
1798
|
protected _createInstance(options?): this;
|
|
1749
1799
|
```
|
|
1750
1800
|
|
|
1751
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1801
|
+
Defined in: [data-structures/heap/heap.ts:779](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L779)
|
|
1752
1802
|
|
|
1753
1803
|
(Protected) Create an empty instance of the same concrete class.
|
|
1754
1804
|
|
|
@@ -1782,7 +1832,7 @@ Time O(1), Space O(1)
|
|
|
1782
1832
|
protected _createLike<EM, RM>(elements?, options?): Heap<EM, RM>;
|
|
1783
1833
|
```
|
|
1784
1834
|
|
|
1785
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1835
|
+
Defined in: [data-structures/heap/heap.ts:793](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L793)
|
|
1786
1836
|
|
|
1787
1837
|
(Protected) Create a like-kind instance seeded by elements.
|
|
1788
1838
|
|
|
@@ -1832,7 +1882,7 @@ Time O(N log N), Space O(N)
|
|
|
1832
1882
|
protected _getIterator(): IterableIterator<E>;
|
|
1833
1883
|
```
|
|
1834
1884
|
|
|
1835
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1885
|
+
Defined in: [data-structures/heap/heap.ts:738](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L738)
|
|
1836
1886
|
|
|
1837
1887
|
Internal iterator factory used by the default iterator.
|
|
1838
1888
|
|
|
@@ -1858,7 +1908,7 @@ Implementations should yield in O(1) per element with O(1) extra space when poss
|
|
|
1858
1908
|
protected _spawnLike<EM, RM>(options?): Heap<EM, RM>;
|
|
1859
1909
|
```
|
|
1860
1910
|
|
|
1861
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1911
|
+
Defined in: [data-structures/heap/heap.ts:812](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L812)
|
|
1862
1912
|
|
|
1863
1913
|
(Protected) Spawn an empty like-kind heap instance.
|
|
1864
1914
|
|