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,515 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
* @author Kirk Qi
|
|
5
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FibonacciHeap = exports.FibonacciHeapNode = exports.Heap = void 0;
|
|
10
|
+
class Heap {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this._nodes = [];
|
|
13
|
+
this._comparator = options.comparator;
|
|
14
|
+
if (options.nodes && options.nodes.length > 0) {
|
|
15
|
+
this._nodes = options.nodes;
|
|
16
|
+
this.fix();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
get nodes() {
|
|
20
|
+
return this._nodes;
|
|
21
|
+
}
|
|
22
|
+
get comparator() {
|
|
23
|
+
return this._comparator;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the size (number of elements) of the heap.
|
|
27
|
+
*/
|
|
28
|
+
get size() {
|
|
29
|
+
return this.nodes.length;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the last element in the heap, which is not necessarily a leaf node.
|
|
33
|
+
* @returns The last element or undefined if the heap is empty.
|
|
34
|
+
*/
|
|
35
|
+
get leaf() {
|
|
36
|
+
var _a;
|
|
37
|
+
return (_a = this.nodes[this.size - 1]) !== null && _a !== void 0 ? _a : undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Static method that creates a binary heap from an array of nodes and a comparison function.
|
|
41
|
+
* @returns A new Heap instance.
|
|
42
|
+
* @param options
|
|
43
|
+
*/
|
|
44
|
+
static heapify(options) {
|
|
45
|
+
return new Heap(options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
49
|
+
* @param element - The element to be inserted.
|
|
50
|
+
*/
|
|
51
|
+
add(element) {
|
|
52
|
+
return this.push(element);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
56
|
+
* @param element - The element to be inserted.
|
|
57
|
+
*/
|
|
58
|
+
push(element) {
|
|
59
|
+
this.nodes.push(element);
|
|
60
|
+
this.bubbleUp(this.nodes.length - 1);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
65
|
+
* @returns The top element or undefined if the heap is empty.
|
|
66
|
+
*/
|
|
67
|
+
poll() {
|
|
68
|
+
if (this.nodes.length === 0) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
if (this.nodes.length === 1) {
|
|
72
|
+
return this.nodes.pop();
|
|
73
|
+
}
|
|
74
|
+
const topValue = this.nodes[0];
|
|
75
|
+
this.nodes[0] = this.nodes.pop();
|
|
76
|
+
this.sinkDown(0);
|
|
77
|
+
return topValue;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
81
|
+
* @returns The top element or undefined if the heap is empty.
|
|
82
|
+
*/
|
|
83
|
+
pop() {
|
|
84
|
+
return this.poll();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Peek at the top element of the heap without removing it.
|
|
88
|
+
* @returns The top element or undefined if the heap is empty.
|
|
89
|
+
*/
|
|
90
|
+
peek() {
|
|
91
|
+
if (this.nodes.length === 0) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
return this.nodes[0];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if the heap is empty.
|
|
98
|
+
* @returns True if the heap is empty, otherwise false.
|
|
99
|
+
*/
|
|
100
|
+
isEmpty() {
|
|
101
|
+
return this.size === 0;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Reset the nodes of the heap. Make the nodes empty.
|
|
105
|
+
*/
|
|
106
|
+
clear() {
|
|
107
|
+
this._nodes = [];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Clear and add nodes of the heap
|
|
111
|
+
* @param nodes
|
|
112
|
+
*/
|
|
113
|
+
refill(nodes) {
|
|
114
|
+
this._nodes = nodes;
|
|
115
|
+
this.fix();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
119
|
+
* @param element - the element to check.
|
|
120
|
+
* @returns Returns true if the specified element is contained; otherwise, returns false.
|
|
121
|
+
*/
|
|
122
|
+
has(element) {
|
|
123
|
+
return this.nodes.includes(element);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
127
|
+
* @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
|
|
128
|
+
* @returns An array containing elements traversed in the specified order.
|
|
129
|
+
*/
|
|
130
|
+
dfs(order) {
|
|
131
|
+
const result = [];
|
|
132
|
+
// Auxiliary recursive function, traverses the binary heap according to the traversal order
|
|
133
|
+
const dfsHelper = (index) => {
|
|
134
|
+
if (index < this.size) {
|
|
135
|
+
if (order === 'in') {
|
|
136
|
+
dfsHelper(2 * index + 1);
|
|
137
|
+
result.push(this.nodes[index]);
|
|
138
|
+
dfsHelper(2 * index + 2);
|
|
139
|
+
}
|
|
140
|
+
else if (order === 'pre') {
|
|
141
|
+
result.push(this.nodes[index]);
|
|
142
|
+
dfsHelper(2 * index + 1);
|
|
143
|
+
dfsHelper(2 * index + 2);
|
|
144
|
+
}
|
|
145
|
+
else if (order === 'post') {
|
|
146
|
+
dfsHelper(2 * index + 1);
|
|
147
|
+
dfsHelper(2 * index + 2);
|
|
148
|
+
result.push(this.nodes[index]);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
dfsHelper(0); // Traverse starting from the root node
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Convert the heap to an array.
|
|
157
|
+
* @returns An array containing the elements of the heap.
|
|
158
|
+
*/
|
|
159
|
+
toArray() {
|
|
160
|
+
return [...this.nodes];
|
|
161
|
+
}
|
|
162
|
+
getNodes() {
|
|
163
|
+
return this.nodes;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Clone the heap, creating a new heap with the same elements.
|
|
167
|
+
* @returns A new Heap instance containing the same elements.
|
|
168
|
+
*/
|
|
169
|
+
clone() {
|
|
170
|
+
const clonedHeap = new Heap({ comparator: this.comparator });
|
|
171
|
+
clonedHeap._nodes = [...this.nodes];
|
|
172
|
+
return clonedHeap;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Sort the elements in the heap and return them as an array.
|
|
176
|
+
* @returns An array containing the elements sorted in ascending order.
|
|
177
|
+
*/
|
|
178
|
+
sort() {
|
|
179
|
+
const visitedNode = [];
|
|
180
|
+
const cloned = this.clone();
|
|
181
|
+
while (cloned.size !== 0) {
|
|
182
|
+
const top = cloned.poll();
|
|
183
|
+
if (top)
|
|
184
|
+
visitedNode.push(top);
|
|
185
|
+
}
|
|
186
|
+
return visitedNode;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Float operation to maintain heap properties after adding an element.
|
|
190
|
+
* @param index - The index of the newly added element.
|
|
191
|
+
*/
|
|
192
|
+
bubbleUp(index) {
|
|
193
|
+
const element = this.nodes[index];
|
|
194
|
+
while (index > 0) {
|
|
195
|
+
const parentIndex = Math.floor((index - 1) / 2);
|
|
196
|
+
const parent = this.nodes[parentIndex];
|
|
197
|
+
if (this.comparator(element, parent) < 0) {
|
|
198
|
+
this.nodes[index] = parent;
|
|
199
|
+
this.nodes[parentIndex] = element;
|
|
200
|
+
index = parentIndex;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Sinking operation to maintain heap properties after removing the top element.
|
|
209
|
+
* @param index - The index from which to start sinking.
|
|
210
|
+
*/
|
|
211
|
+
sinkDown(index) {
|
|
212
|
+
const leftChildIndex = 2 * index + 1;
|
|
213
|
+
const rightChildIndex = 2 * index + 2;
|
|
214
|
+
const length = this.nodes.length;
|
|
215
|
+
let targetIndex = index;
|
|
216
|
+
if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
|
|
217
|
+
targetIndex = leftChildIndex;
|
|
218
|
+
}
|
|
219
|
+
if (rightChildIndex < length && this.comparator(this.nodes[rightChildIndex], this.nodes[targetIndex]) < 0) {
|
|
220
|
+
targetIndex = rightChildIndex;
|
|
221
|
+
}
|
|
222
|
+
if (targetIndex !== index) {
|
|
223
|
+
const temp = this.nodes[index];
|
|
224
|
+
this.nodes[index] = this.nodes[targetIndex];
|
|
225
|
+
this.nodes[targetIndex] = temp;
|
|
226
|
+
this.sinkDown(targetIndex);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Fix the entire heap to maintain heap properties.
|
|
231
|
+
*/
|
|
232
|
+
fix() {
|
|
233
|
+
for (let i = Math.floor(this.size / 2); i >= 0; i--)
|
|
234
|
+
this.sinkDown(i);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.Heap = Heap;
|
|
238
|
+
class FibonacciHeapNode {
|
|
239
|
+
constructor(element, degree = 0) {
|
|
240
|
+
this.element = element;
|
|
241
|
+
this.degree = degree;
|
|
242
|
+
this.marked = false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
exports.FibonacciHeapNode = FibonacciHeapNode;
|
|
246
|
+
class FibonacciHeap {
|
|
247
|
+
constructor(comparator) {
|
|
248
|
+
this._size = 0;
|
|
249
|
+
this.clear();
|
|
250
|
+
this._comparator = comparator || this.defaultComparator;
|
|
251
|
+
if (typeof this.comparator !== 'function') {
|
|
252
|
+
throw new Error('FibonacciHeap constructor: given comparator should be a function.');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
get root() {
|
|
256
|
+
return this._root;
|
|
257
|
+
}
|
|
258
|
+
get size() {
|
|
259
|
+
return this._size;
|
|
260
|
+
}
|
|
261
|
+
get min() {
|
|
262
|
+
return this._min;
|
|
263
|
+
}
|
|
264
|
+
get comparator() {
|
|
265
|
+
return this._comparator;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Get the size (number of elements) of the heap.
|
|
269
|
+
* @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
|
|
270
|
+
*/
|
|
271
|
+
clear() {
|
|
272
|
+
this._root = undefined;
|
|
273
|
+
this._min = undefined;
|
|
274
|
+
this._size = 0;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* O(1) time operation.
|
|
278
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
279
|
+
* @param element
|
|
280
|
+
* @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
|
|
281
|
+
*/
|
|
282
|
+
add(element) {
|
|
283
|
+
return this.push(element);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* O(1) time operation.
|
|
287
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
288
|
+
* @param element
|
|
289
|
+
* @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
|
|
290
|
+
*/
|
|
291
|
+
push(element) {
|
|
292
|
+
const node = this.createNode(element);
|
|
293
|
+
node.left = node;
|
|
294
|
+
node.right = node;
|
|
295
|
+
this.mergeWithRoot(node);
|
|
296
|
+
if (!this.min || this.comparator(node.element, this.min.element) <= 0) {
|
|
297
|
+
this._min = node;
|
|
298
|
+
}
|
|
299
|
+
this._size++;
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* O(1) time operation.
|
|
304
|
+
* Peek at the top element of the heap without removing it.
|
|
305
|
+
* @returns The top element or undefined if the heap is empty.
|
|
306
|
+
* @protected
|
|
307
|
+
*/
|
|
308
|
+
peek() {
|
|
309
|
+
return this.min ? this.min.element : undefined;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* O(1) time operation.
|
|
313
|
+
* Get the size (number of elements) of the heap.
|
|
314
|
+
* @param {FibonacciHeapNode<E>} head - The head of the linked list.
|
|
315
|
+
* @protected
|
|
316
|
+
* @returns FibonacciHeapNode<E>[] - An array containing the nodes of the linked list.
|
|
317
|
+
*/
|
|
318
|
+
consumeLinkedList(head) {
|
|
319
|
+
const nodes = [];
|
|
320
|
+
if (!head)
|
|
321
|
+
return nodes;
|
|
322
|
+
let node = head;
|
|
323
|
+
let flag = false;
|
|
324
|
+
while (true) {
|
|
325
|
+
if (node === head && flag)
|
|
326
|
+
break;
|
|
327
|
+
else if (node === head)
|
|
328
|
+
flag = true;
|
|
329
|
+
if (node) {
|
|
330
|
+
nodes.push(node);
|
|
331
|
+
node = node.right;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return nodes;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* O(log n) time operation.
|
|
338
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
339
|
+
* @param parent
|
|
340
|
+
* @param node
|
|
341
|
+
*/
|
|
342
|
+
mergeWithChild(parent, node) {
|
|
343
|
+
if (!parent.child) {
|
|
344
|
+
parent.child = node;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
node.right = parent.child.right;
|
|
348
|
+
node.left = parent.child;
|
|
349
|
+
parent.child.right.left = node;
|
|
350
|
+
parent.child.right = node;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* O(log n) time operation.
|
|
355
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
356
|
+
* @returns The top element or undefined if the heap is empty.
|
|
357
|
+
*/
|
|
358
|
+
poll() {
|
|
359
|
+
return this.pop();
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* O(log n) time operation.
|
|
363
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
364
|
+
* @returns The top element or undefined if the heap is empty.
|
|
365
|
+
*/
|
|
366
|
+
pop() {
|
|
367
|
+
if (this.size === 0)
|
|
368
|
+
return undefined;
|
|
369
|
+
const z = this.min;
|
|
370
|
+
if (z.child) {
|
|
371
|
+
const nodes = this.consumeLinkedList(z.child);
|
|
372
|
+
for (const node of nodes) {
|
|
373
|
+
this.mergeWithRoot(node);
|
|
374
|
+
node.parent = undefined;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
this.removeFromRoot(z);
|
|
378
|
+
if (z === z.right) {
|
|
379
|
+
this._min = undefined;
|
|
380
|
+
this._root = undefined;
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
this._min = z.right;
|
|
384
|
+
this.consolidate();
|
|
385
|
+
}
|
|
386
|
+
this._size--;
|
|
387
|
+
return z.element;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* O(log n) time operation.
|
|
391
|
+
* merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
|
|
392
|
+
* @param heapToMerge
|
|
393
|
+
*/
|
|
394
|
+
merge(heapToMerge) {
|
|
395
|
+
if (heapToMerge.size === 0) {
|
|
396
|
+
return; // Nothing to merge
|
|
397
|
+
}
|
|
398
|
+
// Merge the root lists of the two heaps
|
|
399
|
+
if (this.root && heapToMerge.root) {
|
|
400
|
+
const thisRoot = this.root;
|
|
401
|
+
const otherRoot = heapToMerge.root;
|
|
402
|
+
const thisRootRight = thisRoot.right;
|
|
403
|
+
const otherRootLeft = otherRoot.left;
|
|
404
|
+
thisRoot.right = otherRoot;
|
|
405
|
+
otherRoot.left = thisRoot;
|
|
406
|
+
thisRootRight.left = otherRootLeft;
|
|
407
|
+
otherRootLeft.right = thisRootRight;
|
|
408
|
+
}
|
|
409
|
+
// Update the minimum node
|
|
410
|
+
if (!this.min || (heapToMerge.min && this.comparator(heapToMerge.min.element, this.min.element) < 0)) {
|
|
411
|
+
this._min = heapToMerge.min;
|
|
412
|
+
}
|
|
413
|
+
// Update the size
|
|
414
|
+
this._size += heapToMerge.size;
|
|
415
|
+
// Clear the heap that was merged
|
|
416
|
+
heapToMerge.clear();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Default comparator function used by the heap.
|
|
420
|
+
* @param {E} a
|
|
421
|
+
* @param {E} b
|
|
422
|
+
* @protected
|
|
423
|
+
*/
|
|
424
|
+
defaultComparator(a, b) {
|
|
425
|
+
if (a < b)
|
|
426
|
+
return -1;
|
|
427
|
+
if (a > b)
|
|
428
|
+
return 1;
|
|
429
|
+
return 0;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Create a new node.
|
|
433
|
+
* @param element
|
|
434
|
+
* @protected
|
|
435
|
+
*/
|
|
436
|
+
createNode(element) {
|
|
437
|
+
return new FibonacciHeapNode(element);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Merge the given node with the root list.
|
|
441
|
+
* @param node - The node to be merged.
|
|
442
|
+
*/
|
|
443
|
+
mergeWithRoot(node) {
|
|
444
|
+
if (!this.root) {
|
|
445
|
+
this._root = node;
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
node.right = this.root.right;
|
|
449
|
+
node.left = this.root;
|
|
450
|
+
this.root.right.left = node;
|
|
451
|
+
this.root.right = node;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* O(log n) time operation.
|
|
456
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
457
|
+
* @param node - The node to be removed.
|
|
458
|
+
* @protected
|
|
459
|
+
*/
|
|
460
|
+
removeFromRoot(node) {
|
|
461
|
+
if (this.root === node)
|
|
462
|
+
this._root = node.right;
|
|
463
|
+
if (node.left)
|
|
464
|
+
node.left.right = node.right;
|
|
465
|
+
if (node.right)
|
|
466
|
+
node.right.left = node.left;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* O(log n) time operation.
|
|
470
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
471
|
+
* @param y
|
|
472
|
+
* @param x
|
|
473
|
+
* @protected
|
|
474
|
+
*/
|
|
475
|
+
link(y, x) {
|
|
476
|
+
this.removeFromRoot(y);
|
|
477
|
+
y.left = y;
|
|
478
|
+
y.right = y;
|
|
479
|
+
this.mergeWithChild(x, y);
|
|
480
|
+
x.degree++;
|
|
481
|
+
y.parent = x;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* O(log n) time operation.
|
|
485
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
486
|
+
* @protected
|
|
487
|
+
*/
|
|
488
|
+
consolidate() {
|
|
489
|
+
const A = new Array(this.size);
|
|
490
|
+
const nodes = this.consumeLinkedList(this.root);
|
|
491
|
+
let x, y, d, t;
|
|
492
|
+
for (const node of nodes) {
|
|
493
|
+
x = node;
|
|
494
|
+
d = x.degree;
|
|
495
|
+
while (A[d]) {
|
|
496
|
+
y = A[d];
|
|
497
|
+
if (this.comparator(x.element, y.element) > 0) {
|
|
498
|
+
t = x;
|
|
499
|
+
x = y;
|
|
500
|
+
y = t;
|
|
501
|
+
}
|
|
502
|
+
this.link(y, x);
|
|
503
|
+
A[d] = undefined;
|
|
504
|
+
d++;
|
|
505
|
+
}
|
|
506
|
+
A[d] = x;
|
|
507
|
+
}
|
|
508
|
+
for (let i = 0; i < this.size; i++) {
|
|
509
|
+
if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
|
|
510
|
+
this._min = A[i];
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
exports.FibonacciHeap = FibonacciHeap;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./max-heap"), exports);
|
|
18
|
+
__exportStar(require("./min-heap"), exports);
|
|
19
|
+
__exportStar(require("./heap"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Kirk Qi
|
|
5
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import { Heap } from './heap';
|
|
9
|
+
import type { Comparator } from '../../types';
|
|
10
|
+
export declare class MaxHeap<E = any> extends Heap<E> {
|
|
11
|
+
constructor(options?: {
|
|
12
|
+
comparator: Comparator<E>;
|
|
13
|
+
nodes?: E[];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Kirk Qi
|
|
6
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MaxHeap = void 0;
|
|
11
|
+
const heap_1 = require("./heap");
|
|
12
|
+
class MaxHeap extends heap_1.Heap {
|
|
13
|
+
constructor(options = {
|
|
14
|
+
comparator: (a, b) => {
|
|
15
|
+
if (!(typeof a === 'number' && typeof b === 'number')) {
|
|
16
|
+
throw new Error('The a, b params of compare function must be number');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return b - a;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}) {
|
|
23
|
+
super(options);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.MaxHeap = MaxHeap;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Kirk Qi
|
|
5
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import { Heap } from './heap';
|
|
9
|
+
import type { Comparator } from '../../types';
|
|
10
|
+
export declare class MinHeap<E = any> extends Heap<E> {
|
|
11
|
+
constructor(options?: {
|
|
12
|
+
comparator: Comparator<E>;
|
|
13
|
+
nodes?: E[];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Kirk Qi
|
|
6
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MinHeap = void 0;
|
|
11
|
+
const heap_1 = require("./heap");
|
|
12
|
+
class MinHeap extends heap_1.Heap {
|
|
13
|
+
constructor(options = {
|
|
14
|
+
comparator: (a, b) => {
|
|
15
|
+
if (!(typeof a === 'number' && typeof b === 'number')) {
|
|
16
|
+
throw new Error('The a, b params of compare function must be number');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return a - b;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}) {
|
|
23
|
+
super(options);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.MinHeap = MinHeap;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './hash';
|
|
2
|
+
export * from './linked-list';
|
|
3
|
+
export * from './stack';
|
|
4
|
+
export * from './queue';
|
|
5
|
+
export * from './graph';
|
|
6
|
+
export * from './binary-tree';
|
|
7
|
+
export * from './tree';
|
|
8
|
+
export * from './heap';
|
|
9
|
+
export * from './priority-queue';
|
|
10
|
+
export * from './matrix';
|
|
11
|
+
export * from './trie';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./hash"), exports);
|
|
18
|
+
__exportStar(require("./linked-list"), exports);
|
|
19
|
+
__exportStar(require("./stack"), exports);
|
|
20
|
+
__exportStar(require("./queue"), exports);
|
|
21
|
+
__exportStar(require("./graph"), exports);
|
|
22
|
+
__exportStar(require("./binary-tree"), exports);
|
|
23
|
+
__exportStar(require("./tree"), exports);
|
|
24
|
+
__exportStar(require("./heap"), exports);
|
|
25
|
+
__exportStar(require("./priority-queue"), exports);
|
|
26
|
+
__exportStar(require("./matrix"), exports);
|
|
27
|
+
__exportStar(require("./trie"), exports);
|