data-structure-typed 1.21.4 → 1.31.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/.github/workflows/ci.yml +30 -0
- package/.prettierignore +6 -0
- package/.prettierrc.js +16 -0
- package/CHANGELOG.md +17 -0
- package/README.md +147 -95
- 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 +2259 -0
- package/docs/classes/AVLTreeNode.html +399 -0
- package/docs/classes/AaTree.html +202 -0
- package/docs/classes/AbstractBinaryTree.html +1913 -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 +2103 -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 +1944 -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 +2101 -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 +2587 -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 +5 -0
- package/lib/data-structures/binary-tree/aa-tree.js +2 -0
- package/{dist → lib}/data-structures/binary-tree/abstract-binary-tree.d.ts +25 -20
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +1307 -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 +147 -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 +106 -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,70 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
29
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
|
+
if (!m) return o;
|
|
31
|
+
var i = m.call(o), r, ar = [], e;
|
|
32
|
+
try {
|
|
33
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
20
34
|
}
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
catch (error) { e = { error: error }; }
|
|
36
|
+
finally {
|
|
37
|
+
try {
|
|
38
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
39
|
+
}
|
|
40
|
+
finally { if (e) throw e.error; }
|
|
23
41
|
}
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
return ar;
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.TreeMultiset = exports.TreeMultisetNode = void 0;
|
|
46
|
+
var types_1 = require("../../types");
|
|
47
|
+
var avl_tree_1 = require("./avl-tree");
|
|
48
|
+
var TreeMultisetNode = (function (_super) {
|
|
49
|
+
__extends(TreeMultisetNode, _super);
|
|
50
|
+
function TreeMultisetNode(id, val, count) {
|
|
51
|
+
if (count === void 0) { count = 1; }
|
|
52
|
+
var _this = _super.call(this, id, val) || this;
|
|
53
|
+
_this._count = count;
|
|
54
|
+
return _this;
|
|
26
55
|
}
|
|
27
|
-
|
|
56
|
+
Object.defineProperty(TreeMultisetNode.prototype, "count", {
|
|
57
|
+
get: function () {
|
|
58
|
+
return this._count;
|
|
59
|
+
},
|
|
60
|
+
set: function (v) {
|
|
61
|
+
this._count = v;
|
|
62
|
+
},
|
|
63
|
+
enumerable: false,
|
|
64
|
+
configurable: true
|
|
65
|
+
});
|
|
66
|
+
return TreeMultisetNode;
|
|
67
|
+
}(avl_tree_1.AVLTreeNode));
|
|
28
68
|
exports.TreeMultisetNode = TreeMultisetNode;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* merge duplicated values.
|
|
36
|
-
* @param {TreeMultisetOptions} [options] - An optional object that contains additional configuration options for the
|
|
37
|
-
* TreeMultiset.
|
|
38
|
-
*/
|
|
39
|
-
constructor(options) {
|
|
40
|
-
super(Object.assign({}, options));
|
|
41
|
-
this._count = 0;
|
|
42
|
-
}
|
|
43
|
-
get count() {
|
|
44
|
-
return this._count;
|
|
69
|
+
var TreeMultiset = (function (_super) {
|
|
70
|
+
__extends(TreeMultiset, _super);
|
|
71
|
+
function TreeMultiset(options) {
|
|
72
|
+
var _this = _super.call(this, __assign({}, options)) || this;
|
|
73
|
+
_this._count = 0;
|
|
74
|
+
return _this;
|
|
45
75
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
55
|
-
createNode(id, val, count) {
|
|
76
|
+
Object.defineProperty(TreeMultiset.prototype, "count", {
|
|
77
|
+
get: function () {
|
|
78
|
+
return this._count;
|
|
79
|
+
},
|
|
80
|
+
enumerable: false,
|
|
81
|
+
configurable: true
|
|
82
|
+
});
|
|
83
|
+
TreeMultiset.prototype.createNode = function (id, val, count) {
|
|
56
84
|
return new TreeMultisetNode(id, val, count);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
|
|
62
|
-
* be swapped with.
|
|
63
|
-
* @returns the `destNode` after swapping its values with the `srcNode`.
|
|
64
|
-
*/
|
|
65
|
-
swapLocation(srcNode, destNode) {
|
|
66
|
-
const { id, val, count, height } = destNode;
|
|
67
|
-
const tempNode = this.createNode(id, val, count);
|
|
85
|
+
};
|
|
86
|
+
TreeMultiset.prototype.swapLocation = function (srcNode, destNode) {
|
|
87
|
+
var id = destNode.id, val = destNode.val, count = destNode.count, height = destNode.height;
|
|
88
|
+
var tempNode = this.createNode(id, val, count);
|
|
68
89
|
if (tempNode) {
|
|
69
90
|
tempNode.height = height;
|
|
70
91
|
destNode.id = srcNode.id;
|
|
@@ -77,20 +98,10 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
77
98
|
srcNode.height = tempNode.height;
|
|
78
99
|
}
|
|
79
100
|
return destNode;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
* The `add` function adds a new node to a binary search tree, maintaining the tree's properties and balancing if
|
|
83
|
-
* necessary.
|
|
84
|
-
* @param {BinaryTreeNodeId | N} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N` (which
|
|
85
|
-
* represents a `BinaryTreeNode`).
|
|
86
|
-
* @param [val] - The `val` parameter represents the value to be added to the binary tree node.
|
|
87
|
-
* @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
|
|
88
|
-
* value should be added to the binary tree. If the `count` parameter is not provided, it defaults to 1.
|
|
89
|
-
* @returns The method `add` returns either the inserted node (`N`), `null`, or `undefined`.
|
|
90
|
-
*/
|
|
91
|
-
add(idOrNode, val, count) {
|
|
101
|
+
};
|
|
102
|
+
TreeMultiset.prototype.add = function (idOrNode, val, count) {
|
|
92
103
|
count = count !== null && count !== void 0 ? count : 1;
|
|
93
|
-
|
|
104
|
+
var inserted = undefined, newNode;
|
|
94
105
|
if (idOrNode instanceof TreeMultisetNode) {
|
|
95
106
|
newNode = this.createNode(idOrNode.id, idOrNode.val, idOrNode.count);
|
|
96
107
|
}
|
|
@@ -107,8 +118,8 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
107
118
|
inserted = this.root;
|
|
108
119
|
}
|
|
109
120
|
else {
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
var cur = this.root;
|
|
122
|
+
var traversing = true;
|
|
112
123
|
while (traversing) {
|
|
113
124
|
if (cur) {
|
|
114
125
|
if (newNode) {
|
|
@@ -120,9 +131,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
120
131
|
inserted = cur;
|
|
121
132
|
}
|
|
122
133
|
else if (this._compare(cur.id, newNode.id) === types_1.CP.gt) {
|
|
123
|
-
// Traverse left of the node
|
|
124
134
|
if (cur.left === undefined) {
|
|
125
|
-
//Add to the left of the current node
|
|
126
135
|
cur.left = newNode;
|
|
127
136
|
this._setSize(this.size + 1);
|
|
128
137
|
this._setCount(this.count + newNode.count);
|
|
@@ -130,30 +139,25 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
130
139
|
inserted = cur.left;
|
|
131
140
|
}
|
|
132
141
|
else {
|
|
133
|
-
//Traverse the left of the current node
|
|
134
142
|
if (cur.left)
|
|
135
143
|
cur = cur.left;
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
else if (this._compare(cur.id, newNode.id) === types_1.CP.lt) {
|
|
139
|
-
// Traverse right of the node
|
|
140
147
|
if (cur.right === undefined) {
|
|
141
|
-
//Add to the right of the current node
|
|
142
148
|
cur.right = newNode;
|
|
143
149
|
this._setSize(this.size + 1);
|
|
144
150
|
this._setCount(this.count + newNode.count);
|
|
145
151
|
traversing = false;
|
|
146
|
-
inserted =
|
|
152
|
+
inserted = cur.right;
|
|
147
153
|
}
|
|
148
154
|
else {
|
|
149
|
-
//Traverse the left of the current node
|
|
150
155
|
if (cur.right)
|
|
151
156
|
cur = cur.right;
|
|
152
157
|
}
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
else {
|
|
156
|
-
// TODO may need to support null inserted
|
|
157
161
|
}
|
|
158
162
|
}
|
|
159
163
|
else {
|
|
@@ -162,19 +166,10 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
if (inserted)
|
|
165
|
-
this.
|
|
169
|
+
this._balancePath(inserted);
|
|
166
170
|
return inserted;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
* The function adds a new node to a binary tree if there is an available slot on the left or right side of the parent
|
|
170
|
-
* node.
|
|
171
|
-
* @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to the tree. It can
|
|
172
|
-
* be either a node object (`N`) or `null`.
|
|
173
|
-
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
|
|
174
|
-
* child.
|
|
175
|
-
* @returns The method returns either the `parent.left`, `parent.right`, or `undefined`.
|
|
176
|
-
*/
|
|
177
|
-
_addTo(newNode, parent) {
|
|
171
|
+
};
|
|
172
|
+
TreeMultiset.prototype._addTo = function (newNode, parent) {
|
|
178
173
|
if (parent) {
|
|
179
174
|
if (parent.left === undefined) {
|
|
180
175
|
parent.left = newNode;
|
|
@@ -199,72 +194,51 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
199
194
|
else {
|
|
200
195
|
return;
|
|
201
196
|
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
*/
|
|
211
|
-
addMany(idsOrNodes, data) {
|
|
212
|
-
var _a;
|
|
213
|
-
// TODO not sure addMany not be run multi times
|
|
214
|
-
const inserted = [];
|
|
215
|
-
const map = new Map();
|
|
216
|
-
for (const idOrNode of idsOrNodes)
|
|
217
|
-
map.set(idOrNode, ((_a = map.get(idOrNode)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
218
|
-
for (let i = 0; i < idsOrNodes.length; i++) {
|
|
219
|
-
const idOrNode = idsOrNodes[i];
|
|
220
|
-
if (map.has(idOrNode)) {
|
|
221
|
-
if (idOrNode instanceof TreeMultisetNode) {
|
|
222
|
-
inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
if (idOrNode === null) {
|
|
226
|
-
inserted.push(this.add(NaN, null, 0));
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
const val = data === null || data === void 0 ? void 0 : data[i], count = map.get(idOrNode);
|
|
230
|
-
inserted.push(this.add(idOrNode, val, count));
|
|
231
|
-
map.delete(idOrNode);
|
|
197
|
+
};
|
|
198
|
+
TreeMultiset.prototype.addMany = function (idsOrNodes, data) {
|
|
199
|
+
var inserted = [];
|
|
200
|
+
for (var i = 0; i < idsOrNodes.length; i++) {
|
|
201
|
+
var idOrNode = idsOrNodes[i];
|
|
202
|
+
if (idOrNode instanceof TreeMultisetNode) {
|
|
203
|
+
inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
|
|
204
|
+
continue;
|
|
232
205
|
}
|
|
206
|
+
if (idOrNode === null) {
|
|
207
|
+
inserted.push(this.add(NaN, null, 0));
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
inserted.push(this.add(idOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
|
|
233
211
|
}
|
|
234
212
|
return inserted;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
* @returns The function `perfectlyBalance()` returns a boolean value.
|
|
240
|
-
*/
|
|
241
|
-
perfectlyBalance() {
|
|
242
|
-
const sorted = this.DFS('in', 'node'), n = sorted.length;
|
|
213
|
+
};
|
|
214
|
+
TreeMultiset.prototype.perfectlyBalance = function () {
|
|
215
|
+
var _this = this;
|
|
216
|
+
var sorted = this.DFS('in', 'node'), n = sorted.length;
|
|
243
217
|
if (sorted.length < 1)
|
|
244
218
|
return false;
|
|
245
219
|
this.clear();
|
|
246
220
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
247
|
-
|
|
221
|
+
var buildBalanceBST_1 = function (l, r) {
|
|
248
222
|
if (l > r)
|
|
249
223
|
return;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
224
|
+
var m = l + Math.floor((r - l) / 2);
|
|
225
|
+
var midNode = sorted[m];
|
|
226
|
+
_this.add(midNode.id, midNode.val, midNode.count);
|
|
227
|
+
buildBalanceBST_1(l, m - 1);
|
|
228
|
+
buildBalanceBST_1(m + 1, r);
|
|
255
229
|
};
|
|
256
|
-
|
|
230
|
+
buildBalanceBST_1(0, n - 1);
|
|
257
231
|
return true;
|
|
258
232
|
}
|
|
259
233
|
else {
|
|
260
|
-
|
|
234
|
+
var stack = [[0, n - 1]];
|
|
261
235
|
while (stack.length > 0) {
|
|
262
|
-
|
|
236
|
+
var popped = stack.pop();
|
|
263
237
|
if (popped) {
|
|
264
|
-
|
|
238
|
+
var _a = __read(popped, 2), l = _a[0], r = _a[1];
|
|
265
239
|
if (l <= r) {
|
|
266
|
-
|
|
267
|
-
|
|
240
|
+
var m = l + Math.floor((r - l) / 2);
|
|
241
|
+
var midNode = sorted[m];
|
|
268
242
|
this.add(midNode.id, midNode.val, midNode.count);
|
|
269
243
|
stack.push([m + 1, r]);
|
|
270
244
|
stack.push([l, m - 1]);
|
|
@@ -273,25 +247,16 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
273
247
|
}
|
|
274
248
|
return true;
|
|
275
249
|
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
* node that needs to be balanced.
|
|
280
|
-
* @param {N | BinaryTreeNodeId | null} nodeOrId - The `nodeOrId` parameter can be one of the following:
|
|
281
|
-
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
|
|
282
|
-
* whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
|
|
283
|
-
* not be taken into account when removing it. If `ignoreCount` is set to `false
|
|
284
|
-
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
285
|
-
*/
|
|
286
|
-
remove(nodeOrId, ignoreCount) {
|
|
287
|
-
const bstDeletedResult = [];
|
|
250
|
+
};
|
|
251
|
+
TreeMultiset.prototype.remove = function (nodeOrId, ignoreCount) {
|
|
252
|
+
var bstDeletedResult = [];
|
|
288
253
|
if (!this.root)
|
|
289
254
|
return bstDeletedResult;
|
|
290
|
-
|
|
255
|
+
var curr = this.get(nodeOrId);
|
|
291
256
|
if (!curr)
|
|
292
257
|
return bstDeletedResult;
|
|
293
|
-
|
|
294
|
-
|
|
258
|
+
var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
|
|
259
|
+
var needBalanced = null, orgCurrent = curr;
|
|
295
260
|
if (curr.count > 1 && !ignoreCount) {
|
|
296
261
|
curr.count--;
|
|
297
262
|
this._setCount(this.count - 1);
|
|
@@ -303,7 +268,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
303
268
|
this._setRoot(curr.right);
|
|
304
269
|
}
|
|
305
270
|
else {
|
|
306
|
-
|
|
271
|
+
var fp = curr.familyPosition;
|
|
307
272
|
if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
|
|
308
273
|
parent.left = curr.right;
|
|
309
274
|
}
|
|
@@ -314,9 +279,9 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
314
279
|
}
|
|
315
280
|
}
|
|
316
281
|
else {
|
|
317
|
-
|
|
282
|
+
var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
|
|
318
283
|
if (leftSubTreeRightMost) {
|
|
319
|
-
|
|
284
|
+
var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
320
285
|
orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
|
|
321
286
|
if (parentOfLeftSubTreeMax) {
|
|
322
287
|
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
|
|
@@ -330,40 +295,32 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
330
295
|
}
|
|
331
296
|
}
|
|
332
297
|
this._setSize(this.size - 1);
|
|
333
|
-
// TODO How to handle when the count of target node is lesser than current node's count
|
|
334
298
|
this._setCount(this.count - orgCurrent.count);
|
|
335
299
|
}
|
|
336
|
-
bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
300
|
+
bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
|
|
337
301
|
if (needBalanced) {
|
|
338
|
-
this.
|
|
302
|
+
this._balancePath(needBalanced);
|
|
339
303
|
}
|
|
340
304
|
return bstDeletedResult;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
* recursive or iterative traversal.
|
|
345
|
-
* @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
|
|
346
|
-
* binary tree.
|
|
347
|
-
* @returns The function `getSubTreeCount` returns an array `[number, number]`.
|
|
348
|
-
*/
|
|
349
|
-
getSubTreeCount(subTreeRoot) {
|
|
350
|
-
const res = [0, 0];
|
|
305
|
+
};
|
|
306
|
+
TreeMultiset.prototype.getSubTreeCount = function (subTreeRoot) {
|
|
307
|
+
var res = [0, 0];
|
|
351
308
|
if (!subTreeRoot)
|
|
352
309
|
return res;
|
|
353
310
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
354
|
-
|
|
311
|
+
var _traverse_1 = function (cur) {
|
|
355
312
|
res[0]++;
|
|
356
313
|
res[1] += cur.count;
|
|
357
|
-
cur.left &&
|
|
358
|
-
cur.right &&
|
|
314
|
+
cur.left && _traverse_1(cur.left);
|
|
315
|
+
cur.right && _traverse_1(cur.right);
|
|
359
316
|
};
|
|
360
|
-
|
|
317
|
+
_traverse_1(subTreeRoot);
|
|
361
318
|
return res;
|
|
362
319
|
}
|
|
363
320
|
else {
|
|
364
|
-
|
|
321
|
+
var stack = [subTreeRoot];
|
|
365
322
|
while (stack.length > 0) {
|
|
366
|
-
|
|
323
|
+
var cur = stack.pop();
|
|
367
324
|
res[0]++;
|
|
368
325
|
res[1] += cur.count;
|
|
369
326
|
cur.right && stack.push(cur.right);
|
|
@@ -371,94 +328,67 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
371
328
|
}
|
|
372
329
|
return res;
|
|
373
330
|
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
* The function `subTreeSumCount` calculates the sum of the `count` property of each node in a subtree, either
|
|
377
|
-
* recursively or iteratively.
|
|
378
|
-
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
|
|
379
|
-
* in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree) or
|
|
380
|
-
* `null` if the subtree is empty.
|
|
381
|
-
* @returns the sum of the count values of all nodes in the subtree rooted at `subTreeRoot`.
|
|
382
|
-
*/
|
|
383
|
-
subTreeSumCount(subTreeRoot) {
|
|
331
|
+
};
|
|
332
|
+
TreeMultiset.prototype.subTreeSumCount = function (subTreeRoot) {
|
|
384
333
|
if (typeof subTreeRoot === 'number')
|
|
385
334
|
subTreeRoot = this.get(subTreeRoot, 'id');
|
|
386
335
|
if (!subTreeRoot)
|
|
387
336
|
return 0;
|
|
388
|
-
|
|
337
|
+
var sum = 0;
|
|
389
338
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
390
|
-
|
|
339
|
+
var _traverse_2 = function (cur) {
|
|
391
340
|
sum += cur.count;
|
|
392
|
-
cur.left &&
|
|
393
|
-
cur.right &&
|
|
341
|
+
cur.left && _traverse_2(cur.left);
|
|
342
|
+
cur.right && _traverse_2(cur.right);
|
|
394
343
|
};
|
|
395
|
-
|
|
344
|
+
_traverse_2(subTreeRoot);
|
|
396
345
|
}
|
|
397
346
|
else {
|
|
398
|
-
|
|
347
|
+
var stack = [subTreeRoot];
|
|
399
348
|
while (stack.length > 0) {
|
|
400
|
-
|
|
349
|
+
var cur = stack.pop();
|
|
401
350
|
sum += cur.count;
|
|
402
351
|
cur.right && stack.push(cur.right);
|
|
403
352
|
cur.left && stack.push(cur.left);
|
|
404
353
|
}
|
|
405
354
|
}
|
|
406
355
|
return sum;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
* the `count` property of each node.
|
|
411
|
-
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
|
|
412
|
-
* in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree), a
|
|
413
|
-
* `BinaryTreeNode` object, or `null` if the subtree is empty.
|
|
414
|
-
* @param {number} delta - The delta parameter is a number that represents the amount by which the count of each node
|
|
415
|
-
* in the subtree should be increased or decreased.
|
|
416
|
-
* @returns a boolean value.
|
|
417
|
-
*/
|
|
418
|
-
subTreeAddCount(subTreeRoot, delta) {
|
|
356
|
+
};
|
|
357
|
+
TreeMultiset.prototype.subTreeAddCount = function (subTreeRoot, delta) {
|
|
358
|
+
var _this = this;
|
|
419
359
|
if (typeof subTreeRoot === 'number')
|
|
420
360
|
subTreeRoot = this.get(subTreeRoot, 'id');
|
|
421
361
|
if (!subTreeRoot)
|
|
422
362
|
return false;
|
|
423
|
-
|
|
363
|
+
var _addByProperty = function (cur) {
|
|
424
364
|
cur.count += delta;
|
|
425
|
-
|
|
365
|
+
_this._setCount(_this.count + delta);
|
|
426
366
|
};
|
|
427
367
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
428
|
-
|
|
368
|
+
var _traverse_3 = function (cur) {
|
|
429
369
|
_addByProperty(cur);
|
|
430
|
-
cur.left &&
|
|
431
|
-
cur.right &&
|
|
370
|
+
cur.left && _traverse_3(cur.left);
|
|
371
|
+
cur.right && _traverse_3(cur.right);
|
|
432
372
|
};
|
|
433
|
-
|
|
373
|
+
_traverse_3(subTreeRoot);
|
|
434
374
|
}
|
|
435
375
|
else {
|
|
436
|
-
|
|
376
|
+
var stack = [subTreeRoot];
|
|
437
377
|
while (stack.length > 0) {
|
|
438
|
-
|
|
378
|
+
var cur = stack.pop();
|
|
439
379
|
_addByProperty(cur);
|
|
440
380
|
cur.right && stack.push(cur.right);
|
|
441
381
|
cur.left && stack.push(cur.left);
|
|
442
382
|
}
|
|
443
383
|
}
|
|
444
384
|
return true;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
* The function `getNodesByCount` returns an array of nodes that have a specific count property, either recursively or
|
|
448
|
-
* using a queue.
|
|
449
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
450
|
-
* `N`. It represents the property of the nodes that you want to search for.
|
|
451
|
-
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
452
|
-
* return only one node that matches the `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne` is set
|
|
453
|
-
* to `true`, the function will return only one node. If `onlyOne`
|
|
454
|
-
* @returns an array of nodes that match the given nodeProperty.
|
|
455
|
-
*/
|
|
456
|
-
getNodesByCount(nodeProperty, onlyOne) {
|
|
385
|
+
};
|
|
386
|
+
TreeMultiset.prototype.getNodesByCount = function (nodeProperty, onlyOne) {
|
|
457
387
|
if (!this.root)
|
|
458
388
|
return [];
|
|
459
|
-
|
|
389
|
+
var result = [];
|
|
460
390
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
461
|
-
|
|
391
|
+
var _traverse_4 = function (cur) {
|
|
462
392
|
if (cur.count === nodeProperty) {
|
|
463
393
|
result.push(cur);
|
|
464
394
|
if (onlyOne)
|
|
@@ -466,15 +396,15 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
466
396
|
}
|
|
467
397
|
if (!cur.left && !cur.right)
|
|
468
398
|
return;
|
|
469
|
-
cur.left &&
|
|
470
|
-
cur.right &&
|
|
399
|
+
cur.left && _traverse_4(cur.left);
|
|
400
|
+
cur.right && _traverse_4(cur.right);
|
|
471
401
|
};
|
|
472
|
-
|
|
402
|
+
_traverse_4(this.root);
|
|
473
403
|
}
|
|
474
404
|
else {
|
|
475
|
-
|
|
405
|
+
var queue = [this.root];
|
|
476
406
|
while (queue.length > 0) {
|
|
477
|
-
|
|
407
|
+
var cur = queue.shift();
|
|
478
408
|
if (cur) {
|
|
479
409
|
if (cur.count === nodeProperty) {
|
|
480
410
|
result.push(cur);
|
|
@@ -487,123 +417,78 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
487
417
|
}
|
|
488
418
|
}
|
|
489
419
|
return result;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* The function "listLevelsCount" takes a node and returns an array of arrays, where each inner array contains the
|
|
502
|
-
* count property of each node at that level.
|
|
503
|
-
* @param {N | null} node - The parameter `node` is of type `N | null`. This means that it can either be an instance of
|
|
504
|
-
* the class `N` or `null`.
|
|
505
|
-
* @returns a 2D array of numbers. Each inner array represents a level in the binary tree, and each number in the inner
|
|
506
|
-
* array represents the count property of a node in that level.
|
|
507
|
-
*/
|
|
508
|
-
listLevelsCount(node) {
|
|
509
|
-
const levels = super.listLevels(node, 'node');
|
|
510
|
-
return levels.map(level => level.map(node => node.count));
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* The `morrisCount` function returns an array of counts for each node in a binary tree, based on a specified traversal
|
|
514
|
-
* pattern.
|
|
515
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The `pattern` parameter is an optional parameter that specifies the
|
|
516
|
-
* traversal pattern for the Morris traversal algorithm. It can have one of three values: 'in', 'pre', or 'post'.
|
|
517
|
-
* @returns The function `morrisCount` returns an array of numbers.
|
|
518
|
-
*/
|
|
519
|
-
morrisCount(pattern) {
|
|
420
|
+
};
|
|
421
|
+
TreeMultiset.prototype.BFSCount = function () {
|
|
422
|
+
var nodes = _super.prototype.BFS.call(this, 'node');
|
|
423
|
+
return nodes.map(function (node) { return node.count; });
|
|
424
|
+
};
|
|
425
|
+
TreeMultiset.prototype.listLevelsCount = function (node) {
|
|
426
|
+
var levels = _super.prototype.listLevels.call(this, node, 'node');
|
|
427
|
+
return levels.map(function (level) { return level.map(function (node) { return node.count; }); });
|
|
428
|
+
};
|
|
429
|
+
TreeMultiset.prototype.morrisCount = function (pattern) {
|
|
520
430
|
pattern = pattern || 'in';
|
|
521
|
-
|
|
522
|
-
return nodes.map(node
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
* The function DFSIterativeCount performs a depth-first search iteratively and returns an array of count values for
|
|
526
|
-
* each node.
|
|
527
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter is a string that specifies the traversal order
|
|
528
|
-
* for the Depth-First Search (DFS) algorithm. It can have one of three values: 'in', 'pre', or 'post'.
|
|
529
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
|
|
530
|
-
* specifies whether to return the nodes or the property names during the depth-first search traversal. If it is set to
|
|
531
|
-
* `'node'`, the function will return the nodes. If it is set to `'property'`, the function will return the property
|
|
532
|
-
* @returns The DFSIterativeCount method returns an array of numbers.
|
|
533
|
-
*/
|
|
534
|
-
DFSIterativeCount(pattern, nodeOrPropertyName) {
|
|
431
|
+
var nodes = _super.prototype.morris.call(this, pattern, 'node');
|
|
432
|
+
return nodes.map(function (node) { return node.count; });
|
|
433
|
+
};
|
|
434
|
+
TreeMultiset.prototype.DFSIterativeCount = function (pattern) {
|
|
535
435
|
pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
|
|
536
|
-
|
|
537
|
-
return nodes.map(node
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
* The DFSCount function returns an array of counts for each node in a depth-first search traversal.
|
|
541
|
-
* @param {DFSOrderPattern} [pattern] - The `pattern` parameter is an optional parameter that specifies the order in
|
|
542
|
-
* which the Depth-First Search (DFS) algorithm should traverse the nodes. It can have one of the following values:
|
|
543
|
-
* @param [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is used to specify whether you want to retrieve the
|
|
544
|
-
* nodes themselves or a specific property of the nodes. If you pass `'count'` as the value for `nodeOrPropertyName`,
|
|
545
|
-
* the function will return an array of the `count` property of each node.
|
|
546
|
-
* @returns The DFSCount method returns an array of numbers representing the count property of each node in the DFS
|
|
547
|
-
* traversal.
|
|
548
|
-
*/
|
|
549
|
-
DFSCount(pattern, nodeOrPropertyName) {
|
|
436
|
+
var nodes = _super.prototype.DFSIterative.call(this, pattern, 'node');
|
|
437
|
+
return nodes.map(function (node) { return node.count; });
|
|
438
|
+
};
|
|
439
|
+
TreeMultiset.prototype.DFSCount = function (pattern) {
|
|
550
440
|
pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
|
|
551
|
-
|
|
552
|
-
return nodes.map(node
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
* value than a given node.
|
|
557
|
-
* @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
|
|
558
|
-
* @returns the sum of the counts of nodes in the binary tree that have a lesser value than the given beginNode.
|
|
559
|
-
*/
|
|
560
|
-
lesserSumCount(beginNode) {
|
|
441
|
+
var nodes = _super.prototype.DFS.call(this, pattern, 'node');
|
|
442
|
+
return nodes.map(function (node) { return node.count; });
|
|
443
|
+
};
|
|
444
|
+
TreeMultiset.prototype.lesserSumCount = function (beginNode) {
|
|
445
|
+
var _this = this;
|
|
561
446
|
if (typeof beginNode === 'number')
|
|
562
447
|
beginNode = this.get(beginNode, 'id');
|
|
563
448
|
if (!beginNode)
|
|
564
449
|
return 0;
|
|
565
450
|
if (!this.root)
|
|
566
451
|
return 0;
|
|
567
|
-
|
|
568
|
-
|
|
452
|
+
var id = beginNode.id;
|
|
453
|
+
var sum = 0;
|
|
569
454
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
570
|
-
|
|
571
|
-
|
|
455
|
+
var _traverse_5 = function (cur) {
|
|
456
|
+
var compared = _this._compare(cur.id, id);
|
|
572
457
|
if (compared === types_1.CP.eq) {
|
|
573
458
|
if (cur.right)
|
|
574
|
-
sum +=
|
|
459
|
+
sum += _this.subTreeSumCount(cur.right);
|
|
575
460
|
return;
|
|
576
461
|
}
|
|
577
462
|
else if (compared === types_1.CP.lt) {
|
|
578
463
|
if (cur.left)
|
|
579
|
-
sum +=
|
|
464
|
+
sum += _this.subTreeSumCount(cur.left);
|
|
580
465
|
sum += cur.count;
|
|
581
466
|
if (cur.right)
|
|
582
|
-
|
|
467
|
+
_traverse_5(cur.right);
|
|
583
468
|
else
|
|
584
469
|
return;
|
|
585
470
|
}
|
|
586
471
|
else {
|
|
587
472
|
if (cur.left)
|
|
588
|
-
|
|
473
|
+
_traverse_5(cur.left);
|
|
589
474
|
else
|
|
590
475
|
return;
|
|
591
476
|
}
|
|
592
477
|
};
|
|
593
|
-
|
|
478
|
+
_traverse_5(this.root);
|
|
594
479
|
}
|
|
595
480
|
else {
|
|
596
|
-
|
|
481
|
+
var queue = [this.root];
|
|
597
482
|
while (queue.length > 0) {
|
|
598
|
-
|
|
483
|
+
var cur = queue.shift();
|
|
599
484
|
if (cur) {
|
|
600
|
-
|
|
485
|
+
var compared = this._compare(cur.id, id);
|
|
601
486
|
if (compared === types_1.CP.eq) {
|
|
602
487
|
if (cur.right)
|
|
603
488
|
sum += this.subTreeSumCount(cur.right);
|
|
604
489
|
return sum;
|
|
605
490
|
}
|
|
606
|
-
else if (compared === types_1.CP.lt) {
|
|
491
|
+
else if (compared === types_1.CP.lt) {
|
|
607
492
|
if (cur.left)
|
|
608
493
|
sum += this.subTreeSumCount(cur.left);
|
|
609
494
|
sum += cur.count;
|
|
@@ -622,44 +507,37 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
622
507
|
}
|
|
623
508
|
}
|
|
624
509
|
return sum;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
* greater than a given ID by a specified delta value.
|
|
629
|
-
* @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be one of the following:
|
|
630
|
-
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the `count` property
|
|
631
|
-
* of each node should be increased.
|
|
632
|
-
* @returns a boolean value.
|
|
633
|
-
*/
|
|
634
|
-
allGreaterNodesAddCount(node, delta) {
|
|
510
|
+
};
|
|
511
|
+
TreeMultiset.prototype.allGreaterNodesAddCount = function (node, delta) {
|
|
512
|
+
var _this = this;
|
|
635
513
|
if (typeof node === 'number')
|
|
636
514
|
node = this.get(node, 'id');
|
|
637
515
|
if (!node)
|
|
638
516
|
return false;
|
|
639
|
-
|
|
517
|
+
var id = node.id;
|
|
640
518
|
if (!this.root)
|
|
641
519
|
return false;
|
|
642
520
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
643
|
-
|
|
644
|
-
|
|
521
|
+
var _traverse_6 = function (cur) {
|
|
522
|
+
var compared = _this._compare(cur.id, id);
|
|
645
523
|
if (compared === types_1.CP.gt)
|
|
646
524
|
cur.count += delta;
|
|
647
525
|
if (!cur.left && !cur.right)
|
|
648
526
|
return;
|
|
649
|
-
if (cur.left &&
|
|
650
|
-
|
|
651
|
-
if (cur.right &&
|
|
652
|
-
|
|
527
|
+
if (cur.left && _this._compare(cur.left.id, id) === types_1.CP.gt)
|
|
528
|
+
_traverse_6(cur.left);
|
|
529
|
+
if (cur.right && _this._compare(cur.right.id, id) === types_1.CP.gt)
|
|
530
|
+
_traverse_6(cur.right);
|
|
653
531
|
};
|
|
654
|
-
|
|
532
|
+
_traverse_6(this.root);
|
|
655
533
|
return true;
|
|
656
534
|
}
|
|
657
535
|
else {
|
|
658
|
-
|
|
536
|
+
var queue = [this.root];
|
|
659
537
|
while (queue.length > 0) {
|
|
660
|
-
|
|
538
|
+
var cur = queue.shift();
|
|
661
539
|
if (cur) {
|
|
662
|
-
|
|
540
|
+
var compared = this._compare(cur.id, id);
|
|
663
541
|
if (compared === types_1.CP.gt)
|
|
664
542
|
cur.count += delta;
|
|
665
543
|
if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
|
|
@@ -670,20 +548,15 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
670
548
|
}
|
|
671
549
|
return true;
|
|
672
550
|
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
*/
|
|
677
|
-
clear() {
|
|
678
|
-
super.clear();
|
|
551
|
+
};
|
|
552
|
+
TreeMultiset.prototype.clear = function () {
|
|
553
|
+
_super.prototype.clear.call(this);
|
|
679
554
|
this._setCount(0);
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
* The function "_setCount" is used to set the value of the "_count" property.
|
|
683
|
-
* @param {number} v - number
|
|
684
|
-
*/
|
|
685
|
-
_setCount(v) {
|
|
555
|
+
};
|
|
556
|
+
TreeMultiset.prototype._setCount = function (v) {
|
|
686
557
|
this._count = v;
|
|
687
|
-
}
|
|
688
|
-
|
|
558
|
+
};
|
|
559
|
+
return TreeMultiset;
|
|
560
|
+
}(avl_tree_1.AVLTree));
|
|
689
561
|
exports.TreeMultiset = TreeMultiset;
|
|
562
|
+
//# sourceMappingURL=tree-multiset.js.map
|