data-structure-typed 2.5.2 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +3 -0
- package/CHANGELOG.md +3 -1
- package/MIGRATION.md +217 -0
- package/README.md +80 -8
- package/README_CN.md +569 -143
- package/SPECIFICATION.md +44 -14
- package/SPECIFICATION.zh-CN.md +44 -14
- package/dist/cjs/binary-tree.cjs +5841 -1678
- package/dist/cjs/graph.cjs +422 -14
- package/dist/cjs/hash.cjs +95 -7
- package/dist/cjs/heap.cjs +174 -16
- package/dist/cjs/index.cjs +7751 -2449
- package/dist/cjs/linked-list.cjs +443 -2
- package/dist/cjs/matrix.cjs +56 -0
- package/dist/cjs/priority-queue.cjs +172 -14
- package/dist/cjs/queue.cjs +435 -0
- package/dist/cjs/stack.cjs +103 -4
- package/dist/cjs/trie.cjs +106 -0
- package/dist/cjs-legacy/binary-tree.cjs +5933 -1772
- package/dist/cjs-legacy/graph.cjs +422 -14
- package/dist/cjs-legacy/hash.cjs +95 -7
- package/dist/cjs-legacy/heap.cjs +174 -16
- package/dist/cjs-legacy/index.cjs +8154 -2854
- package/dist/cjs-legacy/linked-list.cjs +443 -2
- package/dist/cjs-legacy/matrix.cjs +56 -0
- package/dist/cjs-legacy/priority-queue.cjs +172 -14
- package/dist/cjs-legacy/queue.cjs +435 -0
- package/dist/cjs-legacy/stack.cjs +103 -4
- package/dist/cjs-legacy/trie.cjs +106 -0
- package/dist/esm/binary-tree.mjs +5841 -1678
- package/dist/esm/graph.mjs +422 -14
- package/dist/esm/hash.mjs +95 -7
- package/dist/esm/heap.mjs +174 -16
- package/dist/esm/index.mjs +7751 -2449
- package/dist/esm/linked-list.mjs +443 -2
- package/dist/esm/matrix.mjs +56 -0
- package/dist/esm/priority-queue.mjs +172 -14
- package/dist/esm/queue.mjs +435 -0
- package/dist/esm/stack.mjs +103 -4
- package/dist/esm/trie.mjs +106 -0
- package/dist/esm-legacy/binary-tree.mjs +5933 -1772
- package/dist/esm-legacy/graph.mjs +422 -14
- package/dist/esm-legacy/hash.mjs +95 -7
- package/dist/esm-legacy/heap.mjs +174 -16
- package/dist/esm-legacy/index.mjs +8154 -2854
- package/dist/esm-legacy/linked-list.mjs +443 -2
- package/dist/esm-legacy/matrix.mjs +56 -0
- package/dist/esm-legacy/priority-queue.mjs +172 -14
- package/dist/esm-legacy/queue.mjs +435 -0
- package/dist/esm-legacy/stack.mjs +103 -4
- package/dist/esm-legacy/trie.mjs +106 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +171 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/data-structure-typed.js +7784 -2484
- package/dist/umd/data-structure-typed.min.js +4 -4
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +188 -200
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +62 -62
- package/docs-site-docusaurus/docs/api/classes/BST.md +183 -195
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +143 -155
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +99 -85
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +100 -70
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +48 -48
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +52 -52
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +46 -42
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +74 -74
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
- package/docs-site-docusaurus/docs/api/classes/Queue.md +111 -59
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +200 -212
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +75 -75
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +37 -37
- package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +107 -36
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +106 -35
- package/docs-site-docusaurus/docs/api/classes/Trie.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +72 -72
- package/docs-site-docusaurus/docs/guide/architecture.md +75 -7
- package/docs-site-docusaurus/docs/guide/concepts.md +53 -34
- package/docs-site-docusaurus/docs/guide/faq.md +53 -0
- package/docs-site-docusaurus/docs/guide/guides.md +8 -9
- package/docs-site-docusaurus/docs/guide/integrations.md +74 -177
- package/docs-site-docusaurus/docs/guide/overview.md +131 -17
- package/docs-site-docusaurus/src/pages/index.tsx +4 -0
- package/docs-site-docusaurus/typedoc.json +1 -0
- package/jest.integration.config.js +1 -2
- package/package.json +10 -7
- package/src/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +88 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
- package/src/data-structures/binary-tree/binary-tree.ts +242 -81
- package/src/data-structures/binary-tree/bst.ts +173 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +948 -36
- package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
- package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
- package/src/data-structures/binary-tree/tree-set.ts +1260 -251
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +100 -12
- package/src/data-structures/heap/heap.ts +149 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
- package/src/data-structures/matrix/matrix.ts +56 -0
- package/src/data-structures/queue/deque.ts +187 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +84 -0
- package/src/interfaces/binary-tree.ts +1 -9
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: MaxPriorityQueue\<E, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/priority-queue/max-priority-queue.ts:77](https://github.com/zrwusa/data-structure-typed/blob/
|
|
9
|
+
Defined in: [data-structures/priority-queue/max-priority-queue.ts:77](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/priority-queue/max-priority-queue.ts#L77)
|
|
10
10
|
|
|
11
11
|
Max-oriented priority queue (max-heap) built on [PriorityQueue](PriorityQueue.md).
|
|
12
12
|
The default comparator orders primitive values in descending order. If you store objects,
|
|
@@ -104,7 +104,7 @@ Extra record/metadata associated with each element.
|
|
|
104
104
|
new MaxPriorityQueue<E, R>(elements?, options?): MaxPriorityQueue<E, R>;
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
Defined in: [data-structures/priority-queue/max-priority-queue.ts:85](https://github.com/zrwusa/data-structure-typed/blob/
|
|
107
|
+
Defined in: [data-structures/priority-queue/max-priority-queue.ts:85](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/priority-queue/max-priority-queue.ts#L85)
|
|
108
108
|
|
|
109
109
|
Creates a max-priority queue.
|
|
110
110
|
|
|
@@ -150,7 +150,7 @@ PriorityQueue<E, R>.constructor
|
|
|
150
150
|
get comparator(): Comparator<E>;
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
153
|
+
Defined in: [data-structures/heap/heap.ts:1272](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1272)
|
|
154
154
|
|
|
155
155
|
Get the comparator used to order elements.
|
|
156
156
|
|
|
@@ -178,7 +178,7 @@ Comparator function.
|
|
|
178
178
|
get elements(): E[];
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/
|
|
181
|
+
Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L180)
|
|
182
182
|
|
|
183
183
|
Get the backing array of the heap.
|
|
184
184
|
|
|
@@ -206,7 +206,7 @@ Internal elements array.
|
|
|
206
206
|
get leaf(): E | undefined;
|
|
207
207
|
```
|
|
208
208
|
|
|
209
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
209
|
+
Defined in: [data-structures/heap/heap.ts:248](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L248)
|
|
210
210
|
|
|
211
211
|
Get the last leaf element.
|
|
212
212
|
|
|
@@ -234,7 +234,7 @@ Last element or undefined.
|
|
|
234
234
|
get size(): number;
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
237
|
+
Defined in: [data-structures/heap/heap.ts:238](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L238)
|
|
238
238
|
|
|
239
239
|
Get the number of elements.
|
|
240
240
|
|
|
@@ -277,7 +277,7 @@ Heap size.
|
|
|
277
277
|
get toElementFn(): ((rawElement) => E) | undefined;
|
|
278
278
|
```
|
|
279
279
|
|
|
280
|
-
Defined in: [data-structures/base/iterable-element-base.ts:48](https://github.com/zrwusa/data-structure-typed/blob/
|
|
280
|
+
Defined in: [data-structures/base/iterable-element-base.ts:48](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L48)
|
|
281
281
|
|
|
282
282
|
Exposes the current `toElementFn`, if configured.
|
|
283
283
|
|
|
@@ -303,7 +303,7 @@ The converter function or `undefined` when not set.
|
|
|
303
303
|
iterator: IterableIterator<E>;
|
|
304
304
|
```
|
|
305
305
|
|
|
306
|
-
Defined in: [data-structures/base/iterable-element-base.ts:61](https://github.com/zrwusa/data-structure-typed/blob/
|
|
306
|
+
Defined in: [data-structures/base/iterable-element-base.ts:61](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L61)
|
|
307
307
|
|
|
308
308
|
Returns an iterator over the structure's elements.
|
|
309
309
|
|
|
@@ -337,7 +337,7 @@ Producing the iterator is O(1); consuming the entire iterator is Time O(n) with
|
|
|
337
337
|
add(element): boolean;
|
|
338
338
|
```
|
|
339
339
|
|
|
340
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
340
|
+
Defined in: [data-structures/heap/heap.ts:346](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L346)
|
|
341
341
|
|
|
342
342
|
Insert an element.
|
|
343
343
|
|
|
@@ -359,7 +359,7 @@ True.
|
|
|
359
359
|
|
|
360
360
|
#### Remarks
|
|
361
361
|
|
|
362
|
-
Time O(
|
|
362
|
+
Time O(log N) amortized, Space O(1)
|
|
363
363
|
|
|
364
364
|
#### Example
|
|
365
365
|
|
|
@@ -392,7 +392,7 @@ Time O(1) amortized, Space O(1)
|
|
|
392
392
|
addMany(elements): boolean[];
|
|
393
393
|
```
|
|
394
394
|
|
|
395
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
395
|
+
Defined in: [data-structures/heap/heap.ts:400](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L400)
|
|
396
396
|
|
|
397
397
|
Insert many elements from an iterable.
|
|
398
398
|
|
|
@@ -438,7 +438,7 @@ Time O(N log N), Space O(1)
|
|
|
438
438
|
clear(): void;
|
|
439
439
|
```
|
|
440
440
|
|
|
441
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
441
|
+
Defined in: [data-structures/heap/heap.ts:740](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L740)
|
|
442
442
|
|
|
443
443
|
Remove all elements.
|
|
444
444
|
|
|
@@ -475,7 +475,7 @@ Time O(1), Space O(1)
|
|
|
475
475
|
clone(): this;
|
|
476
476
|
```
|
|
477
477
|
|
|
478
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
478
|
+
Defined in: [data-structures/heap/heap.ts:1100](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1100)
|
|
479
479
|
|
|
480
480
|
Deep clone this heap.
|
|
481
481
|
|
|
@@ -514,7 +514,7 @@ Time O(N), Space O(N)
|
|
|
514
514
|
delete(element): boolean;
|
|
515
515
|
```
|
|
516
516
|
|
|
517
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
517
|
+
Defined in: [data-structures/heap/heap.ts:841](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L841)
|
|
518
518
|
|
|
519
519
|
Delete one occurrence of an element.
|
|
520
520
|
|
|
@@ -553,13 +553,41 @@ Time O(N), Space O(1)
|
|
|
553
553
|
|
|
554
554
|
***
|
|
555
555
|
|
|
556
|
-
### deleteBy()
|
|
556
|
+
### ~~deleteBy()~~
|
|
557
557
|
|
|
558
558
|
```ts
|
|
559
559
|
deleteBy(predicate): boolean;
|
|
560
560
|
```
|
|
561
561
|
|
|
562
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
562
|
+
Defined in: [data-structures/heap/heap.ts:865](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L865)
|
|
563
|
+
|
|
564
|
+
#### Parameters
|
|
565
|
+
|
|
566
|
+
##### predicate
|
|
567
|
+
|
|
568
|
+
(`element`, `index`, `heap`) => `boolean`
|
|
569
|
+
|
|
570
|
+
#### Returns
|
|
571
|
+
|
|
572
|
+
`boolean`
|
|
573
|
+
|
|
574
|
+
#### Deprecated
|
|
575
|
+
|
|
576
|
+
Use `deleteWhere` instead. Will be removed in a future major version.
|
|
577
|
+
|
|
578
|
+
#### Inherited from
|
|
579
|
+
|
|
580
|
+
[`PriorityQueue`](PriorityQueue.md).[`deleteBy`](PriorityQueue.md#deleteby)
|
|
581
|
+
|
|
582
|
+
***
|
|
583
|
+
|
|
584
|
+
### deleteWhere()
|
|
585
|
+
|
|
586
|
+
```ts
|
|
587
|
+
deleteWhere(predicate): boolean;
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
Defined in: [data-structures/heap/heap.ts:875](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L875)
|
|
563
591
|
|
|
564
592
|
Delete the first element that matches a predicate.
|
|
565
593
|
|
|
@@ -583,7 +611,7 @@ Time O(N), Space O(1)
|
|
|
583
611
|
|
|
584
612
|
#### Inherited from
|
|
585
613
|
|
|
586
|
-
[`PriorityQueue`](PriorityQueue.md).[`
|
|
614
|
+
[`PriorityQueue`](PriorityQueue.md).[`deleteWhere`](PriorityQueue.md#deletewhere)
|
|
587
615
|
|
|
588
616
|
***
|
|
589
617
|
|
|
@@ -593,7 +621,7 @@ Time O(N), Space O(1)
|
|
|
593
621
|
dfs(order?): E[];
|
|
594
622
|
```
|
|
595
623
|
|
|
596
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
624
|
+
Defined in: [data-structures/heap/heap.ts:950](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L950)
|
|
597
625
|
|
|
598
626
|
Traverse the binary heap as a complete binary tree and collect elements.
|
|
599
627
|
|
|
@@ -638,7 +666,7 @@ Time O(N), Space O(H)
|
|
|
638
666
|
every(predicate, thisArg?): boolean;
|
|
639
667
|
```
|
|
640
668
|
|
|
641
|
-
Defined in: [data-structures/base/iterable-element-base.ts:87](https://github.com/zrwusa/data-structure-typed/blob/
|
|
669
|
+
Defined in: [data-structures/base/iterable-element-base.ts:87](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L87)
|
|
642
670
|
|
|
643
671
|
Tests whether all elements satisfy the predicate.
|
|
644
672
|
|
|
@@ -678,7 +706,7 @@ Time O(n) in the worst case; may exit early when the first failure is found. Spa
|
|
|
678
706
|
filter(callback, thisArg?): this;
|
|
679
707
|
```
|
|
680
708
|
|
|
681
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
709
|
+
Defined in: [data-structures/heap/heap.ts:1156](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1156)
|
|
682
710
|
|
|
683
711
|
Filter elements into a new heap of the same class.
|
|
684
712
|
|
|
@@ -731,7 +759,7 @@ Time O(N log N), Space O(N)
|
|
|
731
759
|
find<S>(predicate, thisArg?): S | undefined;
|
|
732
760
|
```
|
|
733
761
|
|
|
734
|
-
Defined in: [data-structures/base/iterable-element-base.ts:163](https://github.com/zrwusa/data-structure-typed/blob/
|
|
762
|
+
Defined in: [data-structures/base/iterable-element-base.ts:163](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L163)
|
|
735
763
|
|
|
736
764
|
Finds the first element that satisfies the predicate and returns it.
|
|
737
765
|
|
|
@@ -777,7 +805,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
777
805
|
find(predicate, thisArg?): E | undefined;
|
|
778
806
|
```
|
|
779
807
|
|
|
780
|
-
Defined in: [data-structures/base/iterable-element-base.ts:164](https://github.com/zrwusa/data-structure-typed/blob/
|
|
808
|
+
Defined in: [data-structures/base/iterable-element-base.ts:164](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L164)
|
|
781
809
|
|
|
782
810
|
Finds the first element that satisfies the predicate and returns it.
|
|
783
811
|
|
|
@@ -819,7 +847,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
819
847
|
fix(): boolean[];
|
|
820
848
|
```
|
|
821
849
|
|
|
822
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
850
|
+
Defined in: [data-structures/heap/heap.ts:981](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L981)
|
|
823
851
|
|
|
824
852
|
Restore heap order bottom-up (heapify in-place).
|
|
825
853
|
|
|
@@ -845,7 +873,7 @@ Time O(N), Space O(1)
|
|
|
845
873
|
forEach(callbackfn, thisArg?): void;
|
|
846
874
|
```
|
|
847
875
|
|
|
848
|
-
Defined in: [data-structures/base/iterable-element-base.ts:133](https://github.com/zrwusa/data-structure-typed/blob/
|
|
876
|
+
Defined in: [data-structures/base/iterable-element-base.ts:133](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L133)
|
|
849
877
|
|
|
850
878
|
Invokes a callback for each element in iteration order.
|
|
851
879
|
|
|
@@ -885,7 +913,7 @@ Time O(n), Space O(1).
|
|
|
885
913
|
has(element): boolean;
|
|
886
914
|
```
|
|
887
915
|
|
|
888
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
916
|
+
Defined in: [data-structures/heap/heap.ts:788](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L788)
|
|
889
917
|
|
|
890
918
|
Check if an equal element exists in the heap.
|
|
891
919
|
|
|
@@ -930,7 +958,7 @@ Time O(N), Space O(1)
|
|
|
930
958
|
isEmpty(): boolean;
|
|
931
959
|
```
|
|
932
960
|
|
|
933
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
961
|
+
Defined in: [data-structures/heap/heap.ts:688](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L688)
|
|
934
962
|
|
|
935
963
|
Check whether the heap is empty.
|
|
936
964
|
|
|
@@ -971,7 +999,7 @@ map<EM, RM>(
|
|
|
971
999
|
thisArg?): Heap<EM, RM>;
|
|
972
1000
|
```
|
|
973
1001
|
|
|
974
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1002
|
+
Defined in: [data-structures/heap/heap.ts:1221](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1221)
|
|
975
1003
|
|
|
976
1004
|
Map elements into a new heap of possibly different element type.
|
|
977
1005
|
|
|
@@ -1038,7 +1066,7 @@ Time O(N log N), Space O(N)
|
|
|
1038
1066
|
mapSame(callback, thisArg?): this;
|
|
1039
1067
|
```
|
|
1040
1068
|
|
|
1041
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1069
|
+
Defined in: [data-structures/heap/heap.ts:1245](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1245)
|
|
1042
1070
|
|
|
1043
1071
|
Map elements into a new heap of the same element type.
|
|
1044
1072
|
|
|
@@ -1078,7 +1106,7 @@ Time O(N log N), Space O(N)
|
|
|
1078
1106
|
peek(): E | undefined;
|
|
1079
1107
|
```
|
|
1080
1108
|
|
|
1081
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1109
|
+
Defined in: [data-structures/heap/heap.ts:635](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L635)
|
|
1082
1110
|
|
|
1083
1111
|
Get the current top element without removing it.
|
|
1084
1112
|
|
|
@@ -1163,28 +1191,23 @@ Time O(1), Space O(1)
|
|
|
1163
1191
|
|
|
1164
1192
|
***
|
|
1165
1193
|
|
|
1166
|
-
### poll()
|
|
1194
|
+
### ~~poll()~~
|
|
1167
1195
|
|
|
1168
1196
|
```ts
|
|
1169
1197
|
poll(): E | undefined;
|
|
1170
1198
|
```
|
|
1171
1199
|
|
|
1172
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1173
|
-
|
|
1174
|
-
Remove and return the top element.
|
|
1200
|
+
Defined in: [data-structures/heap/heap.ts:511](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L511)
|
|
1175
1201
|
|
|
1176
1202
|
#### Returns
|
|
1177
1203
|
|
|
1178
1204
|
`E` \| `undefined`
|
|
1179
1205
|
|
|
1180
|
-
|
|
1206
|
+
#### Deprecated
|
|
1181
1207
|
|
|
1208
|
+
Use `pop` instead. Will be removed in a future major version.
|
|
1182
1209
|
*
|
|
1183
1210
|
|
|
1184
|
-
#### Remarks
|
|
1185
|
-
|
|
1186
|
-
Time O(log N), Space O(1)
|
|
1187
|
-
|
|
1188
1211
|
#### Example
|
|
1189
1212
|
|
|
1190
1213
|
```ts
|
|
@@ -1220,13 +1243,39 @@ Time O(log N), Space O(1)
|
|
|
1220
1243
|
|
|
1221
1244
|
***
|
|
1222
1245
|
|
|
1246
|
+
### pop()
|
|
1247
|
+
|
|
1248
|
+
```ts
|
|
1249
|
+
pop(): E | undefined;
|
|
1250
|
+
```
|
|
1251
|
+
|
|
1252
|
+
Defined in: [data-structures/heap/heap.ts:520](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L520)
|
|
1253
|
+
|
|
1254
|
+
Remove and return the top element (min or max depending on comparator).
|
|
1255
|
+
|
|
1256
|
+
#### Returns
|
|
1257
|
+
|
|
1258
|
+
`E` \| `undefined`
|
|
1259
|
+
|
|
1260
|
+
The removed top element, or undefined if empty.
|
|
1261
|
+
|
|
1262
|
+
#### Remarks
|
|
1263
|
+
|
|
1264
|
+
Time O(log N) amortized, Space O(1)
|
|
1265
|
+
|
|
1266
|
+
#### Inherited from
|
|
1267
|
+
|
|
1268
|
+
[`PriorityQueue`](PriorityQueue.md).[`pop`](PriorityQueue.md#pop)
|
|
1269
|
+
|
|
1270
|
+
***
|
|
1271
|
+
|
|
1223
1272
|
### print()
|
|
1224
1273
|
|
|
1225
1274
|
```ts
|
|
1226
1275
|
print(): void;
|
|
1227
1276
|
```
|
|
1228
1277
|
|
|
1229
|
-
Defined in: [data-structures/base/iterable-element-base.ts:269](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1278
|
+
Defined in: [data-structures/base/iterable-element-base.ts:269](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L269)
|
|
1230
1279
|
|
|
1231
1280
|
Prints `toVisual()` to the console. Intended for quick debugging.
|
|
1232
1281
|
|
|
@@ -1284,7 +1333,7 @@ Time O(n), Space O(1). Throws if called on an empty structure without `initialVa
|
|
|
1284
1333
|
reduce(callbackfn): E;
|
|
1285
1334
|
```
|
|
1286
1335
|
|
|
1287
|
-
Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1336
|
+
Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L194)
|
|
1288
1337
|
|
|
1289
1338
|
##### Parameters
|
|
1290
1339
|
|
|
@@ -1306,7 +1355,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.c
|
|
|
1306
1355
|
reduce(callbackfn, initialValue): E;
|
|
1307
1356
|
```
|
|
1308
1357
|
|
|
1309
|
-
Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1358
|
+
Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L195)
|
|
1310
1359
|
|
|
1311
1360
|
##### Parameters
|
|
1312
1361
|
|
|
@@ -1332,7 +1381,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.c
|
|
|
1332
1381
|
reduce<U>(callbackfn, initialValue): U;
|
|
1333
1382
|
```
|
|
1334
1383
|
|
|
1335
|
-
Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1384
|
+
Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L196)
|
|
1336
1385
|
|
|
1337
1386
|
##### Type Parameters
|
|
1338
1387
|
|
|
@@ -1360,47 +1409,13 @@ Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.c
|
|
|
1360
1409
|
|
|
1361
1410
|
***
|
|
1362
1411
|
|
|
1363
|
-
### refill()
|
|
1364
|
-
|
|
1365
|
-
```ts
|
|
1366
|
-
refill(elements): boolean[];
|
|
1367
|
-
```
|
|
1368
|
-
|
|
1369
|
-
Defined in: [data-structures/heap/heap.ts:687](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/heap/heap.ts#L687)
|
|
1370
|
-
|
|
1371
|
-
Replace the backing array and rebuild the heap.
|
|
1372
|
-
|
|
1373
|
-
#### Parameters
|
|
1374
|
-
|
|
1375
|
-
##### elements
|
|
1376
|
-
|
|
1377
|
-
`Iterable`\<`E`\>
|
|
1378
|
-
|
|
1379
|
-
Iterable used to refill the heap.
|
|
1380
|
-
|
|
1381
|
-
#### Returns
|
|
1382
|
-
|
|
1383
|
-
`boolean`[]
|
|
1384
|
-
|
|
1385
|
-
Array of per-node results from fixing steps.
|
|
1386
|
-
|
|
1387
|
-
#### Remarks
|
|
1388
|
-
|
|
1389
|
-
Time O(N), Space O(N)
|
|
1390
|
-
|
|
1391
|
-
#### Inherited from
|
|
1392
|
-
|
|
1393
|
-
[`PriorityQueue`](PriorityQueue.md).[`refill`](PriorityQueue.md#refill)
|
|
1394
|
-
|
|
1395
|
-
***
|
|
1396
|
-
|
|
1397
1412
|
### setEquality()
|
|
1398
1413
|
|
|
1399
1414
|
```ts
|
|
1400
1415
|
setEquality(equals): this;
|
|
1401
1416
|
```
|
|
1402
1417
|
|
|
1403
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1418
|
+
Defined in: [data-structures/heap/heap.ts:903](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L903)
|
|
1404
1419
|
|
|
1405
1420
|
Set the equality comparator used by has/delete operations.
|
|
1406
1421
|
|
|
@@ -1434,7 +1449,7 @@ Time O(1), Space O(1)
|
|
|
1434
1449
|
some(predicate, thisArg?): boolean;
|
|
1435
1450
|
```
|
|
1436
1451
|
|
|
1437
|
-
Defined in: [data-structures/base/iterable-element-base.ts:110](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1452
|
+
Defined in: [data-structures/base/iterable-element-base.ts:110](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L110)
|
|
1438
1453
|
|
|
1439
1454
|
Tests whether at least one element satisfies the predicate.
|
|
1440
1455
|
|
|
@@ -1474,7 +1489,7 @@ Time O(n) in the worst case; may exit early on first success. Space O(1).
|
|
|
1474
1489
|
sort(): E[];
|
|
1475
1490
|
```
|
|
1476
1491
|
|
|
1477
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1492
|
+
Defined in: [data-structures/heap/heap.ts:1039](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1039)
|
|
1478
1493
|
|
|
1479
1494
|
Return all elements in ascending order by repeatedly polling.
|
|
1480
1495
|
|
|
@@ -1511,7 +1526,7 @@ Time O(N log N), Space O(N)
|
|
|
1511
1526
|
toArray(): E[];
|
|
1512
1527
|
```
|
|
1513
1528
|
|
|
1514
|
-
Defined in: [data-structures/base/iterable-element-base.ts:246](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1529
|
+
Defined in: [data-structures/base/iterable-element-base.ts:246](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L246)
|
|
1515
1530
|
|
|
1516
1531
|
Materializes the elements into a new array.
|
|
1517
1532
|
|
|
@@ -1537,7 +1552,7 @@ Time O(n), Space O(n).
|
|
|
1537
1552
|
toVisual(): E[];
|
|
1538
1553
|
```
|
|
1539
1554
|
|
|
1540
|
-
Defined in: [data-structures/base/iterable-element-base.ts:258](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1555
|
+
Defined in: [data-structures/base/iterable-element-base.ts:258](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L258)
|
|
1541
1556
|
|
|
1542
1557
|
Returns a representation of the structure suitable for quick visualization.
|
|
1543
1558
|
Defaults to an array of elements; subclasses may override to provide richer visuals.
|
|
@@ -1564,7 +1579,7 @@ Time O(n), Space O(n).
|
|
|
1564
1579
|
values(): IterableIterator<E>;
|
|
1565
1580
|
```
|
|
1566
1581
|
|
|
1567
|
-
Defined in: [data-structures/base/iterable-element-base.ts:72](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1582
|
+
Defined in: [data-structures/base/iterable-element-base.ts:72](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L72)
|
|
1568
1583
|
|
|
1569
1584
|
Returns an iterator over the values (alias of the default iterator).
|
|
1570
1585
|
|
|
@@ -1593,7 +1608,7 @@ static from<T, R, S>(
|
|
|
1593
1608
|
options?): S;
|
|
1594
1609
|
```
|
|
1595
1610
|
|
|
1596
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1611
|
+
Defined in: [data-structures/heap/heap.ts:263](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L263)
|
|
1597
1612
|
|
|
1598
1613
|
Create a heap of the same class from an iterable.
|
|
1599
1614
|
|
|
@@ -1651,7 +1666,7 @@ Time O(N), Space O(N)
|
|
|
1651
1666
|
static heapify<EE, RR>(elements, options): Heap<EE, RR>;
|
|
1652
1667
|
```
|
|
1653
1668
|
|
|
1654
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1669
|
+
Defined in: [data-structures/heap/heap.ts:281](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L281)
|
|
1655
1670
|
|
|
1656
1671
|
Build a Heap from an iterable in linear time given a comparator.
|
|
1657
1672
|
|
|
@@ -1704,7 +1719,7 @@ Time O(N), Space O(N)
|
|
|
1704
1719
|
protected optional _toElementFn?: (rawElement) => E;
|
|
1705
1720
|
```
|
|
1706
1721
|
|
|
1707
|
-
Defined in: [data-structures/base/iterable-element-base.ts:39](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1722
|
+
Defined in: [data-structures/base/iterable-element-base.ts:39](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-element-base.ts#L39)
|
|
1708
1723
|
|
|
1709
1724
|
The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
1710
1725
|
|
|
@@ -1734,7 +1749,7 @@ Time O(1), Space O(1).
|
|
|
1734
1749
|
protected _createInstance(options?): this;
|
|
1735
1750
|
```
|
|
1736
1751
|
|
|
1737
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1752
|
+
Defined in: [data-structures/heap/heap.ts:1318](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1318)
|
|
1738
1753
|
|
|
1739
1754
|
(Protected) Create an empty instance of the same concrete class.
|
|
1740
1755
|
|
|
@@ -1768,7 +1783,7 @@ Time O(1), Space O(1)
|
|
|
1768
1783
|
protected _createLike<EM, RM>(elements?, options?): Heap<EM, RM>;
|
|
1769
1784
|
```
|
|
1770
1785
|
|
|
1771
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1786
|
+
Defined in: [data-structures/heap/heap.ts:1336](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1336)
|
|
1772
1787
|
|
|
1773
1788
|
(Protected) Create a like-kind instance seeded by elements.
|
|
1774
1789
|
|
|
@@ -1818,7 +1833,7 @@ Time O(N log N), Space O(N)
|
|
|
1818
1833
|
protected _getIterator(): IterableIterator<E>;
|
|
1819
1834
|
```
|
|
1820
1835
|
|
|
1821
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1836
|
+
Defined in: [data-structures/heap/heap.ts:1276](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1276)
|
|
1822
1837
|
|
|
1823
1838
|
Internal iterator factory used by the default iterator.
|
|
1824
1839
|
|
|
@@ -1844,7 +1859,7 @@ Implementations should yield in O(1) per element with O(1) extra space when poss
|
|
|
1844
1859
|
protected _spawnLike<EM, RM>(options?): Heap<EM, RM>;
|
|
1845
1860
|
```
|
|
1846
1861
|
|
|
1847
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1862
|
+
Defined in: [data-structures/heap/heap.ts:1356](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1356)
|
|
1848
1863
|
|
|
1849
1864
|
(Protected) Spawn an empty like-kind heap instance.
|
|
1850
1865
|
|