data-structure-typed 1.21.4 → 1.32.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/.auto-changelog +9 -0
- package/.auto-changelog-template.hbs +36 -0
- package/.eslintrc.js +61 -0
- package/.gitattributes +112 -0
- package/.github/workflows/ci.yml +30 -0
- package/.prettierignore +6 -0
- package/.prettierrc.js +16 -0
- package/CHANGELOG.md +17 -0
- package/CODE-OF-CONDUCT.md +80 -0
- package/COMMANDS.md +28 -0
- package/README.md +147 -95
- package/SECURITY.md +15 -0
- package/coverage/clover.xml +3393 -0
- package/coverage/coverage-final.json +67 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +386 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +4966 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +1015 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +313 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +226 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +1714 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/index.html +296 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +121 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +388 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +811 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +2185 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +3205 -0
- package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +1495 -0
- package/coverage/lcov-report/src/data-structures/graph/index.html +176 -0
- package/coverage/lcov-report/src/data-structures/graph/index.ts.html +97 -0
- package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +472 -0
- package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +907 -0
- package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +286 -0
- package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +253 -0
- package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/index.html +206 -0
- package/coverage/lcov-report/src/data-structures/hash/index.ts.html +103 -0
- package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +721 -0
- package/coverage/lcov-report/src/data-structures/heap/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/heap/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +178 -0
- package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +181 -0
- package/coverage/lcov-report/src/data-structures/index.html +116 -0
- package/coverage/lcov-report/src/data-structures/index.ts.html +118 -0
- package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +1804 -0
- package/coverage/lcov-report/src/data-structures/linked-list/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +1588 -0
- package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/matrix/index.html +176 -0
- package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +97 -0
- package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +166 -0
- package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +721 -0
- package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +448 -0
- package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +1033 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +253 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +256 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +1162 -0
- package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +976 -0
- package/coverage/lcov-report/src/data-structures/queue/index.html +146 -0
- package/coverage/lcov-report/src/data-structures/queue/index.ts.html +91 -0
- package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +658 -0
- package/coverage/lcov-report/src/data-structures/stack/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/stack/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +379 -0
- package/coverage/lcov-report/src/data-structures/tree/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/tree/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +292 -0
- package/coverage/lcov-report/src/data-structures/trie/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/trie/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +760 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/index.ts.html +97 -0
- package/coverage/lcov-report/src/interfaces/index.html +116 -0
- package/coverage/lcov-report/src/interfaces/index.ts.html +130 -0
- package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +235 -0
- package/coverage/lcov-report/src/types/data-structures/bst.ts.html +124 -0
- package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +109 -0
- package/coverage/lcov-report/src/types/data-structures/index.html +176 -0
- package/coverage/lcov-report/src/types/data-structures/index.ts.html +130 -0
- package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +106 -0
- package/coverage/lcov-report/src/types/index.html +116 -0
- package/coverage/lcov-report/src/types/index.ts.html +94 -0
- package/coverage/lcov-report/src/types/utils/index.html +116 -0
- package/coverage/lcov-report/src/types/utils/index.ts.html +91 -0
- package/coverage/lcov-report/src/utils/index.html +131 -0
- package/coverage/lcov-report/src/utils/index.ts.html +88 -0
- package/coverage/lcov-report/src/utils/utils.ts.html +322 -0
- package/coverage/lcov-report/test/utils/index.html +146 -0
- package/coverage/lcov-report/test/utils/index.ts.html +91 -0
- package/coverage/lcov-report/test/utils/magnitude.ts.html +148 -0
- package/coverage/lcov-report/test/utils/number.ts.html +94 -0
- package/coverage/lcov.info +6676 -0
- package/dist/data-structures/binary-tree/aa-tree.js +6 -2
- package/dist/data-structures/binary-tree/aa-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +398 -672
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/avl-tree.js +122 -151
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/b-tree.js +6 -2
- package/dist/data-structures/binary-tree/b-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +24 -54
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/binary-tree.js +31 -32
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/bst.js +266 -208
- package/dist/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/index.js.map +1 -0
- package/dist/data-structures/binary-tree/rb-tree.js +46 -37
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/segment-tree.js +124 -127
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/splay-tree.js +6 -2
- package/dist/data-structures/binary-tree/splay-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +227 -354
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -0
- package/dist/data-structures/binary-tree/two-three-tree.js +6 -2
- package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -0
- package/dist/data-structures/graph/abstract-graph.js +582 -609
- package/dist/data-structures/graph/abstract-graph.js.map +1 -0
- package/dist/data-structures/graph/directed-graph.js +276 -312
- package/dist/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/data-structures/graph/index.js +1 -0
- package/dist/data-structures/graph/index.js.map +1 -0
- package/dist/data-structures/graph/map-graph.js +88 -100
- package/dist/data-structures/graph/map-graph.js.map +1 -0
- package/dist/data-structures/graph/undirected-graph.js +180 -195
- package/dist/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/data-structures/hash/coordinate-map.js +46 -58
- package/dist/data-structures/hash/coordinate-map.js.map +1 -0
- package/dist/data-structures/hash/coordinate-set.js +43 -48
- package/dist/data-structures/hash/coordinate-set.js.map +1 -0
- package/dist/data-structures/hash/hash-table.js +6 -2
- package/dist/data-structures/hash/hash-table.js.map +1 -0
- package/dist/data-structures/hash/index.js +1 -0
- package/dist/data-structures/hash/index.js.map +1 -0
- package/dist/data-structures/hash/pair.js +6 -2
- package/dist/data-structures/hash/pair.js.map +1 -0
- package/dist/data-structures/hash/tree-map.js +6 -2
- package/dist/data-structures/hash/tree-map.js.map +1 -0
- package/dist/data-structures/hash/tree-set.js +6 -2
- package/dist/data-structures/hash/tree-set.js.map +1 -0
- package/dist/data-structures/heap/heap.js +83 -120
- package/dist/data-structures/heap/heap.js.map +1 -0
- package/dist/data-structures/heap/index.js +1 -0
- package/dist/data-structures/heap/index.js.map +1 -0
- package/dist/data-structures/heap/max-heap.js +27 -24
- package/dist/data-structures/heap/max-heap.js.map +1 -0
- package/dist/data-structures/heap/min-heap.js +27 -25
- package/dist/data-structures/heap/min-heap.js.map +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/index.js.map +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -307
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -0
- package/dist/data-structures/linked-list/index.js +1 -0
- package/dist/data-structures/linked-list/index.js.map +1 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +223 -251
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +6 -2
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/data-structures/matrix/index.js +1 -0
- package/dist/data-structures/matrix/index.js.map +1 -0
- package/dist/data-structures/matrix/matrix.js +9 -22
- package/dist/data-structures/matrix/matrix.js.map +1 -0
- package/dist/data-structures/matrix/matrix2d.js +75 -149
- package/dist/data-structures/matrix/matrix2d.js.map +1 -0
- package/dist/data-structures/matrix/navigator.js +38 -46
- package/dist/data-structures/matrix/navigator.js.map +1 -0
- package/dist/data-structures/matrix/vector2d.js +90 -254
- package/dist/data-structures/matrix/vector2d.js.map +1 -0
- package/dist/data-structures/priority-queue/index.js +1 -0
- package/dist/data-structures/priority-queue/index.js.map +1 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +47 -32
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +47 -33
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/data-structures/priority-queue/priority-queue.js +150 -241
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -0
- package/dist/data-structures/queue/deque.js +130 -162
- package/dist/data-structures/queue/deque.js.map +1 -0
- package/dist/data-structures/queue/index.js +1 -0
- package/dist/data-structures/queue/index.js.map +1 -0
- package/dist/data-structures/queue/queue.js +181 -100
- package/dist/data-structures/queue/queue.js.map +1 -0
- package/dist/data-structures/stack/index.js +1 -0
- package/dist/data-structures/stack/index.js.map +1 -0
- package/dist/data-structures/stack/stack.js +23 -71
- package/dist/data-structures/stack/stack.js.map +1 -0
- package/dist/data-structures/tree/index.js +1 -0
- package/dist/data-structures/tree/index.js.map +1 -0
- package/dist/data-structures/tree/tree.js +46 -33
- package/dist/data-structures/tree/tree.js.map +1 -0
- package/dist/data-structures/trie/index.js +1 -0
- package/dist/data-structures/trie/index.js.map +1 -0
- package/dist/data-structures/trie/trie.js +201 -129
- package/dist/data-structures/trie/trie.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/abstract-binary-tree.js +1 -0
- package/dist/interfaces/abstract-binary-tree.js.map +1 -0
- package/dist/interfaces/abstract-graph.js +1 -0
- package/dist/interfaces/abstract-graph.js.map +1 -0
- package/dist/interfaces/avl-tree.js +1 -0
- package/dist/interfaces/avl-tree.js.map +1 -0
- package/dist/interfaces/binary-tree.js +1 -0
- package/dist/interfaces/binary-tree.js.map +1 -0
- package/dist/interfaces/bst.js +1 -0
- package/dist/interfaces/bst.js.map +1 -0
- package/dist/interfaces/directed-graph.js +1 -0
- package/dist/interfaces/directed-graph.js.map +1 -0
- package/dist/interfaces/doubly-linked-list.js +1 -0
- package/dist/interfaces/doubly-linked-list.js.map +1 -0
- package/dist/interfaces/heap.js +1 -0
- package/dist/interfaces/heap.js.map +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/navigator.js +1 -0
- package/dist/interfaces/navigator.js.map +1 -0
- package/dist/interfaces/priority-queue.js +1 -0
- package/dist/interfaces/priority-queue.js.map +1 -0
- package/dist/interfaces/rb-tree.js +1 -0
- package/dist/interfaces/rb-tree.js.map +1 -0
- package/dist/interfaces/segment-tree.js +1 -0
- package/dist/interfaces/segment-tree.js.map +1 -0
- package/dist/interfaces/singly-linked-list.js +1 -0
- package/dist/interfaces/singly-linked-list.js.map +1 -0
- package/dist/interfaces/tree-multiset.js +1 -0
- package/dist/interfaces/tree-multiset.js.map +1 -0
- package/dist/interfaces/undirected-graph.js +1 -0
- package/dist/interfaces/undirected-graph.js.map +1 -0
- package/dist/types/data-structures/abstract-binary-tree.js +1 -7
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -0
- package/dist/types/data-structures/abstract-graph.js +1 -0
- package/dist/types/data-structures/abstract-graph.js.map +1 -0
- package/dist/types/data-structures/avl-tree.js +1 -0
- package/dist/types/data-structures/avl-tree.js.map +1 -0
- package/dist/types/data-structures/binary-tree.js +1 -0
- package/dist/types/data-structures/binary-tree.js.map +1 -0
- package/dist/types/data-structures/bst.js +1 -0
- package/dist/types/data-structures/bst.js.map +1 -0
- package/dist/types/data-structures/directed-graph.js +1 -0
- package/dist/types/data-structures/directed-graph.js.map +1 -0
- package/dist/types/data-structures/doubly-linked-list.js +1 -0
- package/dist/types/data-structures/doubly-linked-list.js.map +1 -0
- package/dist/types/data-structures/heap.js +1 -0
- package/dist/types/data-structures/heap.js.map +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/dist/types/data-structures/index.js.map +1 -0
- package/dist/types/data-structures/map-graph.js +1 -0
- package/dist/types/data-structures/map-graph.js.map +1 -0
- package/dist/types/data-structures/navigator.js +1 -0
- package/dist/types/data-structures/navigator.js.map +1 -0
- package/dist/types/data-structures/priority-queue.js +1 -0
- package/dist/types/data-structures/priority-queue.js.map +1 -0
- package/dist/types/data-structures/rb-tree.js +1 -0
- package/dist/types/data-structures/rb-tree.js.map +1 -0
- package/dist/types/data-structures/segment-tree.js +1 -0
- package/dist/types/data-structures/segment-tree.js.map +1 -0
- package/dist/types/data-structures/singly-linked-list.js +1 -0
- package/dist/types/data-structures/singly-linked-list.js.map +1 -0
- package/dist/types/data-structures/tree-multiset.js +1 -0
- package/dist/types/data-structures/tree-multiset.js.map +1 -0
- package/dist/types/helpers.js +1 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/utils/index.js +1 -0
- package/dist/types/utils/index.js.map +1 -0
- package/dist/types/utils/utils.js +1 -0
- package/dist/types/utils/utils.js.map +1 -0
- package/dist/types/utils/validate-type.js +1 -0
- package/dist/types/utils/validate-type.js.map +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/utils.js +108 -22
- package/dist/utils/utils.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +127 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2182 -0
- package/docs/classes/AVLTreeNode.html +399 -0
- package/docs/classes/AaTree.html +202 -0
- package/docs/classes/AbstractBinaryTree.html +1836 -0
- package/docs/classes/AbstractBinaryTreeNode.html +441 -0
- package/docs/classes/AbstractEdge.html +345 -0
- package/docs/classes/AbstractGraph.html +1105 -0
- package/docs/classes/AbstractVertex.html +299 -0
- package/docs/classes/ArrayDeque.html +469 -0
- package/docs/classes/BST.html +2026 -0
- package/docs/classes/BSTNode.html +400 -0
- package/docs/classes/BTree.html +202 -0
- package/docs/classes/BinaryIndexedTree.html +371 -0
- package/docs/classes/BinaryTree.html +1867 -0
- package/docs/classes/BinaryTreeNode.html +399 -0
- package/docs/classes/Character.html +250 -0
- package/docs/classes/CoordinateMap.html +513 -0
- package/docs/classes/CoordinateSet.html +474 -0
- package/docs/classes/Deque.html +1005 -0
- package/docs/classes/DirectedEdge.html +404 -0
- package/docs/classes/DirectedGraph.html +1530 -0
- package/docs/classes/DirectedVertex.html +286 -0
- package/docs/classes/DoublyLinkedList.html +998 -0
- package/docs/classes/DoublyLinkedListNode.html +327 -0
- package/docs/classes/HashTable.html +202 -0
- package/docs/classes/Heap.html +647 -0
- package/docs/classes/HeapItem.html +296 -0
- package/docs/classes/LinkedListQueue.html +884 -0
- package/docs/classes/MapEdge.html +391 -0
- package/docs/classes/MapGraph.html +1583 -0
- package/docs/classes/MapVertex.html +356 -0
- package/docs/classes/Matrix2D.html +532 -0
- package/docs/classes/MatrixNTI2D.html +270 -0
- package/docs/classes/MaxHeap.html +671 -0
- package/docs/classes/MaxPriorityQueue.html +866 -0
- package/docs/classes/MinHeap.html +672 -0
- package/docs/classes/MinPriorityQueue.html +868 -0
- package/docs/classes/Navigator.html +343 -0
- package/docs/classes/ObjectDeque.html +527 -0
- package/docs/classes/Pair.html +202 -0
- package/docs/classes/PriorityQueue.html +790 -0
- package/docs/classes/Queue.html +521 -0
- package/docs/classes/RBTree.html +2024 -0
- package/docs/classes/RBTreeNode.html +431 -0
- package/docs/classes/SegmentTree.html +464 -0
- package/docs/classes/SegmentTreeNode.html +387 -0
- package/docs/classes/SinglyLinkedList.html +830 -0
- package/docs/classes/SinglyLinkedListNode.html +300 -0
- package/docs/classes/SkipLinkedList.html +202 -0
- package/docs/classes/SplayTree.html +202 -0
- package/docs/classes/Stack.html +398 -0
- package/docs/classes/TreeMap.html +202 -0
- package/docs/classes/TreeMultiset.html +2510 -0
- package/docs/classes/TreeMultisetNode.html +447 -0
- package/docs/classes/TreeNode.html +344 -0
- package/docs/classes/TreeSet.html +202 -0
- package/docs/classes/Trie.html +402 -0
- package/docs/classes/TrieNode.html +310 -0
- package/docs/classes/TwoThreeTree.html +202 -0
- package/docs/classes/UndirectedEdge.html +374 -0
- package/docs/classes/UndirectedGraph.html +1285 -0
- package/docs/classes/UndirectedVertex.html +284 -0
- package/docs/classes/Vector2D.html +835 -0
- package/docs/enums/CP.html +211 -0
- package/docs/enums/FamilyPosition.html +239 -0
- package/docs/enums/LoopType.html +212 -0
- package/docs/enums/RBColor.html +204 -0
- package/docs/enums/TopologicalProperty.html +211 -0
- package/docs/functions/arrayRemove.html +208 -0
- package/docs/functions/isThunk.html +186 -0
- package/docs/functions/toThunk.html +186 -0
- package/docs/functions/trampoline.html +186 -0
- package/docs/functions/trampolineAsync.html +186 -0
- package/docs/functions/uuidV4.html +181 -0
- package/docs/index.html +693 -0
- package/docs/interfaces/IAVLTree.html +1245 -0
- package/docs/interfaces/IAbstractBinaryTree.html +1101 -0
- package/docs/interfaces/IAbstractBinaryTreeNode.html +335 -0
- package/docs/interfaces/IAbstractGraph.html +433 -0
- package/docs/interfaces/IBST.html +1245 -0
- package/docs/interfaces/IDirectedGraph.html +570 -0
- package/docs/interfaces/IRBTree.html +1247 -0
- package/docs/interfaces/IUNDirectedGraph.html +463 -0
- package/docs/modules.html +328 -0
- package/docs/types/AVLTreeNodeNested.html +182 -0
- package/docs/types/AVLTreeOptions.html +180 -0
- package/docs/types/AbstractBinaryTreeNodeNested.html +182 -0
- package/docs/types/AbstractBinaryTreeNodeProperties.html +182 -0
- package/docs/types/AbstractBinaryTreeNodeProperty.html +182 -0
- package/docs/types/AbstractBinaryTreeOptions.html +182 -0
- package/docs/types/BSTComparator.html +192 -0
- package/docs/types/BSTNodeNested.html +182 -0
- package/docs/types/BSTOptions.html +182 -0
- package/docs/types/BinaryTreeDeletedResult.html +189 -0
- package/docs/types/BinaryTreeNodeId.html +177 -0
- package/docs/types/BinaryTreeNodeNested.html +182 -0
- package/docs/types/BinaryTreeNodePropertyName.html +177 -0
- package/docs/types/BinaryTreeOptions.html +180 -0
- package/docs/types/DFSOrderPattern.html +177 -0
- package/docs/types/DijkstraResult.html +199 -0
- package/docs/types/Direction.html +177 -0
- package/docs/types/DummyAny.html +190 -0
- package/docs/types/EdgeId.html +177 -0
- package/docs/types/HeapOptions.html +198 -0
- package/docs/types/IAVLTreeNode.html +184 -0
- package/docs/types/IBSTNode.html +184 -0
- package/docs/types/IBinaryTree.html +182 -0
- package/docs/types/IBinaryTreeNode.html +184 -0
- package/docs/types/IRBTreeNode.html +184 -0
- package/docs/types/ITreeMultiset.html +182 -0
- package/docs/types/ITreeMultisetNode.html +184 -0
- package/docs/types/KeyValueObject.html +182 -0
- package/docs/types/KeyValueObjectWithId.html +184 -0
- package/docs/types/MapGraphCoordinate.html +177 -0
- package/docs/types/NavigatorParams.html +211 -0
- package/docs/types/NodeOrPropertyName.html +177 -0
- package/docs/types/NonNumberNonObjectButDefined.html +177 -0
- package/docs/types/ObjectWithNonNumberId.html +184 -0
- package/docs/types/ObjectWithNumberId.html +184 -0
- package/docs/types/ObjectWithoutId.html +177 -0
- package/docs/types/PriorityQueueComparator.html +197 -0
- package/docs/types/PriorityQueueDFSOrderPattern.html +177 -0
- package/docs/types/PriorityQueueOptions.html +191 -0
- package/docs/types/RBTreeNodeNested.html +182 -0
- package/docs/types/RBTreeOptions.html +180 -0
- package/docs/types/RestrictValById.html +177 -0
- package/docs/types/SegmentTreeNodeVal.html +177 -0
- package/docs/types/SpecifyOptional.html +184 -0
- package/docs/types/Thunk.html +185 -0
- package/docs/types/ToThunkFn.html +185 -0
- package/docs/types/TopologicalStatus.html +177 -0
- package/docs/types/TreeMultisetNodeNested.html +182 -0
- package/docs/types/TreeMultisetOptions.html +180 -0
- package/docs/types/TrlAsyncFn.html +190 -0
- package/docs/types/TrlFn.html +190 -0
- package/docs/types/Turning.html +177 -0
- package/docs/types/VertexId.html +177 -0
- package/docs/variables/THUNK_SYMBOL.html +177 -0
- package/jest.config.js +7 -0
- package/lib/data-structures/binary-tree/aa-tree.js +2 -0
- package/{dist → lib}/data-structures/binary-tree/abstract-binary-tree.d.ts +194 -22
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +1291 -0
- package/{dist → lib}/data-structures/binary-tree/avl-tree.d.ts +12 -12
- package/lib/data-structures/binary-tree/avl-tree.js +311 -0
- package/lib/data-structures/binary-tree/b-tree.js +2 -0
- package/lib/data-structures/binary-tree/binary-indexed-tree.js +69 -0
- package/lib/data-structures/binary-tree/binary-tree.js +35 -0
- package/{dist → lib}/data-structures/binary-tree/bst.d.ts +19 -8
- package/lib/data-structures/binary-tree/bst.js +551 -0
- package/lib/data-structures/binary-tree/index.js +12 -0
- package/{dist → lib}/data-structures/binary-tree/rb-tree.d.ts +0 -6
- package/lib/data-structures/binary-tree/rb-tree.js +22 -0
- package/lib/data-structures/binary-tree/segment-tree.js +210 -0
- package/lib/data-structures/binary-tree/splay-tree.js +2 -0
- package/{dist → lib}/data-structures/binary-tree/tree-multiset.d.ts +20 -23
- package/lib/data-structures/binary-tree/tree-multiset.js +673 -0
- package/lib/data-structures/binary-tree/two-three-tree.js +2 -0
- package/lib/data-structures/graph/abstract-graph.js +918 -0
- package/lib/data-structures/graph/directed-graph.js +416 -0
- package/lib/data-structures/graph/index.js +4 -0
- package/lib/data-structures/graph/map-graph.js +105 -0
- package/lib/data-structures/graph/undirected-graph.js +246 -0
- package/lib/data-structures/hash/coordinate-map.js +61 -0
- package/lib/data-structures/hash/coordinate-set.js +51 -0
- package/lib/data-structures/hash/hash-table.js +2 -0
- package/lib/data-structures/hash/index.js +6 -0
- package/lib/data-structures/hash/pair.js +2 -0
- package/lib/data-structures/hash/tree-map.js +2 -0
- package/lib/data-structures/hash/tree-set.js +2 -0
- package/lib/data-structures/heap/heap.js +152 -0
- package/lib/data-structures/heap/index.js +3 -0
- package/lib/data-structures/heap/max-heap.js +26 -0
- package/lib/data-structures/heap/min-heap.js +27 -0
- package/lib/data-structures/index.js +11 -0
- package/{dist → lib}/data-structures/linked-list/doubly-linked-list.d.ts +5 -5
- package/lib/data-structures/linked-list/doubly-linked-list.js +521 -0
- package/lib/data-structures/linked-list/index.js +3 -0
- package/{dist → lib}/data-structures/linked-list/singly-linked-list.d.ts +6 -5
- package/lib/data-structures/linked-list/singly-linked-list.js +443 -0
- package/lib/data-structures/linked-list/skip-linked-list.js +2 -0
- package/lib/data-structures/matrix/index.js +4 -0
- package/lib/data-structures/matrix/matrix.js +24 -0
- package/lib/data-structures/matrix/matrix2d.js +195 -0
- package/lib/data-structures/matrix/navigator.js +101 -0
- package/lib/data-structures/matrix/vector2d.js +287 -0
- package/lib/data-structures/priority-queue/index.js +3 -0
- package/lib/data-structures/priority-queue/max-priority-queue.js +39 -0
- package/lib/data-structures/priority-queue/min-priority-queue.js +40 -0
- package/lib/data-structures/priority-queue/priority-queue.js +317 -0
- package/{dist → lib}/data-structures/queue/deque.d.ts +45 -0
- package/lib/data-structures/queue/deque.js +270 -0
- package/lib/data-structures/queue/index.js +2 -0
- package/{dist → lib}/data-structures/queue/queue.d.ts +47 -13
- package/lib/data-structures/queue/queue.js +165 -0
- package/lib/data-structures/stack/index.js +1 -0
- package/lib/data-structures/stack/stack.js +87 -0
- package/lib/data-structures/tree/index.js +1 -0
- package/lib/data-structures/tree/tree.js +56 -0
- package/lib/data-structures/trie/index.js +1 -0
- package/lib/data-structures/trie/trie.js +205 -0
- package/lib/index.js +4 -0
- package/{dist → lib}/interfaces/avl-tree.d.ts +1 -9
- package/lib/interfaces/binary-tree.d.ts +4 -0
- package/{dist → lib}/interfaces/bst.d.ts +1 -2
- package/lib/interfaces/heap.js +1 -0
- package/lib/interfaces/index.js +15 -0
- package/lib/interfaces/navigator.d.ts +1 -0
- package/lib/interfaces/navigator.js +1 -0
- package/lib/interfaces/priority-queue.d.ts +1 -0
- package/lib/interfaces/priority-queue.js +1 -0
- package/{dist → lib}/interfaces/rb-tree.d.ts +1 -2
- package/lib/interfaces/rb-tree.js +1 -0
- package/lib/interfaces/segment-tree.d.ts +1 -0
- package/lib/interfaces/segment-tree.js +1 -0
- package/lib/interfaces/singly-linked-list.d.ts +1 -0
- package/lib/interfaces/singly-linked-list.js +1 -0
- package/lib/interfaces/tree-multiset.d.ts +5 -0
- package/lib/interfaces/tree-multiset.js +1 -0
- package/lib/interfaces/undirected-graph.js +1 -0
- package/{dist → lib}/types/data-structures/abstract-binary-tree.d.ts +1 -1
- package/lib/types/data-structures/abstract-binary-tree.js +22 -0
- package/lib/types/data-structures/abstract-graph.js +1 -0
- package/{dist → lib}/types/data-structures/avl-tree.d.ts +1 -1
- package/lib/types/data-structures/avl-tree.js +1 -0
- package/lib/types/data-structures/binary-tree.js +1 -0
- package/lib/types/data-structures/bst.js +6 -0
- package/lib/types/data-structures/directed-graph.js +6 -0
- package/lib/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/lib/types/data-structures/doubly-linked-list.js +1 -0
- package/lib/types/data-structures/heap.js +1 -0
- package/lib/types/data-structures/index.js +15 -0
- package/lib/types/data-structures/map-graph.js +1 -0
- package/lib/types/data-structures/navigator.js +1 -0
- package/lib/types/data-structures/priority-queue.js +1 -0
- package/lib/types/data-structures/rb-tree.js +5 -0
- package/lib/types/data-structures/segment-tree.js +1 -0
- package/lib/types/data-structures/singly-linked-list.d.ts +1 -0
- package/lib/types/data-structures/singly-linked-list.js +1 -0
- package/lib/types/data-structures/tree-multiset.js +1 -0
- package/lib/types/helpers.d.ts +1 -0
- package/lib/types/helpers.js +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/utils/index.js +2 -0
- package/{dist → lib}/types/utils/utils.d.ts +1 -1
- package/lib/types/utils/utils.js +1 -0
- package/{dist → lib}/types/utils/validate-type.d.ts +1 -1
- package/lib/types/utils/validate-type.js +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/utils.js +57 -0
- package/package.json +150 -56
- package/rename_clear_files.sh +29 -0
- package/test/integration/avl-tree.test.ts +111 -0
- package/test/integration/bst.test.ts +371 -0
- package/test/integration/heap.test.js +19 -0
- package/test/integration/index.html +44 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +111 -0
- package/test/unit/data-structures/binary-tree/bst.test.ts +371 -0
- package/test/unit/data-structures/binary-tree/overall.test.ts +57 -0
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +405 -0
- package/test/unit/data-structures/graph/abstract-graph.test.ts +5 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +517 -0
- package/test/unit/data-structures/graph/index.ts +2 -0
- package/test/unit/data-structures/graph/map-graph.test.ts +46 -0
- package/test/unit/data-structures/graph/overall.test.ts +50 -0
- package/test/unit/data-structures/graph/undirected-graph.test.ts +60 -0
- package/test/unit/data-structures/heap/heap.test.ts +56 -0
- package/test/unit/data-structures/heap/max-heap.test.ts +42 -0
- package/test/unit/data-structures/heap/min-heap.test.ts +81 -0
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +365 -0
- package/test/unit/data-structures/linked-list/index.ts +4 -0
- package/test/unit/data-structures/linked-list/linked-list.test.ts +37 -0
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +401 -0
- package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +108 -0
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +105 -0
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +27 -0
- package/test/unit/data-structures/queue/queue.test.ts +36 -0
- package/test/utils/index.ts +2 -0
- package/test/utils/magnitude.ts +21 -0
- package/test/utils/number.ts +3 -0
- package/tsconfig.build.json +33 -0
- package/tsconfig.json +38 -0
- package/umd/bundle.min.js +3 -0
- package/umd/bundle.min.js.map +1 -0
- package/webpack.config.js +28 -0
- package/dist/bundle.js +0 -2
- package/dist/interfaces/binary-tree.d.ts +0 -6
- package/dist/interfaces/tree-multiset.d.ts +0 -7
- /package/{dist → lib}/data-structures/binary-tree/aa-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/b-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/binary-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/splay-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/two-three-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/directed-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/map-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/undirected-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/coordinate-map.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/coordinate-set.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/hash-table.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/pair.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/tree-map.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/tree-set.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/max-heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/min-heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/linked-list/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/linked-list/skip-linked-list.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/matrix.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/matrix2d.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/navigator.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/vector2d.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/queue/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/stack/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/stack/stack.d.ts +0 -0
- /package/{dist → lib}/data-structures/tree/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/tree/tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/trie/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/trie/trie.d.ts +0 -0
- /package/{dist → lib}/index.d.ts +0 -0
- /package/{dist → lib}/interfaces/abstract-binary-tree.d.ts +0 -0
- /package/{dist/interfaces/doubly-linked-list.d.ts → lib/interfaces/abstract-binary-tree.js} +0 -0
- /package/{dist → lib}/interfaces/abstract-graph.d.ts +0 -0
- /package/{dist/interfaces/heap.d.ts → lib/interfaces/abstract-graph.js} +0 -0
- /package/{dist/interfaces/navigator.d.ts → lib/interfaces/avl-tree.js} +0 -0
- /package/{dist/interfaces/priority-queue.d.ts → lib/interfaces/binary-tree.js} +0 -0
- /package/{dist/interfaces/segment-tree.d.ts → lib/interfaces/bst.js} +0 -0
- /package/{dist → lib}/interfaces/directed-graph.d.ts +0 -0
- /package/{dist/interfaces/singly-linked-list.d.ts → lib/interfaces/directed-graph.js} +0 -0
- /package/{dist/types/data-structures → lib/interfaces}/doubly-linked-list.d.ts +0 -0
- /package/{dist/types/data-structures/singly-linked-list.d.ts → lib/interfaces/doubly-linked-list.js} +0 -0
- /package/{dist/types/helpers.d.ts → lib/interfaces/heap.d.ts} +0 -0
- /package/{dist → lib}/interfaces/index.d.ts +0 -0
- /package/{dist → lib}/interfaces/undirected-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/abstract-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/binary-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/bst.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/directed-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/heap.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/index.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/map-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/navigator.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/priority-queue.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/rb-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/segment-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/tree-multiset.d.ts +0 -0
- /package/{dist → lib}/types/index.d.ts +0 -0
- /package/{dist → lib}/types/utils/index.d.ts +0 -0
- /package/{dist → lib}/utils/index.d.ts +0 -0
- /package/{dist → lib}/utils/utils.d.ts +0 -0
- /package/{dist/bundle.js.LICENSE.txt → umd/bundle.min.js.LICENSE.txt} +0 -0
|
@@ -1,115 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
9
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
19
|
exports.AbstractBinaryTree = exports.AbstractBinaryTreeNode = void 0;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* The constructor function initializes a BinaryTreeNode object with an id and an optional value.
|
|
16
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
|
|
17
|
-
* of the binary tree node. It is used to distinguish one node from another in the binary tree.
|
|
18
|
-
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value that will be
|
|
19
|
-
* stored in the binary tree node. If no value is provided, it will be set to undefined.
|
|
20
|
-
*/
|
|
21
|
-
constructor(id, val) {
|
|
20
|
+
var utils_1 = require("../../utils");
|
|
21
|
+
var types_1 = require("../../types");
|
|
22
|
+
var AbstractBinaryTreeNode = (function () {
|
|
23
|
+
function AbstractBinaryTreeNode(id, val) {
|
|
22
24
|
this._height = 0;
|
|
23
25
|
this._id = id;
|
|
24
26
|
this._val = val;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
28
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "id", {
|
|
29
|
+
get: function () {
|
|
30
|
+
return this._id;
|
|
31
|
+
},
|
|
32
|
+
set: function (v) {
|
|
33
|
+
this._id = v;
|
|
34
|
+
},
|
|
35
|
+
enumerable: false,
|
|
36
|
+
configurable: true
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "val", {
|
|
39
|
+
get: function () {
|
|
40
|
+
return this._val;
|
|
41
|
+
},
|
|
42
|
+
set: function (value) {
|
|
43
|
+
this._val = value;
|
|
44
|
+
},
|
|
45
|
+
enumerable: false,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "left", {
|
|
49
|
+
get: function () {
|
|
50
|
+
return this._left;
|
|
51
|
+
},
|
|
52
|
+
set: function (v) {
|
|
53
|
+
if (v) {
|
|
54
|
+
v.parent = this;
|
|
55
|
+
}
|
|
56
|
+
this._left = v;
|
|
57
|
+
},
|
|
58
|
+
enumerable: false,
|
|
59
|
+
configurable: true
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "right", {
|
|
62
|
+
get: function () {
|
|
63
|
+
return this._right;
|
|
64
|
+
},
|
|
65
|
+
set: function (v) {
|
|
66
|
+
if (v) {
|
|
67
|
+
v.parent = this;
|
|
68
|
+
}
|
|
69
|
+
this._right = v;
|
|
70
|
+
},
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "parent", {
|
|
75
|
+
get: function () {
|
|
76
|
+
return this._parent;
|
|
77
|
+
},
|
|
78
|
+
set: function (v) {
|
|
79
|
+
this._parent = v;
|
|
80
|
+
},
|
|
81
|
+
enumerable: false,
|
|
82
|
+
configurable: true
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "height", {
|
|
85
|
+
get: function () {
|
|
86
|
+
return this._height;
|
|
87
|
+
},
|
|
88
|
+
set: function (v) {
|
|
89
|
+
this._height = v;
|
|
90
|
+
},
|
|
91
|
+
enumerable: false,
|
|
92
|
+
configurable: true
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
|
|
95
|
+
get: function () {
|
|
96
|
+
var that = this;
|
|
97
|
+
if (that.parent) {
|
|
98
|
+
if (that.parent.left === that) {
|
|
99
|
+
if (that.left || that.right) {
|
|
100
|
+
return types_1.FamilyPosition.ROOT_LEFT;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return types_1.FamilyPosition.LEFT;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (that.parent.right === that) {
|
|
107
|
+
if (that.left || that.right) {
|
|
108
|
+
return types_1.FamilyPosition.ROOT_RIGHT;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return types_1.FamilyPosition.RIGHT;
|
|
112
|
+
}
|
|
78
113
|
}
|
|
79
114
|
else {
|
|
80
|
-
return types_1.FamilyPosition.
|
|
115
|
+
return types_1.FamilyPosition.MAL_NODE;
|
|
81
116
|
}
|
|
82
117
|
}
|
|
83
|
-
else
|
|
118
|
+
else {
|
|
84
119
|
if (that.left || that.right) {
|
|
85
|
-
return types_1.FamilyPosition.
|
|
120
|
+
return types_1.FamilyPosition.ROOT;
|
|
86
121
|
}
|
|
87
122
|
else {
|
|
88
|
-
return types_1.FamilyPosition.
|
|
123
|
+
return types_1.FamilyPosition.ISOLATED;
|
|
89
124
|
}
|
|
90
125
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return types_1.FamilyPosition.ROOT;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return types_1.FamilyPosition.ISOLATED;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
126
|
+
},
|
|
127
|
+
enumerable: false,
|
|
128
|
+
configurable: true
|
|
129
|
+
});
|
|
130
|
+
return AbstractBinaryTreeNode;
|
|
131
|
+
}());
|
|
105
132
|
exports.AbstractBinaryTreeNode = AbstractBinaryTreeNode;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
* The protected constructor initializes the options for an abstract binary tree.
|
|
109
|
-
* @param {AbstractBinaryTreeOptions} [options] - An optional object that contains configuration options for the binary
|
|
110
|
-
* tree.
|
|
111
|
-
*/
|
|
112
|
-
constructor(options) {
|
|
133
|
+
var AbstractBinaryTree = (function () {
|
|
134
|
+
function AbstractBinaryTree(options) {
|
|
113
135
|
this._root = null;
|
|
114
136
|
this._size = 0;
|
|
115
137
|
this._loopType = types_1.LoopType.ITERATIVE;
|
|
@@ -118,42 +140,63 @@ class AbstractBinaryTree {
|
|
|
118
140
|
this._visitedNode = [];
|
|
119
141
|
this._visitedLeftSum = [];
|
|
120
142
|
if (options !== undefined) {
|
|
121
|
-
|
|
143
|
+
var _a = options.loopType, loopType = _a === void 0 ? types_1.LoopType.ITERATIVE : _a;
|
|
122
144
|
this._loopType = loopType;
|
|
123
145
|
}
|
|
124
146
|
this.clear();
|
|
125
147
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "root", {
|
|
149
|
+
get: function () {
|
|
150
|
+
return this._root;
|
|
151
|
+
},
|
|
152
|
+
enumerable: false,
|
|
153
|
+
configurable: true
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "size", {
|
|
156
|
+
get: function () {
|
|
157
|
+
return this._size;
|
|
158
|
+
},
|
|
159
|
+
enumerable: false,
|
|
160
|
+
configurable: true
|
|
161
|
+
});
|
|
162
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "loopType", {
|
|
163
|
+
get: function () {
|
|
164
|
+
return this._loopType;
|
|
165
|
+
},
|
|
166
|
+
enumerable: false,
|
|
167
|
+
configurable: true
|
|
168
|
+
});
|
|
169
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "visitedId", {
|
|
170
|
+
get: function () {
|
|
171
|
+
return this._visitedId;
|
|
172
|
+
},
|
|
173
|
+
enumerable: false,
|
|
174
|
+
configurable: true
|
|
175
|
+
});
|
|
176
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "visitedVal", {
|
|
177
|
+
get: function () {
|
|
178
|
+
return this._visitedVal;
|
|
179
|
+
},
|
|
180
|
+
enumerable: false,
|
|
181
|
+
configurable: true
|
|
182
|
+
});
|
|
183
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "visitedNode", {
|
|
184
|
+
get: function () {
|
|
185
|
+
return this._visitedNode;
|
|
186
|
+
},
|
|
187
|
+
enumerable: false,
|
|
188
|
+
configurable: true
|
|
189
|
+
});
|
|
190
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "visitedLeftSum", {
|
|
191
|
+
get: function () {
|
|
192
|
+
return this._visitedLeftSum;
|
|
193
|
+
},
|
|
194
|
+
enumerable: false,
|
|
195
|
+
configurable: true
|
|
196
|
+
});
|
|
197
|
+
AbstractBinaryTree.prototype.swapLocation = function (srcNode, destNode) {
|
|
198
|
+
var id = destNode.id, val = destNode.val, height = destNode.height;
|
|
199
|
+
var tempNode = this.createNode(id, val);
|
|
157
200
|
if (tempNode) {
|
|
158
201
|
tempNode.height = height;
|
|
159
202
|
destNode.id = srcNode.id;
|
|
@@ -164,46 +207,27 @@ class AbstractBinaryTree {
|
|
|
164
207
|
srcNode.height = tempNode.height;
|
|
165
208
|
}
|
|
166
209
|
return destNode;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
* The clear() function resets the root, size, and maxId properties to their initial values.
|
|
170
|
-
*/
|
|
171
|
-
clear() {
|
|
210
|
+
};
|
|
211
|
+
AbstractBinaryTree.prototype.clear = function () {
|
|
172
212
|
this._root = null;
|
|
173
213
|
this._size = 0;
|
|
174
214
|
this._clearResults();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
178
|
-
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
179
|
-
*/
|
|
180
|
-
isEmpty() {
|
|
215
|
+
};
|
|
216
|
+
AbstractBinaryTree.prototype.isEmpty = function () {
|
|
181
217
|
return this.size === 0;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* The `add` function adds a new node to a binary tree, either by ID or by creating a new node with a given value.
|
|
189
|
-
* @param {BinaryTreeNodeId | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId`, which
|
|
190
|
-
* is a number representing the ID of a binary tree node, or it can be a `N` object, which represents a binary tree
|
|
191
|
-
* node itself. It can also be `null` if no node is specified.
|
|
192
|
-
* @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
|
|
193
|
-
* being added to the binary tree.
|
|
194
|
-
* @returns The function `add` returns either the inserted node (`N`), `null`, or `undefined`.
|
|
195
|
-
*/
|
|
196
|
-
add(idOrNode, val) {
|
|
197
|
-
const _bfs = (root, newNode) => {
|
|
198
|
-
const queue = [root];
|
|
218
|
+
};
|
|
219
|
+
AbstractBinaryTree.prototype.add = function (idOrNode, val) {
|
|
220
|
+
var _this = this;
|
|
221
|
+
var _bfs = function (root, newNode) {
|
|
222
|
+
var queue = [root];
|
|
199
223
|
while (queue.length > 0) {
|
|
200
|
-
|
|
224
|
+
var cur = queue.shift();
|
|
201
225
|
if (cur) {
|
|
202
226
|
if (newNode && cur.id === newNode.id)
|
|
203
227
|
return;
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
return
|
|
228
|
+
var inserted_1 = _this._addTo(newNode, cur);
|
|
229
|
+
if (inserted_1 !== undefined)
|
|
230
|
+
return inserted_1;
|
|
207
231
|
if (cur.left)
|
|
208
232
|
queue.push(cur.left);
|
|
209
233
|
if (cur.right)
|
|
@@ -214,7 +238,7 @@ class AbstractBinaryTree {
|
|
|
214
238
|
}
|
|
215
239
|
return;
|
|
216
240
|
};
|
|
217
|
-
|
|
241
|
+
var inserted, needInsert;
|
|
218
242
|
if (idOrNode === null) {
|
|
219
243
|
needInsert = null;
|
|
220
244
|
}
|
|
@@ -227,7 +251,7 @@ class AbstractBinaryTree {
|
|
|
227
251
|
else {
|
|
228
252
|
return;
|
|
229
253
|
}
|
|
230
|
-
|
|
254
|
+
var existNode = idOrNode ? this.get(idOrNode, 'id') : undefined;
|
|
231
255
|
if (this.root) {
|
|
232
256
|
if (existNode) {
|
|
233
257
|
existNode.val = val;
|
|
@@ -248,80 +272,47 @@ class AbstractBinaryTree {
|
|
|
248
272
|
inserted = this.root;
|
|
249
273
|
}
|
|
250
274
|
return inserted;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
* @returns The function `addMany` returns an array of values `(N | null | undefined)[]`.
|
|
260
|
-
*/
|
|
261
|
-
addMany(idsOrNodes, data) {
|
|
262
|
-
var _a;
|
|
263
|
-
// TODO not sure addMany not be run multi times
|
|
264
|
-
const inserted = [];
|
|
265
|
-
const map = new Map();
|
|
266
|
-
for (const idOrNode of idsOrNodes)
|
|
267
|
-
map.set(idOrNode, ((_a = map.get(idOrNode)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
268
|
-
for (let i = 0; i < idsOrNodes.length; i++) {
|
|
269
|
-
const idOrNode = idsOrNodes[i];
|
|
270
|
-
if (map.has(idOrNode)) {
|
|
271
|
-
if (idOrNode instanceof AbstractBinaryTreeNode) {
|
|
272
|
-
inserted.push(this.add(idOrNode.id, idOrNode.val));
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
if (idOrNode === null) {
|
|
276
|
-
inserted.push(this.add(null));
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
const val = data === null || data === void 0 ? void 0 : data[i];
|
|
280
|
-
inserted.push(this.add(idOrNode, val));
|
|
281
|
-
map.delete(idOrNode);
|
|
275
|
+
};
|
|
276
|
+
AbstractBinaryTree.prototype.addMany = function (idsOrNodes, data) {
|
|
277
|
+
var inserted = [];
|
|
278
|
+
for (var i = 0; i < idsOrNodes.length; i++) {
|
|
279
|
+
var idOrNode = idsOrNodes[i];
|
|
280
|
+
if (idOrNode instanceof AbstractBinaryTreeNode) {
|
|
281
|
+
inserted.push(this.add(idOrNode.id, idOrNode.val));
|
|
282
|
+
continue;
|
|
282
283
|
}
|
|
284
|
+
if (idOrNode === null) {
|
|
285
|
+
inserted.push(this.add(null));
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
var val = data === null || data === void 0 ? void 0 : data[i];
|
|
289
|
+
inserted.push(this.add(idOrNode, val));
|
|
283
290
|
}
|
|
284
291
|
return inserted;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
* The `fill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
|
|
288
|
-
* @param {(BinaryTreeNodeId | N)[]} idsOrNodes - The `idsOrNodes` parameter is an array that can contain either
|
|
289
|
-
* `BinaryTreeNodeId` or `N` values.
|
|
290
|
-
* @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to
|
|
291
|
-
* the nodes being added. If provided, the length of the `data` array should be equal to the length of the `idsOrNodes`
|
|
292
|
-
* array. Each value in the `data` array will be assigned to the
|
|
293
|
-
* @returns The method is returning a boolean value.
|
|
294
|
-
*/
|
|
295
|
-
fill(idsOrNodes, data) {
|
|
292
|
+
};
|
|
293
|
+
AbstractBinaryTree.prototype.fill = function (idsOrNodes, data) {
|
|
296
294
|
this.clear();
|
|
297
295
|
return idsOrNodes.length === this.addMany(idsOrNodes, data).length;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
|
|
305
|
-
* whether to ignore the count of the nodes in the binary tree. If `ignoreCount` is set to `true`, the count of the
|
|
306
|
-
* nodes in the binary tree will not be updated after removing a node. If `ignoreCount`
|
|
307
|
-
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
308
|
-
*/
|
|
309
|
-
remove(nodeOrId, ignoreCount) {
|
|
310
|
-
const bstDeletedResult = [];
|
|
296
|
+
};
|
|
297
|
+
AbstractBinaryTree.prototype.remove = function (nodeOrId, isUpdateAllLeftSum) {
|
|
298
|
+
isUpdateAllLeftSum = isUpdateAllLeftSum === undefined ? true : isUpdateAllLeftSum;
|
|
299
|
+
if (isUpdateAllLeftSum) {
|
|
300
|
+
}
|
|
301
|
+
var bstDeletedResult = [];
|
|
311
302
|
if (!this.root)
|
|
312
303
|
return bstDeletedResult;
|
|
313
|
-
|
|
304
|
+
var curr = typeof nodeOrId === 'number' ? this.get(nodeOrId) : nodeOrId;
|
|
314
305
|
if (!curr)
|
|
315
306
|
return bstDeletedResult;
|
|
316
|
-
|
|
317
|
-
|
|
307
|
+
var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
|
|
308
|
+
var needBalanced = null, orgCurrent = curr;
|
|
318
309
|
if (!curr.left) {
|
|
319
310
|
if (!parent) {
|
|
320
311
|
if (curr.right !== undefined)
|
|
321
312
|
this._setRoot(curr.right);
|
|
322
313
|
}
|
|
323
314
|
else {
|
|
324
|
-
|
|
315
|
+
var fp = curr.familyPosition;
|
|
325
316
|
if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
|
|
326
317
|
parent.left = curr.right;
|
|
327
318
|
}
|
|
@@ -332,9 +323,9 @@ class AbstractBinaryTree {
|
|
|
332
323
|
}
|
|
333
324
|
}
|
|
334
325
|
else {
|
|
335
|
-
|
|
326
|
+
var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
|
|
336
327
|
if (leftSubTreeRightMost) {
|
|
337
|
-
|
|
328
|
+
var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
338
329
|
orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
|
|
339
330
|
if (parentOfLeftSubTreeMax) {
|
|
340
331
|
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
@@ -346,55 +337,43 @@ class AbstractBinaryTree {
|
|
|
346
337
|
}
|
|
347
338
|
}
|
|
348
339
|
this._setSize(this.size - 1);
|
|
349
|
-
bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
340
|
+
bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
|
|
350
341
|
return bstDeletedResult;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
* The function calculates the depth of a node in a binary tree.
|
|
354
|
-
* @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
|
|
355
|
-
* @returns the depth of the given node or binary tree.
|
|
356
|
-
*/
|
|
357
|
-
getDepth(beginRoot) {
|
|
342
|
+
};
|
|
343
|
+
AbstractBinaryTree.prototype.getDepth = function (beginRoot) {
|
|
358
344
|
if (typeof beginRoot === 'number')
|
|
359
345
|
beginRoot = this.get(beginRoot, 'id');
|
|
360
|
-
|
|
346
|
+
var depth = 0;
|
|
361
347
|
while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
|
|
362
348
|
depth++;
|
|
363
349
|
beginRoot = beginRoot.parent;
|
|
364
350
|
}
|
|
365
351
|
return depth;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
* The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
|
|
369
|
-
* @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
|
|
370
|
-
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
|
|
371
|
-
* node), or `null`.
|
|
372
|
-
* @returns the height of the binary tree.
|
|
373
|
-
*/
|
|
374
|
-
getHeight(beginRoot) {
|
|
352
|
+
};
|
|
353
|
+
AbstractBinaryTree.prototype.getHeight = function (beginRoot) {
|
|
375
354
|
beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
|
|
376
355
|
if (typeof beginRoot === 'number')
|
|
377
356
|
beginRoot = this.get(beginRoot, 'id');
|
|
378
357
|
if (!beginRoot)
|
|
379
358
|
return -1;
|
|
380
359
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
381
|
-
|
|
360
|
+
var _getMaxHeight_1 = function (cur) {
|
|
382
361
|
if (!cur)
|
|
383
362
|
return -1;
|
|
384
|
-
|
|
385
|
-
|
|
363
|
+
var leftHeight = _getMaxHeight_1(cur.left);
|
|
364
|
+
var rightHeight = _getMaxHeight_1(cur.right);
|
|
386
365
|
return Math.max(leftHeight, rightHeight) + 1;
|
|
387
366
|
};
|
|
388
|
-
return
|
|
367
|
+
return _getMaxHeight_1(beginRoot);
|
|
389
368
|
}
|
|
390
369
|
else {
|
|
391
370
|
if (!beginRoot) {
|
|
392
371
|
return -1;
|
|
393
372
|
}
|
|
394
|
-
|
|
395
|
-
|
|
373
|
+
var stack = [{ node: beginRoot, depth: 0 }];
|
|
374
|
+
var maxHeight = 0;
|
|
396
375
|
while (stack.length > 0) {
|
|
397
|
-
|
|
376
|
+
var _a = stack.pop(), node = _a.node, depth = _a.depth;
|
|
398
377
|
if (node.left) {
|
|
399
378
|
stack.push({ node: node.left, depth: depth + 1 });
|
|
400
379
|
}
|
|
@@ -405,36 +384,28 @@ class AbstractBinaryTree {
|
|
|
405
384
|
}
|
|
406
385
|
return maxHeight;
|
|
407
386
|
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
* The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
|
|
411
|
-
* approach.
|
|
412
|
-
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type `N` or `null`. It
|
|
413
|
-
* represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided
|
|
414
|
-
* for `beginRoot`, the `this.root` property is used as the default value.
|
|
415
|
-
* @returns The function `getMinHeight` returns the minimum height of the binary tree.
|
|
416
|
-
*/
|
|
417
|
-
getMinHeight(beginRoot) {
|
|
387
|
+
};
|
|
388
|
+
AbstractBinaryTree.prototype.getMinHeight = function (beginRoot) {
|
|
418
389
|
var _a, _b, _c;
|
|
419
390
|
beginRoot = beginRoot || this.root;
|
|
420
391
|
if (!beginRoot)
|
|
421
392
|
return -1;
|
|
422
393
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
423
|
-
|
|
394
|
+
var _getMinHeight_1 = function (cur) {
|
|
424
395
|
if (!cur)
|
|
425
396
|
return 0;
|
|
426
397
|
if (!cur.left && !cur.right)
|
|
427
398
|
return 0;
|
|
428
|
-
|
|
429
|
-
|
|
399
|
+
var leftMinHeight = _getMinHeight_1(cur.left);
|
|
400
|
+
var rightMinHeight = _getMinHeight_1(cur.right);
|
|
430
401
|
return Math.min(leftMinHeight, rightMinHeight) + 1;
|
|
431
402
|
};
|
|
432
|
-
return
|
|
403
|
+
return _getMinHeight_1(beginRoot);
|
|
433
404
|
}
|
|
434
405
|
else {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
406
|
+
var stack = [];
|
|
407
|
+
var node = beginRoot, last = null;
|
|
408
|
+
var depths = new Map();
|
|
438
409
|
while (stack.length > 0 || node) {
|
|
439
410
|
if (node) {
|
|
440
411
|
stack.push(node);
|
|
@@ -445,8 +416,8 @@ class AbstractBinaryTree {
|
|
|
445
416
|
if (!node.right || last === node.right) {
|
|
446
417
|
node = stack.pop();
|
|
447
418
|
if (node) {
|
|
448
|
-
|
|
449
|
-
|
|
419
|
+
var leftMinHeight = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
|
|
420
|
+
var rightMinHeight = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
|
|
450
421
|
depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
|
|
451
422
|
last = node;
|
|
452
423
|
node = null;
|
|
@@ -458,48 +429,31 @@ class AbstractBinaryTree {
|
|
|
458
429
|
}
|
|
459
430
|
return (_c = depths.get(beginRoot)) !== null && _c !== void 0 ? _c : -1;
|
|
460
431
|
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
* @returns The method is returning a boolean value.
|
|
468
|
-
*/
|
|
469
|
-
isPerfectlyBalanced(beginRoot) {
|
|
470
|
-
return (this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot));
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
|
|
474
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
475
|
-
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
476
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
477
|
-
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
|
|
478
|
-
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
479
|
-
* return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the
|
|
480
|
-
* function will stop traversing the tree and return the first matching node. If `only
|
|
481
|
-
* @returns an array of nodes (type N).
|
|
482
|
-
*/
|
|
483
|
-
getNodes(nodeProperty, propertyName, onlyOne) {
|
|
432
|
+
};
|
|
433
|
+
AbstractBinaryTree.prototype.isPerfectlyBalanced = function (beginRoot) {
|
|
434
|
+
return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
|
|
435
|
+
};
|
|
436
|
+
AbstractBinaryTree.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
|
|
437
|
+
var _this = this;
|
|
484
438
|
if (!this.root)
|
|
485
439
|
return [];
|
|
486
440
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
487
|
-
|
|
441
|
+
var result = [];
|
|
488
442
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
489
|
-
|
|
490
|
-
if (
|
|
443
|
+
var _traverse_1 = function (cur) {
|
|
444
|
+
if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
|
|
491
445
|
return;
|
|
492
446
|
if (!cur.left && !cur.right)
|
|
493
447
|
return;
|
|
494
|
-
cur.left &&
|
|
495
|
-
cur.right &&
|
|
448
|
+
cur.left && _traverse_1(cur.left);
|
|
449
|
+
cur.right && _traverse_1(cur.right);
|
|
496
450
|
};
|
|
497
|
-
|
|
451
|
+
_traverse_1(this.root);
|
|
498
452
|
}
|
|
499
453
|
else {
|
|
500
|
-
|
|
454
|
+
var queue = [this.root];
|
|
501
455
|
while (queue.length > 0) {
|
|
502
|
-
|
|
456
|
+
var cur = queue.shift();
|
|
503
457
|
if (cur) {
|
|
504
458
|
if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
|
|
505
459
|
return result;
|
|
@@ -509,212 +463,136 @@ class AbstractBinaryTree {
|
|
|
509
463
|
}
|
|
510
464
|
}
|
|
511
465
|
return result;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
* The function checks if a binary tree node has a specific property.
|
|
515
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
|
|
516
|
-
* It represents the property of the binary tree node that you want to check.
|
|
517
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
518
|
-
* specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
|
|
519
|
-
* @returns a boolean value.
|
|
520
|
-
*/
|
|
521
|
-
has(nodeProperty, propertyName) {
|
|
466
|
+
};
|
|
467
|
+
AbstractBinaryTree.prototype.has = function (nodeProperty, propertyName) {
|
|
522
468
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
523
|
-
// TODO may support finding node by value equal
|
|
524
469
|
return this.getNodes(nodeProperty, propertyName).length > 0;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
* The function returns the first node that matches the given property name and value, or null if no matching node is
|
|
528
|
-
* found.
|
|
529
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
|
|
530
|
-
* It represents the property of the binary tree node that you want to search for.
|
|
531
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
532
|
-
* specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
|
|
533
|
-
* default value is set to `'id'`.
|
|
534
|
-
* @returns either the value of the specified property of the node, or the node itself if no property name is provided.
|
|
535
|
-
* If no matching node is found, it returns null.
|
|
536
|
-
*/
|
|
537
|
-
get(nodeProperty, propertyName) {
|
|
470
|
+
};
|
|
471
|
+
AbstractBinaryTree.prototype.get = function (nodeProperty, propertyName) {
|
|
538
472
|
var _a;
|
|
539
473
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
540
|
-
// TODO may support finding node by value equal
|
|
541
474
|
return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
* @param {N} node - The parameter `node` represents a node in a tree data structure.
|
|
547
|
-
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
|
|
548
|
-
*/
|
|
549
|
-
getPathToRoot(node) {
|
|
550
|
-
// TODO to support get path through passing id
|
|
551
|
-
const result = [];
|
|
475
|
+
};
|
|
476
|
+
AbstractBinaryTree.prototype.getPathToRoot = function (node, isReverse) {
|
|
477
|
+
if (isReverse === void 0) { isReverse = true; }
|
|
478
|
+
var result = [];
|
|
552
479
|
while (node.parent) {
|
|
553
|
-
result.
|
|
480
|
+
result.push(node);
|
|
554
481
|
node = node.parent;
|
|
555
482
|
}
|
|
556
|
-
result.
|
|
557
|
-
return result;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
* The `getLeftMost` function returns the leftmost node in a binary tree, starting from a specified node or the root if
|
|
561
|
-
* no node is specified.
|
|
562
|
-
* @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
|
|
563
|
-
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
|
|
564
|
-
* node), or `null`.
|
|
565
|
-
* @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
|
|
566
|
-
* provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the
|
|
567
|
-
* traversal from the root of the binary tree. If there are no nodes in the binary tree, it returns `null`.
|
|
568
|
-
*/
|
|
569
|
-
getLeftMost(beginRoot) {
|
|
483
|
+
result.push(node);
|
|
484
|
+
return isReverse ? result.reverse() : result;
|
|
485
|
+
};
|
|
486
|
+
AbstractBinaryTree.prototype.getLeftMost = function (beginRoot) {
|
|
570
487
|
if (typeof beginRoot === 'number')
|
|
571
488
|
beginRoot = this.get(beginRoot, 'id');
|
|
572
489
|
beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
|
|
573
490
|
if (!beginRoot)
|
|
574
491
|
return beginRoot;
|
|
575
492
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
576
|
-
|
|
493
|
+
var _traverse_2 = function (cur) {
|
|
577
494
|
if (!cur.left)
|
|
578
495
|
return cur;
|
|
579
|
-
return
|
|
496
|
+
return _traverse_2(cur.left);
|
|
580
497
|
};
|
|
581
|
-
return
|
|
498
|
+
return _traverse_2(beginRoot);
|
|
582
499
|
}
|
|
583
500
|
else {
|
|
584
|
-
|
|
585
|
-
const _traverse = (0, utils_1.trampoline)((cur) => {
|
|
501
|
+
var _traverse_3 = (0, utils_1.trampoline)(function (cur) {
|
|
586
502
|
if (!cur.left)
|
|
587
503
|
return cur;
|
|
588
|
-
return
|
|
504
|
+
return _traverse_3.cont(cur.left);
|
|
589
505
|
});
|
|
590
|
-
return
|
|
506
|
+
return _traverse_3(beginRoot);
|
|
591
507
|
}
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
* The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using
|
|
595
|
-
* tail recursion optimization.
|
|
596
|
-
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N` or `null`. It represents the
|
|
597
|
-
* starting node from which we want to find the rightmost node. If no node is provided, the `node` parameter defaults
|
|
598
|
-
* to `this.root`, which is the root node of the data structure
|
|
599
|
-
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If the `node` parameter is
|
|
600
|
-
* not provided, it defaults to the root node of the tree. If the tree is empty or the `node` parameter is `null`, the
|
|
601
|
-
* function returns `null`.
|
|
602
|
-
*/
|
|
603
|
-
getRightMost(node) {
|
|
604
|
-
// TODO support get right most by passing id in
|
|
508
|
+
};
|
|
509
|
+
AbstractBinaryTree.prototype.getRightMost = function (node) {
|
|
605
510
|
node = node !== null && node !== void 0 ? node : this.root;
|
|
606
511
|
if (!node)
|
|
607
512
|
return node;
|
|
608
513
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
609
|
-
|
|
514
|
+
var _traverse_4 = function (cur) {
|
|
610
515
|
if (!cur.right)
|
|
611
516
|
return cur;
|
|
612
|
-
return
|
|
517
|
+
return _traverse_4(cur.right);
|
|
613
518
|
};
|
|
614
|
-
return
|
|
519
|
+
return _traverse_4(node);
|
|
615
520
|
}
|
|
616
521
|
else {
|
|
617
|
-
|
|
618
|
-
const _traverse = (0, utils_1.trampoline)((cur) => {
|
|
522
|
+
var _traverse_5 = (0, utils_1.trampoline)(function (cur) {
|
|
619
523
|
if (!cur.right)
|
|
620
524
|
return cur;
|
|
621
|
-
return
|
|
525
|
+
return _traverse_5.cont(cur.right);
|
|
622
526
|
});
|
|
623
|
-
return
|
|
527
|
+
return _traverse_5(node);
|
|
624
528
|
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
|
|
628
|
-
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
|
|
629
|
-
* @returns a boolean value.
|
|
630
|
-
*/
|
|
631
|
-
isSubtreeBST(node) {
|
|
632
|
-
// TODO there is a bug
|
|
529
|
+
};
|
|
530
|
+
AbstractBinaryTree.prototype.isSubtreeBST = function (node) {
|
|
633
531
|
if (!node)
|
|
634
532
|
return true;
|
|
635
533
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
636
|
-
|
|
534
|
+
var dfs_1 = function (cur, min, max) {
|
|
637
535
|
if (!cur)
|
|
638
536
|
return true;
|
|
639
537
|
if (cur.id <= min || cur.id >= max)
|
|
640
538
|
return false;
|
|
641
|
-
return
|
|
539
|
+
return dfs_1(cur.left, min, cur.id) && dfs_1(cur.right, cur.id, max);
|
|
642
540
|
};
|
|
643
|
-
return
|
|
541
|
+
return dfs_1(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
|
|
644
542
|
}
|
|
645
543
|
else {
|
|
646
|
-
|
|
647
|
-
|
|
544
|
+
var stack = [];
|
|
545
|
+
var prev = Number.MIN_SAFE_INTEGER, curr = node;
|
|
648
546
|
while (curr || stack.length > 0) {
|
|
649
547
|
while (curr) {
|
|
650
548
|
stack.push(curr);
|
|
651
549
|
curr = curr.left;
|
|
652
550
|
}
|
|
653
551
|
curr = stack.pop();
|
|
654
|
-
if (!
|
|
552
|
+
if (!curr || prev >= curr.id)
|
|
655
553
|
return false;
|
|
656
554
|
prev = curr.id;
|
|
657
555
|
curr = curr.right;
|
|
658
556
|
}
|
|
659
557
|
return true;
|
|
660
558
|
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
* The function isBST checks if the binary search tree is valid.
|
|
664
|
-
* @returns The `isBST()` function is returning a boolean value.
|
|
665
|
-
*/
|
|
666
|
-
isBST() {
|
|
559
|
+
};
|
|
560
|
+
AbstractBinaryTree.prototype.isBST = function () {
|
|
667
561
|
return this.isSubtreeBST(this.root);
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
* @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
|
|
672
|
-
* binary tree.
|
|
673
|
-
* @returns the size of the subtree rooted at `subTreeRoot`.
|
|
674
|
-
*/
|
|
675
|
-
getSubTreeSize(subTreeRoot) {
|
|
676
|
-
// TODO support id passed in
|
|
677
|
-
let size = 0;
|
|
562
|
+
};
|
|
563
|
+
AbstractBinaryTree.prototype.getSubTreeSize = function (subTreeRoot) {
|
|
564
|
+
var size = 0;
|
|
678
565
|
if (!subTreeRoot)
|
|
679
566
|
return size;
|
|
680
567
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
681
|
-
|
|
568
|
+
var _traverse_6 = function (cur) {
|
|
682
569
|
size++;
|
|
683
|
-
cur.left &&
|
|
684
|
-
cur.right &&
|
|
570
|
+
cur.left && _traverse_6(cur.left);
|
|
571
|
+
cur.right && _traverse_6(cur.right);
|
|
685
572
|
};
|
|
686
|
-
|
|
573
|
+
_traverse_6(subTreeRoot);
|
|
687
574
|
return size;
|
|
688
575
|
}
|
|
689
576
|
else {
|
|
690
|
-
|
|
577
|
+
var stack = [subTreeRoot];
|
|
691
578
|
while (stack.length > 0) {
|
|
692
|
-
|
|
579
|
+
var cur = stack.pop();
|
|
693
580
|
size++;
|
|
694
581
|
cur.right && stack.push(cur.right);
|
|
695
582
|
cur.left && stack.push(cur.left);
|
|
696
583
|
}
|
|
697
584
|
return size;
|
|
698
585
|
}
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
* The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
|
|
702
|
-
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
|
|
703
|
-
* tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
|
|
704
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
|
|
705
|
-
* property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is
|
|
706
|
-
* not provided, it defaults to 'id'.
|
|
707
|
-
* @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
|
|
708
|
-
*/
|
|
709
|
-
subTreeSum(subTreeRoot, propertyName) {
|
|
586
|
+
};
|
|
587
|
+
AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
|
|
710
588
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
711
589
|
if (typeof subTreeRoot === 'number')
|
|
712
590
|
subTreeRoot = this.get(subTreeRoot, 'id');
|
|
713
591
|
if (!subTreeRoot)
|
|
714
592
|
return 0;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
593
|
+
var sum = 0;
|
|
594
|
+
var _sumByProperty = function (cur) {
|
|
595
|
+
var needSum;
|
|
718
596
|
switch (propertyName) {
|
|
719
597
|
case 'id':
|
|
720
598
|
needSum = cur.id;
|
|
@@ -729,41 +607,31 @@ class AbstractBinaryTree {
|
|
|
729
607
|
return needSum;
|
|
730
608
|
};
|
|
731
609
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
732
|
-
|
|
610
|
+
var _traverse_7 = function (cur) {
|
|
733
611
|
sum += _sumByProperty(cur);
|
|
734
|
-
cur.left &&
|
|
735
|
-
cur.right &&
|
|
612
|
+
cur.left && _traverse_7(cur.left);
|
|
613
|
+
cur.right && _traverse_7(cur.right);
|
|
736
614
|
};
|
|
737
|
-
|
|
615
|
+
_traverse_7(subTreeRoot);
|
|
738
616
|
}
|
|
739
617
|
else {
|
|
740
|
-
|
|
618
|
+
var stack = [subTreeRoot];
|
|
741
619
|
while (stack.length > 0) {
|
|
742
|
-
|
|
620
|
+
var cur = stack.pop();
|
|
743
621
|
sum += _sumByProperty(cur);
|
|
744
622
|
cur.right && stack.push(cur.right);
|
|
745
623
|
cur.left && stack.push(cur.left);
|
|
746
624
|
}
|
|
747
625
|
}
|
|
748
626
|
return sum;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
|
|
752
|
-
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
|
|
753
|
-
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
|
|
754
|
-
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
755
|
-
* each node in the subtree should be incremented.
|
|
756
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
757
|
-
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
|
|
758
|
-
* @returns a boolean value.
|
|
759
|
-
*/
|
|
760
|
-
subTreeAdd(subTreeRoot, delta, propertyName) {
|
|
627
|
+
};
|
|
628
|
+
AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
|
|
761
629
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
762
630
|
if (typeof subTreeRoot === 'number')
|
|
763
631
|
subTreeRoot = this.get(subTreeRoot, 'id');
|
|
764
632
|
if (!subTreeRoot)
|
|
765
633
|
return false;
|
|
766
|
-
|
|
634
|
+
var _addByProperty = function (cur) {
|
|
767
635
|
switch (propertyName) {
|
|
768
636
|
case 'id':
|
|
769
637
|
cur.id += delta;
|
|
@@ -774,39 +642,30 @@ class AbstractBinaryTree {
|
|
|
774
642
|
}
|
|
775
643
|
};
|
|
776
644
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
777
|
-
|
|
645
|
+
var _traverse_8 = function (cur) {
|
|
778
646
|
_addByProperty(cur);
|
|
779
|
-
cur.left &&
|
|
780
|
-
cur.right &&
|
|
647
|
+
cur.left && _traverse_8(cur.left);
|
|
648
|
+
cur.right && _traverse_8(cur.right);
|
|
781
649
|
};
|
|
782
|
-
|
|
650
|
+
_traverse_8(subTreeRoot);
|
|
783
651
|
}
|
|
784
652
|
else {
|
|
785
|
-
|
|
653
|
+
var stack = [subTreeRoot];
|
|
786
654
|
while (stack.length > 0) {
|
|
787
|
-
|
|
655
|
+
var cur = stack.pop();
|
|
788
656
|
_addByProperty(cur);
|
|
789
657
|
cur.right && stack.push(cur.right);
|
|
790
658
|
cur.left && stack.push(cur.left);
|
|
791
659
|
}
|
|
792
660
|
}
|
|
793
661
|
return true;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
* The BFS function performs a breadth-first search on a binary tree, accumulating properties of each node based on a
|
|
797
|
-
* specified property name.
|
|
798
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
799
|
-
* represents either a node or a property name. If a node is provided, the breadth-first search (BFS) algorithm will be
|
|
800
|
-
* performed starting from that node. If a property name is provided, the BFS algorithm will be performed starting from
|
|
801
|
-
* the
|
|
802
|
-
* @returns an instance of the `AbstractBinaryTreeNodeProperties` class with generic type `N`.
|
|
803
|
-
*/
|
|
804
|
-
BFS(nodeOrPropertyName) {
|
|
662
|
+
};
|
|
663
|
+
AbstractBinaryTree.prototype.BFS = function (nodeOrPropertyName) {
|
|
805
664
|
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
|
|
806
665
|
this._clearResults();
|
|
807
|
-
|
|
666
|
+
var queue = [this.root];
|
|
808
667
|
while (queue.length !== 0) {
|
|
809
|
-
|
|
668
|
+
var cur = queue.shift();
|
|
810
669
|
if (cur) {
|
|
811
670
|
this._accumulatedByPropertyName(cur, nodeOrPropertyName);
|
|
812
671
|
if ((cur === null || cur === void 0 ? void 0 : cur.left) !== null)
|
|
@@ -816,33 +675,23 @@ class AbstractBinaryTree {
|
|
|
816
675
|
}
|
|
817
676
|
}
|
|
818
677
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
* each node based on the specified pattern and property name.
|
|
823
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter is used to specify the traversal order of the
|
|
824
|
-
* binary tree. It can have three possible values:
|
|
825
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is a string that represents
|
|
826
|
-
* the name of a property of the nodes in the binary tree. This property will be used to accumulate values during the
|
|
827
|
-
* depth-first search traversal. If no `nodeOrPropertyName` is provided, the default value is `'id'`.
|
|
828
|
-
* @returns an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the
|
|
829
|
-
* binary tree nodes based on the specified pattern and node or property name.
|
|
830
|
-
*/
|
|
831
|
-
DFS(pattern, nodeOrPropertyName) {
|
|
678
|
+
};
|
|
679
|
+
AbstractBinaryTree.prototype.DFS = function (pattern, nodeOrPropertyName) {
|
|
680
|
+
var _this = this;
|
|
832
681
|
pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
|
|
833
682
|
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
|
|
834
683
|
this._clearResults();
|
|
835
|
-
|
|
684
|
+
var _traverse = function (node) {
|
|
836
685
|
switch (pattern) {
|
|
837
686
|
case 'in':
|
|
838
687
|
if (node.left)
|
|
839
688
|
_traverse(node.left);
|
|
840
|
-
|
|
689
|
+
_this._accumulatedByPropertyName(node, nodeOrPropertyName);
|
|
841
690
|
if (node.right)
|
|
842
691
|
_traverse(node.right);
|
|
843
692
|
break;
|
|
844
693
|
case 'pre':
|
|
845
|
-
|
|
694
|
+
_this._accumulatedByPropertyName(node, nodeOrPropertyName);
|
|
846
695
|
if (node.left)
|
|
847
696
|
_traverse(node.left);
|
|
848
697
|
if (node.right)
|
|
@@ -853,34 +702,22 @@ class AbstractBinaryTree {
|
|
|
853
702
|
_traverse(node.left);
|
|
854
703
|
if (node.right)
|
|
855
704
|
_traverse(node.right);
|
|
856
|
-
|
|
705
|
+
_this._accumulatedByPropertyName(node, nodeOrPropertyName);
|
|
857
706
|
break;
|
|
858
707
|
}
|
|
859
708
|
};
|
|
860
709
|
this.root && _traverse(this.root);
|
|
861
710
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
* The DFSIterative function performs an iterative depth-first search traversal on a binary tree, with the option to
|
|
865
|
-
* specify the traversal pattern and the property name to accumulate results by.
|
|
866
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter determines the order in which the nodes of the
|
|
867
|
-
* binary tree are visited during the depth-first search. It can have one of the following values:
|
|
868
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is used to specify the
|
|
869
|
-
* property of the nodes that you want to retrieve or perform operations on during the depth-first search traversal. By
|
|
870
|
-
* default, it is set to `'id'`, which means that the traversal will accumulate results based on the `id` property of
|
|
871
|
-
* the
|
|
872
|
-
* @returns an object of type AbstractBinaryTreeNodeProperties<N>.
|
|
873
|
-
*/
|
|
874
|
-
DFSIterative(pattern, nodeOrPropertyName) {
|
|
711
|
+
};
|
|
712
|
+
AbstractBinaryTree.prototype.DFSIterative = function (pattern, nodeOrPropertyName) {
|
|
875
713
|
pattern = pattern || 'in';
|
|
876
714
|
nodeOrPropertyName = nodeOrPropertyName || 'id';
|
|
877
715
|
this._clearResults();
|
|
878
716
|
if (!this.root)
|
|
879
717
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
880
|
-
|
|
881
|
-
const stack = [{ opt: 0, node: this.root }];
|
|
718
|
+
var stack = [{ opt: 0, node: this.root }];
|
|
882
719
|
while (stack.length > 0) {
|
|
883
|
-
|
|
720
|
+
var cur = stack.pop();
|
|
884
721
|
if (!cur || !cur.node)
|
|
885
722
|
continue;
|
|
886
723
|
if (cur.opt === 1) {
|
|
@@ -912,28 +749,16 @@ class AbstractBinaryTree {
|
|
|
912
749
|
}
|
|
913
750
|
}
|
|
914
751
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
* The `levelIterative` function performs a level-order traversal on a binary tree and returns the values of the nodes
|
|
918
|
-
* in an array, based on a specified property name.
|
|
919
|
-
* @param {N | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
|
|
920
|
-
* node for the level order traversal. It can be null if no specific node is provided, in which case the root node of
|
|
921
|
-
* the tree is used as the starting node.
|
|
922
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
|
|
923
|
-
* can be either a `BinaryTreeNode` property name or the string `'id'`. If a property name is provided, the function
|
|
924
|
-
* will accumulate results based on that property. If no property name is provided, the function will default to
|
|
925
|
-
* accumulating results
|
|
926
|
-
* @returns The function `levelIterative` returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
|
|
927
|
-
*/
|
|
928
|
-
levelIterative(node, nodeOrPropertyName) {
|
|
752
|
+
};
|
|
753
|
+
AbstractBinaryTree.prototype.levelIterative = function (node, nodeOrPropertyName) {
|
|
929
754
|
nodeOrPropertyName = nodeOrPropertyName || 'id';
|
|
930
755
|
node = node || this.root;
|
|
931
756
|
if (!node)
|
|
932
757
|
return [];
|
|
933
758
|
this._clearResults();
|
|
934
|
-
|
|
759
|
+
var queue = [node];
|
|
935
760
|
while (queue.length > 0) {
|
|
936
|
-
|
|
761
|
+
var cur = queue.shift();
|
|
937
762
|
if (cur) {
|
|
938
763
|
this._accumulatedByPropertyName(cur, nodeOrPropertyName);
|
|
939
764
|
if (cur.left) {
|
|
@@ -945,23 +770,14 @@ class AbstractBinaryTree {
|
|
|
945
770
|
}
|
|
946
771
|
}
|
|
947
772
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
* The `listLevels` function collects nodes from a binary tree by a specified property and organizes them into levels.
|
|
951
|
-
* @param {N | null} node - The `node` parameter is a BinaryTreeNode object or null. It represents the
|
|
952
|
-
* root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.
|
|
953
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
|
|
954
|
-
* specifies the property of the `BinaryTreeNode` object to collect at each level. It can be one of the following
|
|
955
|
-
* values:
|
|
956
|
-
* @returns The function `listLevels` returns a 2D array of `AbstractBinaryTreeNodeProperty<N>` objects.
|
|
957
|
-
*/
|
|
958
|
-
listLevels(node, nodeOrPropertyName) {
|
|
773
|
+
};
|
|
774
|
+
AbstractBinaryTree.prototype.listLevels = function (node, nodeOrPropertyName) {
|
|
959
775
|
nodeOrPropertyName = nodeOrPropertyName || 'id';
|
|
960
776
|
node = node || this.root;
|
|
961
777
|
if (!node)
|
|
962
778
|
return [];
|
|
963
|
-
|
|
964
|
-
|
|
779
|
+
var levelsNodes = [];
|
|
780
|
+
var collectByProperty = function (node, level) {
|
|
965
781
|
switch (nodeOrPropertyName) {
|
|
966
782
|
case 'id':
|
|
967
783
|
levelsNodes[level].push(node.id);
|
|
@@ -978,42 +794,37 @@ class AbstractBinaryTree {
|
|
|
978
794
|
}
|
|
979
795
|
};
|
|
980
796
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
981
|
-
|
|
797
|
+
var _recursive_1 = function (node, level) {
|
|
982
798
|
if (!levelsNodes[level])
|
|
983
799
|
levelsNodes[level] = [];
|
|
984
800
|
collectByProperty(node, level);
|
|
985
801
|
if (node.left)
|
|
986
|
-
|
|
802
|
+
_recursive_1(node.left, level + 1);
|
|
987
803
|
if (node.right)
|
|
988
|
-
|
|
804
|
+
_recursive_1(node.right, level + 1);
|
|
989
805
|
};
|
|
990
|
-
|
|
806
|
+
_recursive_1(node, 0);
|
|
991
807
|
}
|
|
992
808
|
else {
|
|
993
|
-
|
|
809
|
+
var stack = [[node, 0]];
|
|
994
810
|
while (stack.length > 0) {
|
|
995
|
-
|
|
996
|
-
|
|
811
|
+
var head = stack.pop();
|
|
812
|
+
var _a = __read(head, 2), node_1 = _a[0], level = _a[1];
|
|
997
813
|
if (!levelsNodes[level])
|
|
998
814
|
levelsNodes[level] = [];
|
|
999
|
-
collectByProperty(
|
|
1000
|
-
if (
|
|
1001
|
-
stack.push([
|
|
1002
|
-
if (
|
|
1003
|
-
stack.push([
|
|
815
|
+
collectByProperty(node_1, level);
|
|
816
|
+
if (node_1.right)
|
|
817
|
+
stack.push([node_1.right, level + 1]);
|
|
818
|
+
if (node_1.left)
|
|
819
|
+
stack.push([node_1.left, level + 1]);
|
|
1004
820
|
}
|
|
1005
821
|
}
|
|
1006
822
|
return levelsNodes;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
* The function returns the predecessor of a given node in a binary tree.
|
|
1010
|
-
* @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
|
|
1011
|
-
* @returns the predecessor of the given node in a binary tree.
|
|
1012
|
-
*/
|
|
1013
|
-
getPredecessor(node) {
|
|
823
|
+
};
|
|
824
|
+
AbstractBinaryTree.prototype.getPredecessor = function (node) {
|
|
1014
825
|
if (node.left) {
|
|
1015
|
-
|
|
1016
|
-
while (!
|
|
826
|
+
var predecessor = node.left;
|
|
827
|
+
while (!predecessor || (predecessor.right && predecessor.right !== node)) {
|
|
1017
828
|
if (predecessor) {
|
|
1018
829
|
predecessor = predecessor.right;
|
|
1019
830
|
}
|
|
@@ -1023,27 +834,18 @@ class AbstractBinaryTree {
|
|
|
1023
834
|
else {
|
|
1024
835
|
return node;
|
|
1025
836
|
}
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
* traversal algorithm.
|
|
1030
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The `pattern` parameter determines the traversal pattern for the binary
|
|
1031
|
-
* tree. It can have one of three values:
|
|
1032
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is used to specify the
|
|
1033
|
-
* property name of the nodes that you want to retrieve. It can be any valid property name of the nodes in the binary
|
|
1034
|
-
* tree.
|
|
1035
|
-
* @returns an array of AbstractBinaryTreeNodeProperties<N> objects.
|
|
1036
|
-
*/
|
|
1037
|
-
morris(pattern, nodeOrPropertyName) {
|
|
837
|
+
};
|
|
838
|
+
AbstractBinaryTree.prototype.morris = function (pattern, nodeOrPropertyName) {
|
|
839
|
+
var _this = this;
|
|
1038
840
|
if (this.root === null)
|
|
1039
841
|
return [];
|
|
1040
842
|
pattern = pattern || 'in';
|
|
1041
843
|
nodeOrPropertyName = nodeOrPropertyName || 'id';
|
|
1042
844
|
this._clearResults();
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
845
|
+
var cur = this.root;
|
|
846
|
+
var _reverseEdge = function (node) {
|
|
847
|
+
var pre = null;
|
|
848
|
+
var next = null;
|
|
1047
849
|
while (node) {
|
|
1048
850
|
next = node.right;
|
|
1049
851
|
node.right = pre;
|
|
@@ -1052,11 +854,11 @@ class AbstractBinaryTree {
|
|
|
1052
854
|
}
|
|
1053
855
|
return pre;
|
|
1054
856
|
};
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
857
|
+
var _printEdge = function (node) {
|
|
858
|
+
var tail = _reverseEdge(node);
|
|
859
|
+
var cur = tail;
|
|
1058
860
|
while (cur) {
|
|
1059
|
-
|
|
861
|
+
_this._accumulatedByPropertyName(cur, nodeOrPropertyName);
|
|
1060
862
|
cur = cur.right;
|
|
1061
863
|
}
|
|
1062
864
|
_reverseEdge(tail);
|
|
@@ -1065,7 +867,7 @@ class AbstractBinaryTree {
|
|
|
1065
867
|
case 'in':
|
|
1066
868
|
while (cur) {
|
|
1067
869
|
if (cur.left) {
|
|
1068
|
-
|
|
870
|
+
var predecessor = this.getPredecessor(cur);
|
|
1069
871
|
if (!predecessor.right) {
|
|
1070
872
|
predecessor.right = cur;
|
|
1071
873
|
cur = cur.left;
|
|
@@ -1082,7 +884,7 @@ class AbstractBinaryTree {
|
|
|
1082
884
|
case 'pre':
|
|
1083
885
|
while (cur) {
|
|
1084
886
|
if (cur.left) {
|
|
1085
|
-
|
|
887
|
+
var predecessor = this.getPredecessor(cur);
|
|
1086
888
|
if (!predecessor.right) {
|
|
1087
889
|
predecessor.right = cur;
|
|
1088
890
|
this._accumulatedByPropertyName(cur, nodeOrPropertyName);
|
|
@@ -1102,7 +904,7 @@ class AbstractBinaryTree {
|
|
|
1102
904
|
case 'post':
|
|
1103
905
|
while (cur) {
|
|
1104
906
|
if (cur.left) {
|
|
1105
|
-
|
|
907
|
+
var predecessor = this.getPredecessor(cur);
|
|
1106
908
|
if (predecessor.right === null) {
|
|
1107
909
|
predecessor.right = cur;
|
|
1108
910
|
cur = cur.left;
|
|
@@ -1119,21 +921,9 @@ class AbstractBinaryTree {
|
|
|
1119
921
|
break;
|
|
1120
922
|
}
|
|
1121
923
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
* The function adds a new node to a binary tree if there is an available position.
|
|
1125
|
-
* @param {N | null} newNode - The `newNode` parameter is of type `N | null`, which means it can either be a node of
|
|
1126
|
-
* type `N` or `null`. It represents the node that you want to add to the binary tree.
|
|
1127
|
-
* @param {N} parent - The parent parameter is of type N, which represents a node in a binary tree.
|
|
1128
|
-
* @returns either the left or right child node of the parent node, depending on which child is available for adding
|
|
1129
|
-
* the new node. If a new node is added, the function also updates the size of the binary tree. If neither the left nor
|
|
1130
|
-
* right child is available, the function returns undefined. If the parent node is null, the function also returns
|
|
1131
|
-
* undefined.
|
|
1132
|
-
*/
|
|
1133
|
-
_addTo(newNode, parent) {
|
|
924
|
+
};
|
|
925
|
+
AbstractBinaryTree.prototype._addTo = function (newNode, parent) {
|
|
1134
926
|
if (parent) {
|
|
1135
|
-
// When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
|
|
1136
|
-
// In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
|
|
1137
927
|
if (parent.left === undefined) {
|
|
1138
928
|
parent.left = newNode;
|
|
1139
929
|
if (newNode) {
|
|
@@ -1155,86 +945,38 @@ class AbstractBinaryTree {
|
|
|
1155
945
|
else {
|
|
1156
946
|
return;
|
|
1157
947
|
}
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
* The function sets the loop type for a protected variable.
|
|
1161
|
-
* @param {LoopType} value - The value parameter is of type LoopType.
|
|
1162
|
-
*/
|
|
1163
|
-
_setLoopType(value) {
|
|
948
|
+
};
|
|
949
|
+
AbstractBinaryTree.prototype._setLoopType = function (value) {
|
|
1164
950
|
this._loopType = value;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
* The function sets the value of the `_visitedId` property in a protected manner.
|
|
1168
|
-
* @param {BinaryTreeNodeId[]} value - value is an array of BinaryTreeNodeId values.
|
|
1169
|
-
*/
|
|
1170
|
-
_setVisitedId(value) {
|
|
951
|
+
};
|
|
952
|
+
AbstractBinaryTree.prototype._setVisitedId = function (value) {
|
|
1171
953
|
this._visitedId = value;
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
* The function sets the value of the "_visitedVal" property to the given array.
|
|
1175
|
-
* @param value - An array of type N.
|
|
1176
|
-
*/
|
|
1177
|
-
_setVisitedVal(value) {
|
|
954
|
+
};
|
|
955
|
+
AbstractBinaryTree.prototype._setVisitedVal = function (value) {
|
|
1178
956
|
this._visitedVal = value;
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
* The function sets the value of the _visitedNode property.
|
|
1182
|
-
* @param {N[]} value - N[] is an array of elements of type N.
|
|
1183
|
-
*/
|
|
1184
|
-
_setVisitedNode(value) {
|
|
957
|
+
};
|
|
958
|
+
AbstractBinaryTree.prototype._setVisitedNode = function (value) {
|
|
1185
959
|
this._visitedNode = value;
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
* The function sets the value of the `_visitedLeftSum` property to the provided array.
|
|
1189
|
-
* @param {number[]} value - An array of numbers that represents the visited left sum.
|
|
1190
|
-
*/
|
|
1191
|
-
_setVisitedLeftSum(value) {
|
|
960
|
+
};
|
|
961
|
+
AbstractBinaryTree.prototype._setVisitedLeftSum = function (value) {
|
|
1192
962
|
this._visitedLeftSum = value;
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
* The function sets the root property of an object to a given value, and if the value is not null, it also sets the
|
|
1196
|
-
* parent property of the value to undefined.
|
|
1197
|
-
* @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of type `N` or `null`.
|
|
1198
|
-
*/
|
|
1199
|
-
_setRoot(v) {
|
|
963
|
+
};
|
|
964
|
+
AbstractBinaryTree.prototype._setRoot = function (v) {
|
|
1200
965
|
if (v) {
|
|
1201
966
|
v.parent = undefined;
|
|
1202
967
|
}
|
|
1203
968
|
this._root = v;
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
* The function sets the size of a protected variable.
|
|
1207
|
-
* @param {number} v - number
|
|
1208
|
-
*/
|
|
1209
|
-
_setSize(v) {
|
|
969
|
+
};
|
|
970
|
+
AbstractBinaryTree.prototype._setSize = function (v) {
|
|
1210
971
|
this._size = v;
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
* The function `_clearResults` resets the values of several arrays used for tracking visited nodes and their
|
|
1214
|
-
* properties.
|
|
1215
|
-
*/
|
|
1216
|
-
_clearResults() {
|
|
972
|
+
};
|
|
973
|
+
AbstractBinaryTree.prototype._clearResults = function () {
|
|
1217
974
|
this._visitedId = [];
|
|
1218
975
|
this._visitedVal = [];
|
|
1219
976
|
this._visitedNode = [];
|
|
1220
977
|
this._visitedLeftSum = [];
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
* The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
|
|
1224
|
-
* a result array.
|
|
1225
|
-
* @param {N} cur - The current node being processed.
|
|
1226
|
-
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
|
|
1227
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeId` or a `N`
|
|
1228
|
-
* type. It represents the property value that we are comparing against in the switch statement.
|
|
1229
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
1230
|
-
* specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'id'`
|
|
1231
|
-
* or `'val'`. If it is not provided or is not equal to `'id'` or `'val'`, the
|
|
1232
|
-
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
1233
|
-
* stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
|
|
1234
|
-
* `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
|
|
1235
|
-
* @returns a boolean value indicating whether only one matching node should be pushed into the result array.
|
|
1236
|
-
*/
|
|
1237
|
-
_pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne) {
|
|
978
|
+
};
|
|
979
|
+
AbstractBinaryTree.prototype._pushByPropertyNameStopOrNot = function (cur, result, nodeProperty, propertyName, onlyOne) {
|
|
1238
980
|
switch (propertyName) {
|
|
1239
981
|
case 'id':
|
|
1240
982
|
if (cur.id === nodeProperty) {
|
|
@@ -1255,15 +997,8 @@ class AbstractBinaryTree {
|
|
|
1255
997
|
}
|
|
1256
998
|
break;
|
|
1257
999
|
}
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
* The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.
|
|
1261
|
-
* @param {N} node - The `node` parameter is of type `N`, which represents a node in a data structure.
|
|
1262
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
|
|
1263
|
-
* can be either a string representing a property name or a reference to a `Node` object. If it is a string, it
|
|
1264
|
-
* specifies the property name to be used for accumulating values. If it is a `Node` object, it specifies
|
|
1265
|
-
*/
|
|
1266
|
-
_accumulatedByPropertyName(node, nodeOrPropertyName) {
|
|
1000
|
+
};
|
|
1001
|
+
AbstractBinaryTree.prototype._accumulatedByPropertyName = function (node, nodeOrPropertyName) {
|
|
1267
1002
|
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
|
|
1268
1003
|
switch (nodeOrPropertyName) {
|
|
1269
1004
|
case 'id':
|
|
@@ -1279,19 +1014,8 @@ class AbstractBinaryTree {
|
|
|
1279
1014
|
this._visitedId.push(node.id);
|
|
1280
1015
|
break;
|
|
1281
1016
|
}
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
* The time complexity of Morris traversal is O(n), it's may slower than others
|
|
1285
|
-
* The space complexity Morris traversal is O(1) because no using stack
|
|
1286
|
-
*/
|
|
1287
|
-
/**
|
|
1288
|
-
* The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property
|
|
1289
|
-
* name.
|
|
1290
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
1291
|
-
* can accept either a `NodeOrPropertyName` type or be undefined.
|
|
1292
|
-
* @returns The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.
|
|
1293
|
-
*/
|
|
1294
|
-
_getResultByPropertyName(nodeOrPropertyName) {
|
|
1017
|
+
};
|
|
1018
|
+
AbstractBinaryTree.prototype._getResultByPropertyName = function (nodeOrPropertyName) {
|
|
1295
1019
|
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
|
|
1296
1020
|
switch (nodeOrPropertyName) {
|
|
1297
1021
|
case 'id':
|
|
@@ -1303,6 +1027,8 @@ class AbstractBinaryTree {
|
|
|
1303
1027
|
default:
|
|
1304
1028
|
return this._visitedId;
|
|
1305
1029
|
}
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1030
|
+
};
|
|
1031
|
+
return AbstractBinaryTree;
|
|
1032
|
+
}());
|
|
1308
1033
|
exports.AbstractBinaryTree = AbstractBinaryTree;
|
|
1034
|
+
//# sourceMappingURL=abstract-binary-tree.js.map
|