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,13 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: Heap\<E, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/heap/heap.ts:150](https://github.com/zrwusa/data-structure-typed/blob/
|
|
9
|
+
Defined in: [data-structures/heap/heap.ts:150](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L150)
|
|
10
10
|
|
|
11
11
|
Binary heap with pluggable comparator; supports fast insertion and removal of the top element.
|
|
12
12
|
|
|
13
13
|
## Remarks
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Typical operations: O(log N) insert/remove, O(1) peek. Space O(N).
|
|
16
16
|
|
|
17
17
|
## Examples
|
|
18
18
|
|
|
@@ -186,7 +186,7 @@ Min Heap: The value of each parent node is less than or equal to the value of it
|
|
|
186
186
|
new Heap<E, R>(elements?, options?): Heap<E, R>;
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
-
Defined in: [data-structures/heap/heap.ts:161](https://github.com/zrwusa/data-structure-typed/blob/
|
|
189
|
+
Defined in: [data-structures/heap/heap.ts:161](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L161)
|
|
190
190
|
|
|
191
191
|
Create a Heap and optionally bulk-insert elements.
|
|
192
192
|
|
|
@@ -228,7 +228,7 @@ Time O(N), Space O(N)
|
|
|
228
228
|
get comparator(): Comparator<E>;
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
231
|
+
Defined in: [data-structures/heap/heap.ts:1272](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1272)
|
|
232
232
|
|
|
233
233
|
Get the comparator used to order elements.
|
|
234
234
|
|
|
@@ -252,7 +252,7 @@ Comparator function.
|
|
|
252
252
|
get elements(): E[];
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/
|
|
255
|
+
Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L180)
|
|
256
256
|
|
|
257
257
|
Get the backing array of the heap.
|
|
258
258
|
|
|
@@ -276,7 +276,7 @@ Internal elements array.
|
|
|
276
276
|
get leaf(): E | undefined;
|
|
277
277
|
```
|
|
278
278
|
|
|
279
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
279
|
+
Defined in: [data-structures/heap/heap.ts:248](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L248)
|
|
280
280
|
|
|
281
281
|
Get the last leaf element.
|
|
282
282
|
|
|
@@ -300,7 +300,7 @@ Last element or undefined.
|
|
|
300
300
|
get size(): number;
|
|
301
301
|
```
|
|
302
302
|
|
|
303
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
303
|
+
Defined in: [data-structures/heap/heap.ts:238](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L238)
|
|
304
304
|
|
|
305
305
|
Get the number of elements.
|
|
306
306
|
|
|
@@ -339,7 +339,7 @@ Heap size.
|
|
|
339
339
|
get toElementFn(): ((rawElement) => E) | undefined;
|
|
340
340
|
```
|
|
341
341
|
|
|
342
|
-
Defined in: [data-structures/base/iterable-element-base.ts:48](https://github.com/zrwusa/data-structure-typed/blob/
|
|
342
|
+
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)
|
|
343
343
|
|
|
344
344
|
Exposes the current `toElementFn`, if configured.
|
|
345
345
|
|
|
@@ -365,7 +365,7 @@ The converter function or `undefined` when not set.
|
|
|
365
365
|
iterator: IterableIterator<E>;
|
|
366
366
|
```
|
|
367
367
|
|
|
368
|
-
Defined in: [data-structures/base/iterable-element-base.ts:61](https://github.com/zrwusa/data-structure-typed/blob/
|
|
368
|
+
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)
|
|
369
369
|
|
|
370
370
|
Returns an iterator over the structure's elements.
|
|
371
371
|
|
|
@@ -399,7 +399,7 @@ Producing the iterator is O(1); consuming the entire iterator is Time O(n) with
|
|
|
399
399
|
add(element): boolean;
|
|
400
400
|
```
|
|
401
401
|
|
|
402
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
402
|
+
Defined in: [data-structures/heap/heap.ts:346](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L346)
|
|
403
403
|
|
|
404
404
|
Insert an element.
|
|
405
405
|
|
|
@@ -421,7 +421,7 @@ True.
|
|
|
421
421
|
|
|
422
422
|
#### Remarks
|
|
423
423
|
|
|
424
|
-
Time O(
|
|
424
|
+
Time O(log N) amortized, Space O(1)
|
|
425
425
|
|
|
426
426
|
#### Example
|
|
427
427
|
|
|
@@ -450,7 +450,7 @@ Time O(1) amortized, Space O(1)
|
|
|
450
450
|
addMany(elements): boolean[];
|
|
451
451
|
```
|
|
452
452
|
|
|
453
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
453
|
+
Defined in: [data-structures/heap/heap.ts:400](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L400)
|
|
454
454
|
|
|
455
455
|
Insert many elements from an iterable.
|
|
456
456
|
|
|
@@ -492,7 +492,7 @@ Time O(N log N), Space O(1)
|
|
|
492
492
|
clear(): void;
|
|
493
493
|
```
|
|
494
494
|
|
|
495
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
495
|
+
Defined in: [data-structures/heap/heap.ts:740](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L740)
|
|
496
496
|
|
|
497
497
|
Remove all elements.
|
|
498
498
|
|
|
@@ -529,7 +529,7 @@ Time O(1), Space O(1)
|
|
|
529
529
|
clone(): this;
|
|
530
530
|
```
|
|
531
531
|
|
|
532
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
532
|
+
Defined in: [data-structures/heap/heap.ts:1100](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1100)
|
|
533
533
|
|
|
534
534
|
Deep clone this heap.
|
|
535
535
|
|
|
@@ -568,7 +568,7 @@ Time O(N), Space O(N)
|
|
|
568
568
|
delete(element): boolean;
|
|
569
569
|
```
|
|
570
570
|
|
|
571
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
571
|
+
Defined in: [data-structures/heap/heap.ts:841](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L841)
|
|
572
572
|
|
|
573
573
|
Delete one occurrence of an element.
|
|
574
574
|
|
|
@@ -603,13 +603,37 @@ Time O(N), Space O(1)
|
|
|
603
603
|
|
|
604
604
|
***
|
|
605
605
|
|
|
606
|
-
### deleteBy()
|
|
606
|
+
### ~~deleteBy()~~
|
|
607
607
|
|
|
608
608
|
```ts
|
|
609
609
|
deleteBy(predicate): boolean;
|
|
610
610
|
```
|
|
611
611
|
|
|
612
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
612
|
+
Defined in: [data-structures/heap/heap.ts:865](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L865)
|
|
613
|
+
|
|
614
|
+
#### Parameters
|
|
615
|
+
|
|
616
|
+
##### predicate
|
|
617
|
+
|
|
618
|
+
(`element`, `index`, `heap`) => `boolean`
|
|
619
|
+
|
|
620
|
+
#### Returns
|
|
621
|
+
|
|
622
|
+
`boolean`
|
|
623
|
+
|
|
624
|
+
#### Deprecated
|
|
625
|
+
|
|
626
|
+
Use `deleteWhere` instead. Will be removed in a future major version.
|
|
627
|
+
|
|
628
|
+
***
|
|
629
|
+
|
|
630
|
+
### deleteWhere()
|
|
631
|
+
|
|
632
|
+
```ts
|
|
633
|
+
deleteWhere(predicate): boolean;
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
Defined in: [data-structures/heap/heap.ts:875](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L875)
|
|
613
637
|
|
|
614
638
|
Delete the first element that matches a predicate.
|
|
615
639
|
|
|
@@ -639,7 +663,7 @@ Time O(N), Space O(1)
|
|
|
639
663
|
dfs(order?): E[];
|
|
640
664
|
```
|
|
641
665
|
|
|
642
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
666
|
+
Defined in: [data-structures/heap/heap.ts:950](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L950)
|
|
643
667
|
|
|
644
668
|
Traverse the binary heap as a complete binary tree and collect elements.
|
|
645
669
|
|
|
@@ -680,7 +704,7 @@ Time O(N), Space O(H)
|
|
|
680
704
|
every(predicate, thisArg?): boolean;
|
|
681
705
|
```
|
|
682
706
|
|
|
683
|
-
Defined in: [data-structures/base/iterable-element-base.ts:87](https://github.com/zrwusa/data-structure-typed/blob/
|
|
707
|
+
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)
|
|
684
708
|
|
|
685
709
|
Tests whether all elements satisfy the predicate.
|
|
686
710
|
|
|
@@ -720,7 +744,7 @@ Time O(n) in the worst case; may exit early when the first failure is found. Spa
|
|
|
720
744
|
filter(callback, thisArg?): this;
|
|
721
745
|
```
|
|
722
746
|
|
|
723
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
747
|
+
Defined in: [data-structures/heap/heap.ts:1156](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1156)
|
|
724
748
|
|
|
725
749
|
Filter elements into a new heap of the same class.
|
|
726
750
|
|
|
@@ -773,7 +797,7 @@ Time O(N log N), Space O(N)
|
|
|
773
797
|
find<S>(predicate, thisArg?): S | undefined;
|
|
774
798
|
```
|
|
775
799
|
|
|
776
|
-
Defined in: [data-structures/base/iterable-element-base.ts:163](https://github.com/zrwusa/data-structure-typed/blob/
|
|
800
|
+
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)
|
|
777
801
|
|
|
778
802
|
Finds the first element that satisfies the predicate and returns it.
|
|
779
803
|
|
|
@@ -819,7 +843,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
819
843
|
find(predicate, thisArg?): E | undefined;
|
|
820
844
|
```
|
|
821
845
|
|
|
822
|
-
Defined in: [data-structures/base/iterable-element-base.ts:164](https://github.com/zrwusa/data-structure-typed/blob/
|
|
846
|
+
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)
|
|
823
847
|
|
|
824
848
|
Finds the first element that satisfies the predicate and returns it.
|
|
825
849
|
|
|
@@ -861,7 +885,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
861
885
|
fix(): boolean[];
|
|
862
886
|
```
|
|
863
887
|
|
|
864
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
888
|
+
Defined in: [data-structures/heap/heap.ts:981](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L981)
|
|
865
889
|
|
|
866
890
|
Restore heap order bottom-up (heapify in-place).
|
|
867
891
|
|
|
@@ -883,7 +907,7 @@ Time O(N), Space O(1)
|
|
|
883
907
|
forEach(callbackfn, thisArg?): void;
|
|
884
908
|
```
|
|
885
909
|
|
|
886
|
-
Defined in: [data-structures/base/iterable-element-base.ts:133](https://github.com/zrwusa/data-structure-typed/blob/
|
|
910
|
+
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)
|
|
887
911
|
|
|
888
912
|
Invokes a callback for each element in iteration order.
|
|
889
913
|
|
|
@@ -923,7 +947,7 @@ Time O(n), Space O(1).
|
|
|
923
947
|
has(element): boolean;
|
|
924
948
|
```
|
|
925
949
|
|
|
926
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
950
|
+
Defined in: [data-structures/heap/heap.ts:788](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L788)
|
|
927
951
|
|
|
928
952
|
Check if an equal element exists in the heap.
|
|
929
953
|
|
|
@@ -968,7 +992,7 @@ Time O(N), Space O(1)
|
|
|
968
992
|
isEmpty(): boolean;
|
|
969
993
|
```
|
|
970
994
|
|
|
971
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
995
|
+
Defined in: [data-structures/heap/heap.ts:688](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L688)
|
|
972
996
|
|
|
973
997
|
Check whether the heap is empty.
|
|
974
998
|
|
|
@@ -1009,7 +1033,7 @@ map<EM, RM>(
|
|
|
1009
1033
|
thisArg?): Heap<EM, RM>;
|
|
1010
1034
|
```
|
|
1011
1035
|
|
|
1012
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1036
|
+
Defined in: [data-structures/heap/heap.ts:1221](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1221)
|
|
1013
1037
|
|
|
1014
1038
|
Map elements into a new heap of possibly different element type.
|
|
1015
1039
|
|
|
@@ -1076,7 +1100,7 @@ Time O(N log N), Space O(N)
|
|
|
1076
1100
|
mapSame(callback, thisArg?): this;
|
|
1077
1101
|
```
|
|
1078
1102
|
|
|
1079
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1103
|
+
Defined in: [data-structures/heap/heap.ts:1245](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1245)
|
|
1080
1104
|
|
|
1081
1105
|
Map elements into a new heap of the same element type.
|
|
1082
1106
|
|
|
@@ -1116,7 +1140,7 @@ Time O(N log N), Space O(N)
|
|
|
1116
1140
|
peek(): E | undefined;
|
|
1117
1141
|
```
|
|
1118
1142
|
|
|
1119
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1143
|
+
Defined in: [data-structures/heap/heap.ts:635](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L635)
|
|
1120
1144
|
|
|
1121
1145
|
Get the current top element without removing it.
|
|
1122
1146
|
|
|
@@ -1197,28 +1221,23 @@ Time O(1), Space O(1)
|
|
|
1197
1221
|
|
|
1198
1222
|
***
|
|
1199
1223
|
|
|
1200
|
-
### poll()
|
|
1224
|
+
### ~~poll()~~
|
|
1201
1225
|
|
|
1202
1226
|
```ts
|
|
1203
1227
|
poll(): E | undefined;
|
|
1204
1228
|
```
|
|
1205
1229
|
|
|
1206
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1207
|
-
|
|
1208
|
-
Remove and return the top element.
|
|
1230
|
+
Defined in: [data-structures/heap/heap.ts:511](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L511)
|
|
1209
1231
|
|
|
1210
1232
|
#### Returns
|
|
1211
1233
|
|
|
1212
1234
|
`E` \| `undefined`
|
|
1213
1235
|
|
|
1214
|
-
|
|
1236
|
+
#### Deprecated
|
|
1215
1237
|
|
|
1238
|
+
Use `pop` instead. Will be removed in a future major version.
|
|
1216
1239
|
*
|
|
1217
1240
|
|
|
1218
|
-
#### Remarks
|
|
1219
|
-
|
|
1220
|
-
Time O(log N), Space O(1)
|
|
1221
|
-
|
|
1222
1241
|
#### Example
|
|
1223
1242
|
|
|
1224
1243
|
```ts
|
|
@@ -1250,13 +1269,35 @@ Time O(log N), Space O(1)
|
|
|
1250
1269
|
|
|
1251
1270
|
***
|
|
1252
1271
|
|
|
1272
|
+
### pop()
|
|
1273
|
+
|
|
1274
|
+
```ts
|
|
1275
|
+
pop(): E | undefined;
|
|
1276
|
+
```
|
|
1277
|
+
|
|
1278
|
+
Defined in: [data-structures/heap/heap.ts:520](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L520)
|
|
1279
|
+
|
|
1280
|
+
Remove and return the top element (min or max depending on comparator).
|
|
1281
|
+
|
|
1282
|
+
#### Returns
|
|
1283
|
+
|
|
1284
|
+
`E` \| `undefined`
|
|
1285
|
+
|
|
1286
|
+
The removed top element, or undefined if empty.
|
|
1287
|
+
|
|
1288
|
+
#### Remarks
|
|
1289
|
+
|
|
1290
|
+
Time O(log N) amortized, Space O(1)
|
|
1291
|
+
|
|
1292
|
+
***
|
|
1293
|
+
|
|
1253
1294
|
### print()
|
|
1254
1295
|
|
|
1255
1296
|
```ts
|
|
1256
1297
|
print(): void;
|
|
1257
1298
|
```
|
|
1258
1299
|
|
|
1259
|
-
Defined in: [data-structures/base/iterable-element-base.ts:269](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1300
|
+
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)
|
|
1260
1301
|
|
|
1261
1302
|
Prints `toVisual()` to the console. Intended for quick debugging.
|
|
1262
1303
|
|
|
@@ -1314,7 +1355,7 @@ Time O(n), Space O(1). Throws if called on an empty structure without `initialVa
|
|
|
1314
1355
|
reduce(callbackfn): E;
|
|
1315
1356
|
```
|
|
1316
1357
|
|
|
1317
|
-
Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1358
|
+
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)
|
|
1318
1359
|
|
|
1319
1360
|
##### Parameters
|
|
1320
1361
|
|
|
@@ -1336,7 +1377,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.c
|
|
|
1336
1377
|
reduce(callbackfn, initialValue): E;
|
|
1337
1378
|
```
|
|
1338
1379
|
|
|
1339
|
-
Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1380
|
+
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)
|
|
1340
1381
|
|
|
1341
1382
|
##### Parameters
|
|
1342
1383
|
|
|
@@ -1362,7 +1403,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.c
|
|
|
1362
1403
|
reduce<U>(callbackfn, initialValue): U;
|
|
1363
1404
|
```
|
|
1364
1405
|
|
|
1365
|
-
Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1406
|
+
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)
|
|
1366
1407
|
|
|
1367
1408
|
##### Type Parameters
|
|
1368
1409
|
|
|
@@ -1390,43 +1431,13 @@ Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.c
|
|
|
1390
1431
|
|
|
1391
1432
|
***
|
|
1392
1433
|
|
|
1393
|
-
### refill()
|
|
1394
|
-
|
|
1395
|
-
```ts
|
|
1396
|
-
refill(elements): boolean[];
|
|
1397
|
-
```
|
|
1398
|
-
|
|
1399
|
-
Defined in: [data-structures/heap/heap.ts:687](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/heap/heap.ts#L687)
|
|
1400
|
-
|
|
1401
|
-
Replace the backing array and rebuild the heap.
|
|
1402
|
-
|
|
1403
|
-
#### Parameters
|
|
1404
|
-
|
|
1405
|
-
##### elements
|
|
1406
|
-
|
|
1407
|
-
`Iterable`\<`E`\>
|
|
1408
|
-
|
|
1409
|
-
Iterable used to refill the heap.
|
|
1410
|
-
|
|
1411
|
-
#### Returns
|
|
1412
|
-
|
|
1413
|
-
`boolean`[]
|
|
1414
|
-
|
|
1415
|
-
Array of per-node results from fixing steps.
|
|
1416
|
-
|
|
1417
|
-
#### Remarks
|
|
1418
|
-
|
|
1419
|
-
Time O(N), Space O(N)
|
|
1420
|
-
|
|
1421
|
-
***
|
|
1422
|
-
|
|
1423
1434
|
### setEquality()
|
|
1424
1435
|
|
|
1425
1436
|
```ts
|
|
1426
1437
|
setEquality(equals): this;
|
|
1427
1438
|
```
|
|
1428
1439
|
|
|
1429
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1440
|
+
Defined in: [data-structures/heap/heap.ts:903](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L903)
|
|
1430
1441
|
|
|
1431
1442
|
Set the equality comparator used by has/delete operations.
|
|
1432
1443
|
|
|
@@ -1456,7 +1467,7 @@ Time O(1), Space O(1)
|
|
|
1456
1467
|
some(predicate, thisArg?): boolean;
|
|
1457
1468
|
```
|
|
1458
1469
|
|
|
1459
|
-
Defined in: [data-structures/base/iterable-element-base.ts:110](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1470
|
+
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)
|
|
1460
1471
|
|
|
1461
1472
|
Tests whether at least one element satisfies the predicate.
|
|
1462
1473
|
|
|
@@ -1496,7 +1507,7 @@ Time O(n) in the worst case; may exit early on first success. Space O(1).
|
|
|
1496
1507
|
sort(): E[];
|
|
1497
1508
|
```
|
|
1498
1509
|
|
|
1499
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1510
|
+
Defined in: [data-structures/heap/heap.ts:1039](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1039)
|
|
1500
1511
|
|
|
1501
1512
|
Return all elements in ascending order by repeatedly polling.
|
|
1502
1513
|
|
|
@@ -1529,7 +1540,7 @@ Time O(N log N), Space O(N)
|
|
|
1529
1540
|
toArray(): E[];
|
|
1530
1541
|
```
|
|
1531
1542
|
|
|
1532
|
-
Defined in: [data-structures/base/iterable-element-base.ts:246](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1543
|
+
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)
|
|
1533
1544
|
|
|
1534
1545
|
Materializes the elements into a new array.
|
|
1535
1546
|
|
|
@@ -1555,7 +1566,7 @@ Time O(n), Space O(n).
|
|
|
1555
1566
|
toVisual(): E[];
|
|
1556
1567
|
```
|
|
1557
1568
|
|
|
1558
|
-
Defined in: [data-structures/base/iterable-element-base.ts:258](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1569
|
+
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)
|
|
1559
1570
|
|
|
1560
1571
|
Returns a representation of the structure suitable for quick visualization.
|
|
1561
1572
|
Defaults to an array of elements; subclasses may override to provide richer visuals.
|
|
@@ -1582,7 +1593,7 @@ Time O(n), Space O(n).
|
|
|
1582
1593
|
values(): IterableIterator<E>;
|
|
1583
1594
|
```
|
|
1584
1595
|
|
|
1585
|
-
Defined in: [data-structures/base/iterable-element-base.ts:72](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1596
|
+
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)
|
|
1586
1597
|
|
|
1587
1598
|
Returns an iterator over the values (alias of the default iterator).
|
|
1588
1599
|
|
|
@@ -1611,7 +1622,7 @@ static from<T, R, S>(
|
|
|
1611
1622
|
options?): S;
|
|
1612
1623
|
```
|
|
1613
1624
|
|
|
1614
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1625
|
+
Defined in: [data-structures/heap/heap.ts:263](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L263)
|
|
1615
1626
|
|
|
1616
1627
|
Create a heap of the same class from an iterable.
|
|
1617
1628
|
|
|
@@ -1665,7 +1676,7 @@ Time O(N), Space O(N)
|
|
|
1665
1676
|
static heapify<EE, RR>(elements, options): Heap<EE, RR>;
|
|
1666
1677
|
```
|
|
1667
1678
|
|
|
1668
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1679
|
+
Defined in: [data-structures/heap/heap.ts:281](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L281)
|
|
1669
1680
|
|
|
1670
1681
|
Build a Heap from an iterable in linear time given a comparator.
|
|
1671
1682
|
|
|
@@ -1714,7 +1725,7 @@ Time O(N), Space O(N)
|
|
|
1714
1725
|
protected optional _toElementFn?: (rawElement) => E;
|
|
1715
1726
|
```
|
|
1716
1727
|
|
|
1717
|
-
Defined in: [data-structures/base/iterable-element-base.ts:39](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1728
|
+
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)
|
|
1718
1729
|
|
|
1719
1730
|
The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
1720
1731
|
|
|
@@ -1744,7 +1755,7 @@ Time O(1), Space O(1).
|
|
|
1744
1755
|
protected _createInstance(options?): this;
|
|
1745
1756
|
```
|
|
1746
1757
|
|
|
1747
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1758
|
+
Defined in: [data-structures/heap/heap.ts:1318](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1318)
|
|
1748
1759
|
|
|
1749
1760
|
(Protected) Create an empty instance of the same concrete class.
|
|
1750
1761
|
|
|
@@ -1774,7 +1785,7 @@ Time O(1), Space O(1)
|
|
|
1774
1785
|
protected _createLike<EM, RM>(elements?, options?): Heap<EM, RM>;
|
|
1775
1786
|
```
|
|
1776
1787
|
|
|
1777
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1788
|
+
Defined in: [data-structures/heap/heap.ts:1336](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1336)
|
|
1778
1789
|
|
|
1779
1790
|
(Protected) Create a like-kind instance seeded by elements.
|
|
1780
1791
|
|
|
@@ -1820,7 +1831,7 @@ Time O(N log N), Space O(N)
|
|
|
1820
1831
|
protected _getIterator(): IterableIterator<E>;
|
|
1821
1832
|
```
|
|
1822
1833
|
|
|
1823
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1834
|
+
Defined in: [data-structures/heap/heap.ts:1276](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1276)
|
|
1824
1835
|
|
|
1825
1836
|
Internal iterator factory used by the default iterator.
|
|
1826
1837
|
|
|
@@ -1846,7 +1857,7 @@ Implementations should yield in O(1) per element with O(1) extra space when poss
|
|
|
1846
1857
|
protected _spawnLike<EM, RM>(options?): Heap<EM, RM>;
|
|
1847
1858
|
```
|
|
1848
1859
|
|
|
1849
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1860
|
+
Defined in: [data-structures/heap/heap.ts:1356](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1356)
|
|
1850
1861
|
|
|
1851
1862
|
(Protected) Spawn an empty like-kind heap instance.
|
|
1852
1863
|
|