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
|
@@ -3,9 +3,25 @@
|
|
|
3
3
|
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import { SinglyLinkedList } from '../linked-list';
|
|
7
|
+
export declare class LinkedListQueue<T = any> extends SinglyLinkedList<T> {
|
|
8
|
+
/**
|
|
9
|
+
* The enqueue function adds a value to the end of an array.
|
|
10
|
+
* @param {T} value - The value parameter represents the value that you want to add to the queue.
|
|
11
|
+
*/
|
|
12
|
+
enqueue(value: T): void;
|
|
13
|
+
/**
|
|
14
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
15
|
+
* @returns The method is returning the element at the front of the queue, or null if the queue is empty.
|
|
16
|
+
*/
|
|
17
|
+
dequeue(): T | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
20
|
+
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
21
|
+
*/
|
|
22
|
+
peek(): T | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare class Queue<T = any> {
|
|
9
25
|
/**
|
|
10
26
|
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
11
27
|
* @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
|
|
@@ -13,6 +29,17 @@ export declare class Queue<T = number> {
|
|
|
13
29
|
* initialized as an empty array.
|
|
14
30
|
*/
|
|
15
31
|
constructor(elements?: T[]);
|
|
32
|
+
private _nodes;
|
|
33
|
+
get nodes(): T[];
|
|
34
|
+
set nodes(value: T[]);
|
|
35
|
+
private _offset;
|
|
36
|
+
get offset(): number;
|
|
37
|
+
set offset(value: number);
|
|
38
|
+
/**
|
|
39
|
+
* The size function returns the number of elements in an array.
|
|
40
|
+
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
41
|
+
*/
|
|
42
|
+
get size(): number;
|
|
16
43
|
/**
|
|
17
44
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
18
45
|
* @public
|
|
@@ -23,34 +50,40 @@ export declare class Queue<T = number> {
|
|
|
23
50
|
*/
|
|
24
51
|
static fromArray<T>(elements: T[]): Queue<T>;
|
|
25
52
|
/**
|
|
26
|
-
* The
|
|
53
|
+
* The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
|
|
27
54
|
* @param {T} element - The `element` parameter represents the element that you want to add to the queue.
|
|
28
55
|
* @returns The `add` method is returning a `Queue<T>` object.
|
|
29
56
|
*/
|
|
30
|
-
|
|
57
|
+
push(element: T): Queue<T>;
|
|
31
58
|
/**
|
|
32
|
-
* The `
|
|
59
|
+
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
33
60
|
* necessary to optimize performance.
|
|
34
|
-
* @returns The function `
|
|
61
|
+
* @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
|
|
35
62
|
*/
|
|
36
|
-
|
|
63
|
+
shift(): T | undefined;
|
|
37
64
|
/**
|
|
38
65
|
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
|
|
39
66
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
40
67
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
|
|
41
68
|
*/
|
|
42
|
-
peek(): T |
|
|
69
|
+
peek(): T | undefined;
|
|
43
70
|
/**
|
|
44
71
|
* The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
|
|
45
72
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
46
73
|
* array is empty, it returns `null`.
|
|
47
74
|
*/
|
|
48
|
-
peekLast(): T |
|
|
75
|
+
peekLast(): T | undefined;
|
|
49
76
|
/**
|
|
50
|
-
* The
|
|
51
|
-
* @
|
|
77
|
+
* The enqueue function adds a value to the end of a queue.
|
|
78
|
+
* @param {T} value - The value parameter represents the value that you want to add to the queue.
|
|
79
|
+
*/
|
|
80
|
+
enqueue(value: T): void;
|
|
81
|
+
/**
|
|
82
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
83
|
+
* @returns The method is returning a value of type T or null.
|
|
52
84
|
*/
|
|
53
|
-
|
|
85
|
+
dequeue(): T | undefined;
|
|
86
|
+
getAt(index: number): T | undefined;
|
|
54
87
|
/**
|
|
55
88
|
* The function checks if a data structure is empty by comparing its size to zero.
|
|
56
89
|
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
@@ -70,4 +103,5 @@ export declare class Queue<T = number> {
|
|
|
70
103
|
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
71
104
|
*/
|
|
72
105
|
clone(): Queue<T>;
|
|
106
|
+
[Symbol.iterator](): Generator<T, void, unknown>;
|
|
73
107
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
import { SinglyLinkedList } from '../linked-list';
|
|
7
|
+
export class LinkedListQueue extends SinglyLinkedList {
|
|
8
|
+
/**
|
|
9
|
+
* The enqueue function adds a value to the end of an array.
|
|
10
|
+
* @param {T} value - The value parameter represents the value that you want to add to the queue.
|
|
11
|
+
*/
|
|
12
|
+
enqueue(value) {
|
|
13
|
+
this.push(value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
17
|
+
* @returns The method is returning the element at the front of the queue, or null if the queue is empty.
|
|
18
|
+
*/
|
|
19
|
+
dequeue() {
|
|
20
|
+
return this.shift();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
24
|
+
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
25
|
+
*/
|
|
26
|
+
peek() {
|
|
27
|
+
var _a;
|
|
28
|
+
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.val;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class Queue {
|
|
32
|
+
/**
|
|
33
|
+
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
34
|
+
* @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
|
|
35
|
+
* will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
|
|
36
|
+
* initialized as an empty array.
|
|
37
|
+
*/
|
|
38
|
+
constructor(elements) {
|
|
39
|
+
this._nodes = elements || [];
|
|
40
|
+
this._offset = 0;
|
|
41
|
+
}
|
|
42
|
+
get nodes() {
|
|
43
|
+
return this._nodes;
|
|
44
|
+
}
|
|
45
|
+
set nodes(value) {
|
|
46
|
+
this._nodes = value;
|
|
47
|
+
}
|
|
48
|
+
get offset() {
|
|
49
|
+
return this._offset;
|
|
50
|
+
}
|
|
51
|
+
set offset(value) {
|
|
52
|
+
this._offset = value;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The size function returns the number of elements in an array.
|
|
56
|
+
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
57
|
+
*/
|
|
58
|
+
get size() {
|
|
59
|
+
return this.nodes.length - this.offset;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
63
|
+
* @public
|
|
64
|
+
* @static
|
|
65
|
+
* @param {T[]} elements - The "elements" parameter is an array of elements of type T.
|
|
66
|
+
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
67
|
+
* array.
|
|
68
|
+
*/
|
|
69
|
+
static fromArray(elements) {
|
|
70
|
+
return new Queue(elements);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
|
|
74
|
+
* @param {T} element - The `element` parameter represents the element that you want to add to the queue.
|
|
75
|
+
* @returns The `add` method is returning a `Queue<T>` object.
|
|
76
|
+
*/
|
|
77
|
+
push(element) {
|
|
78
|
+
this.nodes.push(element);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
83
|
+
* necessary to optimize performance.
|
|
84
|
+
* @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
|
|
85
|
+
*/
|
|
86
|
+
shift() {
|
|
87
|
+
if (this.size === 0)
|
|
88
|
+
return undefined;
|
|
89
|
+
const first = this.peek();
|
|
90
|
+
this.offset += 1;
|
|
91
|
+
if (this.offset * 2 < this.nodes.length)
|
|
92
|
+
return first;
|
|
93
|
+
// only remove dequeued elements when reaching half size
|
|
94
|
+
// to decrease latency of shifting elements.
|
|
95
|
+
this.nodes = this.nodes.slice(this.offset);
|
|
96
|
+
this.offset = 0;
|
|
97
|
+
return first;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
|
|
101
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
102
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
|
|
103
|
+
*/
|
|
104
|
+
peek() {
|
|
105
|
+
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
|
|
109
|
+
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
110
|
+
* array is empty, it returns `null`.
|
|
111
|
+
*/
|
|
112
|
+
peekLast() {
|
|
113
|
+
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The enqueue function adds a value to the end of a queue.
|
|
117
|
+
* @param {T} value - The value parameter represents the value that you want to add to the queue.
|
|
118
|
+
*/
|
|
119
|
+
enqueue(value) {
|
|
120
|
+
this.push(value);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
124
|
+
* @returns The method is returning a value of type T or null.
|
|
125
|
+
*/
|
|
126
|
+
dequeue() {
|
|
127
|
+
return this.shift();
|
|
128
|
+
}
|
|
129
|
+
getAt(index) {
|
|
130
|
+
return this.nodes[index];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The function checks if a data structure is empty by comparing its size to zero.
|
|
134
|
+
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
135
|
+
*/
|
|
136
|
+
isEmpty() {
|
|
137
|
+
return this.size === 0;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
|
|
141
|
+
* @returns An array of type T is being returned.
|
|
142
|
+
*/
|
|
143
|
+
toArray() {
|
|
144
|
+
return this.nodes.slice(this.offset);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The clear function resets the nodes array and offset to their initial values.
|
|
148
|
+
*/
|
|
149
|
+
clear() {
|
|
150
|
+
this.nodes = [];
|
|
151
|
+
this.offset = 0;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
155
|
+
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
156
|
+
*/
|
|
157
|
+
clone() {
|
|
158
|
+
return new Queue(this.nodes.slice(this.offset));
|
|
159
|
+
}
|
|
160
|
+
*[Symbol.iterator]() {
|
|
161
|
+
for (const item of this.nodes) {
|
|
162
|
+
yield item;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stack';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export class Stack {
|
|
7
|
+
/**
|
|
8
|
+
* The constructor initializes an array of elements, which can be provided as an optional parameter.
|
|
9
|
+
* @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
|
|
10
|
+
* of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
11
|
+
* is provided and is an array, it is assigned to the `_elements
|
|
12
|
+
*/
|
|
13
|
+
constructor(elements) {
|
|
14
|
+
this._elements = Array.isArray(elements) ? elements : [];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
18
|
+
* @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
|
|
19
|
+
* @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
|
|
20
|
+
* array.
|
|
21
|
+
*/
|
|
22
|
+
static fromArray(elements) {
|
|
23
|
+
return new Stack(elements);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The function checks if an array is empty and returns a boolean value.
|
|
27
|
+
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
28
|
+
*/
|
|
29
|
+
isEmpty() {
|
|
30
|
+
return this._elements.length === 0;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The size() function returns the number of elements in an array.
|
|
34
|
+
* @returns The size of the elements array.
|
|
35
|
+
*/
|
|
36
|
+
size() {
|
|
37
|
+
return this._elements.length;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The `peek` function returns the last element of an array, or null if the array is empty.
|
|
41
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
|
|
42
|
+
*/
|
|
43
|
+
peek() {
|
|
44
|
+
if (this.isEmpty())
|
|
45
|
+
return null;
|
|
46
|
+
return this._elements[this._elements.length - 1];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The push function adds an element to the stack and returns the updated stack.
|
|
50
|
+
* @param {T} element - The parameter "element" is of type T, which means it can be any data type.
|
|
51
|
+
* @returns The `push` method is returning the updated `Stack<T>` object.
|
|
52
|
+
*/
|
|
53
|
+
push(element) {
|
|
54
|
+
this._elements.push(element);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
|
|
59
|
+
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
60
|
+
* array is empty, it returns `null`.
|
|
61
|
+
*/
|
|
62
|
+
pop() {
|
|
63
|
+
if (this.isEmpty())
|
|
64
|
+
return null;
|
|
65
|
+
return this._elements.pop() || null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The toArray function returns a copy of the elements in an array.
|
|
69
|
+
* @returns An array of type T.
|
|
70
|
+
*/
|
|
71
|
+
toArray() {
|
|
72
|
+
return this._elements.slice();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The clear function clears the elements array.
|
|
76
|
+
*/
|
|
77
|
+
clear() {
|
|
78
|
+
this._elements = [];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
82
|
+
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
83
|
+
*/
|
|
84
|
+
clone() {
|
|
85
|
+
return new Stack(this._elements.slice());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tree';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export class TreeNode {
|
|
2
|
+
constructor(id, value, children) {
|
|
3
|
+
this._id = id;
|
|
4
|
+
this._value = value || undefined;
|
|
5
|
+
this._children = children || [];
|
|
6
|
+
}
|
|
7
|
+
get id() {
|
|
8
|
+
return this._id;
|
|
9
|
+
}
|
|
10
|
+
set id(value) {
|
|
11
|
+
this._id = value;
|
|
12
|
+
}
|
|
13
|
+
get value() {
|
|
14
|
+
return this._value;
|
|
15
|
+
}
|
|
16
|
+
set value(value) {
|
|
17
|
+
this._value = value;
|
|
18
|
+
}
|
|
19
|
+
get children() {
|
|
20
|
+
return this._children;
|
|
21
|
+
}
|
|
22
|
+
set children(value) {
|
|
23
|
+
this._children = value;
|
|
24
|
+
}
|
|
25
|
+
addChildren(children) {
|
|
26
|
+
if (!this.children) {
|
|
27
|
+
this.children = [];
|
|
28
|
+
}
|
|
29
|
+
if (children instanceof TreeNode) {
|
|
30
|
+
this.children.push(children);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.children = this.children.concat(children);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getHeight() {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
38
|
+
const beginRoot = this;
|
|
39
|
+
let maxDepth = 1;
|
|
40
|
+
if (beginRoot) {
|
|
41
|
+
const bfs = (node, level) => {
|
|
42
|
+
if (level > maxDepth) {
|
|
43
|
+
maxDepth = level;
|
|
44
|
+
}
|
|
45
|
+
const { children } = node;
|
|
46
|
+
if (children) {
|
|
47
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
48
|
+
bfs(children[i], level + 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
bfs(beginRoot, 1);
|
|
53
|
+
}
|
|
54
|
+
return maxDepth;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './trie';
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
export class TrieNode {
|
|
9
|
+
constructor(v) {
|
|
10
|
+
this._val = v;
|
|
11
|
+
this._isEnd = false;
|
|
12
|
+
this._children = new Map();
|
|
13
|
+
}
|
|
14
|
+
get val() {
|
|
15
|
+
return this._val;
|
|
16
|
+
}
|
|
17
|
+
set val(v) {
|
|
18
|
+
this._val = v;
|
|
19
|
+
}
|
|
20
|
+
get children() {
|
|
21
|
+
return this._children;
|
|
22
|
+
}
|
|
23
|
+
set children(v) {
|
|
24
|
+
this._children = v;
|
|
25
|
+
}
|
|
26
|
+
get isEnd() {
|
|
27
|
+
return this._isEnd;
|
|
28
|
+
}
|
|
29
|
+
set isEnd(v) {
|
|
30
|
+
this._isEnd = v;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class Trie {
|
|
34
|
+
constructor(words) {
|
|
35
|
+
this._root = new TrieNode('');
|
|
36
|
+
if (words) {
|
|
37
|
+
for (const i of words) {
|
|
38
|
+
this.add(i);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
get root() {
|
|
43
|
+
return this._root;
|
|
44
|
+
}
|
|
45
|
+
set root(v) {
|
|
46
|
+
this._root = v;
|
|
47
|
+
}
|
|
48
|
+
add(word) {
|
|
49
|
+
let cur = this._root;
|
|
50
|
+
for (const c of word) {
|
|
51
|
+
let nodeC = cur.children.get(c);
|
|
52
|
+
if (!nodeC) {
|
|
53
|
+
nodeC = new TrieNode(c);
|
|
54
|
+
cur.children.set(c, nodeC);
|
|
55
|
+
}
|
|
56
|
+
cur = nodeC;
|
|
57
|
+
}
|
|
58
|
+
cur.isEnd = true;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
has(input) {
|
|
62
|
+
let cur = this._root;
|
|
63
|
+
for (const c of input) {
|
|
64
|
+
const nodeC = cur.children.get(c);
|
|
65
|
+
if (!nodeC)
|
|
66
|
+
return false;
|
|
67
|
+
cur = nodeC;
|
|
68
|
+
}
|
|
69
|
+
return cur.isEnd;
|
|
70
|
+
}
|
|
71
|
+
remove(word) {
|
|
72
|
+
let isDeleted = false;
|
|
73
|
+
const dfs = (cur, i) => {
|
|
74
|
+
const char = word[i];
|
|
75
|
+
const child = cur.children.get(char);
|
|
76
|
+
if (child) {
|
|
77
|
+
if (i === word.length - 1) {
|
|
78
|
+
if (child.isEnd) {
|
|
79
|
+
if (child.children.size > 0) {
|
|
80
|
+
child.isEnd = false;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
cur.children.delete(char);
|
|
84
|
+
}
|
|
85
|
+
isDeleted = true;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const res = dfs(child, i + 1);
|
|
91
|
+
if (res && !cur.isEnd && child.children.size === 0) {
|
|
92
|
+
cur.children.delete(char);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
99
|
+
dfs(this.root, 0);
|
|
100
|
+
return isDeleted;
|
|
101
|
+
}
|
|
102
|
+
// --- start additional methods ---
|
|
103
|
+
/**
|
|
104
|
+
* The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
|
|
105
|
+
* @param {string} input - The input parameter is a string that represents the input value for the function.
|
|
106
|
+
* @returns a boolean value.
|
|
107
|
+
*/
|
|
108
|
+
isAbsPrefix(input) {
|
|
109
|
+
let cur = this._root;
|
|
110
|
+
for (const c of input) {
|
|
111
|
+
const nodeC = cur.children.get(c);
|
|
112
|
+
if (!nodeC)
|
|
113
|
+
return false;
|
|
114
|
+
cur = nodeC;
|
|
115
|
+
}
|
|
116
|
+
return !cur.isEnd;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
|
|
120
|
+
* @param {string} input - The input parameter is a string that represents the prefix we want to check.
|
|
121
|
+
* @returns a boolean value.
|
|
122
|
+
*/
|
|
123
|
+
isPrefix(input) {
|
|
124
|
+
let cur = this._root;
|
|
125
|
+
for (const c of input) {
|
|
126
|
+
const nodeC = cur.children.get(c);
|
|
127
|
+
if (!nodeC)
|
|
128
|
+
return false;
|
|
129
|
+
cur = nodeC;
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
|
|
135
|
+
* @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
|
|
136
|
+
* in the Trie data structure.
|
|
137
|
+
* @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
|
|
138
|
+
*/
|
|
139
|
+
isCommonPrefix(input) {
|
|
140
|
+
let commonPre = '';
|
|
141
|
+
const dfs = (cur) => {
|
|
142
|
+
commonPre += cur.val;
|
|
143
|
+
if (commonPre === input)
|
|
144
|
+
return;
|
|
145
|
+
if (cur.isEnd)
|
|
146
|
+
return;
|
|
147
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
148
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
149
|
+
else
|
|
150
|
+
return;
|
|
151
|
+
};
|
|
152
|
+
dfs(this._root);
|
|
153
|
+
return commonPre === input;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
|
|
157
|
+
* structure.
|
|
158
|
+
* @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
|
|
159
|
+
* Trie.
|
|
160
|
+
*/
|
|
161
|
+
getLongestCommonPrefix() {
|
|
162
|
+
let commonPre = '';
|
|
163
|
+
const dfs = (cur) => {
|
|
164
|
+
commonPre += cur.val;
|
|
165
|
+
if (cur.isEnd)
|
|
166
|
+
return;
|
|
167
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
168
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
169
|
+
else
|
|
170
|
+
return;
|
|
171
|
+
};
|
|
172
|
+
dfs(this._root);
|
|
173
|
+
return commonPre;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
177
|
+
* @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
178
|
+
* trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
|
|
179
|
+
* @returns an array of strings.
|
|
180
|
+
*/
|
|
181
|
+
getAll(prefix = '') {
|
|
182
|
+
const words = [];
|
|
183
|
+
function dfs(node, word) {
|
|
184
|
+
for (const char of node.children.keys()) {
|
|
185
|
+
const charNode = node.children.get(char);
|
|
186
|
+
if (charNode !== undefined) {
|
|
187
|
+
dfs(charNode, word.concat(char));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (node.isEnd) {
|
|
191
|
+
words.push(word);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
let startNode = this._root;
|
|
195
|
+
if (prefix) {
|
|
196
|
+
for (const c of prefix) {
|
|
197
|
+
const nodeC = startNode.children.get(c);
|
|
198
|
+
if (nodeC)
|
|
199
|
+
startNode = nodeC;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
dfs(startNode, prefix);
|
|
203
|
+
return words;
|
|
204
|
+
}
|
|
205
|
+
}
|
package/lib/index.js
ADDED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { AVLTreeNode } from '../data-structures';
|
|
2
2
|
import { IBST, IBSTNode } from './bst';
|
|
3
3
|
import { BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
|
|
4
|
-
export
|
|
5
|
-
}
|
|
4
|
+
export type IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>;
|
|
6
5
|
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
6
|
add(id: BinaryTreeNodeId, val?: N['val'] | null): N | null | undefined;
|
|
8
7
|
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
|
|
9
|
-
balanceFactor(node: N): number;
|
|
10
|
-
updateHeight(node: N): void;
|
|
11
|
-
balancePath(node: N): void;
|
|
12
|
-
balanceLL(A: N): void;
|
|
13
|
-
balanceLR(A: N): void;
|
|
14
|
-
balanceRR(A: N): void;
|
|
15
|
-
balanceRL(A: N): void;
|
|
16
8
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BinaryTreeNode } from '../data-structures';
|
|
2
|
+
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
3
|
+
export type IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> = IAbstractBinaryTreeNode<T, NEIGHBOR>;
|
|
4
|
+
export type IBinaryTree<N extends BinaryTreeNode<N['val'], N>> = IAbstractBinaryTree<N>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BSTNode } from '../data-structures';
|
|
2
2
|
import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
|
|
3
3
|
import { BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName } from '../types';
|
|
4
|
-
export
|
|
5
|
-
}
|
|
4
|
+
export type IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> = IBinaryTreeNode<T, NEIGHBOR>;
|
|
6
5
|
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
|
|
7
6
|
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
8
7
|
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|