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,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
|
|
13
|
+
const uuidV4 = function () {
|
|
14
|
+
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
|
15
|
+
const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
16
|
+
return v.toString(16);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
exports.uuidV4 = uuidV4;
|
|
20
|
+
const arrayRemove = function (array, predicate) {
|
|
21
|
+
let i = -1, len = array ? array.length : 0;
|
|
22
|
+
const result = [];
|
|
23
|
+
while (++i < len) {
|
|
24
|
+
const value = array[i];
|
|
25
|
+
if (predicate(value, i, array)) {
|
|
26
|
+
result.push(value);
|
|
27
|
+
Array.prototype.splice.call(array, i--, 1);
|
|
28
|
+
len--;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
exports.arrayRemove = arrayRemove;
|
|
34
|
+
exports.THUNK_SYMBOL = Symbol('thunk');
|
|
35
|
+
const isThunk = (fnOrValue) => {
|
|
36
|
+
return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
|
|
37
|
+
};
|
|
38
|
+
exports.isThunk = isThunk;
|
|
39
|
+
const toThunk = (fn) => {
|
|
40
|
+
const thunk = () => fn();
|
|
41
|
+
thunk.__THUNK__ = exports.THUNK_SYMBOL;
|
|
42
|
+
return thunk;
|
|
43
|
+
};
|
|
44
|
+
exports.toThunk = toThunk;
|
|
45
|
+
const trampoline = (fn) => {
|
|
46
|
+
const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
|
|
47
|
+
return Object.assign((...args) => {
|
|
48
|
+
let result = fn(...args);
|
|
49
|
+
while ((0, exports.isThunk)(result) && typeof result === 'function') {
|
|
50
|
+
result = result();
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}, { cont });
|
|
54
|
+
};
|
|
55
|
+
exports.trampoline = trampoline;
|
|
56
|
+
const trampolineAsync = (fn) => {
|
|
57
|
+
const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
|
|
58
|
+
return Object.assign((...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
let result = yield fn(...args);
|
|
60
|
+
while ((0, exports.isThunk)(result) && typeof result === 'function') {
|
|
61
|
+
result = yield result();
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}), { cont });
|
|
65
|
+
};
|
|
66
|
+
exports.trampolineAsync = trampolineAsync;
|
|
67
|
+
const getMSB = (value) => {
|
|
68
|
+
if (value <= 0) {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
return 1 << (31 - Math.clz32(value));
|
|
72
|
+
};
|
|
73
|
+
exports.getMSB = getMSB;
|
package/jest.config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
testMatch: ['<rootDir>/test/**/*.test.ts', '<rootDir>/test/**/*.test.js'],
|
|
5
|
+
collectCoverage: true,
|
|
6
|
+
coverageReporters: ['clover', 'json', 'lcov', ['text', {skipFull: true}], "json-summary"],
|
|
7
|
+
coverageDirectory: 'coverage'
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "min-heap-typed",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "Min Heap. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -131,6 +131,6 @@
|
|
|
131
131
|
"typescript": "^4.9.5"
|
|
132
132
|
},
|
|
133
133
|
"dependencies": {
|
|
134
|
-
"data-structure-typed": "^1.
|
|
134
|
+
"data-structure-typed": "^1.41.0"
|
|
135
135
|
}
|
|
136
136
|
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import {BST, BSTNode} from './bst';
|
|
9
|
+
import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BTNKey} from '../../types';
|
|
10
|
+
import {BTNCallback} from '../../types';
|
|
11
|
+
import {IBinaryTree} from '../../interfaces';
|
|
12
|
+
|
|
13
|
+
export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
14
|
+
height: number;
|
|
15
|
+
|
|
16
|
+
constructor(key: BTNKey, value?: V) {
|
|
17
|
+
super(key, value);
|
|
18
|
+
this.height = 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>>
|
|
23
|
+
extends BST<V, N>
|
|
24
|
+
implements IBinaryTree<V, N> {
|
|
25
|
+
/**
|
|
26
|
+
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
27
|
+
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
28
|
+
* constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
|
|
29
|
+
* options.
|
|
30
|
+
*/
|
|
31
|
+
constructor(options?: AVLTreeOptions) {
|
|
32
|
+
super(options);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The function creates a new AVL tree node with the specified key and value.
|
|
37
|
+
* @param {BTNKey} key - The key parameter is the key value that will be associated with
|
|
38
|
+
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
39
|
+
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
40
|
+
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
41
|
+
* node type `N`.
|
|
42
|
+
* @returns a new AVLTreeNode object with the specified key and value.
|
|
43
|
+
*/
|
|
44
|
+
override createNode(key: BTNKey, value?: V): N {
|
|
45
|
+
return new AVLTreeNode<V, N>(key, value) as N;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
50
|
+
* a new node.
|
|
51
|
+
* @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
|
|
52
|
+
* `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
|
|
53
|
+
* @param [value] - The `value` parameter is the value that you want to assign to the new node that you
|
|
54
|
+
* are adding to the binary search tree.
|
|
55
|
+
* @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
|
|
56
|
+
*/
|
|
57
|
+
override add(keyOrNode: BTNKey | N | null, value?: V): N | null | undefined {
|
|
58
|
+
const inserted = super.add(keyOrNode, value);
|
|
59
|
+
if (inserted) this._balancePath(inserted);
|
|
60
|
+
return inserted;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The function overrides the delete method of a binary tree and balances the tree after deleting a
|
|
65
|
+
* node if necessary.
|
|
66
|
+
* @param {ReturnType<C>} identifier - The `identifier` parameter is either a
|
|
67
|
+
* `BTNKey` or a generic type `N`. It represents the property of the node that we are
|
|
68
|
+
* searching for. It can be a specific key value or any other property of the node.
|
|
69
|
+
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
70
|
+
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
71
|
+
* included in the result. The `callback` parameter has a default value of
|
|
72
|
+
* `((node: N) => node.key)`
|
|
73
|
+
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
74
|
+
*/
|
|
75
|
+
override delete<C extends BTNCallback<N>>(
|
|
76
|
+
identifier: ReturnType<C>,
|
|
77
|
+
callback: C = ((node: N) => node.key) as C
|
|
78
|
+
): BinaryTreeDeletedResult<N>[] {
|
|
79
|
+
if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C;
|
|
80
|
+
const deletedResults = super.delete(identifier, callback);
|
|
81
|
+
for (const {needBalanced} of deletedResults) {
|
|
82
|
+
if (needBalanced) {
|
|
83
|
+
this._balancePath(needBalanced);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return deletedResults;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The function swaps the key, value, and height properties between two nodes in a binary tree.
|
|
91
|
+
* @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
|
|
92
|
+
* with the `destNode`.
|
|
93
|
+
* @param {N} destNode - The `destNode` parameter represents the destination node where the values
|
|
94
|
+
* from the source node (`srcNode`) will be swapped to.
|
|
95
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
96
|
+
*/
|
|
97
|
+
protected override _swap(srcNode: N, destNode: N): N {
|
|
98
|
+
const {key, value, height} = destNode;
|
|
99
|
+
const tempNode = this.createNode(key, value);
|
|
100
|
+
|
|
101
|
+
if (tempNode) {
|
|
102
|
+
tempNode.height = height;
|
|
103
|
+
|
|
104
|
+
destNode.key = srcNode.key;
|
|
105
|
+
destNode.value = srcNode.value;
|
|
106
|
+
destNode.height = srcNode.height;
|
|
107
|
+
|
|
108
|
+
srcNode.key = tempNode.key;
|
|
109
|
+
srcNode.value = tempNode.value;
|
|
110
|
+
srcNode.height = tempNode.height;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return destNode;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The function calculates the balance factor of a node in a binary tree.
|
|
118
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
119
|
+
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
120
|
+
* height of the left subtree from the height of the right subtree.
|
|
121
|
+
*/
|
|
122
|
+
protected _balanceFactor(node: N): number {
|
|
123
|
+
if (!node.right)
|
|
124
|
+
// node has no right subtree
|
|
125
|
+
return -node.height;
|
|
126
|
+
else if (!node.left)
|
|
127
|
+
// node has no left subtree
|
|
128
|
+
return +node.height;
|
|
129
|
+
else return node.right.height - node.left.height;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
134
|
+
* right children.
|
|
135
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
136
|
+
*/
|
|
137
|
+
protected _updateHeight(node: N): void {
|
|
138
|
+
if (!node.left && !node.right) node.height = 0;
|
|
139
|
+
else if (!node.left) {
|
|
140
|
+
const rightHeight = node.right ? node.right.height : 0;
|
|
141
|
+
node.height = 1 + rightHeight;
|
|
142
|
+
} else if (!node.right) node.height = 1 + node.left.height;
|
|
143
|
+
else node.height = 1 + Math.max(node.right.height, node.left.height);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
148
|
+
* to restore balance in an AVL tree after inserting a node.
|
|
149
|
+
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
150
|
+
* AVL tree that needs to be balanced.
|
|
151
|
+
*/
|
|
152
|
+
protected _balancePath(node: N): void {
|
|
153
|
+
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
154
|
+
for (let i = 0; i < path.length; i++) {
|
|
155
|
+
// second O(log n)
|
|
156
|
+
const A = path[i];
|
|
157
|
+
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
|
|
158
|
+
this._updateHeight(A); // first O(1)
|
|
159
|
+
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
|
|
160
|
+
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
|
|
161
|
+
switch (
|
|
162
|
+
this._balanceFactor(A) // second O(1)
|
|
163
|
+
) {
|
|
164
|
+
case -2:
|
|
165
|
+
if (A && A.left) {
|
|
166
|
+
if (this._balanceFactor(A.left) <= 0) {
|
|
167
|
+
// second O(1)
|
|
168
|
+
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
|
|
169
|
+
this._balanceLL(A);
|
|
170
|
+
} else {
|
|
171
|
+
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
|
|
172
|
+
this._balanceLR(A);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case +2:
|
|
177
|
+
if (A && A.right) {
|
|
178
|
+
if (this._balanceFactor(A.right) >= 0) {
|
|
179
|
+
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
|
|
180
|
+
this._balanceRR(A);
|
|
181
|
+
} else {
|
|
182
|
+
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
|
|
183
|
+
this._balanceRL(A);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
193
|
+
* @param {N} A - A is a node in a binary tree.
|
|
194
|
+
*/
|
|
195
|
+
protected _balanceLL(A: N): void {
|
|
196
|
+
const parentOfA = A.parent;
|
|
197
|
+
const B = A.left;
|
|
198
|
+
A.parent = B;
|
|
199
|
+
if (B && B.right) {
|
|
200
|
+
B.right.parent = A;
|
|
201
|
+
}
|
|
202
|
+
if (B) B.parent = parentOfA;
|
|
203
|
+
if (A === this.root) {
|
|
204
|
+
if (B) this._setRoot(B);
|
|
205
|
+
} else {
|
|
206
|
+
if (parentOfA?.left === A) {
|
|
207
|
+
parentOfA.left = B;
|
|
208
|
+
} else {
|
|
209
|
+
if (parentOfA) parentOfA.right = B;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (B) {
|
|
214
|
+
A.left = B.right;
|
|
215
|
+
B.right = A;
|
|
216
|
+
}
|
|
217
|
+
this._updateHeight(A);
|
|
218
|
+
if (B) this._updateHeight(B);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
223
|
+
* @param {N} A - A is a node in a binary tree.
|
|
224
|
+
*/
|
|
225
|
+
protected _balanceLR(A: N): void {
|
|
226
|
+
const parentOfA = A.parent;
|
|
227
|
+
const B = A.left;
|
|
228
|
+
let C = null;
|
|
229
|
+
if (B) {
|
|
230
|
+
C = B.right;
|
|
231
|
+
}
|
|
232
|
+
if (A) A.parent = C;
|
|
233
|
+
if (B) B.parent = C;
|
|
234
|
+
|
|
235
|
+
if (C) {
|
|
236
|
+
if (C.left) {
|
|
237
|
+
C.left.parent = B;
|
|
238
|
+
}
|
|
239
|
+
if (C.right) {
|
|
240
|
+
C.right.parent = A;
|
|
241
|
+
}
|
|
242
|
+
C.parent = parentOfA;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (A === this.root) {
|
|
246
|
+
if (C) this._setRoot(C);
|
|
247
|
+
} else {
|
|
248
|
+
if (parentOfA) {
|
|
249
|
+
if (parentOfA.left === A) {
|
|
250
|
+
parentOfA.left = C;
|
|
251
|
+
} else {
|
|
252
|
+
parentOfA.right = C;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (C) {
|
|
258
|
+
A.left = C.right;
|
|
259
|
+
if (B) B.right = C.left;
|
|
260
|
+
C.left = B;
|
|
261
|
+
C.right = A;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
this._updateHeight(A);
|
|
265
|
+
B && this._updateHeight(B);
|
|
266
|
+
C && this._updateHeight(C);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
271
|
+
* @param {N} A - A is a node in a binary tree.
|
|
272
|
+
*/
|
|
273
|
+
protected _balanceRR(A: N): void {
|
|
274
|
+
const parentOfA = A.parent;
|
|
275
|
+
const B = A.right;
|
|
276
|
+
A.parent = B;
|
|
277
|
+
if (B) {
|
|
278
|
+
if (B.left) {
|
|
279
|
+
B.left.parent = A;
|
|
280
|
+
}
|
|
281
|
+
B.parent = parentOfA;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (A === this.root) {
|
|
285
|
+
if (B) this._setRoot(B);
|
|
286
|
+
} else {
|
|
287
|
+
if (parentOfA) {
|
|
288
|
+
if (parentOfA.left === A) {
|
|
289
|
+
parentOfA.left = B;
|
|
290
|
+
} else {
|
|
291
|
+
parentOfA.right = B;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (B) {
|
|
297
|
+
A.right = B.left;
|
|
298
|
+
B.left = A;
|
|
299
|
+
}
|
|
300
|
+
this._updateHeight(A);
|
|
301
|
+
B && this._updateHeight(B);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
306
|
+
* @param {N} A - A is a node in a binary tree.
|
|
307
|
+
*/
|
|
308
|
+
protected _balanceRL(A: N): void {
|
|
309
|
+
const parentOfA = A.parent;
|
|
310
|
+
const B = A.right;
|
|
311
|
+
let C = null;
|
|
312
|
+
if (B) {
|
|
313
|
+
C = B.left;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
A.parent = C;
|
|
317
|
+
if (B) B.parent = C;
|
|
318
|
+
|
|
319
|
+
if (C) {
|
|
320
|
+
if (C.left) {
|
|
321
|
+
C.left.parent = A;
|
|
322
|
+
}
|
|
323
|
+
if (C.right) {
|
|
324
|
+
C.right.parent = B;
|
|
325
|
+
}
|
|
326
|
+
C.parent = parentOfA;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (A === this.root) {
|
|
330
|
+
if (C) this._setRoot(C);
|
|
331
|
+
} else {
|
|
332
|
+
if (parentOfA) {
|
|
333
|
+
if (parentOfA.left === A) {
|
|
334
|
+
parentOfA.left = C;
|
|
335
|
+
} else {
|
|
336
|
+
parentOfA.right = C;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (C) A.right = C.left;
|
|
342
|
+
if (B && C) B.left = C.right;
|
|
343
|
+
if (C) C.left = A;
|
|
344
|
+
if (C) C.right = B;
|
|
345
|
+
|
|
346
|
+
this._updateHeight(A);
|
|
347
|
+
B && this._updateHeight(B);
|
|
348
|
+
C && this._updateHeight(C);
|
|
349
|
+
}
|
|
350
|
+
}
|