min-heap-typed 1.40.0-rc → 1.41.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/.dependency-cruiser.js +422 -422
- package/.eslintrc.js +59 -59
- package/.prettierrc.js +14 -14
- package/README.md +20 -3
- package/coverage/clover.xml +11 -7
- package/coverage/coverage-final.json +95 -1
- package/coverage/coverage-summary.json +59 -2
- package/coverage/lcov-report/base.css +278 -99
- package/coverage/lcov-report/index.html +69 -65
- package/coverage/lcov-report/index.ts.html +36 -35
- package/coverage/lcov-report/sorter.js +15 -5
- package/dist/data-structures/binary-tree/avl-tree.d.ts +106 -0
- package/dist/data-structures/binary-tree/avl-tree.js +347 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +269 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +363 -0
- package/dist/data-structures/binary-tree/binary-tree.js +1135 -0
- package/dist/data-structures/binary-tree/bst.d.ts +167 -0
- package/dist/data-structures/binary-tree/bst.js +512 -0
- package/dist/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/data-structures/binary-tree/index.js +23 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +97 -0
- package/dist/data-structures/binary-tree/rb-tree.js +388 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +67 -0
- package/dist/data-structures/binary-tree/segment-tree.js +180 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +126 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +355 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +313 -0
- package/dist/data-structures/graph/abstract-graph.js +884 -0
- package/dist/data-structures/graph/directed-graph.d.ts +194 -0
- package/dist/data-structures/graph/directed-graph.js +404 -0
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/index.js +20 -0
- package/dist/data-structures/graph/map-graph.d.ts +73 -0
- package/dist/data-structures/graph/map-graph.js +93 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +120 -0
- package/dist/data-structures/graph/undirected-graph.js +239 -0
- package/dist/data-structures/hash/coordinate-map.d.ts +44 -0
- package/dist/data-structures/hash/coordinate-map.js +62 -0
- package/dist/data-structures/hash/coordinate-set.d.ts +36 -0
- package/dist/data-structures/hash/coordinate-set.js +52 -0
- package/dist/data-structures/hash/hash-map.d.ts +50 -0
- package/dist/data-structures/hash/hash-map.js +153 -0
- package/dist/data-structures/hash/hash-table.d.ts +103 -0
- package/dist/data-structures/hash/hash-table.js +236 -0
- package/dist/data-structures/hash/index.d.ts +6 -0
- package/dist/data-structures/hash/index.js +22 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.js +6 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.js +6 -0
- package/dist/data-structures/heap/heap.d.ts +235 -0
- package/dist/data-structures/heap/heap.js +515 -0
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/index.js +19 -0
- package/dist/data-structures/heap/max-heap.d.ts +15 -0
- package/dist/data-structures/heap/max-heap.js +26 -0
- package/dist/data-structures/heap/min-heap.d.ts +15 -0
- package/dist/data-structures/heap/min-heap.js +26 -0
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/index.js +27 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +569 -0
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/index.js +19 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +232 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +533 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +80 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +187 -0
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/index.js +20 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +28 -0
- package/dist/data-structures/matrix/matrix2d.d.ts +107 -0
- package/dist/data-structures/matrix/matrix2d.js +199 -0
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +106 -0
- package/dist/data-structures/matrix/vector2d.d.ts +200 -0
- package/dist/data-structures/matrix/vector2d.js +290 -0
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/index.js +19 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +26 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +26 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/priority-queue.js +17 -0
- package/dist/data-structures/queue/deque.d.ts +161 -0
- package/dist/data-structures/queue/deque.js +264 -0
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/index.js +18 -0
- package/dist/data-structures/queue/queue.d.ts +122 -0
- package/dist/data-structures/queue/queue.js +187 -0
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/index.js +17 -0
- package/dist/data-structures/stack/stack.d.ts +64 -0
- package/dist/data-structures/stack/stack.js +94 -0
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/index.js +17 -0
- package/dist/data-structures/tree/tree.d.ts +8 -0
- package/dist/data-structures/tree/tree.js +40 -0
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/index.js +17 -0
- package/dist/data-structures/trie/trie.d.ts +79 -0
- package/dist/data-structures/trie/trie.js +251 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +18 -4
- package/dist/interfaces/binary-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.js +2 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/doubly-linked-list.js +2 -0
- package/dist/interfaces/graph.d.ts +5 -0
- package/dist/interfaces/graph.js +2 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/heap.js +2 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/interfaces/index.js +24 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/navigator.js +2 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/priority-queue.js +2 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/segment-tree.js +2 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.js +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
- package/dist/types/data-structures/binary-tree/bst.js +2 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/index.js +22 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/rb-tree.js +13 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
- package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
- package/dist/types/data-structures/graph/abstract-graph.js +2 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/graph/directed-graph.js +9 -0
- package/dist/types/data-structures/graph/index.d.ts +3 -0
- package/dist/types/data-structures/graph/index.js +19 -0
- package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/map-graph.js +2 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/undirected-graph.js +2 -0
- package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-map.js +2 -0
- package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-set.js +2 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-map.js +2 -0
- package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-table.js +2 -0
- package/dist/types/data-structures/hash/index.d.ts +1 -0
- package/dist/types/data-structures/hash/index.js +2 -0
- package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-map.js +2 -0
- package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-set.js +2 -0
- package/dist/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/data-structures/heap/heap.js +2 -0
- package/dist/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/data-structures/heap/index.js +17 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/max-heap.js +2 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/min-heap.js +2 -0
- package/dist/types/data-structures/index.d.ts +11 -0
- package/dist/types/data-structures/index.js +27 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/index.d.ts +2 -0
- package/dist/types/data-structures/linked-list/index.js +18 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
- package/dist/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.js +17 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix.js +2 -0
- package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix2d.js +2 -0
- package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/data-structures/matrix/navigator.js +2 -0
- package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/vector2d.js +2 -0
- package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/types/data-structures/priority-queue/index.js +19 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
- package/dist/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/types/data-structures/queue/deque.js +2 -0
- package/dist/types/data-structures/queue/index.d.ts +2 -0
- package/dist/types/data-structures/queue/index.js +18 -0
- package/dist/types/data-structures/queue/queue.d.ts +1 -0
- package/dist/types/data-structures/queue/queue.js +2 -0
- package/dist/types/data-structures/stack/index.d.ts +1 -0
- package/dist/types/data-structures/stack/index.js +17 -0
- package/dist/types/data-structures/stack/stack.d.ts +1 -0
- package/dist/types/data-structures/stack/stack.js +2 -0
- package/dist/types/data-structures/tree/index.d.ts +1 -0
- package/dist/types/data-structures/tree/index.js +17 -0
- package/dist/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/data-structures/tree/tree.js +2 -0
- package/dist/types/data-structures/trie/index.d.ts +1 -0
- package/dist/types/data-structures/trie/index.js +17 -0
- package/dist/types/data-structures/trie/trie.d.ts +1 -0
- package/dist/types/data-structures/trie/trie.js +2 -0
- package/dist/types/helpers.d.ts +8 -0
- package/dist/types/helpers.js +9 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.js +18 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/utils.js +2 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/types/utils/validate-type.js +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +20 -0
- package/dist/utils/utils.js +73 -0
- package/jest.config.js +6 -6
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +350 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1284 -0
- package/src/data-structures/binary-tree/bst.ts +522 -0
- package/src/data-structures/binary-tree/index.ts +7 -0
- package/src/data-structures/binary-tree/rb-tree.ts +426 -0
- package/src/data-structures/binary-tree/segment-tree.ts +190 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +379 -0
- package/src/data-structures/graph/abstract-graph.ts +1000 -0
- package/src/data-structures/graph/directed-graph.ts +449 -0
- package/src/data-structures/graph/index.ts +4 -0
- package/src/data-structures/graph/map-graph.ts +106 -0
- package/src/data-structures/graph/undirected-graph.ts +259 -0
- package/src/data-structures/hash/coordinate-map.ts +63 -0
- package/src/data-structures/hash/coordinate-set.ts +52 -0
- package/src/data-structures/hash/hash-map.ts +185 -0
- package/src/data-structures/hash/hash-table.ts +268 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/tree-map.ts +2 -0
- package/src/data-structures/hash/tree-set.ts +2 -0
- package/src/data-structures/heap/heap.ts +589 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +26 -0
- package/src/data-structures/heap/min-heap.ts +26 -0
- package/src/data-structures/index.ts +11 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +605 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +576 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +221 -0
- package/src/data-structures/matrix/index.ts +4 -0
- package/src/data-structures/matrix/matrix.ts +27 -0
- package/src/data-structures/matrix/matrix2d.ts +211 -0
- package/src/data-structures/matrix/navigator.ts +121 -0
- package/src/data-structures/matrix/vector2d.ts +315 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +25 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +25 -0
- package/src/data-structures/priority-queue/priority-queue.ts +16 -0
- package/src/data-structures/queue/deque.ts +282 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +209 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +102 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +41 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +262 -0
- package/src/index.ts +4 -1
- package/src/interfaces/binary-tree.ts +10 -0
- package/src/interfaces/doubly-linked-list.ts +1 -0
- package/src/interfaces/graph.ts +7 -0
- package/src/interfaces/heap.ts +1 -0
- package/src/interfaces/index.ts +8 -0
- package/src/interfaces/navigator.ts +1 -0
- package/src/interfaces/priority-queue.ts +1 -0
- package/src/interfaces/segment-tree.ts +1 -0
- package/src/interfaces/singly-linked-list.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
- package/src/types/data-structures/binary-tree/bst.ts +11 -0
- package/src/types/data-structures/binary-tree/index.ts +6 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
- package/src/types/data-structures/graph/abstract-graph.ts +11 -0
- package/src/types/data-structures/graph/directed-graph.ts +8 -0
- package/src/types/data-structures/graph/index.ts +3 -0
- package/src/types/data-structures/graph/map-graph.ts +1 -0
- package/src/types/data-structures/graph/undirected-graph.ts +1 -0
- package/src/types/data-structures/hash/coordinate-map.ts +1 -0
- package/src/types/data-structures/hash/coordinate-set.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +1 -0
- package/src/types/data-structures/hash/hash-table.ts +1 -0
- package/src/types/data-structures/hash/index.ts +1 -0
- package/src/types/data-structures/hash/tree-map.ts +1 -0
- package/src/types/data-structures/hash/tree-set.ts +1 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/heap/index.ts +1 -0
- package/src/types/data-structures/heap/max-heap.ts +1 -0
- package/src/types/data-structures/heap/min-heap.ts +1 -0
- package/src/types/data-structures/index.ts +11 -0
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/index.ts +2 -0
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +1 -0
- package/src/types/data-structures/matrix/matrix2d.ts +1 -0
- package/src/types/data-structures/matrix/navigator.ts +14 -0
- package/src/types/data-structures/matrix/vector2d.ts +1 -0
- package/src/types/data-structures/priority-queue/index.ts +3 -0
- package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/data-structures/queue/deque.ts +1 -0
- package/src/types/data-structures/queue/index.ts +2 -0
- package/src/types/data-structures/queue/queue.ts +1 -0
- package/src/types/data-structures/stack/index.ts +1 -0
- package/src/types/data-structures/stack/stack.ts +1 -0
- package/src/types/data-structures/tree/index.ts +1 -0
- package/src/types/data-structures/tree/tree.ts +1 -0
- package/src/types/data-structures/trie/index.ts +1 -0
- package/src/types/data-structures/trie/trie.ts +1 -0
- package/src/types/helpers.ts +11 -0
- package/src/types/index.ts +3 -0
- package/src/types/utils/index.ts +2 -0
- package/src/types/utils/utils.ts +6 -0
- package/src/types/utils/validate-type.ts +35 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +86 -0
- package/tsconfig.json +1 -2
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
* @author Kirk Qi
|
|
4
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
5
|
+
* @license MIT License
|
|
6
|
+
*/
|
|
7
|
+
import type { Comparator, DFSOrderPattern } from '../../types';
|
|
8
|
+
export declare class Heap<E = any> {
|
|
9
|
+
constructor(options: {
|
|
10
|
+
comparator: Comparator<E>;
|
|
11
|
+
nodes?: E[];
|
|
12
|
+
});
|
|
13
|
+
protected _nodes: E[];
|
|
14
|
+
get nodes(): E[];
|
|
15
|
+
protected _comparator: Comparator<E>;
|
|
16
|
+
get comparator(): Comparator<E>;
|
|
17
|
+
/**
|
|
18
|
+
* Get the size (number of elements) of the heap.
|
|
19
|
+
*/
|
|
20
|
+
get size(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Get the last element in the heap, which is not necessarily a leaf node.
|
|
23
|
+
* @returns The last element or undefined if the heap is empty.
|
|
24
|
+
*/
|
|
25
|
+
get leaf(): E | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Static method that creates a binary heap from an array of nodes and a comparison function.
|
|
28
|
+
* @returns A new Heap instance.
|
|
29
|
+
* @param options
|
|
30
|
+
*/
|
|
31
|
+
static heapify<E>(options: {
|
|
32
|
+
nodes: E[];
|
|
33
|
+
comparator: Comparator<E>;
|
|
34
|
+
}): Heap<E>;
|
|
35
|
+
/**
|
|
36
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
37
|
+
* @param element - The element to be inserted.
|
|
38
|
+
*/
|
|
39
|
+
add(element: E): Heap<E>;
|
|
40
|
+
/**
|
|
41
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
42
|
+
* @param element - The element to be inserted.
|
|
43
|
+
*/
|
|
44
|
+
push(element: E): Heap<E>;
|
|
45
|
+
/**
|
|
46
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
47
|
+
* @returns The top element or undefined if the heap is empty.
|
|
48
|
+
*/
|
|
49
|
+
poll(): E | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
52
|
+
* @returns The top element or undefined if the heap is empty.
|
|
53
|
+
*/
|
|
54
|
+
pop(): E | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Peek at the top element of the heap without removing it.
|
|
57
|
+
* @returns The top element or undefined if the heap is empty.
|
|
58
|
+
*/
|
|
59
|
+
peek(): E | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Check if the heap is empty.
|
|
62
|
+
* @returns True if the heap is empty, otherwise false.
|
|
63
|
+
*/
|
|
64
|
+
isEmpty(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Reset the nodes of the heap. Make the nodes empty.
|
|
67
|
+
*/
|
|
68
|
+
clear(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Clear and add nodes of the heap
|
|
71
|
+
* @param nodes
|
|
72
|
+
*/
|
|
73
|
+
refill(nodes: E[]): void;
|
|
74
|
+
/**
|
|
75
|
+
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
76
|
+
* @param element - the element to check.
|
|
77
|
+
* @returns Returns true if the specified element is contained; otherwise, returns false.
|
|
78
|
+
*/
|
|
79
|
+
has(element: E): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
82
|
+
* @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
|
|
83
|
+
* @returns An array containing elements traversed in the specified order.
|
|
84
|
+
*/
|
|
85
|
+
dfs(order: DFSOrderPattern): E[];
|
|
86
|
+
/**
|
|
87
|
+
* Convert the heap to an array.
|
|
88
|
+
* @returns An array containing the elements of the heap.
|
|
89
|
+
*/
|
|
90
|
+
toArray(): E[];
|
|
91
|
+
getNodes(): E[];
|
|
92
|
+
/**
|
|
93
|
+
* Clone the heap, creating a new heap with the same elements.
|
|
94
|
+
* @returns A new Heap instance containing the same elements.
|
|
95
|
+
*/
|
|
96
|
+
clone(): Heap<E>;
|
|
97
|
+
/**
|
|
98
|
+
* Sort the elements in the heap and return them as an array.
|
|
99
|
+
* @returns An array containing the elements sorted in ascending order.
|
|
100
|
+
*/
|
|
101
|
+
sort(): E[];
|
|
102
|
+
/**
|
|
103
|
+
* Float operation to maintain heap properties after adding an element.
|
|
104
|
+
* @param index - The index of the newly added element.
|
|
105
|
+
*/
|
|
106
|
+
protected bubbleUp(index: number): void;
|
|
107
|
+
/**
|
|
108
|
+
* Sinking operation to maintain heap properties after removing the top element.
|
|
109
|
+
* @param index - The index from which to start sinking.
|
|
110
|
+
*/
|
|
111
|
+
protected sinkDown(index: number): void;
|
|
112
|
+
/**
|
|
113
|
+
* Fix the entire heap to maintain heap properties.
|
|
114
|
+
*/
|
|
115
|
+
protected fix(): void;
|
|
116
|
+
}
|
|
117
|
+
export declare class FibonacciHeapNode<E> {
|
|
118
|
+
element: E;
|
|
119
|
+
degree: number;
|
|
120
|
+
left?: FibonacciHeapNode<E>;
|
|
121
|
+
right?: FibonacciHeapNode<E>;
|
|
122
|
+
child?: FibonacciHeapNode<E>;
|
|
123
|
+
parent?: FibonacciHeapNode<E>;
|
|
124
|
+
marked: boolean;
|
|
125
|
+
constructor(element: E, degree?: number);
|
|
126
|
+
}
|
|
127
|
+
export declare class FibonacciHeap<E> {
|
|
128
|
+
constructor(comparator?: Comparator<E>);
|
|
129
|
+
protected _root?: FibonacciHeapNode<E>;
|
|
130
|
+
get root(): FibonacciHeapNode<E> | undefined;
|
|
131
|
+
protected _size: number;
|
|
132
|
+
get size(): number;
|
|
133
|
+
protected _min?: FibonacciHeapNode<E>;
|
|
134
|
+
get min(): FibonacciHeapNode<E> | undefined;
|
|
135
|
+
protected _comparator: Comparator<E>;
|
|
136
|
+
get comparator(): Comparator<E>;
|
|
137
|
+
/**
|
|
138
|
+
* Get the size (number of elements) of the heap.
|
|
139
|
+
* @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
|
|
140
|
+
*/
|
|
141
|
+
clear(): void;
|
|
142
|
+
/**
|
|
143
|
+
* O(1) time operation.
|
|
144
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
145
|
+
* @param element
|
|
146
|
+
* @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
|
|
147
|
+
*/
|
|
148
|
+
add(element: E): FibonacciHeap<E>;
|
|
149
|
+
/**
|
|
150
|
+
* O(1) time operation.
|
|
151
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
152
|
+
* @param element
|
|
153
|
+
* @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
|
|
154
|
+
*/
|
|
155
|
+
push(element: E): FibonacciHeap<E>;
|
|
156
|
+
/**
|
|
157
|
+
* O(1) time operation.
|
|
158
|
+
* Peek at the top element of the heap without removing it.
|
|
159
|
+
* @returns The top element or undefined if the heap is empty.
|
|
160
|
+
* @protected
|
|
161
|
+
*/
|
|
162
|
+
peek(): E | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* O(1) time operation.
|
|
165
|
+
* Get the size (number of elements) of the heap.
|
|
166
|
+
* @param {FibonacciHeapNode<E>} head - The head of the linked list.
|
|
167
|
+
* @protected
|
|
168
|
+
* @returns FibonacciHeapNode<E>[] - An array containing the nodes of the linked list.
|
|
169
|
+
*/
|
|
170
|
+
consumeLinkedList(head?: FibonacciHeapNode<E>): FibonacciHeapNode<E>[];
|
|
171
|
+
/**
|
|
172
|
+
* O(log n) time operation.
|
|
173
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
174
|
+
* @param parent
|
|
175
|
+
* @param node
|
|
176
|
+
*/
|
|
177
|
+
mergeWithChild(parent: FibonacciHeapNode<E>, node: FibonacciHeapNode<E>): void;
|
|
178
|
+
/**
|
|
179
|
+
* O(log n) time operation.
|
|
180
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
181
|
+
* @returns The top element or undefined if the heap is empty.
|
|
182
|
+
*/
|
|
183
|
+
poll(): E | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* O(log n) time operation.
|
|
186
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
187
|
+
* @returns The top element or undefined if the heap is empty.
|
|
188
|
+
*/
|
|
189
|
+
pop(): E | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* O(log n) time operation.
|
|
192
|
+
* merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
|
|
193
|
+
* @param heapToMerge
|
|
194
|
+
*/
|
|
195
|
+
merge(heapToMerge: FibonacciHeap<E>): void;
|
|
196
|
+
/**
|
|
197
|
+
* Default comparator function used by the heap.
|
|
198
|
+
* @param {E} a
|
|
199
|
+
* @param {E} b
|
|
200
|
+
* @protected
|
|
201
|
+
*/
|
|
202
|
+
protected defaultComparator(a: E, b: E): number;
|
|
203
|
+
/**
|
|
204
|
+
* Create a new node.
|
|
205
|
+
* @param element
|
|
206
|
+
* @protected
|
|
207
|
+
*/
|
|
208
|
+
protected createNode(element: E): FibonacciHeapNode<E>;
|
|
209
|
+
/**
|
|
210
|
+
* Merge the given node with the root list.
|
|
211
|
+
* @param node - The node to be merged.
|
|
212
|
+
*/
|
|
213
|
+
protected mergeWithRoot(node: FibonacciHeapNode<E>): void;
|
|
214
|
+
/**
|
|
215
|
+
* O(log n) time operation.
|
|
216
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
217
|
+
* @param node - The node to be removed.
|
|
218
|
+
* @protected
|
|
219
|
+
*/
|
|
220
|
+
protected removeFromRoot(node: FibonacciHeapNode<E>): void;
|
|
221
|
+
/**
|
|
222
|
+
* O(log n) time operation.
|
|
223
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
224
|
+
* @param y
|
|
225
|
+
* @param x
|
|
226
|
+
* @protected
|
|
227
|
+
*/
|
|
228
|
+
protected link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
|
|
229
|
+
/**
|
|
230
|
+
* O(log n) time operation.
|
|
231
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
232
|
+
* @protected
|
|
233
|
+
*/
|
|
234
|
+
protected consolidate(): void;
|
|
235
|
+
}
|