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: MinHeap\<E, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/heap/min-heap.ts:86](https://github.com/zrwusa/data-structure-typed/blob/
|
|
9
|
+
Defined in: [data-structures/heap/min-heap.ts:86](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/min-heap.ts#L86)
|
|
10
10
|
|
|
11
11
|
## Examples
|
|
12
12
|
|
|
@@ -110,7 +110,7 @@ Notes and typical use-cases are documented in [Heap](Heap.md).
|
|
|
110
110
|
new MinHeap<E, R>(elements?, options?): MinHeap<E, R>;
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
Defined in: [data-structures/heap/min-heap.ts:92](https://github.com/zrwusa/data-structure-typed/blob/
|
|
113
|
+
Defined in: [data-structures/heap/min-heap.ts:92](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/min-heap.ts#L92)
|
|
114
114
|
|
|
115
115
|
Create a min-heap.
|
|
116
116
|
|
|
@@ -146,7 +146,7 @@ Optional configuration.
|
|
|
146
146
|
get comparator(): Comparator<E>;
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
149
|
+
Defined in: [data-structures/heap/heap.ts:1272](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1272)
|
|
150
150
|
|
|
151
151
|
Get the comparator used to order elements.
|
|
152
152
|
|
|
@@ -174,7 +174,7 @@ Comparator function.
|
|
|
174
174
|
get elements(): E[];
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/
|
|
177
|
+
Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L180)
|
|
178
178
|
|
|
179
179
|
Get the backing array of the heap.
|
|
180
180
|
|
|
@@ -202,7 +202,7 @@ Internal elements array.
|
|
|
202
202
|
get leaf(): E | undefined;
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
205
|
+
Defined in: [data-structures/heap/heap.ts:248](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L248)
|
|
206
206
|
|
|
207
207
|
Get the last leaf element.
|
|
208
208
|
|
|
@@ -230,7 +230,7 @@ Last element or undefined.
|
|
|
230
230
|
get size(): number;
|
|
231
231
|
```
|
|
232
232
|
|
|
233
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
233
|
+
Defined in: [data-structures/heap/heap.ts:238](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L238)
|
|
234
234
|
|
|
235
235
|
Get the number of elements.
|
|
236
236
|
|
|
@@ -273,7 +273,7 @@ Heap size.
|
|
|
273
273
|
get toElementFn(): ((rawElement) => E) | undefined;
|
|
274
274
|
```
|
|
275
275
|
|
|
276
|
-
Defined in: [data-structures/base/iterable-element-base.ts:48](https://github.com/zrwusa/data-structure-typed/blob/
|
|
276
|
+
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)
|
|
277
277
|
|
|
278
278
|
Exposes the current `toElementFn`, if configured.
|
|
279
279
|
|
|
@@ -299,7 +299,7 @@ The converter function or `undefined` when not set.
|
|
|
299
299
|
iterator: IterableIterator<E>;
|
|
300
300
|
```
|
|
301
301
|
|
|
302
|
-
Defined in: [data-structures/base/iterable-element-base.ts:61](https://github.com/zrwusa/data-structure-typed/blob/
|
|
302
|
+
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)
|
|
303
303
|
|
|
304
304
|
Returns an iterator over the structure's elements.
|
|
305
305
|
|
|
@@ -333,7 +333,7 @@ Producing the iterator is O(1); consuming the entire iterator is Time O(n) with
|
|
|
333
333
|
add(element): boolean;
|
|
334
334
|
```
|
|
335
335
|
|
|
336
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
336
|
+
Defined in: [data-structures/heap/heap.ts:346](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L346)
|
|
337
337
|
|
|
338
338
|
Insert an element.
|
|
339
339
|
|
|
@@ -355,7 +355,7 @@ True.
|
|
|
355
355
|
|
|
356
356
|
#### Remarks
|
|
357
357
|
|
|
358
|
-
Time O(
|
|
358
|
+
Time O(log N) amortized, Space O(1)
|
|
359
359
|
|
|
360
360
|
#### Example
|
|
361
361
|
|
|
@@ -388,7 +388,7 @@ Time O(1) amortized, Space O(1)
|
|
|
388
388
|
addMany(elements): boolean[];
|
|
389
389
|
```
|
|
390
390
|
|
|
391
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
391
|
+
Defined in: [data-structures/heap/heap.ts:400](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L400)
|
|
392
392
|
|
|
393
393
|
Insert many elements from an iterable.
|
|
394
394
|
|
|
@@ -434,7 +434,7 @@ Time O(N log N), Space O(1)
|
|
|
434
434
|
clear(): void;
|
|
435
435
|
```
|
|
436
436
|
|
|
437
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
437
|
+
Defined in: [data-structures/heap/heap.ts:740](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L740)
|
|
438
438
|
|
|
439
439
|
Remove all elements.
|
|
440
440
|
|
|
@@ -471,7 +471,7 @@ Time O(1), Space O(1)
|
|
|
471
471
|
clone(): this;
|
|
472
472
|
```
|
|
473
473
|
|
|
474
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
474
|
+
Defined in: [data-structures/heap/heap.ts:1100](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1100)
|
|
475
475
|
|
|
476
476
|
Deep clone this heap.
|
|
477
477
|
|
|
@@ -510,7 +510,7 @@ Time O(N), Space O(N)
|
|
|
510
510
|
delete(element): boolean;
|
|
511
511
|
```
|
|
512
512
|
|
|
513
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
513
|
+
Defined in: [data-structures/heap/heap.ts:841](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L841)
|
|
514
514
|
|
|
515
515
|
Delete one occurrence of an element.
|
|
516
516
|
|
|
@@ -549,13 +549,41 @@ Time O(N), Space O(1)
|
|
|
549
549
|
|
|
550
550
|
***
|
|
551
551
|
|
|
552
|
-
### deleteBy()
|
|
552
|
+
### ~~deleteBy()~~
|
|
553
553
|
|
|
554
554
|
```ts
|
|
555
555
|
deleteBy(predicate): boolean;
|
|
556
556
|
```
|
|
557
557
|
|
|
558
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
558
|
+
Defined in: [data-structures/heap/heap.ts:865](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L865)
|
|
559
|
+
|
|
560
|
+
#### Parameters
|
|
561
|
+
|
|
562
|
+
##### predicate
|
|
563
|
+
|
|
564
|
+
(`element`, `index`, `heap`) => `boolean`
|
|
565
|
+
|
|
566
|
+
#### Returns
|
|
567
|
+
|
|
568
|
+
`boolean`
|
|
569
|
+
|
|
570
|
+
#### Deprecated
|
|
571
|
+
|
|
572
|
+
Use `deleteWhere` instead. Will be removed in a future major version.
|
|
573
|
+
|
|
574
|
+
#### Inherited from
|
|
575
|
+
|
|
576
|
+
[`Heap`](Heap.md).[`deleteBy`](Heap.md#deleteby)
|
|
577
|
+
|
|
578
|
+
***
|
|
579
|
+
|
|
580
|
+
### deleteWhere()
|
|
581
|
+
|
|
582
|
+
```ts
|
|
583
|
+
deleteWhere(predicate): boolean;
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
Defined in: [data-structures/heap/heap.ts:875](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L875)
|
|
559
587
|
|
|
560
588
|
Delete the first element that matches a predicate.
|
|
561
589
|
|
|
@@ -579,7 +607,7 @@ Time O(N), Space O(1)
|
|
|
579
607
|
|
|
580
608
|
#### Inherited from
|
|
581
609
|
|
|
582
|
-
[`Heap`](Heap.md).[`
|
|
610
|
+
[`Heap`](Heap.md).[`deleteWhere`](Heap.md#deletewhere)
|
|
583
611
|
|
|
584
612
|
***
|
|
585
613
|
|
|
@@ -589,7 +617,7 @@ Time O(N), Space O(1)
|
|
|
589
617
|
dfs(order?): E[];
|
|
590
618
|
```
|
|
591
619
|
|
|
592
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
620
|
+
Defined in: [data-structures/heap/heap.ts:950](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L950)
|
|
593
621
|
|
|
594
622
|
Traverse the binary heap as a complete binary tree and collect elements.
|
|
595
623
|
|
|
@@ -634,7 +662,7 @@ Time O(N), Space O(H)
|
|
|
634
662
|
every(predicate, thisArg?): boolean;
|
|
635
663
|
```
|
|
636
664
|
|
|
637
|
-
Defined in: [data-structures/base/iterable-element-base.ts:87](https://github.com/zrwusa/data-structure-typed/blob/
|
|
665
|
+
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)
|
|
638
666
|
|
|
639
667
|
Tests whether all elements satisfy the predicate.
|
|
640
668
|
|
|
@@ -674,7 +702,7 @@ Time O(n) in the worst case; may exit early when the first failure is found. Spa
|
|
|
674
702
|
filter(callback, thisArg?): this;
|
|
675
703
|
```
|
|
676
704
|
|
|
677
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
705
|
+
Defined in: [data-structures/heap/heap.ts:1156](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1156)
|
|
678
706
|
|
|
679
707
|
Filter elements into a new heap of the same class.
|
|
680
708
|
|
|
@@ -727,7 +755,7 @@ Time O(N log N), Space O(N)
|
|
|
727
755
|
find<S>(predicate, thisArg?): S | undefined;
|
|
728
756
|
```
|
|
729
757
|
|
|
730
|
-
Defined in: [data-structures/base/iterable-element-base.ts:163](https://github.com/zrwusa/data-structure-typed/blob/
|
|
758
|
+
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)
|
|
731
759
|
|
|
732
760
|
Finds the first element that satisfies the predicate and returns it.
|
|
733
761
|
|
|
@@ -773,7 +801,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
773
801
|
find(predicate, thisArg?): E | undefined;
|
|
774
802
|
```
|
|
775
803
|
|
|
776
|
-
Defined in: [data-structures/base/iterable-element-base.ts:164](https://github.com/zrwusa/data-structure-typed/blob/
|
|
804
|
+
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)
|
|
777
805
|
|
|
778
806
|
Finds the first element that satisfies the predicate and returns it.
|
|
779
807
|
|
|
@@ -815,7 +843,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
815
843
|
fix(): boolean[];
|
|
816
844
|
```
|
|
817
845
|
|
|
818
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
846
|
+
Defined in: [data-structures/heap/heap.ts:981](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L981)
|
|
819
847
|
|
|
820
848
|
Restore heap order bottom-up (heapify in-place).
|
|
821
849
|
|
|
@@ -841,7 +869,7 @@ Time O(N), Space O(1)
|
|
|
841
869
|
forEach(callbackfn, thisArg?): void;
|
|
842
870
|
```
|
|
843
871
|
|
|
844
|
-
Defined in: [data-structures/base/iterable-element-base.ts:133](https://github.com/zrwusa/data-structure-typed/blob/
|
|
872
|
+
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)
|
|
845
873
|
|
|
846
874
|
Invokes a callback for each element in iteration order.
|
|
847
875
|
|
|
@@ -881,7 +909,7 @@ Time O(n), Space O(1).
|
|
|
881
909
|
has(element): boolean;
|
|
882
910
|
```
|
|
883
911
|
|
|
884
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
912
|
+
Defined in: [data-structures/heap/heap.ts:788](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L788)
|
|
885
913
|
|
|
886
914
|
Check if an equal element exists in the heap.
|
|
887
915
|
|
|
@@ -926,7 +954,7 @@ Time O(N), Space O(1)
|
|
|
926
954
|
isEmpty(): boolean;
|
|
927
955
|
```
|
|
928
956
|
|
|
929
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
957
|
+
Defined in: [data-structures/heap/heap.ts:688](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L688)
|
|
930
958
|
|
|
931
959
|
Check whether the heap is empty.
|
|
932
960
|
|
|
@@ -967,7 +995,7 @@ map<EM, RM>(
|
|
|
967
995
|
thisArg?): Heap<EM, RM>;
|
|
968
996
|
```
|
|
969
997
|
|
|
970
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
998
|
+
Defined in: [data-structures/heap/heap.ts:1221](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1221)
|
|
971
999
|
|
|
972
1000
|
Map elements into a new heap of possibly different element type.
|
|
973
1001
|
|
|
@@ -1034,7 +1062,7 @@ Time O(N log N), Space O(N)
|
|
|
1034
1062
|
mapSame(callback, thisArg?): this;
|
|
1035
1063
|
```
|
|
1036
1064
|
|
|
1037
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1065
|
+
Defined in: [data-structures/heap/heap.ts:1245](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1245)
|
|
1038
1066
|
|
|
1039
1067
|
Map elements into a new heap of the same element type.
|
|
1040
1068
|
|
|
@@ -1074,7 +1102,7 @@ Time O(N log N), Space O(N)
|
|
|
1074
1102
|
peek(): E | undefined;
|
|
1075
1103
|
```
|
|
1076
1104
|
|
|
1077
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1105
|
+
Defined in: [data-structures/heap/heap.ts:635](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L635)
|
|
1078
1106
|
|
|
1079
1107
|
Get the current top element without removing it.
|
|
1080
1108
|
|
|
@@ -1159,28 +1187,23 @@ Time O(1), Space O(1)
|
|
|
1159
1187
|
|
|
1160
1188
|
***
|
|
1161
1189
|
|
|
1162
|
-
### poll()
|
|
1190
|
+
### ~~poll()~~
|
|
1163
1191
|
|
|
1164
1192
|
```ts
|
|
1165
1193
|
poll(): E | undefined;
|
|
1166
1194
|
```
|
|
1167
1195
|
|
|
1168
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1169
|
-
|
|
1170
|
-
Remove and return the top element.
|
|
1196
|
+
Defined in: [data-structures/heap/heap.ts:511](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L511)
|
|
1171
1197
|
|
|
1172
1198
|
#### Returns
|
|
1173
1199
|
|
|
1174
1200
|
`E` \| `undefined`
|
|
1175
1201
|
|
|
1176
|
-
|
|
1202
|
+
#### Deprecated
|
|
1177
1203
|
|
|
1204
|
+
Use `pop` instead. Will be removed in a future major version.
|
|
1178
1205
|
*
|
|
1179
1206
|
|
|
1180
|
-
#### Remarks
|
|
1181
|
-
|
|
1182
|
-
Time O(log N), Space O(1)
|
|
1183
|
-
|
|
1184
1207
|
#### Example
|
|
1185
1208
|
|
|
1186
1209
|
```ts
|
|
@@ -1216,13 +1239,39 @@ Time O(log N), Space O(1)
|
|
|
1216
1239
|
|
|
1217
1240
|
***
|
|
1218
1241
|
|
|
1242
|
+
### pop()
|
|
1243
|
+
|
|
1244
|
+
```ts
|
|
1245
|
+
pop(): E | undefined;
|
|
1246
|
+
```
|
|
1247
|
+
|
|
1248
|
+
Defined in: [data-structures/heap/heap.ts:520](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L520)
|
|
1249
|
+
|
|
1250
|
+
Remove and return the top element (min or max depending on comparator).
|
|
1251
|
+
|
|
1252
|
+
#### Returns
|
|
1253
|
+
|
|
1254
|
+
`E` \| `undefined`
|
|
1255
|
+
|
|
1256
|
+
The removed top element, or undefined if empty.
|
|
1257
|
+
|
|
1258
|
+
#### Remarks
|
|
1259
|
+
|
|
1260
|
+
Time O(log N) amortized, Space O(1)
|
|
1261
|
+
|
|
1262
|
+
#### Inherited from
|
|
1263
|
+
|
|
1264
|
+
[`Heap`](Heap.md).[`pop`](Heap.md#pop)
|
|
1265
|
+
|
|
1266
|
+
***
|
|
1267
|
+
|
|
1219
1268
|
### print()
|
|
1220
1269
|
|
|
1221
1270
|
```ts
|
|
1222
1271
|
print(): void;
|
|
1223
1272
|
```
|
|
1224
1273
|
|
|
1225
|
-
Defined in: [data-structures/base/iterable-element-base.ts:269](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1274
|
+
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)
|
|
1226
1275
|
|
|
1227
1276
|
Prints `toVisual()` to the console. Intended for quick debugging.
|
|
1228
1277
|
|
|
@@ -1280,7 +1329,7 @@ Time O(n), Space O(1). Throws if called on an empty structure without `initialVa
|
|
|
1280
1329
|
reduce(callbackfn): E;
|
|
1281
1330
|
```
|
|
1282
1331
|
|
|
1283
|
-
Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1332
|
+
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)
|
|
1284
1333
|
|
|
1285
1334
|
##### Parameters
|
|
1286
1335
|
|
|
@@ -1302,7 +1351,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.c
|
|
|
1302
1351
|
reduce(callbackfn, initialValue): E;
|
|
1303
1352
|
```
|
|
1304
1353
|
|
|
1305
|
-
Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1354
|
+
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)
|
|
1306
1355
|
|
|
1307
1356
|
##### Parameters
|
|
1308
1357
|
|
|
@@ -1328,7 +1377,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.c
|
|
|
1328
1377
|
reduce<U>(callbackfn, initialValue): U;
|
|
1329
1378
|
```
|
|
1330
1379
|
|
|
1331
|
-
Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1380
|
+
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)
|
|
1332
1381
|
|
|
1333
1382
|
##### Type Parameters
|
|
1334
1383
|
|
|
@@ -1356,47 +1405,13 @@ Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.c
|
|
|
1356
1405
|
|
|
1357
1406
|
***
|
|
1358
1407
|
|
|
1359
|
-
### refill()
|
|
1360
|
-
|
|
1361
|
-
```ts
|
|
1362
|
-
refill(elements): boolean[];
|
|
1363
|
-
```
|
|
1364
|
-
|
|
1365
|
-
Defined in: [data-structures/heap/heap.ts:687](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/heap/heap.ts#L687)
|
|
1366
|
-
|
|
1367
|
-
Replace the backing array and rebuild the heap.
|
|
1368
|
-
|
|
1369
|
-
#### Parameters
|
|
1370
|
-
|
|
1371
|
-
##### elements
|
|
1372
|
-
|
|
1373
|
-
`Iterable`\<`E`\>
|
|
1374
|
-
|
|
1375
|
-
Iterable used to refill the heap.
|
|
1376
|
-
|
|
1377
|
-
#### Returns
|
|
1378
|
-
|
|
1379
|
-
`boolean`[]
|
|
1380
|
-
|
|
1381
|
-
Array of per-node results from fixing steps.
|
|
1382
|
-
|
|
1383
|
-
#### Remarks
|
|
1384
|
-
|
|
1385
|
-
Time O(N), Space O(N)
|
|
1386
|
-
|
|
1387
|
-
#### Inherited from
|
|
1388
|
-
|
|
1389
|
-
[`Heap`](Heap.md).[`refill`](Heap.md#refill)
|
|
1390
|
-
|
|
1391
|
-
***
|
|
1392
|
-
|
|
1393
1408
|
### setEquality()
|
|
1394
1409
|
|
|
1395
1410
|
```ts
|
|
1396
1411
|
setEquality(equals): this;
|
|
1397
1412
|
```
|
|
1398
1413
|
|
|
1399
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1414
|
+
Defined in: [data-structures/heap/heap.ts:903](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L903)
|
|
1400
1415
|
|
|
1401
1416
|
Set the equality comparator used by has/delete operations.
|
|
1402
1417
|
|
|
@@ -1430,7 +1445,7 @@ Time O(1), Space O(1)
|
|
|
1430
1445
|
some(predicate, thisArg?): boolean;
|
|
1431
1446
|
```
|
|
1432
1447
|
|
|
1433
|
-
Defined in: [data-structures/base/iterable-element-base.ts:110](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1448
|
+
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)
|
|
1434
1449
|
|
|
1435
1450
|
Tests whether at least one element satisfies the predicate.
|
|
1436
1451
|
|
|
@@ -1470,7 +1485,7 @@ Time O(n) in the worst case; may exit early on first success. Space O(1).
|
|
|
1470
1485
|
sort(): E[];
|
|
1471
1486
|
```
|
|
1472
1487
|
|
|
1473
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1488
|
+
Defined in: [data-structures/heap/heap.ts:1039](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1039)
|
|
1474
1489
|
|
|
1475
1490
|
Return all elements in ascending order by repeatedly polling.
|
|
1476
1491
|
|
|
@@ -1507,7 +1522,7 @@ Time O(N log N), Space O(N)
|
|
|
1507
1522
|
toArray(): E[];
|
|
1508
1523
|
```
|
|
1509
1524
|
|
|
1510
|
-
Defined in: [data-structures/base/iterable-element-base.ts:246](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1525
|
+
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)
|
|
1511
1526
|
|
|
1512
1527
|
Materializes the elements into a new array.
|
|
1513
1528
|
|
|
@@ -1533,7 +1548,7 @@ Time O(n), Space O(n).
|
|
|
1533
1548
|
toVisual(): E[];
|
|
1534
1549
|
```
|
|
1535
1550
|
|
|
1536
|
-
Defined in: [data-structures/base/iterable-element-base.ts:258](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1551
|
+
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)
|
|
1537
1552
|
|
|
1538
1553
|
Returns a representation of the structure suitable for quick visualization.
|
|
1539
1554
|
Defaults to an array of elements; subclasses may override to provide richer visuals.
|
|
@@ -1560,7 +1575,7 @@ Time O(n), Space O(n).
|
|
|
1560
1575
|
values(): IterableIterator<E>;
|
|
1561
1576
|
```
|
|
1562
1577
|
|
|
1563
|
-
Defined in: [data-structures/base/iterable-element-base.ts:72](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1578
|
+
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)
|
|
1564
1579
|
|
|
1565
1580
|
Returns an iterator over the values (alias of the default iterator).
|
|
1566
1581
|
|
|
@@ -1589,7 +1604,7 @@ static from<T, R, S>(
|
|
|
1589
1604
|
options?): S;
|
|
1590
1605
|
```
|
|
1591
1606
|
|
|
1592
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1607
|
+
Defined in: [data-structures/heap/heap.ts:263](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L263)
|
|
1593
1608
|
|
|
1594
1609
|
Create a heap of the same class from an iterable.
|
|
1595
1610
|
|
|
@@ -1647,7 +1662,7 @@ Time O(N), Space O(N)
|
|
|
1647
1662
|
static heapify<EE, RR>(elements, options): Heap<EE, RR>;
|
|
1648
1663
|
```
|
|
1649
1664
|
|
|
1650
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1665
|
+
Defined in: [data-structures/heap/heap.ts:281](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L281)
|
|
1651
1666
|
|
|
1652
1667
|
Build a Heap from an iterable in linear time given a comparator.
|
|
1653
1668
|
|
|
@@ -1700,7 +1715,7 @@ Time O(N), Space O(N)
|
|
|
1700
1715
|
protected optional _toElementFn?: (rawElement) => E;
|
|
1701
1716
|
```
|
|
1702
1717
|
|
|
1703
|
-
Defined in: [data-structures/base/iterable-element-base.ts:39](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1718
|
+
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)
|
|
1704
1719
|
|
|
1705
1720
|
The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
1706
1721
|
|
|
@@ -1730,7 +1745,7 @@ Time O(1), Space O(1).
|
|
|
1730
1745
|
protected _createInstance(options?): this;
|
|
1731
1746
|
```
|
|
1732
1747
|
|
|
1733
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1748
|
+
Defined in: [data-structures/heap/heap.ts:1318](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1318)
|
|
1734
1749
|
|
|
1735
1750
|
(Protected) Create an empty instance of the same concrete class.
|
|
1736
1751
|
|
|
@@ -1764,7 +1779,7 @@ Time O(1), Space O(1)
|
|
|
1764
1779
|
protected _createLike<EM, RM>(elements?, options?): Heap<EM, RM>;
|
|
1765
1780
|
```
|
|
1766
1781
|
|
|
1767
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1782
|
+
Defined in: [data-structures/heap/heap.ts:1336](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1336)
|
|
1768
1783
|
|
|
1769
1784
|
(Protected) Create a like-kind instance seeded by elements.
|
|
1770
1785
|
|
|
@@ -1814,7 +1829,7 @@ Time O(N log N), Space O(N)
|
|
|
1814
1829
|
protected _getIterator(): IterableIterator<E>;
|
|
1815
1830
|
```
|
|
1816
1831
|
|
|
1817
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1832
|
+
Defined in: [data-structures/heap/heap.ts:1276](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1276)
|
|
1818
1833
|
|
|
1819
1834
|
Internal iterator factory used by the default iterator.
|
|
1820
1835
|
|
|
@@ -1840,7 +1855,7 @@ Implementations should yield in O(1) per element with O(1) extra space when poss
|
|
|
1840
1855
|
protected _spawnLike<EM, RM>(options?): Heap<EM, RM>;
|
|
1841
1856
|
```
|
|
1842
1857
|
|
|
1843
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1858
|
+
Defined in: [data-structures/heap/heap.ts:1356](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1356)
|
|
1844
1859
|
|
|
1845
1860
|
(Protected) Spawn an empty like-kind heap instance.
|
|
1846
1861
|
|