min-heap-typed 1.40.0-rc → 1.40.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 +355 -0
- package/dist/data-structures/binary-tree/binary-tree.js +1115 -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 +11 -0
- package/dist/data-structures/binary-tree/rb-tree.js +21 -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 +8 -0
- package/dist/types/data-structures/binary-tree/rb-tree.js +8 -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 +1262 -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 +358 -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
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
|
|
2
1
|
<!doctype html>
|
|
3
2
|
<html lang="en">
|
|
4
3
|
|
|
5
4
|
<head>
|
|
6
5
|
<title>Code coverage report for index.ts</title>
|
|
7
|
-
<meta charset="utf-8"
|
|
8
|
-
<link
|
|
9
|
-
<link
|
|
10
|
-
<link rel="shortcut icon" type="image/x-icon"
|
|
11
|
-
<meta
|
|
6
|
+
<meta charset="utf-8"/>
|
|
7
|
+
<link href="prettify.css" rel="stylesheet"/>
|
|
8
|
+
<link href="base.css" rel="stylesheet"/>
|
|
9
|
+
<link href="favicon.png" rel="shortcut icon" type="image/x-icon"/>
|
|
10
|
+
<meta content="width=device-width, initial-scale=1" name="viewport"/>
|
|
12
11
|
<style type='text/css'>
|
|
13
12
|
.coverage-summary .sorter {
|
|
14
13
|
background-image: url(sort-arrow-sprite.png);
|
|
15
14
|
}
|
|
16
15
|
</style>
|
|
17
16
|
</head>
|
|
18
|
-
|
|
17
|
+
|
|
19
18
|
<body>
|
|
20
19
|
<div class='wrapper'>
|
|
21
20
|
<div class='pad1'>
|
|
22
21
|
<h1><a href="index.html">All files</a> index.ts</h1>
|
|
23
22
|
<div class='clearfix'>
|
|
24
|
-
|
|
23
|
+
|
|
25
24
|
<div class='fl pad1y space-right2'>
|
|
26
25
|
<span class="strong">100% </span>
|
|
27
26
|
<span class="quiet">Statements</span>
|
|
28
27
|
<span class='fraction'>3/3</span>
|
|
29
28
|
</div>
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
|
|
30
|
+
|
|
32
31
|
<div class='fl pad1y space-right2'>
|
|
33
32
|
<span class="strong">100% </span>
|
|
34
33
|
<span class="quiet">Branches</span>
|
|
35
34
|
<span class='fraction'>0/0</span>
|
|
36
35
|
</div>
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
|
|
37
|
+
|
|
39
38
|
<div class='fl pad1y space-right2'>
|
|
40
39
|
<span class="strong">100% </span>
|
|
41
40
|
<span class="quiet">Functions</span>
|
|
42
41
|
<span class='fraction'>2/2</span>
|
|
43
42
|
</div>
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
|
|
44
|
+
|
|
46
45
|
<div class='fl pad1y space-right2'>
|
|
47
46
|
<span class="strong">100% </span>
|
|
48
47
|
<span class="quiet">Lines</span>
|
|
49
48
|
<span class='fraction'>1/1</span>
|
|
50
49
|
</div>
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
|
|
51
|
+
|
|
53
52
|
</div>
|
|
54
53
|
<p class="quiet">
|
|
55
|
-
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for
|
|
54
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for
|
|
55
|
+
the previous block.
|
|
56
56
|
</p>
|
|
57
57
|
<template id="filterTemplate">
|
|
58
58
|
<div class="quiet">
|
|
59
59
|
Filter:
|
|
60
|
-
<input oninput="onInput()" type="search"
|
|
60
|
+
<input id="fileSearch" oninput="onInput()" type="search">
|
|
61
61
|
</div>
|
|
62
62
|
</template>
|
|
63
63
|
</div>
|
|
@@ -71,7 +71,8 @@
|
|
|
71
71
|
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
72
|
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
73
|
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
-
<a name='L9'></a><a href='#L9'>9</a></td><td class="line-coverage quiet"><span
|
|
74
|
+
<a name='L9'></a><a href='#L9'>9</a></td><td class="line-coverage quiet"><span
|
|
75
|
+
class="cline-any cline-neutral"> </span>
|
|
75
76
|
<span class="cline-any cline-neutral"> </span>
|
|
76
77
|
<span class="cline-any cline-neutral"> </span>
|
|
77
78
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -89,21 +90,21 @@
|
|
|
89
90
|
export { MinHeap, HeapItem } from 'data-structure-typed';
|
|
90
91
|
</pre></td></tr></table></pre>
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
93
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
94
|
+
</div><!-- /wrapper -->
|
|
95
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
96
|
+
Code coverage generated by
|
|
97
|
+
<a href="https://istanbul.js.org/" rel="noopener noreferrer" target="_blank">istanbul</a>
|
|
98
|
+
at 2023-10-08T10:23:16.441Z
|
|
99
|
+
</div>
|
|
100
|
+
<script src="prettify.js"></script>
|
|
101
|
+
<script>
|
|
102
|
+
window.onload = function () {
|
|
103
|
+
prettyPrint();
|
|
104
|
+
};
|
|
105
|
+
</script>
|
|
106
|
+
<script src="sorter.js"></script>
|
|
107
|
+
<script src="block-navigation.js"></script>
|
|
108
|
+
</body>
|
|
108
109
|
</html>
|
|
109
110
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
var addSorting = (function() {
|
|
2
|
+
var addSorting = (function () {
|
|
3
3
|
'use strict';
|
|
4
4
|
var cols,
|
|
5
5
|
currentSort = {
|
|
@@ -11,14 +11,17 @@ var addSorting = (function() {
|
|
|
11
11
|
function getTable() {
|
|
12
12
|
return document.querySelector('.coverage-summary');
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
// returns the thead element of the summary table
|
|
15
16
|
function getTableHeader() {
|
|
16
17
|
return getTable().querySelector('thead tr');
|
|
17
18
|
}
|
|
19
|
+
|
|
18
20
|
// returns the tbody element of the summary table
|
|
19
21
|
function getTableBody() {
|
|
20
22
|
return getTable().querySelector('tbody');
|
|
21
23
|
}
|
|
24
|
+
|
|
22
25
|
// returns the th element for nth column
|
|
23
26
|
function getNthColumn(n) {
|
|
24
27
|
return getTableHeader().querySelectorAll('th')[n];
|
|
@@ -73,6 +76,7 @@ var addSorting = (function() {
|
|
|
73
76
|
}
|
|
74
77
|
return cols;
|
|
75
78
|
}
|
|
79
|
+
|
|
76
80
|
// attaches a data attribute to every tr element with an object
|
|
77
81
|
// of data values keyed by column name
|
|
78
82
|
function loadRowData(tableRow) {
|
|
@@ -93,6 +97,7 @@ var addSorting = (function() {
|
|
|
93
97
|
}
|
|
94
98
|
return data;
|
|
95
99
|
}
|
|
100
|
+
|
|
96
101
|
// loads all row data
|
|
97
102
|
function loadData() {
|
|
98
103
|
var rows = getTableBody().querySelectorAll('tr'),
|
|
@@ -102,10 +107,11 @@ var addSorting = (function() {
|
|
|
102
107
|
rows[i].data = loadRowData(rows[i]);
|
|
103
108
|
}
|
|
104
109
|
}
|
|
110
|
+
|
|
105
111
|
// sorts the table using the data for the ith column
|
|
106
112
|
function sortByIndex(index, desc) {
|
|
107
113
|
var key = cols[index].key,
|
|
108
|
-
sorter = function(a, b) {
|
|
114
|
+
sorter = function (a, b) {
|
|
109
115
|
a = a.data[key];
|
|
110
116
|
b = b.data[key];
|
|
111
117
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -117,7 +123,7 @@ var addSorting = (function() {
|
|
|
117
123
|
i;
|
|
118
124
|
|
|
119
125
|
if (desc) {
|
|
120
|
-
finalSorter = function(a, b) {
|
|
126
|
+
finalSorter = function (a, b) {
|
|
121
127
|
return -1 * sorter(a, b);
|
|
122
128
|
};
|
|
123
129
|
}
|
|
@@ -133,6 +139,7 @@ var addSorting = (function() {
|
|
|
133
139
|
tableBody.appendChild(rows[i]);
|
|
134
140
|
}
|
|
135
141
|
}
|
|
142
|
+
|
|
136
143
|
// removes sort indicators for current column being sorted
|
|
137
144
|
function removeSortIndicators() {
|
|
138
145
|
var col = getNthColumn(currentSort.index),
|
|
@@ -141,12 +148,14 @@ var addSorting = (function() {
|
|
|
141
148
|
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
142
149
|
col.className = cls;
|
|
143
150
|
}
|
|
151
|
+
|
|
144
152
|
// adds sort indicators for current column being sorted
|
|
145
153
|
function addSortIndicators() {
|
|
146
154
|
getNthColumn(currentSort.index).className += currentSort.desc
|
|
147
155
|
? ' sorted-desc'
|
|
148
156
|
: ' sorted';
|
|
149
157
|
}
|
|
158
|
+
|
|
150
159
|
// adds event listeners for all sorter widgets
|
|
151
160
|
function enableUI() {
|
|
152
161
|
var i,
|
|
@@ -154,7 +163,7 @@ var addSorting = (function() {
|
|
|
154
163
|
ithSorter = function ithSorter(i) {
|
|
155
164
|
var col = cols[i];
|
|
156
165
|
|
|
157
|
-
return function() {
|
|
166
|
+
return function () {
|
|
158
167
|
var desc = col.defaultDescSort;
|
|
159
168
|
|
|
160
169
|
if (currentSort.index === i) {
|
|
@@ -180,8 +189,9 @@ var addSorting = (function() {
|
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
191
|
}
|
|
192
|
+
|
|
183
193
|
// adds sorting functionality to the UI
|
|
184
|
-
return function() {
|
|
194
|
+
return function () {
|
|
185
195
|
if (!getTable()) {
|
|
186
196
|
return;
|
|
187
197
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
13
|
+
height: number;
|
|
14
|
+
constructor(key: BTNKey, value?: V);
|
|
15
|
+
}
|
|
16
|
+
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> {
|
|
17
|
+
/**
|
|
18
|
+
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
19
|
+
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
20
|
+
* constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
|
|
21
|
+
* options.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: AVLTreeOptions);
|
|
24
|
+
/**
|
|
25
|
+
* The function creates a new AVL tree node with the specified key and value.
|
|
26
|
+
* @param {BTNKey} key - The key parameter is the key value that will be associated with
|
|
27
|
+
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
28
|
+
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
29
|
+
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
30
|
+
* node type `N`.
|
|
31
|
+
* @returns a new AVLTreeNode object with the specified key and value.
|
|
32
|
+
*/
|
|
33
|
+
createNode(key: BTNKey, value?: V): N;
|
|
34
|
+
/**
|
|
35
|
+
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
36
|
+
* a new node.
|
|
37
|
+
* @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
|
|
38
|
+
* `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
|
|
39
|
+
* @param [value] - The `value` parameter is the value that you want to assign to the new node that you
|
|
40
|
+
* are adding to the binary search tree.
|
|
41
|
+
* @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
|
|
42
|
+
*/
|
|
43
|
+
add(keyOrNode: BTNKey | N | null, value?: V): N | null | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The function overrides the delete method of a binary tree and balances the tree after deleting a
|
|
46
|
+
* node if necessary.
|
|
47
|
+
* @param {ReturnType<C>} identifier - The `identifier` parameter is either a
|
|
48
|
+
* `BTNKey` or a generic type `N`. It represents the property of the node that we are
|
|
49
|
+
* searching for. It can be a specific key value or any other property of the node.
|
|
50
|
+
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
51
|
+
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
52
|
+
* included in the result. The `callback` parameter has a default value of
|
|
53
|
+
* `((node: N) => node.key)`
|
|
54
|
+
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
55
|
+
*/
|
|
56
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
|
|
57
|
+
/**
|
|
58
|
+
* The function swaps the key, value, and height properties between two nodes in a binary tree.
|
|
59
|
+
* @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
|
|
60
|
+
* with the `destNode`.
|
|
61
|
+
* @param {N} destNode - The `destNode` parameter represents the destination node where the values
|
|
62
|
+
* from the source node (`srcNode`) will be swapped to.
|
|
63
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
64
|
+
*/
|
|
65
|
+
protected _swap(srcNode: N, destNode: N): N;
|
|
66
|
+
/**
|
|
67
|
+
* The function calculates the balance factor of a node in a binary tree.
|
|
68
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
69
|
+
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
70
|
+
* height of the left subtree from the height of the right subtree.
|
|
71
|
+
*/
|
|
72
|
+
protected _balanceFactor(node: N): number;
|
|
73
|
+
/**
|
|
74
|
+
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
75
|
+
* right children.
|
|
76
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
77
|
+
*/
|
|
78
|
+
protected _updateHeight(node: N): void;
|
|
79
|
+
/**
|
|
80
|
+
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
81
|
+
* to restore balance in an AVL tree after inserting a node.
|
|
82
|
+
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
83
|
+
* AVL tree that needs to be balanced.
|
|
84
|
+
*/
|
|
85
|
+
protected _balancePath(node: N): void;
|
|
86
|
+
/**
|
|
87
|
+
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
88
|
+
* @param {N} A - A is a node in a binary tree.
|
|
89
|
+
*/
|
|
90
|
+
protected _balanceLL(A: N): void;
|
|
91
|
+
/**
|
|
92
|
+
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
93
|
+
* @param {N} A - A is a node in a binary tree.
|
|
94
|
+
*/
|
|
95
|
+
protected _balanceLR(A: N): void;
|
|
96
|
+
/**
|
|
97
|
+
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
98
|
+
* @param {N} A - A is a node in a binary tree.
|
|
99
|
+
*/
|
|
100
|
+
protected _balanceRR(A: N): void;
|
|
101
|
+
/**
|
|
102
|
+
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
103
|
+
* @param {N} A - A is a node in a binary tree.
|
|
104
|
+
*/
|
|
105
|
+
protected _balanceRL(A: N): void;
|
|
106
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AVLTree = exports.AVLTreeNode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
10
|
+
*/
|
|
11
|
+
const bst_1 = require("./bst");
|
|
12
|
+
class AVLTreeNode extends bst_1.BSTNode {
|
|
13
|
+
constructor(key, value) {
|
|
14
|
+
super(key, value);
|
|
15
|
+
this.height = 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AVLTreeNode = AVLTreeNode;
|
|
19
|
+
class AVLTree extends bst_1.BST {
|
|
20
|
+
/**
|
|
21
|
+
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
22
|
+
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
23
|
+
* constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
|
|
24
|
+
* options.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super(options);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The function creates a new AVL tree node with the specified key and value.
|
|
31
|
+
* @param {BTNKey} key - The key parameter is the key value that will be associated with
|
|
32
|
+
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
33
|
+
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
34
|
+
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
35
|
+
* node type `N`.
|
|
36
|
+
* @returns a new AVLTreeNode object with the specified key and value.
|
|
37
|
+
*/
|
|
38
|
+
createNode(key, value) {
|
|
39
|
+
return new AVLTreeNode(key, value);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
43
|
+
* a new node.
|
|
44
|
+
* @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
|
|
45
|
+
* `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
|
|
46
|
+
* @param [value] - The `value` parameter is the value that you want to assign to the new node that you
|
|
47
|
+
* are adding to the binary search tree.
|
|
48
|
+
* @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
|
|
49
|
+
*/
|
|
50
|
+
add(keyOrNode, value) {
|
|
51
|
+
const inserted = super.add(keyOrNode, value);
|
|
52
|
+
if (inserted)
|
|
53
|
+
this._balancePath(inserted);
|
|
54
|
+
return inserted;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The function overrides the delete method of a binary tree and balances the tree after deleting a
|
|
58
|
+
* node if necessary.
|
|
59
|
+
* @param {ReturnType<C>} identifier - The `identifier` parameter is either a
|
|
60
|
+
* `BTNKey` or a generic type `N`. It represents the property of the node that we are
|
|
61
|
+
* searching for. It can be a specific key value or any other property of the node.
|
|
62
|
+
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
63
|
+
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
64
|
+
* included in the result. The `callback` parameter has a default value of
|
|
65
|
+
* `((node: N) => node.key)`
|
|
66
|
+
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
67
|
+
*/
|
|
68
|
+
delete(identifier, callback = ((node) => node.key)) {
|
|
69
|
+
if (identifier instanceof AVLTreeNode)
|
|
70
|
+
callback = (node => node);
|
|
71
|
+
const deletedResults = super.delete(identifier, callback);
|
|
72
|
+
for (const { needBalanced } of deletedResults) {
|
|
73
|
+
if (needBalanced) {
|
|
74
|
+
this._balancePath(needBalanced);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return deletedResults;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The function swaps the key, value, and height properties between two nodes in a binary tree.
|
|
81
|
+
* @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
|
|
82
|
+
* with the `destNode`.
|
|
83
|
+
* @param {N} destNode - The `destNode` parameter represents the destination node where the values
|
|
84
|
+
* from the source node (`srcNode`) will be swapped to.
|
|
85
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
86
|
+
*/
|
|
87
|
+
_swap(srcNode, destNode) {
|
|
88
|
+
const { key, value, height } = destNode;
|
|
89
|
+
const tempNode = this.createNode(key, value);
|
|
90
|
+
if (tempNode) {
|
|
91
|
+
tempNode.height = height;
|
|
92
|
+
destNode.key = srcNode.key;
|
|
93
|
+
destNode.value = srcNode.value;
|
|
94
|
+
destNode.height = srcNode.height;
|
|
95
|
+
srcNode.key = tempNode.key;
|
|
96
|
+
srcNode.value = tempNode.value;
|
|
97
|
+
srcNode.height = tempNode.height;
|
|
98
|
+
}
|
|
99
|
+
return destNode;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The function calculates the balance factor of a node in a binary tree.
|
|
103
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
104
|
+
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
105
|
+
* height of the left subtree from the height of the right subtree.
|
|
106
|
+
*/
|
|
107
|
+
_balanceFactor(node) {
|
|
108
|
+
if (!node.right)
|
|
109
|
+
// node has no right subtree
|
|
110
|
+
return -node.height;
|
|
111
|
+
else if (!node.left)
|
|
112
|
+
// node has no left subtree
|
|
113
|
+
return +node.height;
|
|
114
|
+
else
|
|
115
|
+
return node.right.height - node.left.height;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
119
|
+
* right children.
|
|
120
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
121
|
+
*/
|
|
122
|
+
_updateHeight(node) {
|
|
123
|
+
if (!node.left && !node.right)
|
|
124
|
+
node.height = 0;
|
|
125
|
+
else if (!node.left) {
|
|
126
|
+
const rightHeight = node.right ? node.right.height : 0;
|
|
127
|
+
node.height = 1 + rightHeight;
|
|
128
|
+
}
|
|
129
|
+
else if (!node.right)
|
|
130
|
+
node.height = 1 + node.left.height;
|
|
131
|
+
else
|
|
132
|
+
node.height = 1 + Math.max(node.right.height, node.left.height);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
136
|
+
* to restore balance in an AVL tree after inserting a node.
|
|
137
|
+
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
138
|
+
* AVL tree that needs to be balanced.
|
|
139
|
+
*/
|
|
140
|
+
_balancePath(node) {
|
|
141
|
+
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
142
|
+
for (let i = 0; i < path.length; i++) {
|
|
143
|
+
// second O(log n)
|
|
144
|
+
const A = path[i];
|
|
145
|
+
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
|
|
146
|
+
this._updateHeight(A); // first O(1)
|
|
147
|
+
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
|
|
148
|
+
// 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:
|
|
149
|
+
switch (this._balanceFactor(A) // second O(1)
|
|
150
|
+
) {
|
|
151
|
+
case -2:
|
|
152
|
+
if (A && A.left) {
|
|
153
|
+
if (this._balanceFactor(A.left) <= 0) {
|
|
154
|
+
// second O(1)
|
|
155
|
+
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
|
|
156
|
+
this._balanceLL(A);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
|
|
160
|
+
this._balanceLR(A);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
case +2:
|
|
165
|
+
if (A && A.right) {
|
|
166
|
+
if (this._balanceFactor(A.right) >= 0) {
|
|
167
|
+
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
|
|
168
|
+
this._balanceRR(A);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
|
|
172
|
+
this._balanceRL(A);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// 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.
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
181
|
+
* @param {N} A - A is a node in a binary tree.
|
|
182
|
+
*/
|
|
183
|
+
_balanceLL(A) {
|
|
184
|
+
const parentOfA = A.parent;
|
|
185
|
+
const B = A.left;
|
|
186
|
+
A.parent = B;
|
|
187
|
+
if (B && B.right) {
|
|
188
|
+
B.right.parent = A;
|
|
189
|
+
}
|
|
190
|
+
if (B)
|
|
191
|
+
B.parent = parentOfA;
|
|
192
|
+
if (A === this.root) {
|
|
193
|
+
if (B)
|
|
194
|
+
this._setRoot(B);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
if ((parentOfA === null || parentOfA === void 0 ? void 0 : parentOfA.left) === A) {
|
|
198
|
+
parentOfA.left = B;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
if (parentOfA)
|
|
202
|
+
parentOfA.right = B;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (B) {
|
|
206
|
+
A.left = B.right;
|
|
207
|
+
B.right = A;
|
|
208
|
+
}
|
|
209
|
+
this._updateHeight(A);
|
|
210
|
+
if (B)
|
|
211
|
+
this._updateHeight(B);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
215
|
+
* @param {N} A - A is a node in a binary tree.
|
|
216
|
+
*/
|
|
217
|
+
_balanceLR(A) {
|
|
218
|
+
const parentOfA = A.parent;
|
|
219
|
+
const B = A.left;
|
|
220
|
+
let C = null;
|
|
221
|
+
if (B) {
|
|
222
|
+
C = B.right;
|
|
223
|
+
}
|
|
224
|
+
if (A)
|
|
225
|
+
A.parent = C;
|
|
226
|
+
if (B)
|
|
227
|
+
B.parent = C;
|
|
228
|
+
if (C) {
|
|
229
|
+
if (C.left) {
|
|
230
|
+
C.left.parent = B;
|
|
231
|
+
}
|
|
232
|
+
if (C.right) {
|
|
233
|
+
C.right.parent = A;
|
|
234
|
+
}
|
|
235
|
+
C.parent = parentOfA;
|
|
236
|
+
}
|
|
237
|
+
if (A === this.root) {
|
|
238
|
+
if (C)
|
|
239
|
+
this._setRoot(C);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
if (parentOfA) {
|
|
243
|
+
if (parentOfA.left === A) {
|
|
244
|
+
parentOfA.left = C;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
parentOfA.right = C;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (C) {
|
|
252
|
+
A.left = C.right;
|
|
253
|
+
if (B)
|
|
254
|
+
B.right = C.left;
|
|
255
|
+
C.left = B;
|
|
256
|
+
C.right = A;
|
|
257
|
+
}
|
|
258
|
+
this._updateHeight(A);
|
|
259
|
+
B && this._updateHeight(B);
|
|
260
|
+
C && this._updateHeight(C);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
264
|
+
* @param {N} A - A is a node in a binary tree.
|
|
265
|
+
*/
|
|
266
|
+
_balanceRR(A) {
|
|
267
|
+
const parentOfA = A.parent;
|
|
268
|
+
const B = A.right;
|
|
269
|
+
A.parent = B;
|
|
270
|
+
if (B) {
|
|
271
|
+
if (B.left) {
|
|
272
|
+
B.left.parent = A;
|
|
273
|
+
}
|
|
274
|
+
B.parent = parentOfA;
|
|
275
|
+
}
|
|
276
|
+
if (A === this.root) {
|
|
277
|
+
if (B)
|
|
278
|
+
this._setRoot(B);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
if (parentOfA) {
|
|
282
|
+
if (parentOfA.left === A) {
|
|
283
|
+
parentOfA.left = B;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
parentOfA.right = B;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (B) {
|
|
291
|
+
A.right = B.left;
|
|
292
|
+
B.left = A;
|
|
293
|
+
}
|
|
294
|
+
this._updateHeight(A);
|
|
295
|
+
B && this._updateHeight(B);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
299
|
+
* @param {N} A - A is a node in a binary tree.
|
|
300
|
+
*/
|
|
301
|
+
_balanceRL(A) {
|
|
302
|
+
const parentOfA = A.parent;
|
|
303
|
+
const B = A.right;
|
|
304
|
+
let C = null;
|
|
305
|
+
if (B) {
|
|
306
|
+
C = B.left;
|
|
307
|
+
}
|
|
308
|
+
A.parent = C;
|
|
309
|
+
if (B)
|
|
310
|
+
B.parent = C;
|
|
311
|
+
if (C) {
|
|
312
|
+
if (C.left) {
|
|
313
|
+
C.left.parent = A;
|
|
314
|
+
}
|
|
315
|
+
if (C.right) {
|
|
316
|
+
C.right.parent = B;
|
|
317
|
+
}
|
|
318
|
+
C.parent = parentOfA;
|
|
319
|
+
}
|
|
320
|
+
if (A === this.root) {
|
|
321
|
+
if (C)
|
|
322
|
+
this._setRoot(C);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
if (parentOfA) {
|
|
326
|
+
if (parentOfA.left === A) {
|
|
327
|
+
parentOfA.left = C;
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
parentOfA.right = C;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (C)
|
|
335
|
+
A.right = C.left;
|
|
336
|
+
if (B && C)
|
|
337
|
+
B.left = C.right;
|
|
338
|
+
if (C)
|
|
339
|
+
C.left = A;
|
|
340
|
+
if (C)
|
|
341
|
+
C.right = B;
|
|
342
|
+
this._updateHeight(A);
|
|
343
|
+
B && this._updateHeight(B);
|
|
344
|
+
C && this._updateHeight(C);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
exports.AVLTree = AVLTree;
|