data-structure-typed 1.21.3 → 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 +150 -98
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doubly-linked-list.js","sourceRoot":"","sources":["../../../src/data-structures/linked-list/doubly-linked-list.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;IAME,8BAAY,GAAM;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAID,sBAAI,qCAAG;aAAP;YACE,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;aAED,UAAQ,KAAQ;YACd,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QACpB,CAAC;;;OAJA;IAQD,sBAAI,sCAAI;aAAR;YACE,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;aAED,UAAS,KAAqC;YAC5C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;;;OAJA;IAQD,sBAAI,sCAAI;aAAR;YACE,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;aAED,UAAS,KAAqC;YAC5C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;;;OAJA;IAKH,2BAAC;AAAD,CAAC,AAzCD,IAyCC;AAzCY,oDAAoB;AA2CjC;IAIE;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAID,sBAAI,kCAAI;aAAR;YACE,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;aAED,UAAS,KAAqC;YAC5C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;;;OAJA;IAQD,sBAAI,kCAAI;aAAR;YACE,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;aAED,UAAS,KAAqC;YAC5C,IAAI,CAAC,KAAK,GAAG,KAAK,CA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,OAAO,CAAC;aAClC;YACD,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC;YAC5B,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC;YAC5B,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,EAAE;gBAC9B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;aACrB;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IACH,uBAAC;AAAD,CAAC,AA1gBD,IA0gBC;AA1gBY,4CAAgB"}
|
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./singly-linked-list"), exports);
|
|
18
18
|
__exportStar(require("./doubly-linked-list"), exports);
|
|
19
19
|
__exportStar(require("./skip-linked-list"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/data-structures/linked-list/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,uDAAqC;AACrC,qDAAmC"}
|
|
@@ -1,84 +1,144 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var __values = (this && this.__values) || function(o) {
|
|
30
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
31
|
+
if (m) return m.call(o);
|
|
32
|
+
if (o && typeof o.length === "number") return {
|
|
33
|
+
next: function () {
|
|
34
|
+
if (o && i >= o.length) o = void 0;
|
|
35
|
+
return { value: o && o[i++], done: !o };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
39
|
+
};
|
|
40
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
41
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
42
|
+
if (!m) return o;
|
|
43
|
+
var i = m.call(o), r, ar = [], e;
|
|
44
|
+
try {
|
|
45
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
46
|
+
}
|
|
47
|
+
catch (error) { e = { error: error }; }
|
|
48
|
+
finally {
|
|
49
|
+
try {
|
|
50
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
51
|
+
}
|
|
52
|
+
finally { if (e) throw e.error; }
|
|
53
|
+
}
|
|
54
|
+
return ar;
|
|
55
|
+
};
|
|
2
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
57
|
exports.SinglyLinkedList = exports.SinglyLinkedListNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @author Tyler Zeng
|
|
8
|
-
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
-
* @license MIT License
|
|
10
|
-
*/
|
|
11
|
-
class SinglyLinkedListNode {
|
|
12
|
-
/**
|
|
13
|
-
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
14
|
-
* @param {T} val - The "val" parameter is of type T, which means it can be any data type. It represents the value that
|
|
15
|
-
* will be stored in the node of a linked list.
|
|
16
|
-
*/
|
|
17
|
-
constructor(val) {
|
|
58
|
+
var SinglyLinkedListNode = (function () {
|
|
59
|
+
function SinglyLinkedListNode(val) {
|
|
18
60
|
this._val = val;
|
|
19
61
|
this._next = null;
|
|
20
62
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
63
|
+
Object.defineProperty(SinglyLinkedListNode.prototype, "val", {
|
|
64
|
+
get: function () {
|
|
65
|
+
return this._val;
|
|
66
|
+
},
|
|
67
|
+
set: function (value) {
|
|
68
|
+
this._val = value;
|
|
69
|
+
},
|
|
70
|
+
enumerable: false,
|
|
71
|
+
configurable: true
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(SinglyLinkedListNode.prototype, "next", {
|
|
74
|
+
get: function () {
|
|
75
|
+
return this._next;
|
|
76
|
+
},
|
|
77
|
+
set: function (value) {
|
|
78
|
+
this._next = value;
|
|
79
|
+
},
|
|
80
|
+
enumerable: false,
|
|
81
|
+
configurable: true
|
|
82
|
+
});
|
|
83
|
+
return SinglyLinkedListNode;
|
|
84
|
+
}());
|
|
34
85
|
exports.SinglyLinkedListNode = SinglyLinkedListNode;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
38
|
-
*/
|
|
39
|
-
constructor() {
|
|
86
|
+
var SinglyLinkedList = (function () {
|
|
87
|
+
function SinglyLinkedList() {
|
|
40
88
|
this._head = null;
|
|
41
89
|
this._tail = null;
|
|
42
90
|
this._length = 0;
|
|
43
91
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
Object.defineProperty(SinglyLinkedList.prototype, "head", {
|
|
93
|
+
get: function () {
|
|
94
|
+
return this._head;
|
|
95
|
+
},
|
|
96
|
+
set: function (value) {
|
|
97
|
+
this._head = value;
|
|
98
|
+
},
|
|
99
|
+
enumerable: false,
|
|
100
|
+
configurable: true
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(SinglyLinkedList.prototype, "tail", {
|
|
103
|
+
get: function () {
|
|
104
|
+
return this._tail;
|
|
105
|
+
},
|
|
106
|
+
set: function (value) {
|
|
107
|
+
this._tail = value;
|
|
108
|
+
},
|
|
109
|
+
enumerable: false,
|
|
110
|
+
configurable: true
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(SinglyLinkedList.prototype, "length", {
|
|
113
|
+
get: function () {
|
|
114
|
+
return this._length;
|
|
115
|
+
},
|
|
116
|
+
enumerable: false,
|
|
117
|
+
configurable: true
|
|
118
|
+
});
|
|
119
|
+
SinglyLinkedList.fromArray = function (data) {
|
|
120
|
+
var e_1, _a;
|
|
121
|
+
var singlyLinkedList = new SinglyLinkedList();
|
|
122
|
+
try {
|
|
123
|
+
for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
|
|
124
|
+
var item = data_1_1.value;
|
|
125
|
+
singlyLinkedList.push(item);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
129
|
+
finally {
|
|
130
|
+
try {
|
|
131
|
+
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
|
|
132
|
+
}
|
|
133
|
+
finally { if (e_1) throw e_1.error; }
|
|
69
134
|
}
|
|
70
135
|
return singlyLinkedList;
|
|
71
|
-
}
|
|
72
|
-
getLength() {
|
|
136
|
+
};
|
|
137
|
+
SinglyLinkedList.prototype.getLength = function () {
|
|
73
138
|
return this._length;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* @param {T} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
|
|
78
|
-
* any type (T) as specified in the generic type declaration of the class or function.
|
|
79
|
-
*/
|
|
80
|
-
push(data) {
|
|
81
|
-
const newNode = new SinglyLinkedListNode(data);
|
|
139
|
+
};
|
|
140
|
+
SinglyLinkedList.prototype.push = function (data) {
|
|
141
|
+
var newNode = new SinglyLinkedListNode(data);
|
|
82
142
|
if (!this.head) {
|
|
83
143
|
this.head = newNode;
|
|
84
144
|
this.tail = newNode;
|
|
@@ -88,52 +148,37 @@ class SinglyLinkedList {
|
|
|
88
148
|
this.tail = newNode;
|
|
89
149
|
}
|
|
90
150
|
this._length++;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
94
|
-
* pointers accordingly.
|
|
95
|
-
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
96
|
-
* the linked list is empty, it returns `null`.
|
|
97
|
-
*/
|
|
98
|
-
pop() {
|
|
151
|
+
};
|
|
152
|
+
SinglyLinkedList.prototype.pop = function () {
|
|
99
153
|
if (!this.head)
|
|
100
|
-
return
|
|
154
|
+
return undefined;
|
|
101
155
|
if (this.head === this.tail) {
|
|
102
|
-
|
|
156
|
+
var val_1 = this.head.val;
|
|
103
157
|
this.head = null;
|
|
104
158
|
this.tail = null;
|
|
105
159
|
this._length--;
|
|
106
|
-
return
|
|
160
|
+
return val_1;
|
|
107
161
|
}
|
|
108
|
-
|
|
162
|
+
var current = this.head;
|
|
109
163
|
while (current.next !== this.tail) {
|
|
110
164
|
current = current.next;
|
|
111
165
|
}
|
|
112
|
-
|
|
166
|
+
var val = this.tail.val;
|
|
113
167
|
current.next = null;
|
|
114
168
|
this.tail = current;
|
|
115
169
|
this._length--;
|
|
116
170
|
return val;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
* The `shift()` function removes and returns the value of the first node in a linked list.
|
|
120
|
-
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
121
|
-
*/
|
|
122
|
-
shift() {
|
|
171
|
+
};
|
|
172
|
+
SinglyLinkedList.prototype.shift = function () {
|
|
123
173
|
if (!this.head)
|
|
124
|
-
return
|
|
125
|
-
|
|
174
|
+
return undefined;
|
|
175
|
+
var removedNode = this.head;
|
|
126
176
|
this.head = this.head.next;
|
|
127
177
|
this._length--;
|
|
128
178
|
return removedNode.val;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
* @param {T} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
|
|
133
|
-
* linked list.
|
|
134
|
-
*/
|
|
135
|
-
unshift(val) {
|
|
136
|
-
const newNode = new SinglyLinkedListNode(val);
|
|
179
|
+
};
|
|
180
|
+
SinglyLinkedList.prototype.unshift = function (val) {
|
|
181
|
+
var newNode = new SinglyLinkedListNode(val);
|
|
137
182
|
if (!this.head) {
|
|
138
183
|
this.head = newNode;
|
|
139
184
|
this.tail = newNode;
|
|
@@ -143,73 +188,45 @@ class SinglyLinkedList {
|
|
|
143
188
|
this.head = newNode;
|
|
144
189
|
}
|
|
145
190
|
this._length++;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
149
|
-
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
150
|
-
* retrieve from the list.
|
|
151
|
-
* @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or
|
|
152
|
-
* `null` if the index is out of bounds.
|
|
153
|
-
*/
|
|
154
|
-
getAt(index) {
|
|
191
|
+
};
|
|
192
|
+
SinglyLinkedList.prototype.getAt = function (index) {
|
|
155
193
|
if (index < 0 || index >= this.length)
|
|
156
|
-
return
|
|
157
|
-
|
|
158
|
-
for (
|
|
194
|
+
return undefined;
|
|
195
|
+
var current = this.head;
|
|
196
|
+
for (var i = 0; i < index; i++) {
|
|
159
197
|
current = current.next;
|
|
160
198
|
}
|
|
161
199
|
return current.val;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
|
|
167
|
-
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<T>` object if the node at the
|
|
168
|
-
* specified index exists, or `null` if the index is out of bounds.
|
|
169
|
-
*/
|
|
170
|
-
getNodeAt(index) {
|
|
171
|
-
let current = this.head;
|
|
172
|
-
for (let i = 0; i < index; i++) {
|
|
200
|
+
};
|
|
201
|
+
SinglyLinkedList.prototype.getNodeAt = function (index) {
|
|
202
|
+
var current = this.head;
|
|
203
|
+
for (var i = 0; i < index; i++) {
|
|
173
204
|
current = current.next;
|
|
174
205
|
}
|
|
175
206
|
return current;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
179
|
-
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
180
|
-
* data structure. It is of type number.
|
|
181
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
|
|
182
|
-
* bounds.
|
|
183
|
-
*/
|
|
184
|
-
deleteAt(index) {
|
|
207
|
+
};
|
|
208
|
+
SinglyLinkedList.prototype.deleteAt = function (index) {
|
|
185
209
|
if (index < 0 || index >= this.length)
|
|
186
|
-
return
|
|
210
|
+
return undefined;
|
|
187
211
|
if (index === 0)
|
|
188
212
|
return this.shift();
|
|
189
213
|
if (index === this.length - 1)
|
|
190
214
|
return this.pop();
|
|
191
|
-
|
|
192
|
-
|
|
215
|
+
var prevNode = this.getNodeAt(index - 1);
|
|
216
|
+
var removedNode = prevNode.next;
|
|
193
217
|
prevNode.next = removedNode.next;
|
|
194
218
|
this._length--;
|
|
195
219
|
return removedNode.val;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
* @param {T | SinglyLinkedListNode<T>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `T`
|
|
200
|
-
* or a `SinglyLinkedListNode<T>` object.
|
|
201
|
-
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
|
|
202
|
-
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
203
|
-
*/
|
|
204
|
-
delete(valueOrNode) {
|
|
205
|
-
let value;
|
|
220
|
+
};
|
|
221
|
+
SinglyLinkedList.prototype.delete = function (valueOrNode) {
|
|
222
|
+
var value;
|
|
206
223
|
if (valueOrNode instanceof SinglyLinkedListNode) {
|
|
207
224
|
value = valueOrNode.val;
|
|
208
225
|
}
|
|
209
226
|
else {
|
|
210
227
|
value = valueOrNode;
|
|
211
228
|
}
|
|
212
|
-
|
|
229
|
+
var current = this.head, prev = null;
|
|
213
230
|
while (current) {
|
|
214
231
|
if (current.val === value) {
|
|
215
232
|
if (prev === null) {
|
|
@@ -231,17 +248,8 @@ class SinglyLinkedList {
|
|
|
231
248
|
current = current.next;
|
|
232
249
|
}
|
|
233
250
|
return false;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
237
|
-
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
238
|
-
* linked list. It is of type number.
|
|
239
|
-
* @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the
|
|
240
|
-
* specified index.
|
|
241
|
-
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
242
|
-
* if the index is out of bounds.
|
|
243
|
-
*/
|
|
244
|
-
insertAt(index, val) {
|
|
251
|
+
};
|
|
252
|
+
SinglyLinkedList.prototype.insertAt = function (index, val) {
|
|
245
253
|
if (index < 0 || index > this.length)
|
|
246
254
|
return false;
|
|
247
255
|
if (index === 0) {
|
|
@@ -252,69 +260,47 @@ class SinglyLinkedList {
|
|
|
252
260
|
this.push(val);
|
|
253
261
|
return true;
|
|
254
262
|
}
|
|
255
|
-
|
|
256
|
-
|
|
263
|
+
var newNode = new SinglyLinkedListNode(val);
|
|
264
|
+
var prevNode = this.getNodeAt(index - 1);
|
|
257
265
|
newNode.next = prevNode.next;
|
|
258
266
|
prevNode.next = newNode;
|
|
259
267
|
this._length++;
|
|
260
268
|
return true;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
264
|
-
* whether it is empty or not.
|
|
265
|
-
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
|
266
|
-
*/
|
|
267
|
-
isEmpty() {
|
|
269
|
+
};
|
|
270
|
+
SinglyLinkedList.prototype.isEmpty = function () {
|
|
268
271
|
return this.length === 0;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
272
|
-
*/
|
|
273
|
-
clear() {
|
|
272
|
+
};
|
|
273
|
+
SinglyLinkedList.prototype.clear = function () {
|
|
274
274
|
this._head = null;
|
|
275
275
|
this._tail = null;
|
|
276
276
|
this._length = 0;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
*/
|
|
282
|
-
toArray() {
|
|
283
|
-
const array = [];
|
|
284
|
-
let current = this.head;
|
|
277
|
+
};
|
|
278
|
+
SinglyLinkedList.prototype.toArray = function () {
|
|
279
|
+
var array = [];
|
|
280
|
+
var current = this.head;
|
|
285
281
|
while (current) {
|
|
286
282
|
array.push(current.val);
|
|
287
283
|
current = current.next;
|
|
288
284
|
}
|
|
289
285
|
return array;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
* @returns The reverse() method does not return anything. It has a return type of void.
|
|
294
|
-
*/
|
|
295
|
-
reverse() {
|
|
286
|
+
};
|
|
287
|
+
SinglyLinkedList.prototype.reverse = function () {
|
|
288
|
+
var _a;
|
|
296
289
|
if (!this.head || this.head === this.tail)
|
|
297
290
|
return;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
291
|
+
var prev = null;
|
|
292
|
+
var current = this.head;
|
|
293
|
+
var next = null;
|
|
301
294
|
while (current) {
|
|
302
295
|
next = current.next;
|
|
303
296
|
current.next = prev;
|
|
304
297
|
prev = current;
|
|
305
298
|
current = next;
|
|
306
299
|
}
|
|
307
|
-
[this.
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
|
|
312
|
-
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
313
|
-
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
314
|
-
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
315
|
-
*/
|
|
316
|
-
find(callback) {
|
|
317
|
-
let current = this.head;
|
|
300
|
+
_a = __read([this.tail, this.head], 2), this.head = _a[0], this.tail = _a[1];
|
|
301
|
+
};
|
|
302
|
+
SinglyLinkedList.prototype.find = function (callback) {
|
|
303
|
+
var current = this.head;
|
|
318
304
|
while (current) {
|
|
319
305
|
if (callback(current.val)) {
|
|
320
306
|
return current.val;
|
|
@@ -322,16 +308,10 @@ class SinglyLinkedList {
|
|
|
322
308
|
current = current.next;
|
|
323
309
|
}
|
|
324
310
|
return null;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
* @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
|
|
330
|
-
* value is not found, it returns -1.
|
|
331
|
-
*/
|
|
332
|
-
indexOf(value) {
|
|
333
|
-
let index = 0;
|
|
334
|
-
let current = this.head;
|
|
311
|
+
};
|
|
312
|
+
SinglyLinkedList.prototype.indexOf = function (value) {
|
|
313
|
+
var index = 0;
|
|
314
|
+
var current = this.head;
|
|
335
315
|
while (current) {
|
|
336
316
|
if (current.val === value) {
|
|
337
317
|
return index;
|
|
@@ -340,16 +320,9 @@ class SinglyLinkedList {
|
|
|
340
320
|
current = current.next;
|
|
341
321
|
}
|
|
342
322
|
return -1;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
* null.
|
|
347
|
-
* @param {T} value - The value parameter is the value that we want to search for in the linked list.
|
|
348
|
-
* @returns a `SinglyLinkedListNode<T>` if a node with the specified value is found in the linked list. If no node with
|
|
349
|
-
* the specified value is found, the function returns `null`.
|
|
350
|
-
*/
|
|
351
|
-
findNode(value) {
|
|
352
|
-
let current = this.head;
|
|
323
|
+
};
|
|
324
|
+
SinglyLinkedList.prototype.findNode = function (value) {
|
|
325
|
+
var current = this.head;
|
|
353
326
|
while (current) {
|
|
354
327
|
if (current.val === value) {
|
|
355
328
|
return current;
|
|
@@ -357,19 +330,11 @@ class SinglyLinkedList {
|
|
|
357
330
|
current = current.next;
|
|
358
331
|
}
|
|
359
332
|
return null;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
* The `insertBefore` function inserts a new value before an existing value in a singly linked list.
|
|
363
|
-
* @param {T | SinglyLinkedListNode<T>} existingValueOrNode - The existing value or node that you want to insert the
|
|
364
|
-
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
365
|
-
* @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
|
|
366
|
-
* @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
|
|
367
|
-
* inserted before the existing value, and `false` otherwise.
|
|
368
|
-
*/
|
|
369
|
-
insertBefore(existingValueOrNode, newValue) {
|
|
333
|
+
};
|
|
334
|
+
SinglyLinkedList.prototype.insertBefore = function (existingValueOrNode, newValue) {
|
|
370
335
|
if (!this.head)
|
|
371
336
|
return false;
|
|
372
|
-
|
|
337
|
+
var existingValue;
|
|
373
338
|
if (existingValueOrNode instanceof SinglyLinkedListNode) {
|
|
374
339
|
existingValue = existingValueOrNode.val;
|
|
375
340
|
}
|
|
@@ -380,10 +345,10 @@ class SinglyLinkedList {
|
|
|
380
345
|
this.unshift(newValue);
|
|
381
346
|
return true;
|
|
382
347
|
}
|
|
383
|
-
|
|
348
|
+
var current = this.head;
|
|
384
349
|
while (current.next) {
|
|
385
350
|
if (current.next.val === existingValue) {
|
|
386
|
-
|
|
351
|
+
var newNode = new SinglyLinkedListNode(newValue);
|
|
387
352
|
newNode.next = current.next;
|
|
388
353
|
current.next = newNode;
|
|
389
354
|
this._length++;
|
|
@@ -392,17 +357,9 @@ class SinglyLinkedList {
|
|
|
392
357
|
current = current.next;
|
|
393
358
|
}
|
|
394
359
|
return false;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* @param {T | SinglyLinkedListNode<T>} existingValueOrNode - The existing value or node in the linked list after which
|
|
399
|
-
* the new value will be inserted. It can be either the value of the existing node or the existing node itself.
|
|
400
|
-
* @param {T} newValue - The value that you want to insert into the linked list after the existing value or node.
|
|
401
|
-
* @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
|
|
402
|
-
* existing value or node, and false if the existing value or node was not found in the linked list.
|
|
403
|
-
*/
|
|
404
|
-
insertAfter(existingValueOrNode, newValue) {
|
|
405
|
-
let existingNode;
|
|
360
|
+
};
|
|
361
|
+
SinglyLinkedList.prototype.insertAfter = function (existingValueOrNode, newValue) {
|
|
362
|
+
var existingNode;
|
|
406
363
|
if (existingValueOrNode instanceof SinglyLinkedListNode) {
|
|
407
364
|
existingNode = existingValueOrNode;
|
|
408
365
|
}
|
|
@@ -410,7 +367,7 @@ class SinglyLinkedList {
|
|
|
410
367
|
existingNode = this.findNode(existingValueOrNode);
|
|
411
368
|
}
|
|
412
369
|
if (existingNode) {
|
|
413
|
-
|
|
370
|
+
var newNode = new SinglyLinkedListNode(newValue);
|
|
414
371
|
newNode.next = existingNode.next;
|
|
415
372
|
existingNode.next = newNode;
|
|
416
373
|
if (existingNode === this.tail) {
|
|
@@ -420,15 +377,10 @@ class SinglyLinkedList {
|
|
|
420
377
|
return true;
|
|
421
378
|
}
|
|
422
379
|
return false;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
* @returns The count of occurrences of the given value in the linked list.
|
|
428
|
-
*/
|
|
429
|
-
countOccurrences(value) {
|
|
430
|
-
let count = 0;
|
|
431
|
-
let current = this.head;
|
|
380
|
+
};
|
|
381
|
+
SinglyLinkedList.prototype.countOccurrences = function (value) {
|
|
382
|
+
var count = 0;
|
|
383
|
+
var current = this.head;
|
|
432
384
|
while (current) {
|
|
433
385
|
if (current.val === value) {
|
|
434
386
|
count++;
|
|
@@ -436,6 +388,26 @@ class SinglyLinkedList {
|
|
|
436
388
|
current = current.next;
|
|
437
389
|
}
|
|
438
390
|
return count;
|
|
439
|
-
}
|
|
440
|
-
|
|
391
|
+
};
|
|
392
|
+
SinglyLinkedList.prototype[Symbol.iterator] = function () {
|
|
393
|
+
var current;
|
|
394
|
+
return __generator(this, function (_a) {
|
|
395
|
+
switch (_a.label) {
|
|
396
|
+
case 0:
|
|
397
|
+
current = this.head;
|
|
398
|
+
_a.label = 1;
|
|
399
|
+
case 1:
|
|
400
|
+
if (!current) return [3, 3];
|
|
401
|
+
return [4, current.val];
|
|
402
|
+
case 2:
|
|
403
|
+
_a.sent();
|
|
404
|
+
current = current.next;
|
|
405
|
+
return [3, 1];
|
|
406
|
+
case 3: return [2];
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
return SinglyLinkedList;
|
|
411
|
+
}());
|
|
441
412
|
exports.SinglyLinkedList = SinglyLinkedList;
|
|
413
|
+
//# sourceMappingURL=singly-linked-list.js.map
|