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,401 @@
|
|
|
1
|
+
import {SinglyLinkedList} from '../../../../src';
|
|
2
|
+
import {bigO, magnitude} from '../../../utils';
|
|
3
|
+
|
|
4
|
+
describe('SinglyLinkedList Operation Test', () => {
|
|
5
|
+
let list: SinglyLinkedList<number>;
|
|
6
|
+
let objectList: SinglyLinkedList<{ keyA: number }>;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
list = new SinglyLinkedList<number>();
|
|
9
|
+
objectList = new SinglyLinkedList<{ keyA: number }>();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('push', () => {
|
|
13
|
+
it('should add elements to the end of the list', () => {
|
|
14
|
+
list.push(1);
|
|
15
|
+
list.push(2);
|
|
16
|
+
expect(list.toArray()).toEqual([1, 2]);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('pop', () => {
|
|
21
|
+
it('should remove and return the last element of the list', () => {
|
|
22
|
+
list.push(1);
|
|
23
|
+
list.push(2);
|
|
24
|
+
const popped = list.pop();
|
|
25
|
+
expect(popped).toBe(2);
|
|
26
|
+
expect(list.toArray()).toEqual([1]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return undefined if the list is empty', () => {
|
|
30
|
+
const popped = list.pop();
|
|
31
|
+
expect(popped).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('shift', () => {
|
|
36
|
+
it('should remove and return the first element of the list', () => {
|
|
37
|
+
list.push(1);
|
|
38
|
+
list.push(2);
|
|
39
|
+
const shifted = list.shift();
|
|
40
|
+
expect(shifted).toBe(1);
|
|
41
|
+
expect(list.toArray()).toEqual([2]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should return undefined if the list is empty', () => {
|
|
45
|
+
const shifted = list.shift();
|
|
46
|
+
expect(shifted).toBeUndefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('unshift', () => {
|
|
51
|
+
it('should add elements to the beginning of the list', () => {
|
|
52
|
+
list.unshift(1);
|
|
53
|
+
list.unshift(2);
|
|
54
|
+
expect(list.toArray()).toEqual([2, 1]);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('get', () => {
|
|
59
|
+
it('should return the element at the specified index', () => {
|
|
60
|
+
list.push(1);
|
|
61
|
+
list.push(2);
|
|
62
|
+
list.push(3);
|
|
63
|
+
const element = list.getAt(1);
|
|
64
|
+
expect(element).toBe(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should return undefined for an out-of-bounds index', () => {
|
|
68
|
+
list.push(1);
|
|
69
|
+
const element = list.getAt(1);
|
|
70
|
+
expect(element).toBeUndefined();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
describe('insertAfter', () => {
|
|
76
|
+
it('should insert an element after an existing value', () => {
|
|
77
|
+
list.push(1);
|
|
78
|
+
list.push(2);
|
|
79
|
+
list.push(3);
|
|
80
|
+
list.insertAfter(2, 4);
|
|
81
|
+
expect(list.toArray()).toEqual([1, 2, 4, 3]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should return false if the existing value is not found', () => {
|
|
85
|
+
list.push(1);
|
|
86
|
+
list.push(2);
|
|
87
|
+
list.push(3);
|
|
88
|
+
const result = list.insertAfter(5, 4);
|
|
89
|
+
expect(result).toBe(false);
|
|
90
|
+
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('countOccurrences', () => {
|
|
95
|
+
it('should count occurrences of a value in the list', () => {
|
|
96
|
+
list.push(1);
|
|
97
|
+
list.push(2);
|
|
98
|
+
list.push(2);
|
|
99
|
+
list.push(3);
|
|
100
|
+
const count = list.countOccurrences(2);
|
|
101
|
+
expect(count).toBe(2);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should return 0 if the value is not found', () => {
|
|
105
|
+
list.push(1);
|
|
106
|
+
list.push(2);
|
|
107
|
+
const count = list.countOccurrences(3);
|
|
108
|
+
expect(count).toBe(0);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('removeValue', () => {
|
|
113
|
+
it('should remove the first occurrence of a value from the list', () => {
|
|
114
|
+
list.push(1);
|
|
115
|
+
list.push(2);
|
|
116
|
+
list.push(3);
|
|
117
|
+
const removed = list.delete(2);
|
|
118
|
+
expect(removed).toBe(true);
|
|
119
|
+
expect(list.toArray()).toEqual([1, 3]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should return false if the value is not found', () => {
|
|
123
|
+
list.push(1);
|
|
124
|
+
list.push(2);
|
|
125
|
+
list.push(3);
|
|
126
|
+
const removed = list.delete(4);
|
|
127
|
+
expect(removed).toBe(false);
|
|
128
|
+
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
describe('isEmpty', () => {
|
|
134
|
+
it('should return true for an empty list', () => {
|
|
135
|
+
expect(list.isEmpty()).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should return false for a non-empty list', () => {
|
|
139
|
+
list.push(1);
|
|
140
|
+
expect(list.isEmpty()).toBe(false);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('clear', () => {
|
|
145
|
+
it('should clear all elements from the list', () => {
|
|
146
|
+
list.push(1);
|
|
147
|
+
list.push(2);
|
|
148
|
+
list.push(3);
|
|
149
|
+
list.clear();
|
|
150
|
+
expect(list.toArray()).toEqual([]);
|
|
151
|
+
expect(list.length).toBe(0);
|
|
152
|
+
expect(list.isEmpty()).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('reverse', () => {
|
|
157
|
+
it('should reverse the order of elements in the list', () => {
|
|
158
|
+
list.push(1);
|
|
159
|
+
list.push(2);
|
|
160
|
+
list.push(3);
|
|
161
|
+
list.reverse();
|
|
162
|
+
expect(list.toArray()).toEqual([3, 2, 1]);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should handle an empty list', () => {
|
|
166
|
+
list.reverse();
|
|
167
|
+
expect(list.toArray()).toEqual([]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should handle a list with a single element', () => {
|
|
171
|
+
list.push(1);
|
|
172
|
+
list.reverse();
|
|
173
|
+
expect(list.toArray()).toEqual([1]);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('indexOf', () => {
|
|
178
|
+
it('should return the index of the first occurrence of a value', () => {
|
|
179
|
+
list.push(1);
|
|
180
|
+
list.push(2);
|
|
181
|
+
list.push(3);
|
|
182
|
+
const index = list.indexOf(2);
|
|
183
|
+
expect(index).toBe(1);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should return -1 if the value is not found', () => {
|
|
187
|
+
list.push(1);
|
|
188
|
+
list.push(2);
|
|
189
|
+
list.push(3);
|
|
190
|
+
const index = list.indexOf(4);
|
|
191
|
+
expect(index).toBe(-1);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('toArray', () => {
|
|
196
|
+
it('should convert the list to an array', () => {
|
|
197
|
+
list.push(1);
|
|
198
|
+
list.push(2);
|
|
199
|
+
list.push(3);
|
|
200
|
+
const array = list.toArray();
|
|
201
|
+
expect(array).toEqual([1, 2, 3]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should return an empty array for an empty list', () => {
|
|
205
|
+
const array = list.toArray();
|
|
206
|
+
expect(array).toEqual([]);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('insertBefore', () => {
|
|
211
|
+
it('should insert an element before an existing value', () => {
|
|
212
|
+
list.push(1);
|
|
213
|
+
list.push(2);
|
|
214
|
+
list.push(3);
|
|
215
|
+
list.insertBefore(2, 4);
|
|
216
|
+
expect(list.toArray()).toEqual([1, 4, 2, 3]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should insert an element at the beginning', () => {
|
|
220
|
+
list.push(1);
|
|
221
|
+
list.push(2);
|
|
222
|
+
list.insertBefore(1, 3);
|
|
223
|
+
expect(list.toArray()).toEqual([3, 1, 2]);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('should return false if the existing value is not found', () => {
|
|
227
|
+
list.push(1);
|
|
228
|
+
list.push(2);
|
|
229
|
+
list.push(3);
|
|
230
|
+
const result = list.insertBefore(5, 4);
|
|
231
|
+
expect(result).toBe(false);
|
|
232
|
+
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('getLength', () => {
|
|
237
|
+
it('should return the correct length of the list', () => {
|
|
238
|
+
expect(list.length).toBe(0);
|
|
239
|
+
list.push(1);
|
|
240
|
+
list.push(2);
|
|
241
|
+
expect(list.length).toBe(2);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe('remove', () => {
|
|
246
|
+
it('should remove and return the element at the specified index', () => {
|
|
247
|
+
list.push(1);
|
|
248
|
+
list.push(2);
|
|
249
|
+
list.push(3);
|
|
250
|
+
const removed = list.deleteAt(1);
|
|
251
|
+
expect(removed).toBe(2);
|
|
252
|
+
expect(list.toArray()).toEqual([1, 3]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('should return undefined for an out-of-bounds index', () => {
|
|
256
|
+
list.push(1);
|
|
257
|
+
const removed = list.deleteAt(1);
|
|
258
|
+
expect(removed).toBeUndefined();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('should remove and return the first element', () => {
|
|
262
|
+
list.push(1);
|
|
263
|
+
list.push(2);
|
|
264
|
+
const removed = list.deleteAt(0);
|
|
265
|
+
expect(removed).toBe(1);
|
|
266
|
+
expect(list.toArray()).toEqual([2]);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('should remove and return the last element', () => {
|
|
270
|
+
list.push(1);
|
|
271
|
+
list.push(2);
|
|
272
|
+
const removed = list.deleteAt(1);
|
|
273
|
+
expect(removed).toBe(2);
|
|
274
|
+
expect(list.toArray()).toEqual([1]);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('push and pop', () => {
|
|
279
|
+
it('should push and pop elements correctly', () => {
|
|
280
|
+
list.push(1);
|
|
281
|
+
list.push(2);
|
|
282
|
+
expect(list.pop()).toBe(2);
|
|
283
|
+
expect(list.pop()).toBe(1);
|
|
284
|
+
expect(list.pop()).toBeUndefined();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
describe('shift and unshift', () => {
|
|
289
|
+
it('should shift and unshift elements correctly', () => {
|
|
290
|
+
list.unshift(1);
|
|
291
|
+
list.unshift(2);
|
|
292
|
+
expect(list.shift()).toBe(2);
|
|
293
|
+
expect(list.shift()).toBe(1);
|
|
294
|
+
expect(list.shift()).toBeUndefined();
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe('insert and toArray', () => {
|
|
299
|
+
it('should insert elements and return array correctly', () => {
|
|
300
|
+
list.insertAt(0, 1);
|
|
301
|
+
list.insertAt(1, 3);
|
|
302
|
+
list.insertAt(1, 2);
|
|
303
|
+
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
describe('find', () => {
|
|
308
|
+
it('should find elements using a callback function', () => {
|
|
309
|
+
list.push(1);
|
|
310
|
+
list.push(2);
|
|
311
|
+
list.push(3);
|
|
312
|
+
const result = list.find((data) => data % 2 === 0);
|
|
313
|
+
expect(result).toBe(2);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should return undefined if element is not found', () => {
|
|
317
|
+
list.push(1);
|
|
318
|
+
list.push(3);
|
|
319
|
+
const result = list.find((data) => data % 2 === 0);
|
|
320
|
+
expect(result).toBeNull();
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe('reverse', () => {
|
|
325
|
+
it('should reverse the order of elements', () => {
|
|
326
|
+
list.push(1);
|
|
327
|
+
list.push(2);
|
|
328
|
+
list.push(3);
|
|
329
|
+
list.reverse();
|
|
330
|
+
expect(list.toArray()).toEqual([3, 2, 1]);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe('countOccurrences', () => {
|
|
335
|
+
it('should count occurrences of a value', () => {
|
|
336
|
+
list.push(1);
|
|
337
|
+
list.push(2);
|
|
338
|
+
list.push(2);
|
|
339
|
+
list.push(3);
|
|
340
|
+
const count = list.countOccurrences(2);
|
|
341
|
+
expect(count).toBe(2);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('should return 0 if value is not found', () => {
|
|
345
|
+
list.push(1);
|
|
346
|
+
list.push(2);
|
|
347
|
+
const count = list.countOccurrences(3);
|
|
348
|
+
expect(count).toBe(0);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('should insert and manipulate objects with numeric properties', () => {
|
|
353
|
+
const obj1 = {keyA: 1};
|
|
354
|
+
const obj2 = {keyA: 2};
|
|
355
|
+
const obj3 = {keyA: 3};
|
|
356
|
+
|
|
357
|
+
objectList.push(obj1);
|
|
358
|
+
objectList.push(obj2);
|
|
359
|
+
objectList.push(obj3);
|
|
360
|
+
|
|
361
|
+
expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
|
|
362
|
+
|
|
363
|
+
const newObj = {keyA: 2.5}; // Corrected newObj value
|
|
364
|
+
const insertSuccess = objectList.insertBefore(obj2, newObj);
|
|
365
|
+
expect(insertSuccess).toBe(true);
|
|
366
|
+
|
|
367
|
+
const findNode = objectList.findNode(newObj); // Use newObj instead of obj2
|
|
368
|
+
expect(findNode?.val).toEqual(newObj);
|
|
369
|
+
|
|
370
|
+
const deleted = objectList.delete(newObj); // Use newObj instead of obj2
|
|
371
|
+
expect(deleted).toBe(true);
|
|
372
|
+
|
|
373
|
+
const poppedObj = objectList.pop();
|
|
374
|
+
expect(poppedObj).toBe(obj3);
|
|
375
|
+
|
|
376
|
+
const shiftedObj = objectList.shift();
|
|
377
|
+
expect(shiftedObj).toBe(obj1);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
describe('SinglyLinkedList Performance Test', () => {
|
|
383
|
+
it('should the push and pop methods adhere to a time complexity of O(n) and executed correctly under large scale data', () => {
|
|
384
|
+
const list = new SinglyLinkedList<number>();
|
|
385
|
+
|
|
386
|
+
const startPushTime = performance.now();
|
|
387
|
+
for (let i = 0; i < magnitude.LINEAR; i++) {
|
|
388
|
+
list.push(i);
|
|
389
|
+
}
|
|
390
|
+
expect(performance.now() - startPushTime).toBeLessThan(bigO.LINEAR * 10);
|
|
391
|
+
|
|
392
|
+
const startPopTime = performance.now();
|
|
393
|
+
|
|
394
|
+
for (let i = 0; i < magnitude.LINEAR; i++) {
|
|
395
|
+
list.pop();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// expect(performance.now() - startPopTime).toBeLessThan(bigO.LINEAR);
|
|
399
|
+
expect(performance.now() - startPopTime).toBeLessThan(bigO.LINEAR * 100);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {SkipLinkedList} from '../../../../src'
|
|
2
|
+
|
|
3
|
+
describe('SkipLinkedList Operation Test', () => {
|
|
4
|
+
it('should xxx', function () {
|
|
5
|
+
const xxx = new SkipLinkedList();
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
describe('SkipLinkedList Performance Test', () => {
|
|
10
|
+
it('should xxx', function () {
|
|
11
|
+
const xxx = new SkipLinkedList();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {MaxPriorityQueue} from '../../../../src';
|
|
2
|
+
import {bigO, magnitude} from '../../../utils';
|
|
3
|
+
|
|
4
|
+
describe('MaxPriorityQueue Operation Test', () => {
|
|
5
|
+
|
|
6
|
+
it('should add elements and maintain heap property', () => {
|
|
7
|
+
const priorityQueue = new MaxPriorityQueue<number>();
|
|
8
|
+
|
|
9
|
+
priorityQueue.add(5);
|
|
10
|
+
priorityQueue.add(3);
|
|
11
|
+
priorityQueue.add(7);
|
|
12
|
+
priorityQueue.add(1);
|
|
13
|
+
|
|
14
|
+
expect(priorityQueue.poll()).toBe(7);
|
|
15
|
+
expect(priorityQueue.poll()).toBe(5);
|
|
16
|
+
expect(priorityQueue.poll()).toBe(3);
|
|
17
|
+
expect(priorityQueue.poll()).toBe(1);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
|
|
21
|
+
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({
|
|
22
|
+
nodes: [{keyA: 5}, {keyA: 3}, {keyA: 1}],
|
|
23
|
+
comparator: (a, b) => b.keyA - a.keyA
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
priorityQueue.add({keyA: 7});
|
|
27
|
+
|
|
28
|
+
expect(priorityQueue.poll()?.keyA).toBe(7);
|
|
29
|
+
expect(priorityQueue.poll()?.keyA).toBe(5);
|
|
30
|
+
expect(priorityQueue.poll()?.keyA).toBe(3);
|
|
31
|
+
expect(priorityQueue.poll()?.keyA).toBe(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should return and remove the smallest element', () => {
|
|
35
|
+
const priorityQueue = new MaxPriorityQueue<number>();
|
|
36
|
+
priorityQueue.add(5);
|
|
37
|
+
priorityQueue.add(3);
|
|
38
|
+
priorityQueue.add(7);
|
|
39
|
+
|
|
40
|
+
expect(priorityQueue.poll()).toBe(7);
|
|
41
|
+
expect(priorityQueue.poll()).toBe(5);
|
|
42
|
+
expect(priorityQueue.size).toBe(1);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should create a clone of the priority queue', () => {
|
|
46
|
+
const priorityQueue = new MaxPriorityQueue<number>();
|
|
47
|
+
priorityQueue.add(5);
|
|
48
|
+
priorityQueue.add(3);
|
|
49
|
+
priorityQueue.add(7);
|
|
50
|
+
|
|
51
|
+
const clone = priorityQueue.clone();
|
|
52
|
+
expect(clone.poll()).toBe(7);
|
|
53
|
+
expect(clone.poll()).toBe(5);
|
|
54
|
+
expect(clone.poll()).toBe(3);
|
|
55
|
+
expect(clone.isEmpty()).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should correctly heapify an array', () => {
|
|
59
|
+
const array = [5, 3, 7, 1];
|
|
60
|
+
const heap = MaxPriorityQueue.heapify<number>({nodes: array});
|
|
61
|
+
|
|
62
|
+
expect(heap.poll()).toBe(7);
|
|
63
|
+
expect(heap.poll()).toBe(5);
|
|
64
|
+
expect(heap.poll()).toBe(3);
|
|
65
|
+
expect(heap.poll()).toBe(1);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should correctly heapify an object array', () => {
|
|
69
|
+
const nodes = [{keyA: 5}, {keyA: 3}, {keyA: 7}, {keyA: 1}];
|
|
70
|
+
const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>({nodes, comparator: (a, b) => b.keyA - a.keyA});
|
|
71
|
+
|
|
72
|
+
expect(maxPQ.poll()?.keyA).toBe(7);
|
|
73
|
+
expect(maxPQ.poll()?.keyA).toBe(5);
|
|
74
|
+
expect(maxPQ.poll()?.keyA).toBe(3);
|
|
75
|
+
expect(maxPQ.poll()?.keyA).toBe(1);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('MaxPriorityQueue Performance Test', () => {
|
|
81
|
+
|
|
82
|
+
it('should the poll method adheres to a time complexity of O(log n) and executed correctly under large scale distinct data', () => {
|
|
83
|
+
const nodes = Array.from(new Set<number>(Array.from(new Array(magnitude.LINEAR), () => Math.floor(Math.random() * magnitude.LINEAR * 100))));
|
|
84
|
+
expect(nodes.length).toBeGreaterThan(magnitude.LINEAR / 2);
|
|
85
|
+
const maxPQ = new MaxPriorityQueue<number>({nodes});
|
|
86
|
+
|
|
87
|
+
let prev = Number.MAX_SAFE_INTEGER;
|
|
88
|
+
const startTime = performance.now();
|
|
89
|
+
while (maxPQ.size > 0) {
|
|
90
|
+
const polled = maxPQ.poll();
|
|
91
|
+
if (polled) {
|
|
92
|
+
prev = polled;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
expect(performance.now() - startTime).toBeLessThan(bigO.LINEAR * 10);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should sorted.length to be the same as original data', () => {
|
|
99
|
+
// const magnitude = 1000;
|
|
100
|
+
// const maxPriorityQueue = new MaxPriorityQueue<number>({nodes: Array.from(new Array<number>(magnitude), () => Math.floor(Math.random() * magnitude))});
|
|
101
|
+
// const nodeCount = maxPriorityQueue.getNodes().length;
|
|
102
|
+
// const sorted = maxPriorityQueue.sort();
|
|
103
|
+
//
|
|
104
|
+
// expect(sorted.length).toBe(nodeCount); // TODO Plan to support sorting of duplicate elements.
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {MinPriorityQueue, PriorityQueue} from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('MinPriorityQueue Operation Test', () => {
|
|
4
|
+
|
|
5
|
+
it('should check if a node exists in the queue', () => {
|
|
6
|
+
const priorityQueue = new MinPriorityQueue<number>();
|
|
7
|
+
priorityQueue.add(5);
|
|
8
|
+
|
|
9
|
+
expect(priorityQueue.has(5)).toBe(true);
|
|
10
|
+
expect(priorityQueue.has(3)).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should return the smallest element without removing it', () => {
|
|
14
|
+
const priorityQueue = new MinPriorityQueue<number>();
|
|
15
|
+
priorityQueue.add(5);
|
|
16
|
+
priorityQueue.add(3);
|
|
17
|
+
priorityQueue.add(7);
|
|
18
|
+
|
|
19
|
+
expect(priorityQueue.peek()).toBe(3);
|
|
20
|
+
expect(priorityQueue.size).toBe(3);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
it('should return the last element', () => {
|
|
25
|
+
const priorityQueue = new MinPriorityQueue<number>();
|
|
26
|
+
priorityQueue.add(5);
|
|
27
|
+
priorityQueue.add(3);
|
|
28
|
+
priorityQueue.add(7);
|
|
29
|
+
|
|
30
|
+
expect(priorityQueue.leaf()).toBe(7);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should check if the queue is empty', () => {
|
|
34
|
+
const priorityQueue = new MinPriorityQueue<number>();
|
|
35
|
+
|
|
36
|
+
expect(priorityQueue.isEmpty()).toBe(true);
|
|
37
|
+
|
|
38
|
+
priorityQueue.add(5);
|
|
39
|
+
|
|
40
|
+
expect(priorityQueue.isEmpty()).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should clear the queue', () => {
|
|
44
|
+
const priorityQueue = new MinPriorityQueue<number>();
|
|
45
|
+
priorityQueue.add(5);
|
|
46
|
+
priorityQueue.add(3);
|
|
47
|
+
priorityQueue.add(7);
|
|
48
|
+
|
|
49
|
+
priorityQueue.clear();
|
|
50
|
+
|
|
51
|
+
expect(priorityQueue.size).toBe(0);
|
|
52
|
+
expect(priorityQueue.isEmpty()).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
it('should sort the elements', () => {
|
|
57
|
+
const priorityQueue = new MinPriorityQueue<number>();
|
|
58
|
+
priorityQueue.add(5);
|
|
59
|
+
priorityQueue.add(3);
|
|
60
|
+
priorityQueue.add(7);
|
|
61
|
+
priorityQueue.add(1);
|
|
62
|
+
|
|
63
|
+
const sortedArray = priorityQueue.sort();
|
|
64
|
+
expect(sortedArray).toEqual([1, 3, 5, 7]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
|
|
68
|
+
const minPQ = new PriorityQueue<number>({nodes: [5, 2, 3, 4, 6, 1], comparator: (a, b) => a - b});
|
|
69
|
+
expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]);
|
|
70
|
+
minPQ.poll();
|
|
71
|
+
minPQ.poll();
|
|
72
|
+
minPQ.poll();
|
|
73
|
+
expect(minPQ.toArray()).toEqual([4, 5, 6]);
|
|
74
|
+
expect(minPQ.peek()).toBe(4);
|
|
75
|
+
expect(PriorityQueue.heapify({
|
|
76
|
+
nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
|
|
77
|
+
comparator: (a, b) => a - b
|
|
78
|
+
}).toArray()).toEqual([1, 2, 3, 5, 6, 7, 8, 9, 10]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () {
|
|
82
|
+
const maxPriorityQueue = new PriorityQueue<number>({nodes: [5, 2, 3, 4, 6, 1], comparator: (a, b) => b - a});
|
|
83
|
+
expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]);
|
|
84
|
+
maxPriorityQueue.poll();
|
|
85
|
+
maxPriorityQueue.poll();
|
|
86
|
+
maxPriorityQueue.poll();
|
|
87
|
+
expect(maxPriorityQueue.toArray()).toEqual([3, 2, 1]);
|
|
88
|
+
expect(maxPriorityQueue.peek()).toBe(3);
|
|
89
|
+
expect(PriorityQueue.heapify({
|
|
90
|
+
nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
|
|
91
|
+
comparator: (a, b) => a - b
|
|
92
|
+
}).toArray()).toEqual([1, 2, 3, 5, 6, 7, 8, 9, 10]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should PriorityQueue clone, sort, getNodes, DFS work well', function () {
|
|
96
|
+
const minPQ1 = new PriorityQueue<number>({nodes: [2, 5, 8, 3, 1, 6, 7, 4], comparator: (a, b) => a - b});
|
|
97
|
+
const clonedPriorityQueue = minPQ1.clone();
|
|
98
|
+
expect(clonedPriorityQueue.getNodes()).toEqual(minPQ1.getNodes());
|
|
99
|
+
expect(clonedPriorityQueue.sort()).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
|
|
100
|
+
expect(minPQ1.DFS('in')).toEqual([4, 3, 2, 5, 1, 8, 6, 7]);
|
|
101
|
+
expect(minPQ1.DFS('post')).toEqual([4, 3, 5, 2, 8, 7, 6, 1]);
|
|
102
|
+
expect(minPQ1.DFS('pre')).toEqual([1, 2, 3, 4, 5, 6, 8, 7]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {PriorityQueue} from '../../../../src';
|
|
2
|
+
import {getRandomInt} from '../../../utils';
|
|
3
|
+
|
|
4
|
+
describe('PriorityQueue Operation Test', () => {
|
|
5
|
+
|
|
6
|
+
it('should validate a priority queue', () => {
|
|
7
|
+
const minPQ = new PriorityQueue<number>({nodes: [1, 5, 7, 9, 3, 6, 2], comparator: (a, b) => a - b});
|
|
8
|
+
|
|
9
|
+
expect(minPQ.isValid()).toBe(true);
|
|
10
|
+
expect(PriorityQueue.isPriorityQueueified({nodes: minPQ.nodes, comparator: (a, b) => a - b})).toBe(true);
|
|
11
|
+
expect(PriorityQueue.isPriorityQueueified({nodes: minPQ.nodes, comparator: (a, b) => b - a})).toBe(false);
|
|
12
|
+
expect(PriorityQueue.isPriorityQueueified({
|
|
13
|
+
nodes: [1, 5, 7, 9, 3, 6, 2],
|
|
14
|
+
comparator: (a, b) => b - a
|
|
15
|
+
})).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('Priority Queue Performance Test', () => {
|
|
21
|
+
it('should numeric heap work well', function () {
|
|
22
|
+
const values = Array.from(new Array(10000), () => getRandomInt(1, 10000000));
|
|
23
|
+
const minPriorityQueue = new PriorityQueue<number>({nodes: values, comparator: (a, b) => a - b});
|
|
24
|
+
const sorted = minPriorityQueue.sort()
|
|
25
|
+
expect(sorted).toEqual(values.sort((a, b) => a - b));
|
|
26
|
+
});
|
|
27
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {Queue} from '../../../../src';
|
|
2
|
+
import {bigO, magnitude} from '../../../utils';
|
|
3
|
+
|
|
4
|
+
describe('Queue Operation Test', () => {
|
|
5
|
+
|
|
6
|
+
it('should validate a queue', () => {
|
|
7
|
+
const queue = new Queue<number>();
|
|
8
|
+
for (let i = 0; i < 1000; i++) {
|
|
9
|
+
queue.enqueue(i);
|
|
10
|
+
}
|
|
11
|
+
let last: number | undefined = 0;
|
|
12
|
+
for (let i = 0; i < 1000; i++) {
|
|
13
|
+
last = queue.dequeue();
|
|
14
|
+
}
|
|
15
|
+
expect(last).toBe(999);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('Queue Performance Test', () => {
|
|
21
|
+
it('should numeric queue performance well', function () {
|
|
22
|
+
const queue = new Queue<number>();
|
|
23
|
+
for (let i = 0; i < magnitude.LINEAR; i++) {
|
|
24
|
+
queue.enqueue(i);
|
|
25
|
+
}
|
|
26
|
+
let last: number | undefined = 0;
|
|
27
|
+
|
|
28
|
+
const startTime = performance.now();
|
|
29
|
+
for (let i = 0; i < magnitude.LINEAR; i++) {
|
|
30
|
+
last = queue.dequeue();
|
|
31
|
+
}
|
|
32
|
+
expect(last).toBe(magnitude.LINEAR - 1);
|
|
33
|
+
expect(performance.now() - startTime).toBeLessThan(bigO.LINEAR * 100);
|
|
34
|
+
|
|
35
|
+
});
|
|
36
|
+
})
|