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: PriorityQueue\<E, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/priority-queue/priority-queue.ts:75](https://github.com/zrwusa/data-structure-typed/blob/
|
|
9
|
+
Defined in: [data-structures/priority-queue/priority-queue.ts:75](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/priority-queue/priority-queue.ts#L75)
|
|
10
10
|
|
|
11
11
|
## Examples
|
|
12
12
|
|
|
@@ -106,7 +106,7 @@ Defined in: [data-structures/priority-queue/priority-queue.ts:75](https://github
|
|
|
106
106
|
get comparator(): Comparator<E>;
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
109
|
+
Defined in: [data-structures/heap/heap.ts:1272](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1272)
|
|
110
110
|
|
|
111
111
|
Get the comparator used to order elements.
|
|
112
112
|
|
|
@@ -134,7 +134,7 @@ Comparator function.
|
|
|
134
134
|
get elements(): E[];
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/
|
|
137
|
+
Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L180)
|
|
138
138
|
|
|
139
139
|
Get the backing array of the heap.
|
|
140
140
|
|
|
@@ -162,7 +162,7 @@ Internal elements array.
|
|
|
162
162
|
get leaf(): E | undefined;
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
165
|
+
Defined in: [data-structures/heap/heap.ts:248](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L248)
|
|
166
166
|
|
|
167
167
|
Get the last leaf element.
|
|
168
168
|
|
|
@@ -190,7 +190,7 @@ Last element or undefined.
|
|
|
190
190
|
get size(): number;
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
193
|
+
Defined in: [data-structures/heap/heap.ts:238](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L238)
|
|
194
194
|
|
|
195
195
|
Get the number of elements.
|
|
196
196
|
|
|
@@ -233,7 +233,7 @@ Heap size.
|
|
|
233
233
|
get toElementFn(): ((rawElement) => E) | undefined;
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
-
Defined in: [data-structures/base/iterable-element-base.ts:48](https://github.com/zrwusa/data-structure-typed/blob/
|
|
236
|
+
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)
|
|
237
237
|
|
|
238
238
|
Exposes the current `toElementFn`, if configured.
|
|
239
239
|
|
|
@@ -259,7 +259,7 @@ The converter function or `undefined` when not set.
|
|
|
259
259
|
iterator: IterableIterator<E>;
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
-
Defined in: [data-structures/base/iterable-element-base.ts:61](https://github.com/zrwusa/data-structure-typed/blob/
|
|
262
|
+
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)
|
|
263
263
|
|
|
264
264
|
Returns an iterator over the structure's elements.
|
|
265
265
|
|
|
@@ -293,7 +293,7 @@ Producing the iterator is O(1); consuming the entire iterator is Time O(n) with
|
|
|
293
293
|
add(element): boolean;
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
296
|
+
Defined in: [data-structures/heap/heap.ts:346](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L346)
|
|
297
297
|
|
|
298
298
|
Insert an element.
|
|
299
299
|
|
|
@@ -315,7 +315,7 @@ True.
|
|
|
315
315
|
|
|
316
316
|
#### Remarks
|
|
317
317
|
|
|
318
|
-
Time O(
|
|
318
|
+
Time O(log N) amortized, Space O(1)
|
|
319
319
|
|
|
320
320
|
#### Example
|
|
321
321
|
|
|
@@ -348,7 +348,7 @@ Time O(1) amortized, Space O(1)
|
|
|
348
348
|
addMany(elements): boolean[];
|
|
349
349
|
```
|
|
350
350
|
|
|
351
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
351
|
+
Defined in: [data-structures/heap/heap.ts:400](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L400)
|
|
352
352
|
|
|
353
353
|
Insert many elements from an iterable.
|
|
354
354
|
|
|
@@ -394,7 +394,7 @@ Time O(N log N), Space O(1)
|
|
|
394
394
|
clear(): void;
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
397
|
+
Defined in: [data-structures/heap/heap.ts:740](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L740)
|
|
398
398
|
|
|
399
399
|
Remove all elements.
|
|
400
400
|
|
|
@@ -431,7 +431,7 @@ Time O(1), Space O(1)
|
|
|
431
431
|
clone(): this;
|
|
432
432
|
```
|
|
433
433
|
|
|
434
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
434
|
+
Defined in: [data-structures/heap/heap.ts:1100](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1100)
|
|
435
435
|
|
|
436
436
|
Deep clone this heap.
|
|
437
437
|
|
|
@@ -470,7 +470,7 @@ Time O(N), Space O(N)
|
|
|
470
470
|
delete(element): boolean;
|
|
471
471
|
```
|
|
472
472
|
|
|
473
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
473
|
+
Defined in: [data-structures/heap/heap.ts:841](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L841)
|
|
474
474
|
|
|
475
475
|
Delete one occurrence of an element.
|
|
476
476
|
|
|
@@ -509,13 +509,41 @@ Time O(N), Space O(1)
|
|
|
509
509
|
|
|
510
510
|
***
|
|
511
511
|
|
|
512
|
-
### deleteBy()
|
|
512
|
+
### ~~deleteBy()~~
|
|
513
513
|
|
|
514
514
|
```ts
|
|
515
515
|
deleteBy(predicate): boolean;
|
|
516
516
|
```
|
|
517
517
|
|
|
518
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
518
|
+
Defined in: [data-structures/heap/heap.ts:865](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L865)
|
|
519
|
+
|
|
520
|
+
#### Parameters
|
|
521
|
+
|
|
522
|
+
##### predicate
|
|
523
|
+
|
|
524
|
+
(`element`, `index`, `heap`) => `boolean`
|
|
525
|
+
|
|
526
|
+
#### Returns
|
|
527
|
+
|
|
528
|
+
`boolean`
|
|
529
|
+
|
|
530
|
+
#### Deprecated
|
|
531
|
+
|
|
532
|
+
Use `deleteWhere` instead. Will be removed in a future major version.
|
|
533
|
+
|
|
534
|
+
#### Inherited from
|
|
535
|
+
|
|
536
|
+
[`Heap`](Heap.md).[`deleteBy`](Heap.md#deleteby)
|
|
537
|
+
|
|
538
|
+
***
|
|
539
|
+
|
|
540
|
+
### deleteWhere()
|
|
541
|
+
|
|
542
|
+
```ts
|
|
543
|
+
deleteWhere(predicate): boolean;
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
Defined in: [data-structures/heap/heap.ts:875](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L875)
|
|
519
547
|
|
|
520
548
|
Delete the first element that matches a predicate.
|
|
521
549
|
|
|
@@ -539,7 +567,7 @@ Time O(N), Space O(1)
|
|
|
539
567
|
|
|
540
568
|
#### Inherited from
|
|
541
569
|
|
|
542
|
-
[`Heap`](Heap.md).[`
|
|
570
|
+
[`Heap`](Heap.md).[`deleteWhere`](Heap.md#deletewhere)
|
|
543
571
|
|
|
544
572
|
***
|
|
545
573
|
|
|
@@ -549,7 +577,7 @@ Time O(N), Space O(1)
|
|
|
549
577
|
dfs(order?): E[];
|
|
550
578
|
```
|
|
551
579
|
|
|
552
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
580
|
+
Defined in: [data-structures/heap/heap.ts:950](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L950)
|
|
553
581
|
|
|
554
582
|
Traverse the binary heap as a complete binary tree and collect elements.
|
|
555
583
|
|
|
@@ -594,7 +622,7 @@ Time O(N), Space O(H)
|
|
|
594
622
|
every(predicate, thisArg?): boolean;
|
|
595
623
|
```
|
|
596
624
|
|
|
597
|
-
Defined in: [data-structures/base/iterable-element-base.ts:87](https://github.com/zrwusa/data-structure-typed/blob/
|
|
625
|
+
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)
|
|
598
626
|
|
|
599
627
|
Tests whether all elements satisfy the predicate.
|
|
600
628
|
|
|
@@ -634,7 +662,7 @@ Time O(n) in the worst case; may exit early when the first failure is found. Spa
|
|
|
634
662
|
filter(callback, thisArg?): this;
|
|
635
663
|
```
|
|
636
664
|
|
|
637
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
665
|
+
Defined in: [data-structures/heap/heap.ts:1156](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1156)
|
|
638
666
|
|
|
639
667
|
Filter elements into a new heap of the same class.
|
|
640
668
|
|
|
@@ -687,7 +715,7 @@ Time O(N log N), Space O(N)
|
|
|
687
715
|
find<S>(predicate, thisArg?): S | undefined;
|
|
688
716
|
```
|
|
689
717
|
|
|
690
|
-
Defined in: [data-structures/base/iterable-element-base.ts:163](https://github.com/zrwusa/data-structure-typed/blob/
|
|
718
|
+
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)
|
|
691
719
|
|
|
692
720
|
Finds the first element that satisfies the predicate and returns it.
|
|
693
721
|
|
|
@@ -733,7 +761,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
733
761
|
find(predicate, thisArg?): E | undefined;
|
|
734
762
|
```
|
|
735
763
|
|
|
736
|
-
Defined in: [data-structures/base/iterable-element-base.ts:164](https://github.com/zrwusa/data-structure-typed/blob/
|
|
764
|
+
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)
|
|
737
765
|
|
|
738
766
|
Finds the first element that satisfies the predicate and returns it.
|
|
739
767
|
|
|
@@ -775,7 +803,7 @@ Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
|
775
803
|
fix(): boolean[];
|
|
776
804
|
```
|
|
777
805
|
|
|
778
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
806
|
+
Defined in: [data-structures/heap/heap.ts:981](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L981)
|
|
779
807
|
|
|
780
808
|
Restore heap order bottom-up (heapify in-place).
|
|
781
809
|
|
|
@@ -801,7 +829,7 @@ Time O(N), Space O(1)
|
|
|
801
829
|
forEach(callbackfn, thisArg?): void;
|
|
802
830
|
```
|
|
803
831
|
|
|
804
|
-
Defined in: [data-structures/base/iterable-element-base.ts:133](https://github.com/zrwusa/data-structure-typed/blob/
|
|
832
|
+
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)
|
|
805
833
|
|
|
806
834
|
Invokes a callback for each element in iteration order.
|
|
807
835
|
|
|
@@ -841,7 +869,7 @@ Time O(n), Space O(1).
|
|
|
841
869
|
has(element): boolean;
|
|
842
870
|
```
|
|
843
871
|
|
|
844
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
872
|
+
Defined in: [data-structures/heap/heap.ts:788](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L788)
|
|
845
873
|
|
|
846
874
|
Check if an equal element exists in the heap.
|
|
847
875
|
|
|
@@ -886,7 +914,7 @@ Time O(N), Space O(1)
|
|
|
886
914
|
isEmpty(): boolean;
|
|
887
915
|
```
|
|
888
916
|
|
|
889
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
917
|
+
Defined in: [data-structures/heap/heap.ts:688](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L688)
|
|
890
918
|
|
|
891
919
|
Check whether the heap is empty.
|
|
892
920
|
|
|
@@ -927,7 +955,7 @@ map<EM, RM>(
|
|
|
927
955
|
thisArg?): Heap<EM, RM>;
|
|
928
956
|
```
|
|
929
957
|
|
|
930
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
958
|
+
Defined in: [data-structures/heap/heap.ts:1221](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1221)
|
|
931
959
|
|
|
932
960
|
Map elements into a new heap of possibly different element type.
|
|
933
961
|
|
|
@@ -994,7 +1022,7 @@ Time O(N log N), Space O(N)
|
|
|
994
1022
|
mapSame(callback, thisArg?): this;
|
|
995
1023
|
```
|
|
996
1024
|
|
|
997
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1025
|
+
Defined in: [data-structures/heap/heap.ts:1245](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1245)
|
|
998
1026
|
|
|
999
1027
|
Map elements into a new heap of the same element type.
|
|
1000
1028
|
|
|
@@ -1034,7 +1062,7 @@ Time O(N log N), Space O(N)
|
|
|
1034
1062
|
peek(): E | undefined;
|
|
1035
1063
|
```
|
|
1036
1064
|
|
|
1037
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1065
|
+
Defined in: [data-structures/heap/heap.ts:635](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L635)
|
|
1038
1066
|
|
|
1039
1067
|
Get the current top element without removing it.
|
|
1040
1068
|
|
|
@@ -1119,28 +1147,23 @@ Time O(1), Space O(1)
|
|
|
1119
1147
|
|
|
1120
1148
|
***
|
|
1121
1149
|
|
|
1122
|
-
### poll()
|
|
1150
|
+
### ~~poll()~~
|
|
1123
1151
|
|
|
1124
1152
|
```ts
|
|
1125
1153
|
poll(): E | undefined;
|
|
1126
1154
|
```
|
|
1127
1155
|
|
|
1128
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1129
|
-
|
|
1130
|
-
Remove and return the top element.
|
|
1156
|
+
Defined in: [data-structures/heap/heap.ts:511](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L511)
|
|
1131
1157
|
|
|
1132
1158
|
#### Returns
|
|
1133
1159
|
|
|
1134
1160
|
`E` \| `undefined`
|
|
1135
1161
|
|
|
1136
|
-
|
|
1162
|
+
#### Deprecated
|
|
1137
1163
|
|
|
1164
|
+
Use `pop` instead. Will be removed in a future major version.
|
|
1138
1165
|
*
|
|
1139
1166
|
|
|
1140
|
-
#### Remarks
|
|
1141
|
-
|
|
1142
|
-
Time O(log N), Space O(1)
|
|
1143
|
-
|
|
1144
1167
|
#### Example
|
|
1145
1168
|
|
|
1146
1169
|
```ts
|
|
@@ -1176,13 +1199,39 @@ Time O(log N), Space O(1)
|
|
|
1176
1199
|
|
|
1177
1200
|
***
|
|
1178
1201
|
|
|
1202
|
+
### pop()
|
|
1203
|
+
|
|
1204
|
+
```ts
|
|
1205
|
+
pop(): E | undefined;
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
Defined in: [data-structures/heap/heap.ts:520](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L520)
|
|
1209
|
+
|
|
1210
|
+
Remove and return the top element (min or max depending on comparator).
|
|
1211
|
+
|
|
1212
|
+
#### Returns
|
|
1213
|
+
|
|
1214
|
+
`E` \| `undefined`
|
|
1215
|
+
|
|
1216
|
+
The removed top element, or undefined if empty.
|
|
1217
|
+
|
|
1218
|
+
#### Remarks
|
|
1219
|
+
|
|
1220
|
+
Time O(log N) amortized, Space O(1)
|
|
1221
|
+
|
|
1222
|
+
#### Inherited from
|
|
1223
|
+
|
|
1224
|
+
[`Heap`](Heap.md).[`pop`](Heap.md#pop)
|
|
1225
|
+
|
|
1226
|
+
***
|
|
1227
|
+
|
|
1179
1228
|
### print()
|
|
1180
1229
|
|
|
1181
1230
|
```ts
|
|
1182
1231
|
print(): void;
|
|
1183
1232
|
```
|
|
1184
1233
|
|
|
1185
|
-
Defined in: [data-structures/base/iterable-element-base.ts:269](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1234
|
+
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)
|
|
1186
1235
|
|
|
1187
1236
|
Prints `toVisual()` to the console. Intended for quick debugging.
|
|
1188
1237
|
|
|
@@ -1240,7 +1289,7 @@ Time O(n), Space O(1). Throws if called on an empty structure without `initialVa
|
|
|
1240
1289
|
reduce(callbackfn): E;
|
|
1241
1290
|
```
|
|
1242
1291
|
|
|
1243
|
-
Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1292
|
+
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)
|
|
1244
1293
|
|
|
1245
1294
|
##### Parameters
|
|
1246
1295
|
|
|
@@ -1262,7 +1311,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.c
|
|
|
1262
1311
|
reduce(callbackfn, initialValue): E;
|
|
1263
1312
|
```
|
|
1264
1313
|
|
|
1265
|
-
Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1314
|
+
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)
|
|
1266
1315
|
|
|
1267
1316
|
##### Parameters
|
|
1268
1317
|
|
|
@@ -1288,7 +1337,7 @@ Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.c
|
|
|
1288
1337
|
reduce<U>(callbackfn, initialValue): U;
|
|
1289
1338
|
```
|
|
1290
1339
|
|
|
1291
|
-
Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1340
|
+
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)
|
|
1292
1341
|
|
|
1293
1342
|
##### Type Parameters
|
|
1294
1343
|
|
|
@@ -1316,47 +1365,13 @@ Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.c
|
|
|
1316
1365
|
|
|
1317
1366
|
***
|
|
1318
1367
|
|
|
1319
|
-
### refill()
|
|
1320
|
-
|
|
1321
|
-
```ts
|
|
1322
|
-
refill(elements): boolean[];
|
|
1323
|
-
```
|
|
1324
|
-
|
|
1325
|
-
Defined in: [data-structures/heap/heap.ts:687](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/heap/heap.ts#L687)
|
|
1326
|
-
|
|
1327
|
-
Replace the backing array and rebuild the heap.
|
|
1328
|
-
|
|
1329
|
-
#### Parameters
|
|
1330
|
-
|
|
1331
|
-
##### elements
|
|
1332
|
-
|
|
1333
|
-
`Iterable`\<`E`\>
|
|
1334
|
-
|
|
1335
|
-
Iterable used to refill the heap.
|
|
1336
|
-
|
|
1337
|
-
#### Returns
|
|
1338
|
-
|
|
1339
|
-
`boolean`[]
|
|
1340
|
-
|
|
1341
|
-
Array of per-node results from fixing steps.
|
|
1342
|
-
|
|
1343
|
-
#### Remarks
|
|
1344
|
-
|
|
1345
|
-
Time O(N), Space O(N)
|
|
1346
|
-
|
|
1347
|
-
#### Inherited from
|
|
1348
|
-
|
|
1349
|
-
[`Heap`](Heap.md).[`refill`](Heap.md#refill)
|
|
1350
|
-
|
|
1351
|
-
***
|
|
1352
|
-
|
|
1353
1368
|
### setEquality()
|
|
1354
1369
|
|
|
1355
1370
|
```ts
|
|
1356
1371
|
setEquality(equals): this;
|
|
1357
1372
|
```
|
|
1358
1373
|
|
|
1359
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1374
|
+
Defined in: [data-structures/heap/heap.ts:903](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L903)
|
|
1360
1375
|
|
|
1361
1376
|
Set the equality comparator used by has/delete operations.
|
|
1362
1377
|
|
|
@@ -1390,7 +1405,7 @@ Time O(1), Space O(1)
|
|
|
1390
1405
|
some(predicate, thisArg?): boolean;
|
|
1391
1406
|
```
|
|
1392
1407
|
|
|
1393
|
-
Defined in: [data-structures/base/iterable-element-base.ts:110](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1408
|
+
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)
|
|
1394
1409
|
|
|
1395
1410
|
Tests whether at least one element satisfies the predicate.
|
|
1396
1411
|
|
|
@@ -1430,7 +1445,7 @@ Time O(n) in the worst case; may exit early on first success. Space O(1).
|
|
|
1430
1445
|
sort(): E[];
|
|
1431
1446
|
```
|
|
1432
1447
|
|
|
1433
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1448
|
+
Defined in: [data-structures/heap/heap.ts:1039](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1039)
|
|
1434
1449
|
|
|
1435
1450
|
Return all elements in ascending order by repeatedly polling.
|
|
1436
1451
|
|
|
@@ -1467,7 +1482,7 @@ Time O(N log N), Space O(N)
|
|
|
1467
1482
|
toArray(): E[];
|
|
1468
1483
|
```
|
|
1469
1484
|
|
|
1470
|
-
Defined in: [data-structures/base/iterable-element-base.ts:246](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1485
|
+
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)
|
|
1471
1486
|
|
|
1472
1487
|
Materializes the elements into a new array.
|
|
1473
1488
|
|
|
@@ -1493,7 +1508,7 @@ Time O(n), Space O(n).
|
|
|
1493
1508
|
toVisual(): E[];
|
|
1494
1509
|
```
|
|
1495
1510
|
|
|
1496
|
-
Defined in: [data-structures/base/iterable-element-base.ts:258](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1511
|
+
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)
|
|
1497
1512
|
|
|
1498
1513
|
Returns a representation of the structure suitable for quick visualization.
|
|
1499
1514
|
Defaults to an array of elements; subclasses may override to provide richer visuals.
|
|
@@ -1520,7 +1535,7 @@ Time O(n), Space O(n).
|
|
|
1520
1535
|
values(): IterableIterator<E>;
|
|
1521
1536
|
```
|
|
1522
1537
|
|
|
1523
|
-
Defined in: [data-structures/base/iterable-element-base.ts:72](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1538
|
+
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)
|
|
1524
1539
|
|
|
1525
1540
|
Returns an iterator over the values (alias of the default iterator).
|
|
1526
1541
|
|
|
@@ -1549,7 +1564,7 @@ static from<T, R, S>(
|
|
|
1549
1564
|
options?): S;
|
|
1550
1565
|
```
|
|
1551
1566
|
|
|
1552
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1567
|
+
Defined in: [data-structures/heap/heap.ts:263](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L263)
|
|
1553
1568
|
|
|
1554
1569
|
Create a heap of the same class from an iterable.
|
|
1555
1570
|
|
|
@@ -1607,7 +1622,7 @@ Time O(N), Space O(N)
|
|
|
1607
1622
|
static heapify<EE, RR>(elements, options): Heap<EE, RR>;
|
|
1608
1623
|
```
|
|
1609
1624
|
|
|
1610
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1625
|
+
Defined in: [data-structures/heap/heap.ts:281](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L281)
|
|
1611
1626
|
|
|
1612
1627
|
Build a Heap from an iterable in linear time given a comparator.
|
|
1613
1628
|
|
|
@@ -1660,7 +1675,7 @@ Time O(N), Space O(N)
|
|
|
1660
1675
|
protected optional _toElementFn?: (rawElement) => E;
|
|
1661
1676
|
```
|
|
1662
1677
|
|
|
1663
|
-
Defined in: [data-structures/base/iterable-element-base.ts:39](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1678
|
+
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)
|
|
1664
1679
|
|
|
1665
1680
|
The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
1666
1681
|
|
|
@@ -1690,7 +1705,7 @@ Time O(1), Space O(1).
|
|
|
1690
1705
|
protected _createInstance(options?): this;
|
|
1691
1706
|
```
|
|
1692
1707
|
|
|
1693
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1708
|
+
Defined in: [data-structures/heap/heap.ts:1318](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1318)
|
|
1694
1709
|
|
|
1695
1710
|
(Protected) Create an empty instance of the same concrete class.
|
|
1696
1711
|
|
|
@@ -1724,7 +1739,7 @@ Time O(1), Space O(1)
|
|
|
1724
1739
|
protected _createLike<EM, RM>(elements?, options?): Heap<EM, RM>;
|
|
1725
1740
|
```
|
|
1726
1741
|
|
|
1727
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1742
|
+
Defined in: [data-structures/heap/heap.ts:1336](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1336)
|
|
1728
1743
|
|
|
1729
1744
|
(Protected) Create a like-kind instance seeded by elements.
|
|
1730
1745
|
|
|
@@ -1774,7 +1789,7 @@ Time O(N log N), Space O(N)
|
|
|
1774
1789
|
protected _getIterator(): IterableIterator<E>;
|
|
1775
1790
|
```
|
|
1776
1791
|
|
|
1777
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1792
|
+
Defined in: [data-structures/heap/heap.ts:1276](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1276)
|
|
1778
1793
|
|
|
1779
1794
|
Internal iterator factory used by the default iterator.
|
|
1780
1795
|
|
|
@@ -1800,7 +1815,7 @@ Implementations should yield in O(1) per element with O(1) extra space when poss
|
|
|
1800
1815
|
protected _spawnLike<EM, RM>(options?): Heap<EM, RM>;
|
|
1801
1816
|
```
|
|
1802
1817
|
|
|
1803
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
1818
|
+
Defined in: [data-structures/heap/heap.ts:1356](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L1356)
|
|
1804
1819
|
|
|
1805
1820
|
(Protected) Spawn an empty like-kind heap instance.
|
|
1806
1821
|
|