data-structure-typed 1.21.4 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.auto-changelog +9 -0
- package/.auto-changelog-template.hbs +36 -0
- package/.eslintrc.js +61 -0
- package/.gitattributes +112 -0
- package/.github/workflows/ci.yml +30 -0
- package/.prettierignore +6 -0
- package/.prettierrc.js +16 -0
- package/CHANGELOG.md +17 -0
- package/CODE-OF-CONDUCT.md +80 -0
- package/COMMANDS.md +28 -0
- package/README.md +147 -95
- package/SECURITY.md +15 -0
- package/coverage/clover.xml +3393 -0
- package/coverage/coverage-final.json +67 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +386 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +4966 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +1015 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +313 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +226 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +1714 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/index.html +296 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +121 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +388 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +811 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +2185 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +3205 -0
- package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +1495 -0
- package/coverage/lcov-report/src/data-structures/graph/index.html +176 -0
- package/coverage/lcov-report/src/data-structures/graph/index.ts.html +97 -0
- package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +472 -0
- package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +907 -0
- package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +286 -0
- package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +253 -0
- package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/index.html +206 -0
- package/coverage/lcov-report/src/data-structures/hash/index.ts.html +103 -0
- package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +721 -0
- package/coverage/lcov-report/src/data-structures/heap/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/heap/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +178 -0
- package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +181 -0
- package/coverage/lcov-report/src/data-structures/index.html +116 -0
- package/coverage/lcov-report/src/data-structures/index.ts.html +118 -0
- package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +1804 -0
- package/coverage/lcov-report/src/data-structures/linked-list/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +1588 -0
- package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/matrix/index.html +176 -0
- package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +97 -0
- package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +166 -0
- package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +721 -0
- package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +448 -0
- package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +1033 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +253 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +256 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +1162 -0
- package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +976 -0
- package/coverage/lcov-report/src/data-structures/queue/index.html +146 -0
- package/coverage/lcov-report/src/data-structures/queue/index.ts.html +91 -0
- package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +658 -0
- package/coverage/lcov-report/src/data-structures/stack/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/stack/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +379 -0
- package/coverage/lcov-report/src/data-structures/tree/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/tree/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +292 -0
- package/coverage/lcov-report/src/data-structures/trie/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/trie/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +760 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/index.ts.html +97 -0
- package/coverage/lcov-report/src/interfaces/index.html +116 -0
- package/coverage/lcov-report/src/interfaces/index.ts.html +130 -0
- package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +235 -0
- package/coverage/lcov-report/src/types/data-structures/bst.ts.html +124 -0
- package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +109 -0
- package/coverage/lcov-report/src/types/data-structures/index.html +176 -0
- package/coverage/lcov-report/src/types/data-structures/index.ts.html +130 -0
- package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +106 -0
- package/coverage/lcov-report/src/types/index.html +116 -0
- package/coverage/lcov-report/src/types/index.ts.html +94 -0
- package/coverage/lcov-report/src/types/utils/index.html +116 -0
- package/coverage/lcov-report/src/types/utils/index.ts.html +91 -0
- package/coverage/lcov-report/src/utils/index.html +131 -0
- package/coverage/lcov-report/src/utils/index.ts.html +88 -0
- package/coverage/lcov-report/src/utils/utils.ts.html +322 -0
- package/coverage/lcov-report/test/utils/index.html +146 -0
- package/coverage/lcov-report/test/utils/index.ts.html +91 -0
- package/coverage/lcov-report/test/utils/magnitude.ts.html +148 -0
- package/coverage/lcov-report/test/utils/number.ts.html +94 -0
- package/coverage/lcov.info +6676 -0
- package/dist/data-structures/binary-tree/aa-tree.js +6 -2
- package/dist/data-structures/binary-tree/aa-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +398 -672
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/avl-tree.js +122 -151
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/b-tree.js +6 -2
- package/dist/data-structures/binary-tree/b-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +24 -54
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/binary-tree.js +31 -32
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/bst.js +266 -208
- package/dist/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/index.js.map +1 -0
- package/dist/data-structures/binary-tree/rb-tree.js +46 -37
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/segment-tree.js +124 -127
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/splay-tree.js +6 -2
- package/dist/data-structures/binary-tree/splay-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +227 -354
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -0
- package/dist/data-structures/binary-tree/two-three-tree.js +6 -2
- package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -0
- package/dist/data-structures/graph/abstract-graph.js +582 -609
- package/dist/data-structures/graph/abstract-graph.js.map +1 -0
- package/dist/data-structures/graph/directed-graph.js +276 -312
- package/dist/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/data-structures/graph/index.js +1 -0
- package/dist/data-structures/graph/index.js.map +1 -0
- package/dist/data-structures/graph/map-graph.js +88 -100
- package/dist/data-structures/graph/map-graph.js.map +1 -0
- package/dist/data-structures/graph/undirected-graph.js +180 -195
- package/dist/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/data-structures/hash/coordinate-map.js +46 -58
- package/dist/data-structures/hash/coordinate-map.js.map +1 -0
- package/dist/data-structures/hash/coordinate-set.js +43 -48
- package/dist/data-structures/hash/coordinate-set.js.map +1 -0
- package/dist/data-structures/hash/hash-table.js +6 -2
- package/dist/data-structures/hash/hash-table.js.map +1 -0
- package/dist/data-structures/hash/index.js +1 -0
- package/dist/data-structures/hash/index.js.map +1 -0
- package/dist/data-structures/hash/pair.js +6 -2
- package/dist/data-structures/hash/pair.js.map +1 -0
- package/dist/data-structures/hash/tree-map.js +6 -2
- package/dist/data-structures/hash/tree-map.js.map +1 -0
- package/dist/data-structures/hash/tree-set.js +6 -2
- package/dist/data-structures/hash/tree-set.js.map +1 -0
- package/dist/data-structures/heap/heap.js +83 -120
- package/dist/data-structures/heap/heap.js.map +1 -0
- package/dist/data-structures/heap/index.js +1 -0
- package/dist/data-structures/heap/index.js.map +1 -0
- package/dist/data-structures/heap/max-heap.js +27 -24
- package/dist/data-structures/heap/max-heap.js.map +1 -0
- package/dist/data-structures/heap/min-heap.js +27 -25
- package/dist/data-structures/heap/min-heap.js.map +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/index.js.map +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -307
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -0
- package/dist/data-structures/linked-list/index.js +1 -0
- package/dist/data-structures/linked-list/index.js.map +1 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +223 -251
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +6 -2
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/data-structures/matrix/index.js +1 -0
- package/dist/data-structures/matrix/index.js.map +1 -0
- package/dist/data-structures/matrix/matrix.js +9 -22
- package/dist/data-structures/matrix/matrix.js.map +1 -0
- package/dist/data-structures/matrix/matrix2d.js +75 -149
- package/dist/data-structures/matrix/matrix2d.js.map +1 -0
- package/dist/data-structures/matrix/navigator.js +38 -46
- package/dist/data-structures/matrix/navigator.js.map +1 -0
- package/dist/data-structures/matrix/vector2d.js +90 -254
- package/dist/data-structures/matrix/vector2d.js.map +1 -0
- package/dist/data-structures/priority-queue/index.js +1 -0
- package/dist/data-structures/priority-queue/index.js.map +1 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +47 -32
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +47 -33
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/data-structures/priority-queue/priority-queue.js +150 -241
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -0
- package/dist/data-structures/queue/deque.js +130 -162
- package/dist/data-structures/queue/deque.js.map +1 -0
- package/dist/data-structures/queue/index.js +1 -0
- package/dist/data-structures/queue/index.js.map +1 -0
- package/dist/data-structures/queue/queue.js +181 -100
- package/dist/data-structures/queue/queue.js.map +1 -0
- package/dist/data-structures/stack/index.js +1 -0
- package/dist/data-structures/stack/index.js.map +1 -0
- package/dist/data-structures/stack/stack.js +23 -71
- package/dist/data-structures/stack/stack.js.map +1 -0
- package/dist/data-structures/tree/index.js +1 -0
- package/dist/data-structures/tree/index.js.map +1 -0
- package/dist/data-structures/tree/tree.js +46 -33
- package/dist/data-structures/tree/tree.js.map +1 -0
- package/dist/data-structures/trie/index.js +1 -0
- package/dist/data-structures/trie/index.js.map +1 -0
- package/dist/data-structures/trie/trie.js +201 -129
- package/dist/data-structures/trie/trie.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/abstract-binary-tree.js +1 -0
- package/dist/interfaces/abstract-binary-tree.js.map +1 -0
- package/dist/interfaces/abstract-graph.js +1 -0
- package/dist/interfaces/abstract-graph.js.map +1 -0
- package/dist/interfaces/avl-tree.js +1 -0
- package/dist/interfaces/avl-tree.js.map +1 -0
- package/dist/interfaces/binary-tree.js +1 -0
- package/dist/interfaces/binary-tree.js.map +1 -0
- package/dist/interfaces/bst.js +1 -0
- package/dist/interfaces/bst.js.map +1 -0
- package/dist/interfaces/directed-graph.js +1 -0
- package/dist/interfaces/directed-graph.js.map +1 -0
- package/dist/interfaces/doubly-linked-list.js +1 -0
- package/dist/interfaces/doubly-linked-list.js.map +1 -0
- package/dist/interfaces/heap.js +1 -0
- package/dist/interfaces/heap.js.map +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/navigator.js +1 -0
- package/dist/interfaces/navigator.js.map +1 -0
- package/dist/interfaces/priority-queue.js +1 -0
- package/dist/interfaces/priority-queue.js.map +1 -0
- package/dist/interfaces/rb-tree.js +1 -0
- package/dist/interfaces/rb-tree.js.map +1 -0
- package/dist/interfaces/segment-tree.js +1 -0
- package/dist/interfaces/segment-tree.js.map +1 -0
- package/dist/interfaces/singly-linked-list.js +1 -0
- package/dist/interfaces/singly-linked-list.js.map +1 -0
- package/dist/interfaces/tree-multiset.js +1 -0
- package/dist/interfaces/tree-multiset.js.map +1 -0
- package/dist/interfaces/undirected-graph.js +1 -0
- package/dist/interfaces/undirected-graph.js.map +1 -0
- package/dist/types/data-structures/abstract-binary-tree.js +1 -7
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -0
- package/dist/types/data-structures/abstract-graph.js +1 -0
- package/dist/types/data-structures/abstract-graph.js.map +1 -0
- package/dist/types/data-structures/avl-tree.js +1 -0
- package/dist/types/data-structures/avl-tree.js.map +1 -0
- package/dist/types/data-structures/binary-tree.js +1 -0
- package/dist/types/data-structures/binary-tree.js.map +1 -0
- package/dist/types/data-structures/bst.js +1 -0
- package/dist/types/data-structures/bst.js.map +1 -0
- package/dist/types/data-structures/directed-graph.js +1 -0
- package/dist/types/data-structures/directed-graph.js.map +1 -0
- package/dist/types/data-structures/doubly-linked-list.js +1 -0
- package/dist/types/data-structures/doubly-linked-list.js.map +1 -0
- package/dist/types/data-structures/heap.js +1 -0
- package/dist/types/data-structures/heap.js.map +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/dist/types/data-structures/index.js.map +1 -0
- package/dist/types/data-structures/map-graph.js +1 -0
- package/dist/types/data-structures/map-graph.js.map +1 -0
- package/dist/types/data-structures/navigator.js +1 -0
- package/dist/types/data-structures/navigator.js.map +1 -0
- package/dist/types/data-structures/priority-queue.js +1 -0
- package/dist/types/data-structures/priority-queue.js.map +1 -0
- package/dist/types/data-structures/rb-tree.js +1 -0
- package/dist/types/data-structures/rb-tree.js.map +1 -0
- package/dist/types/data-structures/segment-tree.js +1 -0
- package/dist/types/data-structures/segment-tree.js.map +1 -0
- package/dist/types/data-structures/singly-linked-list.js +1 -0
- package/dist/types/data-structures/singly-linked-list.js.map +1 -0
- package/dist/types/data-structures/tree-multiset.js +1 -0
- package/dist/types/data-structures/tree-multiset.js.map +1 -0
- package/dist/types/helpers.js +1 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/utils/index.js +1 -0
- package/dist/types/utils/index.js.map +1 -0
- package/dist/types/utils/utils.js +1 -0
- package/dist/types/utils/utils.js.map +1 -0
- package/dist/types/utils/validate-type.js +1 -0
- package/dist/types/utils/validate-type.js.map +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/utils.js +108 -22
- package/dist/utils/utils.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +127 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2182 -0
- package/docs/classes/AVLTreeNode.html +399 -0
- package/docs/classes/AaTree.html +202 -0
- package/docs/classes/AbstractBinaryTree.html +1836 -0
- package/docs/classes/AbstractBinaryTreeNode.html +441 -0
- package/docs/classes/AbstractEdge.html +345 -0
- package/docs/classes/AbstractGraph.html +1105 -0
- package/docs/classes/AbstractVertex.html +299 -0
- package/docs/classes/ArrayDeque.html +469 -0
- package/docs/classes/BST.html +2026 -0
- package/docs/classes/BSTNode.html +400 -0
- package/docs/classes/BTree.html +202 -0
- package/docs/classes/BinaryIndexedTree.html +371 -0
- package/docs/classes/BinaryTree.html +1867 -0
- package/docs/classes/BinaryTreeNode.html +399 -0
- package/docs/classes/Character.html +250 -0
- package/docs/classes/CoordinateMap.html +513 -0
- package/docs/classes/CoordinateSet.html +474 -0
- package/docs/classes/Deque.html +1005 -0
- package/docs/classes/DirectedEdge.html +404 -0
- package/docs/classes/DirectedGraph.html +1530 -0
- package/docs/classes/DirectedVertex.html +286 -0
- package/docs/classes/DoublyLinkedList.html +998 -0
- package/docs/classes/DoublyLinkedListNode.html +327 -0
- package/docs/classes/HashTable.html +202 -0
- package/docs/classes/Heap.html +647 -0
- package/docs/classes/HeapItem.html +296 -0
- package/docs/classes/LinkedListQueue.html +884 -0
- package/docs/classes/MapEdge.html +391 -0
- package/docs/classes/MapGraph.html +1583 -0
- package/docs/classes/MapVertex.html +356 -0
- package/docs/classes/Matrix2D.html +532 -0
- package/docs/classes/MatrixNTI2D.html +270 -0
- package/docs/classes/MaxHeap.html +671 -0
- package/docs/classes/MaxPriorityQueue.html +866 -0
- package/docs/classes/MinHeap.html +672 -0
- package/docs/classes/MinPriorityQueue.html +868 -0
- package/docs/classes/Navigator.html +343 -0
- package/docs/classes/ObjectDeque.html +527 -0
- package/docs/classes/Pair.html +202 -0
- package/docs/classes/PriorityQueue.html +790 -0
- package/docs/classes/Queue.html +521 -0
- package/docs/classes/RBTree.html +2024 -0
- package/docs/classes/RBTreeNode.html +431 -0
- package/docs/classes/SegmentTree.html +464 -0
- package/docs/classes/SegmentTreeNode.html +387 -0
- package/docs/classes/SinglyLinkedList.html +830 -0
- package/docs/classes/SinglyLinkedListNode.html +300 -0
- package/docs/classes/SkipLinkedList.html +202 -0
- package/docs/classes/SplayTree.html +202 -0
- package/docs/classes/Stack.html +398 -0
- package/docs/classes/TreeMap.html +202 -0
- package/docs/classes/TreeMultiset.html +2510 -0
- package/docs/classes/TreeMultisetNode.html +447 -0
- package/docs/classes/TreeNode.html +344 -0
- package/docs/classes/TreeSet.html +202 -0
- package/docs/classes/Trie.html +402 -0
- package/docs/classes/TrieNode.html +310 -0
- package/docs/classes/TwoThreeTree.html +202 -0
- package/docs/classes/UndirectedEdge.html +374 -0
- package/docs/classes/UndirectedGraph.html +1285 -0
- package/docs/classes/UndirectedVertex.html +284 -0
- package/docs/classes/Vector2D.html +835 -0
- package/docs/enums/CP.html +211 -0
- package/docs/enums/FamilyPosition.html +239 -0
- package/docs/enums/LoopType.html +212 -0
- package/docs/enums/RBColor.html +204 -0
- package/docs/enums/TopologicalProperty.html +211 -0
- package/docs/functions/arrayRemove.html +208 -0
- package/docs/functions/isThunk.html +186 -0
- package/docs/functions/toThunk.html +186 -0
- package/docs/functions/trampoline.html +186 -0
- package/docs/functions/trampolineAsync.html +186 -0
- package/docs/functions/uuidV4.html +181 -0
- package/docs/index.html +693 -0
- package/docs/interfaces/IAVLTree.html +1245 -0
- package/docs/interfaces/IAbstractBinaryTree.html +1101 -0
- package/docs/interfaces/IAbstractBinaryTreeNode.html +335 -0
- package/docs/interfaces/IAbstractGraph.html +433 -0
- package/docs/interfaces/IBST.html +1245 -0
- package/docs/interfaces/IDirectedGraph.html +570 -0
- package/docs/interfaces/IRBTree.html +1247 -0
- package/docs/interfaces/IUNDirectedGraph.html +463 -0
- package/docs/modules.html +328 -0
- package/docs/types/AVLTreeNodeNested.html +182 -0
- package/docs/types/AVLTreeOptions.html +180 -0
- package/docs/types/AbstractBinaryTreeNodeNested.html +182 -0
- package/docs/types/AbstractBinaryTreeNodeProperties.html +182 -0
- package/docs/types/AbstractBinaryTreeNodeProperty.html +182 -0
- package/docs/types/AbstractBinaryTreeOptions.html +182 -0
- package/docs/types/BSTComparator.html +192 -0
- package/docs/types/BSTNodeNested.html +182 -0
- package/docs/types/BSTOptions.html +182 -0
- package/docs/types/BinaryTreeDeletedResult.html +189 -0
- package/docs/types/BinaryTreeNodeId.html +177 -0
- package/docs/types/BinaryTreeNodeNested.html +182 -0
- package/docs/types/BinaryTreeNodePropertyName.html +177 -0
- package/docs/types/BinaryTreeOptions.html +180 -0
- package/docs/types/DFSOrderPattern.html +177 -0
- package/docs/types/DijkstraResult.html +199 -0
- package/docs/types/Direction.html +177 -0
- package/docs/types/DummyAny.html +190 -0
- package/docs/types/EdgeId.html +177 -0
- package/docs/types/HeapOptions.html +198 -0
- package/docs/types/IAVLTreeNode.html +184 -0
- package/docs/types/IBSTNode.html +184 -0
- package/docs/types/IBinaryTree.html +182 -0
- package/docs/types/IBinaryTreeNode.html +184 -0
- package/docs/types/IRBTreeNode.html +184 -0
- package/docs/types/ITreeMultiset.html +182 -0
- package/docs/types/ITreeMultisetNode.html +184 -0
- package/docs/types/KeyValueObject.html +182 -0
- package/docs/types/KeyValueObjectWithId.html +184 -0
- package/docs/types/MapGraphCoordinate.html +177 -0
- package/docs/types/NavigatorParams.html +211 -0
- package/docs/types/NodeOrPropertyName.html +177 -0
- package/docs/types/NonNumberNonObjectButDefined.html +177 -0
- package/docs/types/ObjectWithNonNumberId.html +184 -0
- package/docs/types/ObjectWithNumberId.html +184 -0
- package/docs/types/ObjectWithoutId.html +177 -0
- package/docs/types/PriorityQueueComparator.html +197 -0
- package/docs/types/PriorityQueueDFSOrderPattern.html +177 -0
- package/docs/types/PriorityQueueOptions.html +191 -0
- package/docs/types/RBTreeNodeNested.html +182 -0
- package/docs/types/RBTreeOptions.html +180 -0
- package/docs/types/RestrictValById.html +177 -0
- package/docs/types/SegmentTreeNodeVal.html +177 -0
- package/docs/types/SpecifyOptional.html +184 -0
- package/docs/types/Thunk.html +185 -0
- package/docs/types/ToThunkFn.html +185 -0
- package/docs/types/TopologicalStatus.html +177 -0
- package/docs/types/TreeMultisetNodeNested.html +182 -0
- package/docs/types/TreeMultisetOptions.html +180 -0
- package/docs/types/TrlAsyncFn.html +190 -0
- package/docs/types/TrlFn.html +190 -0
- package/docs/types/Turning.html +177 -0
- package/docs/types/VertexId.html +177 -0
- package/docs/variables/THUNK_SYMBOL.html +177 -0
- package/jest.config.js +7 -0
- package/lib/data-structures/binary-tree/aa-tree.js +2 -0
- package/{dist → lib}/data-structures/binary-tree/abstract-binary-tree.d.ts +194 -22
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +1291 -0
- package/{dist → lib}/data-structures/binary-tree/avl-tree.d.ts +12 -12
- package/lib/data-structures/binary-tree/avl-tree.js +311 -0
- package/lib/data-structures/binary-tree/b-tree.js +2 -0
- package/lib/data-structures/binary-tree/binary-indexed-tree.js +69 -0
- package/lib/data-structures/binary-tree/binary-tree.js +35 -0
- package/{dist → lib}/data-structures/binary-tree/bst.d.ts +19 -8
- package/lib/data-structures/binary-tree/bst.js +551 -0
- package/lib/data-structures/binary-tree/index.js +12 -0
- package/{dist → lib}/data-structures/binary-tree/rb-tree.d.ts +0 -6
- package/lib/data-structures/binary-tree/rb-tree.js +22 -0
- package/lib/data-structures/binary-tree/segment-tree.js +210 -0
- package/lib/data-structures/binary-tree/splay-tree.js +2 -0
- package/{dist → lib}/data-structures/binary-tree/tree-multiset.d.ts +20 -23
- package/lib/data-structures/binary-tree/tree-multiset.js +673 -0
- package/lib/data-structures/binary-tree/two-three-tree.js +2 -0
- package/lib/data-structures/graph/abstract-graph.js +918 -0
- package/lib/data-structures/graph/directed-graph.js +416 -0
- package/lib/data-structures/graph/index.js +4 -0
- package/lib/data-structures/graph/map-graph.js +105 -0
- package/lib/data-structures/graph/undirected-graph.js +246 -0
- package/lib/data-structures/hash/coordinate-map.js +61 -0
- package/lib/data-structures/hash/coordinate-set.js +51 -0
- package/lib/data-structures/hash/hash-table.js +2 -0
- package/lib/data-structures/hash/index.js +6 -0
- package/lib/data-structures/hash/pair.js +2 -0
- package/lib/data-structures/hash/tree-map.js +2 -0
- package/lib/data-structures/hash/tree-set.js +2 -0
- package/lib/data-structures/heap/heap.js +152 -0
- package/lib/data-structures/heap/index.js +3 -0
- package/lib/data-structures/heap/max-heap.js +26 -0
- package/lib/data-structures/heap/min-heap.js +27 -0
- package/lib/data-structures/index.js +11 -0
- package/{dist → lib}/data-structures/linked-list/doubly-linked-list.d.ts +5 -5
- package/lib/data-structures/linked-list/doubly-linked-list.js +521 -0
- package/lib/data-structures/linked-list/index.js +3 -0
- package/{dist → lib}/data-structures/linked-list/singly-linked-list.d.ts +6 -5
- package/lib/data-structures/linked-list/singly-linked-list.js +443 -0
- package/lib/data-structures/linked-list/skip-linked-list.js +2 -0
- package/lib/data-structures/matrix/index.js +4 -0
- package/lib/data-structures/matrix/matrix.js +24 -0
- package/lib/data-structures/matrix/matrix2d.js +195 -0
- package/lib/data-structures/matrix/navigator.js +101 -0
- package/lib/data-structures/matrix/vector2d.js +287 -0
- package/lib/data-structures/priority-queue/index.js +3 -0
- package/lib/data-structures/priority-queue/max-priority-queue.js +39 -0
- package/lib/data-structures/priority-queue/min-priority-queue.js +40 -0
- package/lib/data-structures/priority-queue/priority-queue.js +317 -0
- package/{dist → lib}/data-structures/queue/deque.d.ts +45 -0
- package/lib/data-structures/queue/deque.js +270 -0
- package/lib/data-structures/queue/index.js +2 -0
- package/{dist → lib}/data-structures/queue/queue.d.ts +47 -13
- package/lib/data-structures/queue/queue.js +165 -0
- package/lib/data-structures/stack/index.js +1 -0
- package/lib/data-structures/stack/stack.js +87 -0
- package/lib/data-structures/tree/index.js +1 -0
- package/lib/data-structures/tree/tree.js +56 -0
- package/lib/data-structures/trie/index.js +1 -0
- package/lib/data-structures/trie/trie.js +205 -0
- package/lib/index.js +4 -0
- package/{dist → lib}/interfaces/avl-tree.d.ts +1 -9
- package/lib/interfaces/binary-tree.d.ts +4 -0
- package/{dist → lib}/interfaces/bst.d.ts +1 -2
- package/lib/interfaces/heap.js +1 -0
- package/lib/interfaces/index.js +15 -0
- package/lib/interfaces/navigator.d.ts +1 -0
- package/lib/interfaces/navigator.js +1 -0
- package/lib/interfaces/priority-queue.d.ts +1 -0
- package/lib/interfaces/priority-queue.js +1 -0
- package/{dist → lib}/interfaces/rb-tree.d.ts +1 -2
- package/lib/interfaces/rb-tree.js +1 -0
- package/lib/interfaces/segment-tree.d.ts +1 -0
- package/lib/interfaces/segment-tree.js +1 -0
- package/lib/interfaces/singly-linked-list.d.ts +1 -0
- package/lib/interfaces/singly-linked-list.js +1 -0
- package/lib/interfaces/tree-multiset.d.ts +5 -0
- package/lib/interfaces/tree-multiset.js +1 -0
- package/lib/interfaces/undirected-graph.js +1 -0
- package/{dist → lib}/types/data-structures/abstract-binary-tree.d.ts +1 -1
- package/lib/types/data-structures/abstract-binary-tree.js +22 -0
- package/lib/types/data-structures/abstract-graph.js +1 -0
- package/{dist → lib}/types/data-structures/avl-tree.d.ts +1 -1
- package/lib/types/data-structures/avl-tree.js +1 -0
- package/lib/types/data-structures/binary-tree.js +1 -0
- package/lib/types/data-structures/bst.js +6 -0
- package/lib/types/data-structures/directed-graph.js +6 -0
- package/lib/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/lib/types/data-structures/doubly-linked-list.js +1 -0
- package/lib/types/data-structures/heap.js +1 -0
- package/lib/types/data-structures/index.js +15 -0
- package/lib/types/data-structures/map-graph.js +1 -0
- package/lib/types/data-structures/navigator.js +1 -0
- package/lib/types/data-structures/priority-queue.js +1 -0
- package/lib/types/data-structures/rb-tree.js +5 -0
- package/lib/types/data-structures/segment-tree.js +1 -0
- package/lib/types/data-structures/singly-linked-list.d.ts +1 -0
- package/lib/types/data-structures/singly-linked-list.js +1 -0
- package/lib/types/data-structures/tree-multiset.js +1 -0
- package/lib/types/helpers.d.ts +1 -0
- package/lib/types/helpers.js +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/utils/index.js +2 -0
- package/{dist → lib}/types/utils/utils.d.ts +1 -1
- package/lib/types/utils/utils.js +1 -0
- package/{dist → lib}/types/utils/validate-type.d.ts +1 -1
- package/lib/types/utils/validate-type.js +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/utils.js +57 -0
- package/package.json +150 -56
- package/rename_clear_files.sh +29 -0
- package/test/integration/avl-tree.test.ts +111 -0
- package/test/integration/bst.test.ts +371 -0
- package/test/integration/heap.test.js +19 -0
- package/test/integration/index.html +44 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +111 -0
- package/test/unit/data-structures/binary-tree/bst.test.ts +371 -0
- package/test/unit/data-structures/binary-tree/overall.test.ts +57 -0
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +405 -0
- package/test/unit/data-structures/graph/abstract-graph.test.ts +5 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +517 -0
- package/test/unit/data-structures/graph/index.ts +2 -0
- package/test/unit/data-structures/graph/map-graph.test.ts +46 -0
- package/test/unit/data-structures/graph/overall.test.ts +50 -0
- package/test/unit/data-structures/graph/undirected-graph.test.ts +60 -0
- package/test/unit/data-structures/heap/heap.test.ts +56 -0
- package/test/unit/data-structures/heap/max-heap.test.ts +42 -0
- package/test/unit/data-structures/heap/min-heap.test.ts +81 -0
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +365 -0
- package/test/unit/data-structures/linked-list/index.ts +4 -0
- package/test/unit/data-structures/linked-list/linked-list.test.ts +37 -0
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +401 -0
- package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +108 -0
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +105 -0
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +27 -0
- package/test/unit/data-structures/queue/queue.test.ts +36 -0
- package/test/utils/index.ts +2 -0
- package/test/utils/magnitude.ts +21 -0
- package/test/utils/number.ts +3 -0
- package/tsconfig.build.json +33 -0
- package/tsconfig.json +38 -0
- package/umd/bundle.min.js +3 -0
- package/umd/bundle.min.js.map +1 -0
- package/webpack.config.js +28 -0
- package/dist/bundle.js +0 -2
- package/dist/interfaces/binary-tree.d.ts +0 -6
- package/dist/interfaces/tree-multiset.d.ts +0 -7
- /package/{dist → lib}/data-structures/binary-tree/aa-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/b-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/binary-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/splay-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/two-three-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/directed-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/map-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/undirected-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/coordinate-map.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/coordinate-set.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/hash-table.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/pair.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/tree-map.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/tree-set.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/max-heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/min-heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/linked-list/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/linked-list/skip-linked-list.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/matrix.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/matrix2d.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/navigator.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/vector2d.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/queue/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/stack/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/stack/stack.d.ts +0 -0
- /package/{dist → lib}/data-structures/tree/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/tree/tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/trie/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/trie/trie.d.ts +0 -0
- /package/{dist → lib}/index.d.ts +0 -0
- /package/{dist → lib}/interfaces/abstract-binary-tree.d.ts +0 -0
- /package/{dist/interfaces/doubly-linked-list.d.ts → lib/interfaces/abstract-binary-tree.js} +0 -0
- /package/{dist → lib}/interfaces/abstract-graph.d.ts +0 -0
- /package/{dist/interfaces/heap.d.ts → lib/interfaces/abstract-graph.js} +0 -0
- /package/{dist/interfaces/navigator.d.ts → lib/interfaces/avl-tree.js} +0 -0
- /package/{dist/interfaces/priority-queue.d.ts → lib/interfaces/binary-tree.js} +0 -0
- /package/{dist/interfaces/segment-tree.d.ts → lib/interfaces/bst.js} +0 -0
- /package/{dist → lib}/interfaces/directed-graph.d.ts +0 -0
- /package/{dist/interfaces/singly-linked-list.d.ts → lib/interfaces/directed-graph.js} +0 -0
- /package/{dist/types/data-structures → lib/interfaces}/doubly-linked-list.d.ts +0 -0
- /package/{dist/types/data-structures/singly-linked-list.d.ts → lib/interfaces/doubly-linked-list.js} +0 -0
- /package/{dist/types/helpers.d.ts → lib/interfaces/heap.d.ts} +0 -0
- /package/{dist → lib}/interfaces/index.d.ts +0 -0
- /package/{dist → lib}/interfaces/undirected-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/abstract-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/binary-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/bst.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/directed-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/heap.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/index.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/map-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/navigator.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/priority-queue.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/rb-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/segment-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/tree-multiset.d.ts +0 -0
- /package/{dist → lib}/types/index.d.ts +0 -0
- /package/{dist → lib}/types/utils/index.d.ts +0 -0
- /package/{dist → lib}/utils/index.d.ts +0 -0
- /package/{dist → lib}/utils/utils.d.ts +0 -0
- /package/{dist/bundle.js.LICENSE.txt → umd/bundle.min.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {MaxHeap, MinHeap} from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('Heap Operation Test', () => {
|
|
4
|
+
it('should numeric heap work well', function () {
|
|
5
|
+
const minNumHeap = new MinHeap<number>();
|
|
6
|
+
minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9);
|
|
7
|
+
expect(minNumHeap.has(1)).toBe(true);
|
|
8
|
+
expect(minNumHeap.has(2)).toBe(true);
|
|
9
|
+
expect(minNumHeap.poll()).toBe(0);
|
|
10
|
+
expect(minNumHeap.poll()).toBe(1);
|
|
11
|
+
expect(minNumHeap.peek()).toBe(2);
|
|
12
|
+
expect(!minNumHeap.has(1));
|
|
13
|
+
expect(minNumHeap.has(2));
|
|
14
|
+
const arrFromHeap = minNumHeap.toArray();
|
|
15
|
+
expect(arrFromHeap.length).toBe(4);
|
|
16
|
+
expect(arrFromHeap[0]).toBe(2);
|
|
17
|
+
expect(arrFromHeap[1]).toBe(5);
|
|
18
|
+
expect(arrFromHeap[2]).toBe(9);
|
|
19
|
+
expect(arrFromHeap[3]).toBe(6);
|
|
20
|
+
expect(minNumHeap.sort()).toEqual([2, 5, 6, 9]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should object heap work well', function () {
|
|
24
|
+
const minHeap = new MinHeap<{ a: string }>();
|
|
25
|
+
minHeap.add(1, {a: 'a1'});
|
|
26
|
+
minHeap.add(6, {a: 'a6'});
|
|
27
|
+
minHeap.add(2, {a: 'a2'});
|
|
28
|
+
minHeap.add(0, {a: 'a0'});
|
|
29
|
+
|
|
30
|
+
expect(minHeap.peek()).toEqual({a: 'a0'});
|
|
31
|
+
expect(minHeap.toArray()).toEqual(([{'a': 'a0'}, {'a': 'a1'}, {'a': 'a2'}, {'a': 'a6'}]));
|
|
32
|
+
let i = 0;
|
|
33
|
+
const expectPolled = [{'a': 'a0'}, {'a': 'a1'}, {'a': 'a2'}, {'a': 'a6'}];
|
|
34
|
+
while (minHeap.size > 0) {
|
|
35
|
+
expect(minHeap.poll()).toEqual(expectPolled[i]);
|
|
36
|
+
i++;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const maxHeap = new MaxHeap<{ a: string }>();
|
|
40
|
+
maxHeap.add(1, {a: 'a1'});
|
|
41
|
+
maxHeap.add(6, {a: 'a6'});
|
|
42
|
+
maxHeap.add(5, {a: 'a5'});
|
|
43
|
+
maxHeap.add(2, {a: 'a2'});
|
|
44
|
+
maxHeap.add(0, {a: 'a0'});
|
|
45
|
+
maxHeap.add(9, {a: 'a9'});
|
|
46
|
+
expect(maxHeap.peek()).toEqual({'a': 'a9'});
|
|
47
|
+
expect(maxHeap.toArray()).toEqual([{'a': 'a9'}, {'a': 'a2'}, {'a': 'a6'}, {'a': 'a1'}, {'a': 'a0'}, {'a': 'a5'}]);
|
|
48
|
+
const maxExpectPolled = [{'a': 'a9'}, {'a': 'a6'}, {'a': 'a5'}, {'a': 'a2'}, {'a': 'a1'}, {'a': 'a0'}];
|
|
49
|
+
let maxI = 0;
|
|
50
|
+
while (maxHeap.size > 0) {
|
|
51
|
+
expect(maxHeap.poll()).toEqual(maxExpectPolled[maxI]);
|
|
52
|
+
maxI++;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {HeapItem, MaxHeap} from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('MaxHeap Operation Test', () => {
|
|
4
|
+
|
|
5
|
+
it('should object Max Heap operations be proper', function () {
|
|
6
|
+
const maxHeap = new MaxHeap<{ keyA: string }>();
|
|
7
|
+
const myObj1 = {keyA: 'a1'}, myObj6 = {keyA: 'a6'}, myObj5 = {keyA: 'a5'}, myObj2 = {keyA: 'a2'},
|
|
8
|
+
myObj0 = {keyA: 'a0'}, myObj9 = {keyA: 'a9'};
|
|
9
|
+
maxHeap.add(1, myObj1);
|
|
10
|
+
expect(maxHeap.has(myObj1)).toBe(true);
|
|
11
|
+
expect(maxHeap.has(myObj9)).toBe(false);
|
|
12
|
+
maxHeap.add(6, myObj6);
|
|
13
|
+
expect(maxHeap.has(myObj6)).toBe(true);
|
|
14
|
+
maxHeap.add(5, myObj5);
|
|
15
|
+
expect(maxHeap.has(myObj5)).toBe(true);
|
|
16
|
+
maxHeap.add(2, myObj2);
|
|
17
|
+
expect(maxHeap.has(myObj2)).toBe(true);
|
|
18
|
+
expect(maxHeap.has(myObj6)).toBe(true);
|
|
19
|
+
maxHeap.add(0, myObj0);
|
|
20
|
+
expect(maxHeap.has(myObj0)).toBe(true);
|
|
21
|
+
expect(maxHeap.has(myObj9)).toBe(false);
|
|
22
|
+
maxHeap.add(9, myObj9);
|
|
23
|
+
expect(maxHeap.has(myObj9)).toBe(true);
|
|
24
|
+
|
|
25
|
+
const peek9 = maxHeap.peek(true);
|
|
26
|
+
peek9 && peek9.val && expect(peek9.val.keyA).toBe('a9');
|
|
27
|
+
|
|
28
|
+
const heapToArr = maxHeap.toArray(true);
|
|
29
|
+
expect(heapToArr.map(item => item?.val?.keyA)).toEqual(['a9', 'a2', 'a6', 'a1', 'a0', 'a5']);
|
|
30
|
+
|
|
31
|
+
const values = ['a9', 'a6', 'a5', 'a2', 'a1', 'a0'];
|
|
32
|
+
let i = 0;
|
|
33
|
+
while (maxHeap.size > 0) {
|
|
34
|
+
const polled = maxHeap.poll(true);
|
|
35
|
+
expect(polled).toBeInstanceOf(HeapItem);
|
|
36
|
+
polled && expect(polled.val).toHaveProperty('keyA');
|
|
37
|
+
polled && polled.val && expect(polled.val.keyA).toBe(values[i]);
|
|
38
|
+
i++;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {HeapItem, MinHeap} from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('MinHeap Operation Test', () => {
|
|
4
|
+
|
|
5
|
+
it('should numeric Min Heap operations be proper', function () {
|
|
6
|
+
const minNumHeap = new MinHeap<number>();
|
|
7
|
+
expect(minNumHeap).toBeInstanceOf(MinHeap);
|
|
8
|
+
|
|
9
|
+
minNumHeap.add(1);
|
|
10
|
+
expect(minNumHeap.has(1)).toBe(true);
|
|
11
|
+
minNumHeap.add(6);
|
|
12
|
+
expect(minNumHeap.has(2)).toBe(false);
|
|
13
|
+
expect(minNumHeap.has(6)).toBe(true);
|
|
14
|
+
minNumHeap.add(2);
|
|
15
|
+
expect(minNumHeap.has(2)).toBe(true);
|
|
16
|
+
minNumHeap.add(0);
|
|
17
|
+
expect(minNumHeap.has(0)).toBe(true);
|
|
18
|
+
minNumHeap.add(5);
|
|
19
|
+
expect(minNumHeap.has(5)).toBe(true);
|
|
20
|
+
minNumHeap.add(9);
|
|
21
|
+
expect(minNumHeap.has(9)).toBe(true);
|
|
22
|
+
expect(minNumHeap.size).toBe(6);
|
|
23
|
+
|
|
24
|
+
const poll1 = minNumHeap.poll(true);
|
|
25
|
+
expect(poll1).toBeInstanceOf(HeapItem)
|
|
26
|
+
poll1 instanceof HeapItem && expect(poll1.val).toBe(0);
|
|
27
|
+
|
|
28
|
+
const poll2 = minNumHeap.poll(true);
|
|
29
|
+
expect(poll2).toBeInstanceOf(HeapItem)
|
|
30
|
+
poll2 instanceof HeapItem && expect(poll2.val).toBe(1);
|
|
31
|
+
|
|
32
|
+
const peek1 = minNumHeap.peek(true);
|
|
33
|
+
expect(peek1).toBeInstanceOf(HeapItem)
|
|
34
|
+
peek1 instanceof HeapItem && expect(peek1.val).toBe(2);
|
|
35
|
+
|
|
36
|
+
const heapArray = minNumHeap.toArray(true);
|
|
37
|
+
expect(heapArray).toBeInstanceOf(Array);
|
|
38
|
+
expect(heapArray.map(item => item?.priority)).toEqual([2, 5, 9, 6]);
|
|
39
|
+
expect(minNumHeap.size).toBe(4);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should object Min Heap operations be proper', function () {
|
|
43
|
+
class MyObject {
|
|
44
|
+
keyA: string;
|
|
45
|
+
|
|
46
|
+
constructor(keyA: string) {
|
|
47
|
+
this.keyA = keyA;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const minObjHeap = new MinHeap<MyObject>();
|
|
52
|
+
|
|
53
|
+
const obj1 = new MyObject('a1'), obj6 = new MyObject('a6'), obj2 = new MyObject('a2'),
|
|
54
|
+
obj0 = new MyObject('a0');
|
|
55
|
+
minObjHeap.add(1, obj1);
|
|
56
|
+
expect(minObjHeap.has(obj1)).toBe(true);
|
|
57
|
+
expect(minObjHeap.has(obj6)).toBe(false);
|
|
58
|
+
minObjHeap.add(6, obj6);
|
|
59
|
+
expect(minObjHeap.has(obj6)).toBe(true);
|
|
60
|
+
minObjHeap.add(2, obj2);
|
|
61
|
+
expect(minObjHeap.has(obj2)).toBe(true);
|
|
62
|
+
minObjHeap.add(0, obj0);
|
|
63
|
+
expect(minObjHeap.has(obj0)).toBe(true);
|
|
64
|
+
|
|
65
|
+
const peek = minObjHeap.peek(true);
|
|
66
|
+
peek && peek.val && expect(peek.val.keyA).toBe('a0');
|
|
67
|
+
|
|
68
|
+
const heapToArr = minObjHeap.toArray(true);
|
|
69
|
+
expect(heapToArr.map(item => item?.val?.keyA)).toEqual(['a0', 'a1', 'a2', 'a6']);
|
|
70
|
+
|
|
71
|
+
const values = ['a0', 'a1', 'a2', 'a6'];
|
|
72
|
+
let i = 0;
|
|
73
|
+
while (minObjHeap.size > 0) {
|
|
74
|
+
const polled = minObjHeap.poll(true);
|
|
75
|
+
expect(polled).toBeInstanceOf(HeapItem);
|
|
76
|
+
polled && expect(polled.val).toBeInstanceOf(MyObject);
|
|
77
|
+
polled && polled.val && expect(polled.val.keyA).toBe(values[i]);
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import {DoublyLinkedList} from '../../../../src';
|
|
2
|
+
import {bigO, magnitude} from '../../../utils';
|
|
3
|
+
|
|
4
|
+
describe('DoublyLinkedList Operation Test', () => {
|
|
5
|
+
let list: DoublyLinkedList<number>;
|
|
6
|
+
let objectList: DoublyLinkedList<{ keyA: number }>;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
list = new DoublyLinkedList();
|
|
10
|
+
objectList = new DoublyLinkedList();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should initialize an empty list', () => {
|
|
14
|
+
expect(list.length).toBe(0);
|
|
15
|
+
expect(list.head).toBeNull();
|
|
16
|
+
expect(list.tail).toBeNull();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should push elements to the list', () => {
|
|
20
|
+
list.push(1);
|
|
21
|
+
list.push(2);
|
|
22
|
+
list.push(3);
|
|
23
|
+
expect(list.length).toBe(3);
|
|
24
|
+
expect(list.head!.val).toBe(1);
|
|
25
|
+
expect(list.tail!.val).toBe(3);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should pop elements from the end of the list', () => {
|
|
29
|
+
list.push(1);
|
|
30
|
+
list.push(2);
|
|
31
|
+
const poppedValue = list.pop();
|
|
32
|
+
expect(poppedValue).toBe(2);
|
|
33
|
+
expect(list.length).toBe(1);
|
|
34
|
+
expect(list.head!.val).toBe(1);
|
|
35
|
+
expect(list.tail!.val).toBe(1);
|
|
36
|
+
});
|
|
37
|
+
it('should insert elements at specific positions', () => {
|
|
38
|
+
list.push(1);
|
|
39
|
+
list.push(2);
|
|
40
|
+
list.push(3);
|
|
41
|
+
|
|
42
|
+
// Inserting at the beginning
|
|
43
|
+
list.insertAt(0, 0);
|
|
44
|
+
expect(list.length).toBe(4);
|
|
45
|
+
expect(list.getAt(0)).toBe(0);
|
|
46
|
+
expect(list.getAt(1)).toBe(1);
|
|
47
|
+
|
|
48
|
+
// Inserting in the middle
|
|
49
|
+
list.insertAt(2, 1.5);
|
|
50
|
+
expect(list.length).toBe(5);
|
|
51
|
+
expect(list.getAt(2)).toBe(1.5);
|
|
52
|
+
expect(list.getAt(3)).toBe(2);
|
|
53
|
+
|
|
54
|
+
// Inserting at the end
|
|
55
|
+
list.insertAt(5, 4);
|
|
56
|
+
expect(list.length).toBe(6);
|
|
57
|
+
expect(list.getAt(5)).toBe(4);
|
|
58
|
+
expect(list.tail!.val).toBe(4);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should delete elements at specific positions', () => {
|
|
62
|
+
list.push(1);
|
|
63
|
+
list.push(2);
|
|
64
|
+
list.push(3);
|
|
65
|
+
|
|
66
|
+
// Deleting from the beginning
|
|
67
|
+
const deletedValue = list.deleteAt(0);
|
|
68
|
+
expect(deletedValue).toBe(1);
|
|
69
|
+
expect(list.length).toBe(2);
|
|
70
|
+
expect(list.head!.val).toBe(2);
|
|
71
|
+
|
|
72
|
+
// Deleting from the middle
|
|
73
|
+
list.deleteAt(0); // Deleting the second element
|
|
74
|
+
expect(list.length).toBe(1);
|
|
75
|
+
expect(list.head!.val).toBe(3);
|
|
76
|
+
|
|
77
|
+
// Deleting from the end
|
|
78
|
+
list.deleteAt(0);
|
|
79
|
+
expect(list.length).toBe(0);
|
|
80
|
+
expect(list.head).toBeNull();
|
|
81
|
+
expect(list.tail).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should delete elements by value', () => {
|
|
85
|
+
list.push(1);
|
|
86
|
+
list.push(2);
|
|
87
|
+
list.push(3);
|
|
88
|
+
|
|
89
|
+
list.delete(2);
|
|
90
|
+
expect(list.length).toBe(2);
|
|
91
|
+
expect(list.head!.val).toBe(1);
|
|
92
|
+
expect(list.tail!.val).toBe(3);
|
|
93
|
+
|
|
94
|
+
list.delete(1);
|
|
95
|
+
expect(list.length).toBe(1);
|
|
96
|
+
expect(list.head!.val).toBe(3);
|
|
97
|
+
|
|
98
|
+
list.delete(3);
|
|
99
|
+
expect(list.length).toBe(0);
|
|
100
|
+
expect(list.head).toBeNull();
|
|
101
|
+
expect(list.tail).toBeNull();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should reverse the linked list', () => {
|
|
105
|
+
list.push(1);
|
|
106
|
+
list.push(2);
|
|
107
|
+
list.push(3);
|
|
108
|
+
|
|
109
|
+
list.reverse();
|
|
110
|
+
|
|
111
|
+
expect(list.toArray()).toEqual([3, 2, 1]);
|
|
112
|
+
expect(list.toArrayReverse()).toEqual([1, 2, 3]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should map elements using a callback function', () => {
|
|
116
|
+
list.push(1);
|
|
117
|
+
list.push(2);
|
|
118
|
+
list.push(3);
|
|
119
|
+
|
|
120
|
+
const mappedList = list.map((val) => val * 2);
|
|
121
|
+
|
|
122
|
+
expect(mappedList.toArray()).toEqual([2, 4, 6]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should filter elements using a callback function', () => {
|
|
126
|
+
list.push(1);
|
|
127
|
+
list.push(2);
|
|
128
|
+
list.push(3);
|
|
129
|
+
list.push(4);
|
|
130
|
+
|
|
131
|
+
const filteredList = list.filter((val) => val % 2 === 0);
|
|
132
|
+
|
|
133
|
+
expect(filteredList.toArray()).toEqual([2, 4]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should reduce elements using a callback function and an initial value', () => {
|
|
137
|
+
list.push(1);
|
|
138
|
+
list.push(2);
|
|
139
|
+
list.push(3);
|
|
140
|
+
list.push(4);
|
|
141
|
+
|
|
142
|
+
const sum = list.reduce((acc, val) => acc + val, 0);
|
|
143
|
+
|
|
144
|
+
expect(sum).toBe(10);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should insert an element after a specific value', () => {
|
|
148
|
+
list.push(1);
|
|
149
|
+
list.push(2);
|
|
150
|
+
list.push(3);
|
|
151
|
+
|
|
152
|
+
list.insertAfter(2, 2.5);
|
|
153
|
+
|
|
154
|
+
expect(list.toArray()).toEqual([1, 2, 2.5, 3]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should insert an element before a specific value', () => {
|
|
158
|
+
list.push(1);
|
|
159
|
+
list.push(2);
|
|
160
|
+
list.push(3);
|
|
161
|
+
|
|
162
|
+
list.insertBefore(2, 1.5);
|
|
163
|
+
|
|
164
|
+
expect(list.toArray()).toEqual([1, 1.5, 2, 3]);
|
|
165
|
+
});
|
|
166
|
+
it('should find the first element that satisfies a condition', () => {
|
|
167
|
+
list.push(1);
|
|
168
|
+
list.push(2);
|
|
169
|
+
list.push(3);
|
|
170
|
+
|
|
171
|
+
const found = list.find((val) => val % 2 === 0);
|
|
172
|
+
|
|
173
|
+
expect(found).toBe(2);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should find the index of an element', () => {
|
|
177
|
+
list.push(1);
|
|
178
|
+
list.push(2);
|
|
179
|
+
list.push(3);
|
|
180
|
+
|
|
181
|
+
const index = list.indexOf(2);
|
|
182
|
+
|
|
183
|
+
expect(index).toBe(1);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should find the last element that satisfies a condition', () => {
|
|
187
|
+
list.push(1);
|
|
188
|
+
list.push(2);
|
|
189
|
+
list.push(3);
|
|
190
|
+
list.push(4);
|
|
191
|
+
|
|
192
|
+
const lastEven = list.findLast((val) => val % 2 === 0);
|
|
193
|
+
|
|
194
|
+
expect(lastEven).toBe(4);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('should clear the linked list', () => {
|
|
198
|
+
list.push(1);
|
|
199
|
+
list.push(2);
|
|
200
|
+
list.push(3);
|
|
201
|
+
|
|
202
|
+
list.clear();
|
|
203
|
+
|
|
204
|
+
expect(list.length).toBe(0);
|
|
205
|
+
expect(list.head).toBe(null);
|
|
206
|
+
expect(list.tail).toBe(null);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should create a reversed array of values', () => {
|
|
210
|
+
list.push(1);
|
|
211
|
+
list.push(2);
|
|
212
|
+
list.push(3);
|
|
213
|
+
|
|
214
|
+
const reversedArray = list.toArrayReverse();
|
|
215
|
+
|
|
216
|
+
expect(reversedArray).toEqual([3, 2, 1]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should reverse the linked list', () => {
|
|
220
|
+
list.push(1);
|
|
221
|
+
list.push(2);
|
|
222
|
+
list.push(3);
|
|
223
|
+
|
|
224
|
+
list.reverse();
|
|
225
|
+
|
|
226
|
+
expect(list.toArray()).toEqual([3, 2, 1]);
|
|
227
|
+
expect(list.head?.val).toBe(3);
|
|
228
|
+
expect(list.tail?.val).toBe(1);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should iterate over each element and apply a callback', () => {
|
|
232
|
+
list.push(1);
|
|
233
|
+
list.push(2);
|
|
234
|
+
list.push(3);
|
|
235
|
+
|
|
236
|
+
const result: number[] = [];
|
|
237
|
+
list.forEach((val) => {
|
|
238
|
+
result.push(val * 2);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(result).toEqual([2, 4, 6]);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should create a new linked list by applying a mapping function', () => {
|
|
245
|
+
list.push(1);
|
|
246
|
+
list.push(2);
|
|
247
|
+
list.push(3);
|
|
248
|
+
|
|
249
|
+
const mappedList = list.map((val) => val * 2);
|
|
250
|
+
|
|
251
|
+
expect(mappedList.toArray()).toEqual([2, 4, 6]);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should create a new linked list by filtering elements', () => {
|
|
255
|
+
list.push(1);
|
|
256
|
+
list.push(2);
|
|
257
|
+
list.push(3);
|
|
258
|
+
list.push(4);
|
|
259
|
+
|
|
260
|
+
const filteredList = list.filter((val) => val % 2 === 0);
|
|
261
|
+
|
|
262
|
+
expect(filteredList.toArray()).toEqual([2, 4]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('should reduce the linked list to a single value', () => {
|
|
266
|
+
list.push(1);
|
|
267
|
+
list.push(2);
|
|
268
|
+
list.push(3);
|
|
269
|
+
|
|
270
|
+
const sum = list.reduce((acc, val) => acc + val, 0);
|
|
271
|
+
|
|
272
|
+
expect(sum).toBe(6);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('should insert a new value after an existing value', () => {
|
|
276
|
+
list.push(1);
|
|
277
|
+
list.push(2);
|
|
278
|
+
list.push(3);
|
|
279
|
+
|
|
280
|
+
const success = list.insertAfter(2, 4);
|
|
281
|
+
expect(success).toBe(true);
|
|
282
|
+
expect(list.toArray()).toEqual([1, 2, 4, 3]);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('should insert a new value before an existing value', () => {
|
|
286
|
+
list.push(1);
|
|
287
|
+
list.push(2);
|
|
288
|
+
list.push(3);
|
|
289
|
+
|
|
290
|
+
const success = list.insertBefore(2, 0);
|
|
291
|
+
expect(success).toBe(true);
|
|
292
|
+
expect(list.toArray()).toEqual([1, 0, 2, 3]);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('should not insert a new value after a non-existing value', () => {
|
|
296
|
+
list.push(1);
|
|
297
|
+
list.push(2);
|
|
298
|
+
list.push(3);
|
|
299
|
+
|
|
300
|
+
const success = list.insertAfter(4, 5);
|
|
301
|
+
expect(success).toBe(false);
|
|
302
|
+
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('should not insert a new value before a non-existing value', () => {
|
|
306
|
+
list.push(1);
|
|
307
|
+
list.push(2);
|
|
308
|
+
list.push(3);
|
|
309
|
+
|
|
310
|
+
const success = list.insertBefore(4, 0);
|
|
311
|
+
expect(success).toBe(false);
|
|
312
|
+
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('should insert and manipulate objects with numeric properties', () => {
|
|
316
|
+
const obj1 = {keyA: 10};
|
|
317
|
+
const obj2 = {keyA: 20};
|
|
318
|
+
const obj3 = {keyA: 30};
|
|
319
|
+
|
|
320
|
+
objectList.push(obj1);
|
|
321
|
+
objectList.push(obj2);
|
|
322
|
+
objectList.push(obj3);
|
|
323
|
+
|
|
324
|
+
expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
|
|
325
|
+
|
|
326
|
+
const newObj = {keyA: 25}; // Corrected newObj value
|
|
327
|
+
const insertSuccess = objectList.insertBefore(obj2, newObj);
|
|
328
|
+
expect(insertSuccess).toBe(true);
|
|
329
|
+
|
|
330
|
+
const findNode = objectList.findNode(newObj); // Use newObj instead of obj2
|
|
331
|
+
expect(findNode?.val).toEqual(newObj);
|
|
332
|
+
|
|
333
|
+
const deleted = objectList.delete(newObj); // Use newObj instead of obj2
|
|
334
|
+
expect(deleted).toBe(true);
|
|
335
|
+
|
|
336
|
+
const poppedObj = objectList.pop();
|
|
337
|
+
expect(poppedObj).toBe(obj3);
|
|
338
|
+
|
|
339
|
+
const shiftedObj = objectList.shift();
|
|
340
|
+
expect(shiftedObj).toBe(obj1);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
describe('DoublyLinkedList Performance Test', () => {
|
|
346
|
+
it('should the push and pop methods adhere to a time complexity of O(n) and executed correctly under large scale data', () => {
|
|
347
|
+
const list = new DoublyLinkedList<number>();
|
|
348
|
+
|
|
349
|
+
const startPushTime = performance.now();
|
|
350
|
+
for (let i = 0; i < magnitude.LINEAR; i++) {
|
|
351
|
+
list.unshift(i);
|
|
352
|
+
}
|
|
353
|
+
expect(performance.now() - startPushTime).toBeLessThan(bigO.LINEAR * 10);
|
|
354
|
+
|
|
355
|
+
expect(list.length).toBeGreaterThan(0);
|
|
356
|
+
const startPopTime = performance.now();
|
|
357
|
+
for (let i = 0; i < magnitude.LINEAR; i++) {
|
|
358
|
+
list.shift();
|
|
359
|
+
}
|
|
360
|
+
expect(performance.now() - startPopTime).toBeLessThan(bigO.LINEAR * 10);
|
|
361
|
+
|
|
362
|
+
expect(list.pop()).toBeUndefined();
|
|
363
|
+
expect(list.length).toBe(0);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {DoublyLinkedList, DoublyLinkedListNode, SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
|
|
2
|
+
import {bigO, magnitude} from '../../../utils';
|
|
3
|
+
|
|
4
|
+
describe('LinkedList Performance Test', () => {
|
|
5
|
+
it('should DoublyLinkedList insertBefore faster than SinglyLinkedList', () => {
|
|
6
|
+
const doublyList = new DoublyLinkedList<number>();
|
|
7
|
+
|
|
8
|
+
const startPushTime = performance.now();
|
|
9
|
+
let midNode: DoublyLinkedListNode | null = null;
|
|
10
|
+
const midIndex = Math.floor((magnitude.SQUARED) / 2);
|
|
11
|
+
for (let i = 0; i < magnitude.SQUARED; i++) {
|
|
12
|
+
doublyList.push(i);
|
|
13
|
+
if (i === midIndex) {
|
|
14
|
+
midNode = doublyList.findNode(i);
|
|
15
|
+
} else if (i > midIndex && midNode) {
|
|
16
|
+
doublyList.insertBefore(midNode, i);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const doublyListPushCost = performance.now() - startPushTime;
|
|
20
|
+
|
|
21
|
+
const singlyList = new SinglyLinkedList<number>();
|
|
22
|
+
let midSinglyNode: SinglyLinkedListNode | null = null;
|
|
23
|
+
|
|
24
|
+
const startSinglyPushTime = performance.now();
|
|
25
|
+
for (let i = 0; i < magnitude.SQUARED; i++) {
|
|
26
|
+
singlyList.push(i);
|
|
27
|
+
if (i === midIndex) {
|
|
28
|
+
midSinglyNode = singlyList.findNode(i);
|
|
29
|
+
} else if (i > midIndex && midSinglyNode) {
|
|
30
|
+
singlyList.insertBefore(midSinglyNode.val, i);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const singlyListPushCost = performance.now() - startSinglyPushTime;
|
|
35
|
+
expect(doublyListPushCost).toBeLessThan(bigO.SQUARED * 2);
|
|
36
|
+
});
|
|
37
|
+
});
|