data-structure-typed 1.40.0-rc → 1.41.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/.eslintrc.js +7 -5
- package/.github/workflows/ci.yml +2 -20
- package/.travis.yml +3 -4
- package/CHANGELOG.md +23 -1
- package/CONTRIBUTING.md +13 -0
- package/README.md +20 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +106 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +348 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +270 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +363 -0
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +1136 -0
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +167 -0
- package/dist/cjs/data-structures/binary-tree/bst.js +513 -0
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/cjs/data-structures/binary-tree/index.js +24 -0
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +97 -0
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +389 -0
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +67 -0
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +181 -0
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +126 -0
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +356 -0
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +313 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js +885 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -0
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +194 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +405 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/cjs/data-structures/graph/index.js.map +1 -0
- package/dist/cjs/data-structures/graph/map-graph.d.ts +73 -0
- package/dist/cjs/data-structures/graph/map-graph.js +94 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -0
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +120 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js +240 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/cjs/data-structures/hash/coordinate-map.d.ts +44 -0
- package/dist/cjs/data-structures/hash/coordinate-map.js +63 -0
- package/dist/cjs/data-structures/hash/coordinate-map.js.map +1 -0
- package/dist/cjs/data-structures/hash/coordinate-set.d.ts +36 -0
- package/dist/cjs/data-structures/hash/coordinate-set.js +53 -0
- package/dist/cjs/data-structures/hash/coordinate-set.js.map +1 -0
- package/dist/cjs/data-structures/hash/hash-map.d.ts +50 -0
- package/dist/cjs/data-structures/hash/hash-map.js +154 -0
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -0
- package/dist/cjs/data-structures/hash/hash-table.d.ts +103 -0
- package/dist/cjs/data-structures/hash/hash-table.js +237 -0
- package/dist/cjs/data-structures/hash/hash-table.js.map +1 -0
- package/dist/cjs/data-structures/hash/index.d.ts +6 -0
- package/dist/cjs/data-structures/hash/index.js +23 -0
- package/dist/cjs/data-structures/hash/index.js.map +1 -0
- package/dist/cjs/data-structures/hash/tree-map.js.map +1 -0
- package/dist/cjs/data-structures/hash/tree-set.js.map +1 -0
- package/dist/cjs/data-structures/heap/heap.d.ts +235 -0
- package/dist/cjs/data-structures/heap/heap.js +516 -0
- package/dist/cjs/data-structures/heap/heap.js.map +1 -0
- package/dist/cjs/data-structures/heap/index.js.map +1 -0
- package/dist/cjs/data-structures/heap/max-heap.d.ts +15 -0
- package/dist/cjs/data-structures/heap/max-heap.js +27 -0
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -0
- package/dist/cjs/data-structures/heap/min-heap.d.ts +15 -0
- package/dist/cjs/data-structures/heap/min-heap.js +27 -0
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -0
- package/dist/cjs/data-structures/index.js.map +1 -0
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +570 -0
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -0
- package/dist/cjs/data-structures/linked-list/index.js.map +1 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +232 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +534 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +80 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +188 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/cjs/data-structures/matrix/index.js.map +1 -0
- package/dist/cjs/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -0
- package/dist/cjs/data-structures/matrix/matrix2d.d.ts +107 -0
- package/dist/cjs/data-structures/matrix/matrix2d.js +200 -0
- package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -0
- package/dist/cjs/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -0
- package/dist/cjs/data-structures/matrix/vector2d.d.ts +200 -0
- package/dist/cjs/data-structures/matrix/vector2d.js +291 -0
- package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -0
- package/dist/cjs/data-structures/priority-queue/index.js.map +1 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +27 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +27 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +15 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +18 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -0
- package/dist/cjs/data-structures/queue/deque.d.ts +161 -0
- package/dist/cjs/data-structures/queue/deque.js +265 -0
- package/dist/cjs/data-structures/queue/deque.js.map +1 -0
- package/dist/cjs/data-structures/queue/index.js.map +1 -0
- package/dist/cjs/data-structures/queue/queue.d.ts +122 -0
- package/dist/cjs/data-structures/queue/queue.js +188 -0
- package/dist/cjs/data-structures/queue/queue.js.map +1 -0
- package/dist/cjs/data-structures/stack/index.js.map +1 -0
- package/dist/cjs/data-structures/stack/stack.d.ts +64 -0
- package/dist/cjs/data-structures/stack/stack.js +95 -0
- package/dist/cjs/data-structures/stack/stack.js.map +1 -0
- package/dist/cjs/data-structures/tree/index.js.map +1 -0
- package/dist/cjs/data-structures/tree/tree.d.ts +8 -0
- package/dist/cjs/data-structures/tree/tree.js +41 -0
- package/dist/cjs/data-structures/tree/tree.js.map +1 -0
- package/dist/cjs/data-structures/trie/index.js.map +1 -0
- package/dist/cjs/data-structures/trie/trie.d.ts +79 -0
- package/dist/cjs/data-structures/trie/trie.js +252 -0
- package/dist/cjs/data-structures/trie/trie.js.map +1 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces/binary-tree.d.ts +7 -0
- package/dist/cjs/interfaces/binary-tree.js.map +1 -0
- package/dist/cjs/interfaces/doubly-linked-list.js.map +1 -0
- package/dist/cjs/interfaces/graph.d.ts +5 -0
- package/dist/cjs/interfaces/graph.js +3 -0
- package/dist/cjs/interfaces/graph.js.map +1 -0
- package/dist/cjs/interfaces/heap.js.map +1 -0
- package/dist/cjs/interfaces/index.d.ts +8 -0
- package/dist/cjs/interfaces/index.js +25 -0
- package/dist/cjs/interfaces/index.js.map +1 -0
- package/dist/cjs/interfaces/navigator.js.map +1 -0
- package/dist/cjs/interfaces/priority-queue.js.map +1 -0
- package/dist/cjs/interfaces/segment-tree.js.map +1 -0
- package/dist/cjs/interfaces/singly-linked-list.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +25 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +7 -0
- package/dist/cjs/types/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +6 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js +23 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -0
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.js +14 -0
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/segment-tree.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-multiset.js.map +1 -0
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +10 -0
- package/dist/cjs/types/data-structures/graph/abstract-graph.js.map +1 -0
- package/dist/cjs/types/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/cjs/types/data-structures/graph/index.d.ts +3 -0
- package/dist/cjs/types/data-structures/graph/index.js +20 -0
- package/dist/cjs/types/data-structures/graph/index.js.map +1 -0
- package/dist/cjs/types/data-structures/graph/map-graph.js.map +1 -0
- package/dist/cjs/types/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/cjs/types/data-structures/hash/coordinate-map.js +3 -0
- package/dist/cjs/types/data-structures/hash/coordinate-map.js.map +1 -0
- package/dist/cjs/types/data-structures/hash/coordinate-set.js +3 -0
- package/dist/cjs/types/data-structures/hash/coordinate-set.js.map +1 -0
- package/dist/cjs/types/data-structures/hash/hash-map.js +3 -0
- package/dist/cjs/types/data-structures/hash/hash-map.js.map +1 -0
- package/dist/cjs/types/data-structures/hash/hash-table.js +3 -0
- package/dist/cjs/types/data-structures/hash/hash-table.js.map +1 -0
- package/dist/cjs/types/data-structures/hash/index.js +3 -0
- package/dist/cjs/types/data-structures/hash/index.js.map +1 -0
- package/dist/cjs/types/data-structures/hash/tree-map.js +3 -0
- package/dist/cjs/types/data-structures/hash/tree-map.js.map +1 -0
- package/dist/cjs/types/data-structures/hash/tree-set.js +3 -0
- package/dist/cjs/types/data-structures/hash/tree-set.js.map +1 -0
- package/dist/cjs/types/data-structures/heap/heap.js.map +1 -0
- package/dist/cjs/types/data-structures/heap/index.d.ts +1 -0
- package/dist/cjs/types/data-structures/heap/index.js +18 -0
- package/dist/cjs/types/data-structures/heap/index.js.map +1 -0
- package/dist/cjs/types/data-structures/heap/max-heap.js +3 -0
- package/dist/cjs/types/data-structures/heap/max-heap.js.map +1 -0
- package/dist/cjs/types/data-structures/heap/min-heap.js +3 -0
- package/dist/cjs/types/data-structures/heap/min-heap.js.map +1 -0
- package/dist/cjs/types/data-structures/index.d.ts +11 -0
- package/dist/cjs/types/data-structures/index.js +28 -0
- package/dist/cjs/types/data-structures/index.js.map +1 -0
- package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js.map +1 -0
- package/dist/cjs/types/data-structures/linked-list/index.d.ts +2 -0
- package/dist/cjs/types/data-structures/linked-list/index.js +19 -0
- package/dist/cjs/types/data-structures/linked-list/index.js.map +1 -0
- package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/cjs/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/cjs/types/data-structures/matrix/index.js +18 -0
- package/dist/cjs/types/data-structures/matrix/index.js.map +1 -0
- package/dist/cjs/types/data-structures/matrix/matrix.js +3 -0
- package/dist/cjs/types/data-structures/matrix/matrix.js.map +1 -0
- package/dist/cjs/types/data-structures/matrix/matrix2d.js +3 -0
- package/dist/cjs/types/data-structures/matrix/matrix2d.js.map +1 -0
- package/dist/cjs/types/data-structures/matrix/navigator.js.map +1 -0
- package/dist/cjs/types/data-structures/matrix/vector2d.js +3 -0
- package/dist/cjs/types/data-structures/matrix/vector2d.js.map +1 -0
- package/dist/cjs/types/data-structures/priority-queue/index.js +20 -0
- package/dist/cjs/types/data-structures/priority-queue/index.js.map +1 -0
- package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.js.map +1 -0
- package/dist/cjs/types/data-structures/queue/deque.js +3 -0
- package/dist/cjs/types/data-structures/queue/deque.js.map +1 -0
- package/dist/cjs/types/data-structures/queue/index.js +19 -0
- package/dist/cjs/types/data-structures/queue/index.js.map +1 -0
- package/dist/cjs/types/data-structures/queue/queue.js +3 -0
- package/dist/cjs/types/data-structures/queue/queue.js.map +1 -0
- package/dist/cjs/types/data-structures/stack/index.js +18 -0
- package/dist/cjs/types/data-structures/stack/index.js.map +1 -0
- package/dist/cjs/types/data-structures/stack/stack.js +3 -0
- package/dist/cjs/types/data-structures/stack/stack.js.map +1 -0
- package/dist/cjs/types/data-structures/tree/index.js +18 -0
- package/dist/cjs/types/data-structures/tree/index.js.map +1 -0
- package/dist/cjs/types/data-structures/tree/tree.js +3 -0
- package/dist/cjs/types/data-structures/tree/tree.js.map +1 -0
- package/dist/cjs/types/data-structures/trie/index.js +18 -0
- package/dist/cjs/types/data-structures/trie/index.js.map +1 -0
- package/dist/cjs/types/data-structures/trie/trie.js +3 -0
- package/dist/cjs/types/data-structures/trie/trie.js.map +1 -0
- package/dist/cjs/types/helpers.d.ts +8 -0
- package/dist/cjs/types/helpers.js +10 -0
- package/dist/cjs/types/helpers.js.map +1 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/utils/index.js.map +1 -0
- package/dist/cjs/types/utils/utils.js.map +1 -0
- package/dist/cjs/types/utils/validate-type.js.map +1 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/utils.d.ts +20 -0
- package/dist/cjs/utils/utils.js +74 -0
- package/dist/cjs/utils/utils.js.map +1 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +106 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +348 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +274 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +363 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +1147 -0
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +167 -0
- package/dist/mjs/data-structures/binary-tree/bst.js +509 -0
- package/dist/mjs/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/mjs/data-structures/binary-tree/index.js +23 -0
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +97 -0
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +393 -0
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +67 -0
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +182 -0
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +126 -0
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +356 -0
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +313 -0
- package/dist/mjs/data-structures/graph/abstract-graph.js +883 -0
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +194 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +406 -0
- package/dist/mjs/data-structures/graph/index.js +20 -0
- package/dist/mjs/data-structures/graph/map-graph.d.ts +73 -0
- package/dist/mjs/data-structures/graph/map-graph.js +96 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +120 -0
- package/dist/mjs/data-structures/graph/undirected-graph.js +239 -0
- package/dist/mjs/data-structures/hash/coordinate-map.d.ts +44 -0
- package/dist/mjs/data-structures/hash/coordinate-map.js +62 -0
- package/dist/mjs/data-structures/hash/coordinate-set.d.ts +36 -0
- package/dist/mjs/data-structures/hash/coordinate-set.js +52 -0
- package/dist/mjs/data-structures/hash/hash-map.d.ts +50 -0
- package/dist/mjs/data-structures/hash/hash-map.js +159 -0
- package/dist/mjs/data-structures/hash/hash-table.d.ts +103 -0
- package/dist/mjs/data-structures/hash/hash-table.js +243 -0
- package/dist/mjs/data-structures/hash/index.d.ts +6 -0
- package/dist/mjs/data-structures/hash/index.js +22 -0
- package/dist/mjs/data-structures/hash/tree-map.js +6 -0
- package/dist/mjs/data-structures/hash/tree-set.js +6 -0
- package/dist/mjs/data-structures/heap/heap.d.ts +235 -0
- package/dist/mjs/data-structures/heap/heap.js +525 -0
- package/dist/mjs/data-structures/heap/index.js +19 -0
- package/dist/mjs/data-structures/heap/max-heap.d.ts +15 -0
- package/dist/mjs/data-structures/heap/max-heap.js +26 -0
- package/dist/mjs/data-structures/heap/min-heap.d.ts +15 -0
- package/dist/mjs/data-structures/heap/min-heap.js +26 -0
- package/dist/mjs/data-structures/index.js +27 -0
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +573 -0
- package/dist/mjs/data-structures/linked-list/index.js +19 -0
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +232 -0
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +538 -0
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +80 -0
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +194 -0
- package/dist/mjs/data-structures/matrix/index.js +20 -0
- package/dist/mjs/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/mjs/data-structures/matrix/matrix.js +29 -0
- package/dist/mjs/data-structures/matrix/matrix2d.d.ts +107 -0
- package/dist/mjs/data-structures/matrix/matrix2d.js +200 -0
- package/dist/mjs/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/mjs/data-structures/matrix/navigator.js +113 -0
- package/dist/mjs/data-structures/matrix/vector2d.d.ts +200 -0
- package/dist/mjs/data-structures/matrix/vector2d.js +293 -0
- package/dist/mjs/data-structures/priority-queue/index.js +19 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +26 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +26 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +15 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +17 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +161 -0
- package/dist/mjs/data-structures/queue/deque.js +257 -0
- package/dist/mjs/data-structures/queue/index.js +18 -0
- package/dist/mjs/data-structures/queue/queue.d.ts +122 -0
- package/dist/mjs/data-structures/queue/queue.js +188 -0
- package/dist/mjs/data-structures/stack/index.js +17 -0
- package/dist/mjs/data-structures/stack/stack.d.ts +64 -0
- package/dist/mjs/data-structures/stack/stack.js +95 -0
- package/dist/mjs/data-structures/tree/index.js +17 -0
- package/dist/mjs/data-structures/tree/tree.d.ts +8 -0
- package/dist/mjs/data-structures/tree/tree.js +43 -0
- package/dist/mjs/data-structures/trie/index.js +17 -0
- package/dist/mjs/data-structures/trie/trie.d.ts +79 -0
- package/dist/mjs/data-structures/trie/trie.js +256 -0
- package/dist/mjs/index.js +20 -0
- package/dist/mjs/interfaces/binary-tree.d.ts +7 -0
- package/dist/mjs/interfaces/binary-tree.js +2 -0
- package/dist/mjs/interfaces/doubly-linked-list.js +2 -0
- package/dist/mjs/interfaces/graph.d.ts +5 -0
- package/dist/mjs/interfaces/graph.js +2 -0
- package/dist/mjs/interfaces/heap.js +2 -0
- package/dist/mjs/interfaces/index.d.ts +8 -0
- package/dist/mjs/interfaces/index.js +24 -0
- package/dist/mjs/interfaces/navigator.js +2 -0
- package/dist/mjs/interfaces/priority-queue.js +2 -0
- package/dist/mjs/interfaces/segment-tree.js +2 -0
- package/dist/mjs/interfaces/singly-linked-list.js +2 -0
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.js +2 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +24 -0
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +7 -0
- package/dist/mjs/types/data-structures/binary-tree/bst.js +2 -0
- package/dist/mjs/types/data-structures/binary-tree/index.d.ts +6 -0
- package/dist/mjs/types/data-structures/binary-tree/index.js +22 -0
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -0
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.js +13 -0
- package/dist/mjs/types/data-structures/binary-tree/segment-tree.js +2 -0
- package/dist/mjs/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
- package/dist/mjs/types/data-structures/binary-tree/tree-multiset.js +2 -0
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +10 -0
- package/dist/mjs/types/data-structures/graph/abstract-graph.js +2 -0
- package/dist/mjs/types/data-structures/graph/directed-graph.js +9 -0
- package/dist/mjs/types/data-structures/graph/index.d.ts +3 -0
- package/dist/mjs/types/data-structures/graph/index.js +19 -0
- package/dist/mjs/types/data-structures/graph/map-graph.js +2 -0
- package/dist/mjs/types/data-structures/graph/undirected-graph.js +2 -0
- package/dist/mjs/types/data-structures/hash/coordinate-map.js +2 -0
- package/dist/mjs/types/data-structures/hash/coordinate-set.js +2 -0
- package/dist/mjs/types/data-structures/hash/hash-map.js +2 -0
- package/dist/mjs/types/data-structures/hash/hash-table.js +2 -0
- package/dist/mjs/types/data-structures/hash/index.js +2 -0
- package/dist/mjs/types/data-structures/hash/tree-map.js +2 -0
- package/dist/mjs/types/data-structures/hash/tree-set.js +2 -0
- package/dist/mjs/types/data-structures/heap/heap.js +2 -0
- package/dist/mjs/types/data-structures/heap/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/heap/index.js +17 -0
- package/dist/mjs/types/data-structures/heap/max-heap.js +2 -0
- package/dist/mjs/types/data-structures/heap/min-heap.js +2 -0
- package/dist/mjs/types/data-structures/index.d.ts +11 -0
- package/dist/mjs/types/data-structures/index.js +27 -0
- package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.js +2 -0
- package/dist/mjs/types/data-structures/linked-list/index.d.ts +2 -0
- package/dist/mjs/types/data-structures/linked-list/index.js +18 -0
- package/dist/mjs/types/data-structures/linked-list/singly-linked-list.js +2 -0
- package/dist/mjs/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
- package/dist/mjs/types/data-structures/linked-list/skip-linked-list.js +2 -0
- package/dist/mjs/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/matrix/index.js +17 -0
- package/dist/mjs/types/data-structures/matrix/matrix.d.ts +1 -0
- package/dist/mjs/types/data-structures/matrix/matrix.js +2 -0
- package/dist/mjs/types/data-structures/matrix/matrix2d.d.ts +1 -0
- package/dist/mjs/types/data-structures/matrix/matrix2d.js +2 -0
- package/dist/mjs/types/data-structures/matrix/navigator.js +2 -0
- package/dist/mjs/types/data-structures/matrix/vector2d.d.ts +1 -0
- package/dist/mjs/types/data-structures/matrix/vector2d.js +2 -0
- package/dist/mjs/types/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/mjs/types/data-structures/priority-queue/index.js +19 -0
- package/dist/mjs/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/mjs/types/data-structures/priority-queue/max-priority-queue.js +2 -0
- package/dist/mjs/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/mjs/types/data-structures/priority-queue/min-priority-queue.js +2 -0
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.js +2 -0
- package/dist/mjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/mjs/types/data-structures/queue/deque.js +2 -0
- package/dist/mjs/types/data-structures/queue/index.d.ts +2 -0
- package/dist/mjs/types/data-structures/queue/index.js +18 -0
- package/dist/mjs/types/data-structures/queue/queue.d.ts +1 -0
- package/dist/mjs/types/data-structures/queue/queue.js +2 -0
- package/dist/mjs/types/data-structures/stack/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/stack/index.js +17 -0
- package/dist/mjs/types/data-structures/stack/stack.d.ts +1 -0
- package/dist/mjs/types/data-structures/stack/stack.js +2 -0
- package/dist/mjs/types/data-structures/tree/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/tree/index.js +17 -0
- package/dist/mjs/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/mjs/types/data-structures/tree/tree.js +2 -0
- package/dist/mjs/types/data-structures/trie/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/trie/index.js +17 -0
- package/dist/mjs/types/data-structures/trie/trie.d.ts +1 -0
- package/dist/mjs/types/data-structures/trie/trie.js +2 -0
- package/dist/mjs/types/helpers.d.ts +8 -0
- package/dist/mjs/types/helpers.js +9 -0
- package/dist/mjs/types/index.js +19 -0
- package/dist/mjs/types/utils/index.js +18 -0
- package/dist/mjs/types/utils/utils.js +2 -0
- package/dist/mjs/types/utils/validate-type.js +2 -0
- package/dist/mjs/utils/index.js +17 -0
- package/dist/mjs/utils/utils.d.ts +20 -0
- package/dist/mjs/utils/utils.js +64 -0
- package/dist/umd/data-structure-typed.min.js +27 -0
- package/dist/umd/data-structure-typed.min.js.map +1 -0
- package/package.json +28 -22
- package/src/data-structures/binary-tree/avl-tree.ts +88 -74
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +265 -35
- package/src/data-structures/binary-tree/binary-tree.ts +1263 -26
- package/src/data-structures/binary-tree/bst.ts +217 -237
- package/src/data-structures/binary-tree/index.ts +0 -5
- package/src/data-structures/binary-tree/rb-tree.ts +416 -356
- package/src/data-structures/binary-tree/segment-tree.ts +25 -92
- package/src/data-structures/binary-tree/tree-multiset.ts +113 -422
- package/src/data-structures/graph/abstract-graph.ts +169 -214
- package/src/data-structures/graph/directed-graph.ts +105 -126
- package/src/data-structures/graph/map-graph.ts +29 -57
- package/src/data-structures/graph/undirected-graph.ts +67 -82
- package/src/data-structures/hash/coordinate-map.ts +0 -4
- package/src/data-structures/hash/coordinate-set.ts +0 -4
- package/src/data-structures/hash/hash-map.ts +65 -83
- package/src/data-structures/hash/hash-table.ts +109 -118
- package/src/data-structures/hash/index.ts +0 -1
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/heap/heap.ts +505 -128
- package/src/data-structures/heap/max-heap.ts +16 -21
- package/src/data-structures/heap/min-heap.ts +16 -22
- package/src/data-structures/linked-list/doubly-linked-list.ts +143 -174
- package/src/data-structures/linked-list/singly-linked-list.ts +174 -99
- package/src/data-structures/linked-list/skip-linked-list.ts +104 -49
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/matrix2d.ts +12 -14
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/matrix/vector2d.ts +2 -3
- package/src/data-structures/priority-queue/max-priority-queue.ts +15 -46
- package/src/data-structures/priority-queue/min-priority-queue.ts +15 -47
- package/src/data-structures/priority-queue/priority-queue.ts +7 -350
- package/src/data-structures/queue/deque.ts +62 -77
- package/src/data-structures/queue/queue.ts +39 -21
- package/src/data-structures/stack/stack.ts +13 -9
- package/src/data-structures/tree/tree.ts +10 -38
- package/src/data-structures/trie/trie.ts +108 -71
- package/src/interfaces/binary-tree.ts +7 -4
- package/src/interfaces/graph.ts +7 -0
- package/src/interfaces/index.ts +1 -8
- package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
- package/src/types/data-structures/binary-tree/bst.ts +11 -0
- package/src/types/data-structures/binary-tree/index.ts +6 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
- package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
- package/src/types/data-structures/graph/abstract-graph.ts +11 -0
- package/src/types/data-structures/graph/index.ts +3 -0
- package/src/types/data-structures/graph/undirected-graph.ts +1 -0
- package/src/types/data-structures/hash/coordinate-map.ts +1 -0
- package/src/types/data-structures/hash/coordinate-set.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +1 -0
- package/src/types/data-structures/hash/hash-table.ts +1 -0
- package/src/types/data-structures/hash/tree-map.ts +1 -0
- package/src/types/data-structures/hash/tree-set.ts +1 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/heap/index.ts +1 -0
- package/src/types/data-structures/heap/max-heap.ts +1 -0
- package/src/types/data-structures/heap/min-heap.ts +1 -0
- package/src/types/data-structures/index.ts +8 -13
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/index.ts +2 -0
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +1 -0
- package/src/types/data-structures/matrix/matrix2d.ts +1 -0
- package/src/types/data-structures/matrix/navigator.ts +14 -0
- package/src/types/data-structures/matrix/vector2d.ts +1 -0
- package/src/types/data-structures/priority-queue/index.ts +3 -0
- package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/data-structures/queue/deque.ts +1 -0
- package/src/types/data-structures/queue/index.ts +2 -0
- package/src/types/data-structures/queue/queue.ts +1 -0
- package/src/types/data-structures/stack/index.ts +1 -0
- package/src/types/data-structures/stack/stack.ts +1 -0
- package/src/types/data-structures/tree/index.ts +1 -0
- package/src/types/data-structures/tree/tree.ts +1 -0
- package/src/types/data-structures/trie/index.ts +1 -0
- package/src/types/data-structures/trie/trie.ts +1 -0
- package/src/types/helpers.ts +11 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
- package/src/utils/utils.ts +7 -0
- package/test/config.js +4 -0
- package/test/config.ts +1 -0
- package/test/integration/avl-tree.test.ts +24 -22
- package/test/integration/bst.test.ts +52 -47
- package/test/integration/index.html +3 -4
- package/test/types/index.js +29 -0
- package/test/types/utils/big-o.js +2 -0
- package/test/types/utils/big-o.ts +1 -0
- package/test/types/utils/index.js +29 -0
- package/test/types/utils/index.ts +1 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +184 -23
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +320 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +393 -40
- package/test/unit/data-structures/binary-tree/bst.test.ts +506 -48
- package/test/unit/data-structures/binary-tree/overall.test.ts +8 -7
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +240 -41
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +296 -215
- package/test/unit/data-structures/graph/abstract-graph.test.ts +97 -2
- package/test/unit/data-structures/graph/directed-graph.test.ts +76 -31
- package/test/unit/data-structures/graph/map-graph.test.ts +93 -12
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +93 -3
- package/test/unit/data-structures/hash/coordinate-map.test.ts +20 -0
- package/test/unit/data-structures/hash/coordinate-set.test.ts +25 -0
- package/test/unit/data-structures/hash/hash-map.test.ts +2 -3
- package/test/unit/data-structures/hash/hash-table.test.ts +10 -8
- package/test/unit/data-structures/heap/heap.test.ts +218 -20
- package/test/unit/data-structures/heap/max-heap.test.ts +50 -42
- package/test/unit/data-structures/heap/min-heap.test.ts +38 -68
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +86 -27
- package/test/unit/data-structures/linked-list/linked-list.test.ts +4 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +71 -27
- package/test/unit/data-structures/linked-list/skip-list.test.ts +33 -2
- package/test/unit/data-structures/matrix/matrix2d.test.ts +207 -0
- package/test/unit/data-structures/matrix/navigator.test.ts +167 -2
- package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +10 -11
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +14 -30
- package/test/unit/data-structures/queue/deque.test.ts +303 -23
- package/test/unit/data-structures/queue/queue.test.ts +52 -8
- package/test/unit/data-structures/tree/tree.test.ts +2 -2
- package/test/unit/data-structures/trie/trie.test.ts +743 -13
- package/test/utils/big-o.js +212 -0
- package/test/utils/big-o.ts +201 -0
- package/test/utils/index.js +30 -0
- package/test/utils/index.ts +1 -1
- package/test/utils/number.js +14 -0
- package/tsconfig-base.json +27 -0
- package/tsconfig-cjs.json +9 -0
- package/tsup.config.js +18 -0
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.LICENSE.txt +15 -0
- package/umd/bundle.min.js.map +1 -1
- package/dist/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/data-structures/binary-tree/aa-tree.js +0 -7
- package/dist/data-structures/binary-tree/aa-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +0 -527
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +0 -1199
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -94
- package/dist/data-structures/binary-tree/avl-tree.js +0 -336
- package/dist/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/data-structures/binary-tree/b-tree.js +0 -7
- package/dist/data-structures/binary-tree/b-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -46
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -74
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -31
- package/dist/data-structures/binary-tree/binary-tree.js +0 -41
- package/dist/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/bst.d.ts +0 -133
- package/dist/data-structures/binary-tree/bst.js +0 -554
- package/dist/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/data-structures/binary-tree/index.d.ts +0 -12
- package/dist/data-structures/binary-tree/index.js +0 -29
- package/dist/data-structures/binary-tree/index.js.map +0 -1
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -13
- package/dist/data-structures/binary-tree/rb-tree.js +0 -28
- package/dist/data-structures/binary-tree/rb-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -83
- package/dist/data-structures/binary-tree/segment-tree.js +0 -229
- package/dist/data-structures/binary-tree/segment-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/data-structures/binary-tree/splay-tree.js +0 -7
- package/dist/data-structures/binary-tree/splay-tree.js.map +0 -1
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +0 -209
- package/dist/data-structures/binary-tree/tree-multiset.js +0 -669
- package/dist/data-structures/binary-tree/tree-multiset.js.map +0 -1
- package/dist/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/data-structures/binary-tree/two-three-tree.js +0 -7
- package/dist/data-structures/binary-tree/two-three-tree.js.map +0 -1
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -332
- package/dist/data-structures/graph/abstract-graph.js +0 -925
- package/dist/data-structures/graph/abstract-graph.js.map +0 -1
- package/dist/data-structures/graph/directed-graph.d.ts +0 -200
- package/dist/data-structures/graph/directed-graph.js +0 -423
- package/dist/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/data-structures/graph/index.js.map +0 -1
- package/dist/data-structures/graph/map-graph.d.ts +0 -79
- package/dist/data-structures/graph/map-graph.js +0 -112
- package/dist/data-structures/graph/map-graph.js.map +0 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -127
- package/dist/data-structures/graph/undirected-graph.js +0 -253
- package/dist/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/data-structures/hash/coordinate-map.d.ts +0 -45
- package/dist/data-structures/hash/coordinate-map.js +0 -66
- package/dist/data-structures/hash/coordinate-map.js.map +0 -1
- package/dist/data-structures/hash/coordinate-set.d.ts +0 -37
- package/dist/data-structures/hash/coordinate-set.js +0 -56
- package/dist/data-structures/hash/coordinate-set.js.map +0 -1
- package/dist/data-structures/hash/hash-map.d.ts +0 -56
- package/dist/data-structures/hash/hash-map.js +0 -172
- package/dist/data-structures/hash/hash-map.js.map +0 -1
- package/dist/data-structures/hash/hash-table.d.ts +0 -106
- package/dist/data-structures/hash/hash-table.js +0 -246
- package/dist/data-structures/hash/hash-table.js.map +0 -1
- package/dist/data-structures/hash/index.d.ts +0 -7
- package/dist/data-structures/hash/index.js +0 -24
- package/dist/data-structures/hash/index.js.map +0 -1
- package/dist/data-structures/hash/pair.d.ts +0 -2
- package/dist/data-structures/hash/pair.js +0 -7
- package/dist/data-structures/hash/pair.js.map +0 -1
- package/dist/data-structures/hash/tree-map.js.map +0 -1
- package/dist/data-structures/hash/tree-set.js.map +0 -1
- package/dist/data-structures/heap/heap.d.ts +0 -83
- package/dist/data-structures/heap/heap.js +0 -158
- package/dist/data-structures/heap/heap.js.map +0 -1
- package/dist/data-structures/heap/index.js.map +0 -1
- package/dist/data-structures/heap/max-heap.d.ts +0 -23
- package/dist/data-structures/heap/max-heap.js +0 -31
- package/dist/data-structures/heap/max-heap.js.map +0 -1
- package/dist/data-structures/heap/min-heap.d.ts +0 -24
- package/dist/data-structures/heap/min-heap.js +0 -32
- package/dist/data-structures/heap/min-heap.js.map +0 -1
- package/dist/data-structures/index.js.map +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -234
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -584
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +0 -1
- package/dist/data-structures/linked-list/index.js.map +0 -1
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -157
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -449
- package/dist/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -61
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -143
- package/dist/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/data-structures/matrix/index.js.map +0 -1
- package/dist/data-structures/matrix/matrix.d.ts +0 -21
- package/dist/data-structures/matrix/matrix.js.map +0 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +0 -108
- package/dist/data-structures/matrix/matrix2d.js +0 -201
- package/dist/data-structures/matrix/matrix2d.js.map +0 -1
- package/dist/data-structures/matrix/navigator.d.ts +0 -52
- package/dist/data-structures/matrix/navigator.js.map +0 -1
- package/dist/data-structures/matrix/vector2d.d.ts +0 -201
- package/dist/data-structures/matrix/vector2d.js +0 -292
- package/dist/data-structures/matrix/vector2d.js.map +0 -1
- package/dist/data-structures/priority-queue/index.js.map +0 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -44
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -45
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -180
- package/dist/data-structures/priority-queue/priority-queue.js +0 -322
- package/dist/data-structures/priority-queue/priority-queue.js.map +0 -1
- package/dist/data-structures/queue/deque.d.ts +0 -165
- package/dist/data-structures/queue/deque.js +0 -277
- package/dist/data-structures/queue/deque.js.map +0 -1
- package/dist/data-structures/queue/index.js.map +0 -1
- package/dist/data-structures/queue/queue.d.ts +0 -107
- package/dist/data-structures/queue/queue.js +0 -171
- package/dist/data-structures/queue/queue.js.map +0 -1
- package/dist/data-structures/stack/index.js.map +0 -1
- package/dist/data-structures/stack/stack.d.ts +0 -63
- package/dist/data-structures/stack/stack.js +0 -92
- package/dist/data-structures/stack/stack.js.map +0 -1
- package/dist/data-structures/tree/index.js.map +0 -1
- package/dist/data-structures/tree/tree.d.ts +0 -14
- package/dist/data-structures/tree/tree.js +0 -61
- package/dist/data-structures/tree/tree.js.map +0 -1
- package/dist/data-structures/trie/index.js.map +0 -1
- package/dist/data-structures/trie/trie.d.ts +0 -61
- package/dist/data-structures/trie/trie.js +0 -211
- package/dist/data-structures/trie/trie.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interfaces/abstract-binary-tree.d.ts +0 -7
- package/dist/interfaces/abstract-binary-tree.js +0 -3
- package/dist/interfaces/abstract-binary-tree.js.map +0 -1
- package/dist/interfaces/abstract-graph.d.ts +0 -5
- package/dist/interfaces/abstract-graph.js.map +0 -1
- package/dist/interfaces/avl-tree.d.ts +0 -7
- package/dist/interfaces/avl-tree.js.map +0 -1
- package/dist/interfaces/binary-tree.d.ts +0 -6
- package/dist/interfaces/binary-tree.js.map +0 -1
- package/dist/interfaces/bst.d.ts +0 -6
- package/dist/interfaces/bst.js.map +0 -1
- package/dist/interfaces/directed-graph.d.ts +0 -3
- package/dist/interfaces/directed-graph.js +0 -3
- package/dist/interfaces/directed-graph.js.map +0 -1
- package/dist/interfaces/doubly-linked-list.js.map +0 -1
- package/dist/interfaces/heap.js.map +0 -1
- package/dist/interfaces/index.d.ts +0 -15
- package/dist/interfaces/index.js +0 -32
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/navigator.js.map +0 -1
- package/dist/interfaces/priority-queue.js.map +0 -1
- package/dist/interfaces/rb-tree.d.ts +0 -6
- package/dist/interfaces/rb-tree.js +0 -3
- package/dist/interfaces/rb-tree.js.map +0 -1
- package/dist/interfaces/segment-tree.js.map +0 -1
- package/dist/interfaces/singly-linked-list.js.map +0 -1
- package/dist/interfaces/tree-multiset.d.ts +0 -6
- package/dist/interfaces/tree-multiset.js.map +0 -1
- package/dist/interfaces/undirected-graph.d.ts +0 -3
- package/dist/interfaces/undirected-graph.js.map +0 -1
- package/dist/types/data-structures/abstract-binary-tree.d.ts +0 -34
- package/dist/types/data-structures/abstract-binary-tree.js +0 -25
- package/dist/types/data-structures/abstract-binary-tree.js.map +0 -1
- package/dist/types/data-structures/abstract-graph.d.ts +0 -11
- package/dist/types/data-structures/abstract-graph.js +0 -3
- package/dist/types/data-structures/abstract-graph.js.map +0 -1
- package/dist/types/data-structures/avl-tree.d.ts +0 -4
- package/dist/types/data-structures/avl-tree.js +0 -3
- package/dist/types/data-structures/avl-tree.js.map +0 -1
- package/dist/types/data-structures/binary-tree.d.ts +0 -4
- package/dist/types/data-structures/binary-tree.js +0 -3
- package/dist/types/data-structures/binary-tree.js.map +0 -1
- package/dist/types/data-structures/bst.d.ts +0 -13
- package/dist/types/data-structures/bst.js +0 -10
- package/dist/types/data-structures/bst.js.map +0 -1
- package/dist/types/data-structures/directed-graph.js.map +0 -1
- package/dist/types/data-structures/doubly-linked-list.js.map +0 -1
- package/dist/types/data-structures/hash.js +0 -3
- package/dist/types/data-structures/hash.js.map +0 -1
- package/dist/types/data-structures/heap.d.ts +0 -3
- package/dist/types/data-structures/heap.js.map +0 -1
- package/dist/types/data-structures/index.d.ts +0 -16
- package/dist/types/data-structures/index.js +0 -33
- package/dist/types/data-structures/index.js.map +0 -1
- package/dist/types/data-structures/map-graph.js.map +0 -1
- package/dist/types/data-structures/navigator.js.map +0 -1
- package/dist/types/data-structures/priority-queue.d.ts +0 -7
- package/dist/types/data-structures/priority-queue.js.map +0 -1
- package/dist/types/data-structures/rb-tree.d.ts +0 -8
- package/dist/types/data-structures/rb-tree.js +0 -9
- package/dist/types/data-structures/rb-tree.js.map +0 -1
- package/dist/types/data-structures/segment-tree.js.map +0 -1
- package/dist/types/data-structures/singly-linked-list.js.map +0 -1
- package/dist/types/data-structures/tree-multiset.d.ts +0 -4
- package/dist/types/data-structures/tree-multiset.js +0 -3
- package/dist/types/data-structures/tree-multiset.js.map +0 -1
- package/dist/types/helpers.js +0 -3
- package/dist/types/helpers.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/utils/index.js.map +0 -1
- package/dist/types/utils/utils.js.map +0 -1
- package/dist/types/utils/validate-type.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -19
- package/dist/utils/utils.js +0 -67
- package/dist/utils/utils.js.map +0 -1
- package/lib/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/lib/data-structures/binary-tree/aa-tree.js +0 -2
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +0 -527
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +0 -1193
- package/lib/data-structures/binary-tree/avl-tree.d.ts +0 -94
- package/lib/data-structures/binary-tree/avl-tree.js +0 -330
- package/lib/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/lib/data-structures/binary-tree/b-tree.js +0 -2
- package/lib/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -46
- package/lib/data-structures/binary-tree/binary-indexed-tree.js +0 -69
- package/lib/data-structures/binary-tree/binary-tree.d.ts +0 -31
- package/lib/data-structures/binary-tree/binary-tree.js +0 -35
- package/lib/data-structures/binary-tree/bst.d.ts +0 -133
- package/lib/data-structures/binary-tree/bst.js +0 -548
- package/lib/data-structures/binary-tree/index.d.ts +0 -12
- package/lib/data-structures/binary-tree/index.js +0 -12
- package/lib/data-structures/binary-tree/rb-tree.d.ts +0 -13
- package/lib/data-structures/binary-tree/rb-tree.js +0 -22
- package/lib/data-structures/binary-tree/segment-tree.d.ts +0 -83
- package/lib/data-structures/binary-tree/segment-tree.js +0 -223
- package/lib/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/lib/data-structures/binary-tree/splay-tree.js +0 -2
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +0 -209
- package/lib/data-structures/binary-tree/tree-multiset.js +0 -663
- package/lib/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/lib/data-structures/binary-tree/two-three-tree.js +0 -2
- package/lib/data-structures/graph/abstract-graph.d.ts +0 -332
- package/lib/data-structures/graph/abstract-graph.js +0 -918
- package/lib/data-structures/graph/directed-graph.d.ts +0 -200
- package/lib/data-structures/graph/directed-graph.js +0 -416
- package/lib/data-structures/graph/index.js +0 -4
- package/lib/data-structures/graph/map-graph.d.ts +0 -79
- package/lib/data-structures/graph/map-graph.js +0 -105
- package/lib/data-structures/graph/undirected-graph.d.ts +0 -127
- package/lib/data-structures/graph/undirected-graph.js +0 -246
- package/lib/data-structures/hash/coordinate-map.d.ts +0 -45
- package/lib/data-structures/hash/coordinate-map.js +0 -61
- package/lib/data-structures/hash/coordinate-set.d.ts +0 -37
- package/lib/data-structures/hash/coordinate-set.js +0 -51
- package/lib/data-structures/hash/hash-map.d.ts +0 -56
- package/lib/data-structures/hash/hash-map.js +0 -167
- package/lib/data-structures/hash/hash-table.d.ts +0 -106
- package/lib/data-structures/hash/hash-table.js +0 -240
- package/lib/data-structures/hash/index.d.ts +0 -7
- package/lib/data-structures/hash/index.js +0 -7
- package/lib/data-structures/hash/pair.d.ts +0 -2
- package/lib/data-structures/hash/pair.js +0 -2
- package/lib/data-structures/hash/tree-map.js +0 -2
- package/lib/data-structures/hash/tree-set.js +0 -2
- package/lib/data-structures/heap/heap.d.ts +0 -83
- package/lib/data-structures/heap/heap.js +0 -152
- package/lib/data-structures/heap/index.js +0 -3
- package/lib/data-structures/heap/max-heap.d.ts +0 -23
- package/lib/data-structures/heap/max-heap.js +0 -26
- package/lib/data-structures/heap/min-heap.d.ts +0 -24
- package/lib/data-structures/heap/min-heap.js +0 -27
- package/lib/data-structures/index.js +0 -11
- package/lib/data-structures/linked-list/doubly-linked-list.d.ts +0 -234
- package/lib/data-structures/linked-list/doubly-linked-list.js +0 -578
- package/lib/data-structures/linked-list/index.js +0 -3
- package/lib/data-structures/linked-list/singly-linked-list.d.ts +0 -157
- package/lib/data-structures/linked-list/singly-linked-list.js +0 -443
- package/lib/data-structures/linked-list/skip-linked-list.d.ts +0 -61
- package/lib/data-structures/linked-list/skip-linked-list.js +0 -137
- package/lib/data-structures/matrix/index.js +0 -4
- package/lib/data-structures/matrix/matrix.d.ts +0 -21
- package/lib/data-structures/matrix/matrix.js +0 -24
- package/lib/data-structures/matrix/matrix2d.d.ts +0 -108
- package/lib/data-structures/matrix/matrix2d.js +0 -196
- package/lib/data-structures/matrix/navigator.d.ts +0 -52
- package/lib/data-structures/matrix/navigator.js +0 -101
- package/lib/data-structures/matrix/vector2d.d.ts +0 -201
- package/lib/data-structures/matrix/vector2d.js +0 -287
- package/lib/data-structures/priority-queue/max-priority-queue.d.ts +0 -15
- package/lib/data-structures/priority-queue/max-priority-queue.js +0 -39
- package/lib/data-structures/priority-queue/min-priority-queue.d.ts +0 -15
- package/lib/data-structures/priority-queue/min-priority-queue.js +0 -40
- package/lib/data-structures/priority-queue/priority-queue.d.ts +0 -180
- package/lib/data-structures/priority-queue/priority-queue.js +0 -317
- package/lib/data-structures/queue/deque.d.ts +0 -165
- package/lib/data-structures/queue/deque.js +0 -270
- package/lib/data-structures/queue/queue.d.ts +0 -107
- package/lib/data-structures/queue/queue.js +0 -165
- package/lib/data-structures/stack/stack.d.ts +0 -63
- package/lib/data-structures/stack/stack.js +0 -87
- package/lib/data-structures/tree/tree.d.ts +0 -14
- package/lib/data-structures/tree/tree.js +0 -56
- package/lib/data-structures/trie/trie.d.ts +0 -61
- package/lib/data-structures/trie/trie.js +0 -205
- package/lib/index.js +0 -4
- package/lib/interfaces/abstract-binary-tree.d.ts +0 -7
- package/lib/interfaces/abstract-graph.d.ts +0 -5
- package/lib/interfaces/avl-tree.d.ts +0 -7
- package/lib/interfaces/binary-tree.d.ts +0 -6
- package/lib/interfaces/bst.d.ts +0 -6
- package/lib/interfaces/directed-graph.d.ts +0 -3
- package/lib/interfaces/index.d.ts +0 -15
- package/lib/interfaces/index.js +0 -15
- package/lib/interfaces/rb-tree.d.ts +0 -6
- package/lib/interfaces/tree-multiset.d.ts +0 -6
- package/lib/interfaces/undirected-graph.d.ts +0 -3
- package/lib/types/data-structures/abstract-binary-tree.d.ts +0 -34
- package/lib/types/data-structures/abstract-binary-tree.js +0 -21
- package/lib/types/data-structures/abstract-graph.d.ts +0 -11
- package/lib/types/data-structures/avl-tree.d.ts +0 -4
- package/lib/types/data-structures/binary-tree.d.ts +0 -4
- package/lib/types/data-structures/bst.d.ts +0 -13
- package/lib/types/data-structures/bst.js +0 -6
- package/lib/types/data-structures/directed-graph.js +0 -6
- package/lib/types/data-structures/heap.d.ts +0 -3
- package/lib/types/data-structures/index.d.ts +0 -16
- package/lib/types/data-structures/index.js +0 -16
- package/lib/types/data-structures/priority-queue.d.ts +0 -7
- package/lib/types/data-structures/rb-tree.d.ts +0 -8
- package/lib/types/data-structures/rb-tree.js +0 -5
- package/lib/types/data-structures/tree-multiset.d.ts +0 -4
- package/lib/types/index.js +0 -3
- package/lib/types/utils/index.js +0 -2
- package/lib/utils/utils.d.ts +0 -19
- package/lib/utils/utils.js +0 -57
- package/scripts/rename_clear_files.sh +0 -29
- package/src/data-structures/binary-tree/aa-tree.ts +0 -1
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +0 -1556
- package/src/data-structures/binary-tree/b-tree.ts +0 -1
- package/src/data-structures/binary-tree/splay-tree.ts +0 -1
- package/src/data-structures/binary-tree/two-three-tree.ts +0 -1
- package/src/data-structures/hash/pair.ts +0 -1
- package/src/interfaces/abstract-binary-tree.ts +0 -8
- package/src/interfaces/abstract-graph.ts +0 -7
- package/src/interfaces/avl-tree.ts +0 -8
- package/src/interfaces/bst.ts +0 -6
- package/src/interfaces/directed-graph.ts +0 -3
- package/src/interfaces/rb-tree.ts +0 -6
- package/src/interfaces/tree-multiset.ts +0 -7
- package/src/interfaces/undirected-graph.ts +0 -3
- package/src/types/data-structures/abstract-binary-tree.ts +0 -49
- package/src/types/data-structures/abstract-graph.ts +0 -11
- package/src/types/data-structures/avl-tree.ts +0 -5
- package/src/types/data-structures/binary-tree.ts +0 -5
- package/src/types/data-structures/bst.ts +0 -13
- package/src/types/data-structures/heap.ts +0 -5
- package/src/types/data-structures/navigator.ts +0 -13
- package/src/types/data-structures/priority-queue.ts +0 -9
- package/src/types/data-structures/rb-tree.ts +0 -8
- package/src/types/data-structures/tree-multiset.ts +0 -6
- package/test/utils/magnitude.ts +0 -21
- /package/dist/{data-structures → cjs/data-structures}/graph/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/graph/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/hash/tree-map.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/hash/tree-map.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/hash/tree-set.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/hash/tree-set.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/heap/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/heap/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/linked-list/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/linked-list/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/matrix/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/matrix/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/matrix/matrix.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/matrix/navigator.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/priority-queue/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/queue/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/stack/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/tree/index.js +0 -0
- /package/dist/{data-structures → cjs/data-structures}/trie/index.d.ts +0 -0
- /package/dist/{data-structures → cjs/data-structures}/trie/index.js +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{interfaces → cjs/interfaces}/binary-tree.js +0 -0
- /package/dist/{interfaces → cjs/interfaces}/doubly-linked-list.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/doubly-linked-list.js +0 -0
- /package/dist/{interfaces → cjs/interfaces}/heap.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/heap.js +0 -0
- /package/dist/{interfaces → cjs/interfaces}/navigator.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/navigator.js +0 -0
- /package/dist/{interfaces → cjs/interfaces}/priority-queue.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/priority-queue.js +0 -0
- /package/dist/{interfaces → cjs/interfaces}/segment-tree.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/segment-tree.js +0 -0
- /package/dist/{interfaces → cjs/interfaces}/singly-linked-list.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/singly-linked-list.js +0 -0
- /package/dist/{interfaces → cjs/types/data-structures/binary-tree}/avl-tree.js +0 -0
- /package/dist/{types/data-structures/doubly-linked-list.d.ts → cjs/types/data-structures/binary-tree/binary-indexed-tree.d.ts} +0 -0
- /package/dist/{interfaces → cjs/types/data-structures/binary-tree}/bst.js +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/binary-tree}/segment-tree.d.ts +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/binary-tree}/segment-tree.js +0 -0
- /package/dist/{interfaces → cjs/types/data-structures/binary-tree}/tree-multiset.js +0 -0
- /package/dist/{interfaces → cjs/types/data-structures/graph}/abstract-graph.js +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/graph}/directed-graph.d.ts +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/graph}/directed-graph.js +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/graph}/map-graph.d.ts +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/graph}/map-graph.js +0 -0
- /package/dist/{types/data-structures/singly-linked-list.d.ts → cjs/types/data-structures/graph/undirected-graph.d.ts} +0 -0
- /package/dist/{interfaces → cjs/types/data-structures/graph}/undirected-graph.js +0 -0
- /package/dist/{types/helpers.d.ts → cjs/types/data-structures/hash/coordinate-map.d.ts} +0 -0
- /package/{lib/interfaces/abstract-binary-tree.js → dist/cjs/types/data-structures/hash/coordinate-set.d.ts} +0 -0
- /package/{lib/interfaces/abstract-graph.js → dist/cjs/types/data-structures/hash/hash-map.d.ts} +0 -0
- /package/{lib/interfaces/avl-tree.js → dist/cjs/types/data-structures/hash/hash-table.d.ts} +0 -0
- /package/dist/{types/data-structures/hash.d.ts → cjs/types/data-structures/hash/index.d.ts} +0 -0
- /package/{lib/interfaces/binary-tree.js → dist/cjs/types/data-structures/hash/tree-map.d.ts} +0 -0
- /package/{lib/interfaces/bst.js → dist/cjs/types/data-structures/hash/tree-set.d.ts} +0 -0
- /package/{lib/interfaces → dist/cjs/types/data-structures/heap}/heap.d.ts +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/heap}/heap.js +0 -0
- /package/{lib/interfaces/directed-graph.js → dist/cjs/types/data-structures/heap/max-heap.d.ts} +0 -0
- /package/{lib/interfaces/doubly-linked-list.d.ts → dist/cjs/types/data-structures/heap/min-heap.d.ts} +0 -0
- /package/{lib/types/data-structures → dist/cjs/types/data-structures/linked-list}/doubly-linked-list.d.ts +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/linked-list}/doubly-linked-list.js +0 -0
- /package/{lib/interfaces → dist/cjs/types/data-structures/linked-list}/singly-linked-list.d.ts +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/linked-list}/singly-linked-list.js +0 -0
- /package/{lib/interfaces/doubly-linked-list.js → dist/cjs/types/data-structures/linked-list/skip-linked-list.d.ts} +0 -0
- /package/{lib/interfaces/heap.js → dist/cjs/types/data-structures/matrix/matrix.d.ts} +0 -0
- /package/{lib/interfaces/navigator.d.ts → dist/cjs/types/data-structures/matrix/matrix2d.d.ts} +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/matrix}/navigator.d.ts +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/matrix}/navigator.js +0 -0
- /package/{lib/interfaces/navigator.js → dist/cjs/types/data-structures/matrix/vector2d.d.ts} +0 -0
- /package/{lib → dist/cjs/types}/data-structures/priority-queue/index.d.ts +0 -0
- /package/{lib/interfaces/priority-queue.d.ts → dist/cjs/types/data-structures/priority-queue/max-priority-queue.d.ts} +0 -0
- /package/{lib/interfaces/priority-queue.js → dist/cjs/types/data-structures/priority-queue/min-priority-queue.d.ts} +0 -0
- /package/{lib/interfaces/rb-tree.js → dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts} +0 -0
- /package/dist/{types/data-structures → cjs/types/data-structures/priority-queue}/priority-queue.js +0 -0
- /package/{lib/interfaces/segment-tree.d.ts → dist/cjs/types/data-structures/queue/deque.d.ts} +0 -0
- /package/{lib → dist/cjs/types}/data-structures/queue/index.d.ts +0 -0
- /package/{lib/interfaces/segment-tree.js → dist/cjs/types/data-structures/queue/queue.d.ts} +0 -0
- /package/{lib → dist/cjs/types}/data-structures/stack/index.d.ts +0 -0
- /package/{lib/interfaces/singly-linked-list.js → dist/cjs/types/data-structures/stack/stack.d.ts} +0 -0
- /package/{lib → dist/cjs/types}/data-structures/tree/index.d.ts +0 -0
- /package/{lib/interfaces/tree-multiset.js → dist/cjs/types/data-structures/tree/tree.d.ts} +0 -0
- /package/{lib → dist/cjs/types}/data-structures/trie/index.d.ts +0 -0
- /package/{lib/interfaces/undirected-graph.js → dist/cjs/types/data-structures/trie/trie.d.ts} +0 -0
- /package/dist/{types → cjs/types}/index.d.ts +0 -0
- /package/dist/{types → cjs/types}/index.js +0 -0
- /package/dist/{types → cjs/types}/utils/index.d.ts +0 -0
- /package/dist/{types → cjs/types}/utils/index.js +0 -0
- /package/dist/{types → cjs/types}/utils/utils.d.ts +0 -0
- /package/dist/{types → cjs/types}/utils/utils.js +0 -0
- /package/dist/{types → cjs/types}/utils/validate-type.d.ts +0 -0
- /package/dist/{types → cjs/types}/utils/validate-type.js +0 -0
- /package/dist/{utils → cjs/utils}/index.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/index.js +0 -0
- /package/{lib → dist/mjs}/data-structures/graph/index.d.ts +0 -0
- /package/{lib → dist/mjs}/data-structures/hash/tree-map.d.ts +0 -0
- /package/{lib → dist/mjs}/data-structures/hash/tree-set.d.ts +0 -0
- /package/{lib → dist/mjs}/data-structures/heap/index.d.ts +0 -0
- /package/{lib → dist/mjs}/data-structures/index.d.ts +0 -0
- /package/{lib → dist/mjs}/data-structures/linked-list/index.d.ts +0 -0
- /package/{lib → dist/mjs}/data-structures/matrix/index.d.ts +0 -0
- /package/{lib/data-structures/priority-queue/index.js → dist/mjs/data-structures/priority-queue/index.d.ts} +0 -0
- /package/{lib/data-structures/queue/index.js → dist/mjs/data-structures/queue/index.d.ts} +0 -0
- /package/{lib/data-structures/stack/index.js → dist/mjs/data-structures/stack/index.d.ts} +0 -0
- /package/{lib/data-structures/tree/index.js → dist/mjs/data-structures/tree/index.d.ts} +0 -0
- /package/{lib/data-structures/trie/index.js → dist/mjs/data-structures/trie/index.d.ts} +0 -0
- /package/{lib → dist/mjs}/index.d.ts +0 -0
- /package/{lib/types/data-structures/abstract-graph.js → dist/mjs/interfaces/doubly-linked-list.d.ts} +0 -0
- /package/{lib/types/data-structures/avl-tree.js → dist/mjs/interfaces/heap.d.ts} +0 -0
- /package/{lib/types/data-structures/binary-tree.js → dist/mjs/interfaces/navigator.d.ts} +0 -0
- /package/{lib/types/data-structures/doubly-linked-list.js → dist/mjs/interfaces/priority-queue.d.ts} +0 -0
- /package/{lib/types/data-structures/hash.js → dist/mjs/interfaces/segment-tree.d.ts} +0 -0
- /package/{lib/types/data-structures → dist/mjs/interfaces}/singly-linked-list.d.ts +0 -0
- /package/{lib/types/data-structures/heap.js → dist/mjs/types/data-structures/binary-tree/binary-indexed-tree.d.ts} +0 -0
- /package/{lib/types/data-structures → dist/mjs/types/data-structures/binary-tree}/segment-tree.d.ts +0 -0
- /package/{lib/types/data-structures → dist/mjs/types/data-structures/graph}/directed-graph.d.ts +0 -0
- /package/{lib/types/data-structures → dist/mjs/types/data-structures/graph}/map-graph.d.ts +0 -0
- /package/{lib/types/data-structures/map-graph.js → dist/mjs/types/data-structures/graph/undirected-graph.d.ts} +0 -0
- /package/{lib/types/data-structures/navigator.js → dist/mjs/types/data-structures/hash/coordinate-map.d.ts} +0 -0
- /package/{lib/types/data-structures/priority-queue.js → dist/mjs/types/data-structures/hash/coordinate-set.d.ts} +0 -0
- /package/{lib/types/data-structures/segment-tree.js → dist/mjs/types/data-structures/hash/hash-map.d.ts} +0 -0
- /package/{lib/types/data-structures/singly-linked-list.js → dist/mjs/types/data-structures/hash/hash-table.d.ts} +0 -0
- /package/{lib/types/data-structures/hash.d.ts → dist/mjs/types/data-structures/hash/index.d.ts} +0 -0
- /package/{lib/types/data-structures/tree-multiset.js → dist/mjs/types/data-structures/hash/tree-map.d.ts} +0 -0
- /package/{lib/types/helpers.d.ts → dist/mjs/types/data-structures/hash/tree-set.d.ts} +0 -0
- /package/{lib/types/helpers.js → dist/mjs/types/data-structures/heap/heap.d.ts} +0 -0
- /package/{lib/types/utils/utils.js → dist/mjs/types/data-structures/heap/max-heap.d.ts} +0 -0
- /package/{lib/types/utils/validate-type.js → dist/mjs/types/data-structures/heap/min-heap.d.ts} +0 -0
- /package/{src/types/data-structures/doubly-linked-list.ts → dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts} +0 -0
- /package/{src/types/data-structures/singly-linked-list.ts → dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts} +0 -0
- /package/{lib/types/data-structures → dist/mjs/types/data-structures/matrix}/navigator.d.ts +0 -0
- /package/{lib → dist/mjs}/types/index.d.ts +0 -0
- /package/{lib → dist/mjs}/types/utils/index.d.ts +0 -0
- /package/{lib → dist/mjs}/types/utils/utils.d.ts +0 -0
- /package/{lib → dist/mjs}/types/utils/validate-type.d.ts +0 -0
- /package/{lib → dist/mjs}/utils/index.d.ts +0 -0
- /package/src/types/data-structures/{segment-tree.ts → binary-tree/segment-tree.ts} +0 -0
- /package/src/types/data-structures/{directed-graph.ts → graph/directed-graph.ts} +0 -0
- /package/src/types/data-structures/{map-graph.ts → graph/map-graph.ts} +0 -0
- /package/src/types/data-structures/{hash.ts → hash/index.ts} +0 -0
- /package/{lib/utils/index.js → test/types/index.ts} +0 -0
|
@@ -1,85 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Kirk Qi
|
|
5
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import {arrayRemove, uuidV4} from '../../utils';
|
|
9
9
|
import {PriorityQueue} from '../priority-queue';
|
|
10
10
|
import type {DijkstraResult, VertexKey} from '../../types';
|
|
11
|
-
import {
|
|
11
|
+
import {IGraph} from '../../interfaces';
|
|
12
|
+
import {Queue} from '../queue';
|
|
12
13
|
|
|
13
14
|
export abstract class AbstractVertex<V = any> {
|
|
15
|
+
key: VertexKey;
|
|
16
|
+
value: V | undefined;
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
* The function is a protected constructor that takes an key and an optional value as parameters.
|
|
16
20
|
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
17
21
|
* used to uniquely identify the vertex object.
|
|
18
|
-
* @param {V} [
|
|
22
|
+
* @param {V} [value] - The parameter "value" is an optional parameter of type V. It is used to assign a value to the
|
|
19
23
|
* vertex. If no value is provided, it will be set to undefined.
|
|
20
24
|
*/
|
|
21
|
-
protected constructor(key: VertexKey,
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private _key: VertexKey;
|
|
27
|
-
|
|
28
|
-
get key(): VertexKey {
|
|
29
|
-
return this._key;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
set key(v: VertexKey) {
|
|
33
|
-
this._key = v;
|
|
25
|
+
protected constructor(key: VertexKey, value?: V) {
|
|
26
|
+
this.key = key;
|
|
27
|
+
this.value = value;
|
|
34
28
|
}
|
|
35
29
|
|
|
36
|
-
private _val: V | undefined;
|
|
37
|
-
|
|
38
|
-
get val(): V | undefined {
|
|
39
|
-
return this._val;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
set val(value: V | undefined) {
|
|
43
|
-
this._val = value;
|
|
44
|
-
}
|
|
45
30
|
}
|
|
46
31
|
|
|
47
|
-
export abstract class AbstractEdge<
|
|
32
|
+
export abstract class AbstractEdge<E = any> {
|
|
33
|
+
value: E | undefined;
|
|
34
|
+
weight: number;
|
|
35
|
+
|
|
48
36
|
/**
|
|
49
37
|
* The above function is a protected constructor that initializes the weight, value, and hash code properties of an
|
|
50
38
|
* object.
|
|
51
39
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
|
|
52
40
|
* a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
|
|
53
41
|
* will be assigned.
|
|
54
|
-
* @param {
|
|
42
|
+
* @param {VO} [value] - The `value` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
|
|
55
43
|
* meaning it can be omitted when creating an instance of the class.
|
|
56
44
|
*/
|
|
57
|
-
protected constructor(weight?: number,
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
45
|
+
protected constructor(weight?: number, value?: E) {
|
|
46
|
+
this.weight = weight !== undefined ? weight : 1;
|
|
47
|
+
this.value = value;
|
|
60
48
|
this._hashCode = uuidV4();
|
|
61
49
|
}
|
|
62
50
|
|
|
63
|
-
private _val: V | undefined;
|
|
64
|
-
|
|
65
|
-
get val(): V | undefined {
|
|
66
|
-
return this._val;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
set val(value: V | undefined) {
|
|
70
|
-
this._val = value;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private _weight: number;
|
|
74
|
-
|
|
75
|
-
get weight(): number {
|
|
76
|
-
return this._weight;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
set weight(v: number) {
|
|
80
|
-
this._weight = v;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
51
|
protected _hashCode: string;
|
|
84
52
|
|
|
85
53
|
get hashCode(): string {
|
|
@@ -90,25 +58,17 @@ export abstract class AbstractEdge<V = any> {
|
|
|
90
58
|
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
91
59
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
92
60
|
*/
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* The function sets the value of the _hashCode property to the provided string.
|
|
96
|
-
* @param {string} v - The parameter "v" is of type string and represents the value that will be assigned to the
|
|
97
|
-
* "_hashCode" property.
|
|
98
|
-
*/
|
|
99
|
-
protected _setHashCode(v: string) {
|
|
100
|
-
this._hashCode = v;
|
|
101
|
-
}
|
|
102
61
|
}
|
|
103
62
|
|
|
104
63
|
export abstract class AbstractGraph<
|
|
105
|
-
V
|
|
106
|
-
E
|
|
107
|
-
>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
64
|
+
V = any,
|
|
65
|
+
E = any,
|
|
66
|
+
VO extends AbstractVertex<V> = AbstractVertex<V>,
|
|
67
|
+
EO extends AbstractEdge<E> = AbstractEdge<E>
|
|
68
|
+
> implements IGraph<V, E, VO, EO> {
|
|
69
|
+
protected _vertices: Map<VertexKey, VO> = new Map<VertexKey, VO>();
|
|
70
|
+
|
|
71
|
+
get vertices(): Map<VertexKey, VO> {
|
|
112
72
|
return this._vertices;
|
|
113
73
|
}
|
|
114
74
|
|
|
@@ -116,9 +76,9 @@ export abstract class AbstractGraph<
|
|
|
116
76
|
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
117
77
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
118
78
|
* @param key
|
|
119
|
-
* @param
|
|
79
|
+
* @param value
|
|
120
80
|
*/
|
|
121
|
-
abstract createVertex(key: VertexKey,
|
|
81
|
+
abstract createVertex(key: VertexKey, value?: V): VO;
|
|
122
82
|
|
|
123
83
|
/**
|
|
124
84
|
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
@@ -126,23 +86,23 @@ export abstract class AbstractGraph<
|
|
|
126
86
|
* @param srcOrV1
|
|
127
87
|
* @param destOrV2
|
|
128
88
|
* @param weight
|
|
129
|
-
* @param
|
|
89
|
+
* @param value
|
|
130
90
|
*/
|
|
131
|
-
abstract createEdge(srcOrV1: VertexKey
|
|
91
|
+
abstract createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
132
92
|
|
|
133
|
-
abstract
|
|
93
|
+
abstract deleteEdge(edge: EO): EO | null;
|
|
134
94
|
|
|
135
|
-
abstract getEdge(srcOrKey:
|
|
95
|
+
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | null;
|
|
136
96
|
|
|
137
|
-
abstract degreeOf(vertexOrKey:
|
|
97
|
+
abstract degreeOf(vertexOrKey: VO | VertexKey): number;
|
|
138
98
|
|
|
139
|
-
abstract edgeSet():
|
|
99
|
+
abstract edgeSet(): EO[];
|
|
140
100
|
|
|
141
|
-
abstract edgesOf(vertexOrKey:
|
|
101
|
+
abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
142
102
|
|
|
143
|
-
abstract getNeighbors(vertexOrKey:
|
|
103
|
+
abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
144
104
|
|
|
145
|
-
abstract getEndsOfEdge(edge:
|
|
105
|
+
abstract getEndsOfEdge(edge: EO): [VO, VO] | null;
|
|
146
106
|
|
|
147
107
|
/**
|
|
148
108
|
* The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
|
|
@@ -151,77 +111,77 @@ export abstract class AbstractGraph<
|
|
|
151
111
|
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
|
|
152
112
|
* map. If the vertex does not exist, it returns `null`.
|
|
153
113
|
*/
|
|
154
|
-
getVertex(vertexKey: VertexKey):
|
|
114
|
+
getVertex(vertexKey: VertexKey): VO | null {
|
|
155
115
|
return this._vertices.get(vertexKey) || null;
|
|
156
116
|
}
|
|
157
117
|
|
|
158
118
|
/**
|
|
159
119
|
* The function checks if a vertex exists in a graph.
|
|
160
|
-
* @param {
|
|
120
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
161
121
|
* (`VertexKey`).
|
|
162
122
|
* @returns a boolean value.
|
|
163
123
|
*/
|
|
164
|
-
hasVertex(vertexOrKey:
|
|
124
|
+
hasVertex(vertexOrKey: VO | VertexKey): boolean {
|
|
165
125
|
return this._vertices.has(this._getVertexKey(vertexOrKey));
|
|
166
126
|
}
|
|
167
127
|
|
|
168
|
-
addVertex(vertex:
|
|
128
|
+
addVertex(vertex: VO): boolean;
|
|
169
129
|
|
|
170
|
-
addVertex(key: VertexKey,
|
|
130
|
+
addVertex(key: VertexKey, value?: V): boolean;
|
|
171
131
|
|
|
172
|
-
addVertex(keyOrVertex: VertexKey |
|
|
132
|
+
addVertex(keyOrVertex: VertexKey | VO, value?: V): boolean {
|
|
173
133
|
if (keyOrVertex instanceof AbstractVertex) {
|
|
174
134
|
return this._addVertexOnly(keyOrVertex);
|
|
175
135
|
} else {
|
|
176
|
-
const newVertex = this.createVertex(keyOrVertex,
|
|
136
|
+
const newVertex = this.createVertex(keyOrVertex, value);
|
|
177
137
|
return this._addVertexOnly(newVertex);
|
|
178
138
|
}
|
|
179
139
|
}
|
|
180
140
|
|
|
181
141
|
/**
|
|
182
|
-
* The `
|
|
183
|
-
* @param {
|
|
142
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
143
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
184
144
|
* (`VertexKey`).
|
|
185
145
|
* @returns The method is returning a boolean value.
|
|
186
146
|
*/
|
|
187
|
-
|
|
147
|
+
deleteVertex(vertexOrKey: VO | VertexKey): boolean {
|
|
188
148
|
const vertexKey = this._getVertexKey(vertexOrKey);
|
|
189
149
|
return this._vertices.delete(vertexKey);
|
|
190
150
|
}
|
|
191
151
|
|
|
192
152
|
/**
|
|
193
153
|
* The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
|
|
194
|
-
* @param {
|
|
154
|
+
* @param {VO[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`VO[]`) or an array
|
|
195
155
|
* of vertex IDs (`VertexKey[]`).
|
|
196
156
|
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
|
|
197
157
|
* were removed.
|
|
198
158
|
*/
|
|
199
|
-
|
|
159
|
+
removeManyVertices(vertices: VO[] | VertexKey[]): boolean {
|
|
200
160
|
const removed: boolean[] = [];
|
|
201
161
|
for (const v of vertices) {
|
|
202
|
-
removed.push(this.
|
|
162
|
+
removed.push(this.deleteVertex(v));
|
|
203
163
|
}
|
|
204
164
|
return removed.length > 0;
|
|
205
165
|
}
|
|
206
166
|
|
|
207
167
|
/**
|
|
208
168
|
* The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
|
|
209
|
-
* @param {VertexKey |
|
|
210
|
-
* identifier of a vertex in a graph, while
|
|
211
|
-
* @param {VertexKey |
|
|
212
|
-
* `VertexKey` or a `
|
|
169
|
+
* @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
|
|
170
|
+
* identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
|
|
171
|
+
* @param {VertexKey | VO} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
|
|
172
|
+
* `VertexKey` or a `VO` type, which represents the type of the vertex.
|
|
213
173
|
* @returns A boolean value is being returned.
|
|
214
174
|
*/
|
|
215
|
-
hasEdge(v1: VertexKey |
|
|
175
|
+
hasEdge(v1: VertexKey | VO, v2: VertexKey | VO): boolean {
|
|
216
176
|
const edge = this.getEdge(v1, v2);
|
|
217
177
|
return !!edge;
|
|
218
178
|
}
|
|
219
179
|
|
|
220
|
-
addEdge(edge:
|
|
180
|
+
addEdge(edge: EO): boolean;
|
|
221
181
|
|
|
222
|
-
addEdge(src:
|
|
182
|
+
addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, value?: E): boolean;
|
|
223
183
|
|
|
224
|
-
addEdge(srcOrEdge:
|
|
184
|
+
addEdge(srcOrEdge: VO | VertexKey | EO, dest?: VO | VertexKey, weight?: number, value?: E): boolean {
|
|
225
185
|
if (srcOrEdge instanceof AbstractEdge) {
|
|
226
186
|
return this._addEdgeOnly(srcOrEdge);
|
|
227
187
|
} else {
|
|
@@ -229,7 +189,7 @@ export abstract class AbstractGraph<
|
|
|
229
189
|
if (!(this.hasVertex(srcOrEdge) && this.hasVertex(dest))) return false;
|
|
230
190
|
if (srcOrEdge instanceof AbstractVertex) srcOrEdge = srcOrEdge.key;
|
|
231
191
|
if (dest instanceof AbstractVertex) dest = dest.key;
|
|
232
|
-
const newEdge = this.createEdge(srcOrEdge, dest, weight,
|
|
192
|
+
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
233
193
|
return this._addEdgeOnly(newEdge);
|
|
234
194
|
} else {
|
|
235
195
|
throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
|
|
@@ -239,16 +199,16 @@ export abstract class AbstractGraph<
|
|
|
239
199
|
|
|
240
200
|
/**
|
|
241
201
|
* The function sets the weight of an edge between two vertices in a graph.
|
|
242
|
-
* @param {VertexKey |
|
|
202
|
+
* @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
|
|
243
203
|
* the source vertex of the edge.
|
|
244
|
-
* @param {VertexKey |
|
|
245
|
-
* either a `VertexKey` or a vertex object `
|
|
204
|
+
* @param {VertexKey | VO} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
|
|
205
|
+
* either a `VertexKey` or a vertex object `VO`.
|
|
246
206
|
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
|
|
247
207
|
* and the destination vertex (destOrKey).
|
|
248
208
|
* @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
|
|
249
209
|
* the weight of the edge and return true. If the edge does not exist, the function will return false.
|
|
250
210
|
*/
|
|
251
|
-
setEdgeWeight(srcOrKey: VertexKey |
|
|
211
|
+
setEdgeWeight(srcOrKey: VertexKey | VO, destOrKey: VertexKey | VO, weight: number): boolean {
|
|
252
212
|
const edge = this.getEdge(srcOrKey, destOrKey);
|
|
253
213
|
if (edge) {
|
|
254
214
|
edge.weight = weight;
|
|
@@ -260,20 +220,20 @@ export abstract class AbstractGraph<
|
|
|
260
220
|
|
|
261
221
|
/**
|
|
262
222
|
* The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
|
|
263
|
-
* @param {
|
|
223
|
+
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
264
224
|
* It is the starting vertex for finding paths.
|
|
265
|
-
* @param {
|
|
266
|
-
* @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`
|
|
225
|
+
* @param {VO | VertexKey} v2 - The parameter `v2` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
226
|
+
* @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`VO[][]`).
|
|
267
227
|
*/
|
|
268
|
-
getAllPathsBetween(v1:
|
|
269
|
-
const paths:
|
|
228
|
+
getAllPathsBetween(v1: VO | VertexKey, v2: VO | VertexKey): VO[][] {
|
|
229
|
+
const paths: VO[][] = [];
|
|
270
230
|
const vertex1 = this._getVertex(v1);
|
|
271
231
|
const vertex2 = this._getVertex(v2);
|
|
272
232
|
if (!(vertex1 && vertex2)) {
|
|
273
233
|
return [];
|
|
274
234
|
}
|
|
275
235
|
|
|
276
|
-
const dfs = (cur:
|
|
236
|
+
const dfs = (cur: VO, dest: VO, visiting: Map<VO, boolean>, path: VO[]) => {
|
|
277
237
|
visiting.set(cur, true);
|
|
278
238
|
|
|
279
239
|
if (cur === dest) {
|
|
@@ -285,23 +245,23 @@ export abstract class AbstractGraph<
|
|
|
285
245
|
if (!visiting.get(neighbor)) {
|
|
286
246
|
path.push(neighbor);
|
|
287
247
|
dfs(neighbor, dest, visiting, path);
|
|
288
|
-
arrayRemove(path, (vertex:
|
|
248
|
+
arrayRemove(path, (vertex: VO) => vertex === neighbor);
|
|
289
249
|
}
|
|
290
250
|
}
|
|
291
251
|
|
|
292
252
|
visiting.set(cur, false);
|
|
293
253
|
};
|
|
294
254
|
|
|
295
|
-
dfs(vertex1, vertex2, new Map<
|
|
255
|
+
dfs(vertex1, vertex2, new Map<VO, boolean>(), []);
|
|
296
256
|
return paths;
|
|
297
257
|
}
|
|
298
258
|
|
|
299
259
|
/**
|
|
300
260
|
* The function calculates the sum of weights along a given path.
|
|
301
|
-
* @param {
|
|
261
|
+
* @param {VO[]} path - An array of vertices (VO) representing a path in a graph.
|
|
302
262
|
* @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
|
|
303
263
|
*/
|
|
304
|
-
getPathSumWeight(path:
|
|
264
|
+
getPathSumWeight(path: VO[]): number {
|
|
305
265
|
let sum = 0;
|
|
306
266
|
for (let i = 0; i < path.length; i++) {
|
|
307
267
|
sum += this.getEdge(path[i], path[i + 1])?.weight || 0;
|
|
@@ -312,8 +272,8 @@ export abstract class AbstractGraph<
|
|
|
312
272
|
/**
|
|
313
273
|
* The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
|
|
314
274
|
* weights or using a breadth-first search algorithm.
|
|
315
|
-
* @param {
|
|
316
|
-
* @param {
|
|
275
|
+
* @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
|
|
276
|
+
* @param {VO | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
|
|
317
277
|
* you want to find the minimum cost or weight from the source vertex `v1`.
|
|
318
278
|
* @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
|
|
319
279
|
* If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
|
|
@@ -323,7 +283,7 @@ export abstract class AbstractGraph<
|
|
|
323
283
|
* vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
|
|
324
284
|
* minimum number of
|
|
325
285
|
*/
|
|
326
|
-
getMinCostBetween(v1:
|
|
286
|
+
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | null {
|
|
327
287
|
if (isWeight === undefined) isWeight = false;
|
|
328
288
|
|
|
329
289
|
if (isWeight) {
|
|
@@ -341,12 +301,12 @@ export abstract class AbstractGraph<
|
|
|
341
301
|
return null;
|
|
342
302
|
}
|
|
343
303
|
|
|
344
|
-
const visited: Map<
|
|
345
|
-
const queue
|
|
304
|
+
const visited: Map<VO, boolean> = new Map();
|
|
305
|
+
const queue = new Queue<VO>([vertex1]);
|
|
346
306
|
visited.set(vertex1, true);
|
|
347
307
|
let cost = 0;
|
|
348
|
-
while (queue.
|
|
349
|
-
for (let i = 0; i < queue.
|
|
308
|
+
while (queue.size > 0) {
|
|
309
|
+
for (let i = 0; i < queue.size; i++) {
|
|
350
310
|
const cur = queue.shift();
|
|
351
311
|
if (cur === vertex2) {
|
|
352
312
|
return cost;
|
|
@@ -371,17 +331,17 @@ export abstract class AbstractGraph<
|
|
|
371
331
|
/**
|
|
372
332
|
* The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
|
|
373
333
|
* using a breadth-first search algorithm.
|
|
374
|
-
* @param {
|
|
375
|
-
* object (`
|
|
376
|
-
* @param {
|
|
334
|
+
* @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
|
|
335
|
+
* object (`VO`) or a vertex ID (`VertexKey`).
|
|
336
|
+
* @param {VO | VertexKey} v2 - VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum
|
|
377
337
|
* path.
|
|
378
338
|
* @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
|
|
379
339
|
* minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
|
|
380
340
|
* to false, the function will use breadth-first search (BFS) to find the minimum path.
|
|
381
|
-
* @returns The function `getMinPathBetween` returns an array of vertices (`
|
|
341
|
+
* @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
|
|
382
342
|
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `null`.
|
|
383
343
|
*/
|
|
384
|
-
getMinPathBetween(v1:
|
|
344
|
+
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): VO[] | null {
|
|
385
345
|
if (isWeight === undefined) isWeight = false;
|
|
386
346
|
|
|
387
347
|
if (isWeight) {
|
|
@@ -400,14 +360,14 @@ export abstract class AbstractGraph<
|
|
|
400
360
|
return allPaths[minIndex] || null;
|
|
401
361
|
} else {
|
|
402
362
|
// BFS
|
|
403
|
-
let minPath:
|
|
363
|
+
let minPath: VO[] = [];
|
|
404
364
|
const vertex1 = this._getVertex(v1);
|
|
405
365
|
const vertex2 = this._getVertex(v2);
|
|
406
366
|
if (!(vertex1 && vertex2)) {
|
|
407
367
|
return [];
|
|
408
368
|
}
|
|
409
369
|
|
|
410
|
-
const dfs = (cur:
|
|
370
|
+
const dfs = (cur: VO, dest: VO, visiting: Map<VO, boolean>, path: VO[]) => {
|
|
411
371
|
visiting.set(cur, true);
|
|
412
372
|
|
|
413
373
|
if (cur === dest) {
|
|
@@ -420,29 +380,29 @@ export abstract class AbstractGraph<
|
|
|
420
380
|
if (!visiting.get(neighbor)) {
|
|
421
381
|
path.push(neighbor);
|
|
422
382
|
dfs(neighbor, dest, visiting, path);
|
|
423
|
-
arrayRemove(path, (vertex:
|
|
383
|
+
arrayRemove(path, (vertex: VO) => vertex === neighbor);
|
|
424
384
|
}
|
|
425
385
|
}
|
|
426
386
|
|
|
427
387
|
visiting.set(cur, false);
|
|
428
388
|
};
|
|
429
389
|
|
|
430
|
-
dfs(vertex1, vertex2, new Map<
|
|
390
|
+
dfs(vertex1, vertex2, new Map<VO, boolean>(), []);
|
|
431
391
|
return minPath;
|
|
432
392
|
}
|
|
433
393
|
}
|
|
434
394
|
|
|
435
395
|
/**
|
|
436
|
-
* Dijkstra algorithm time: O(VE) space: O(
|
|
396
|
+
* Dijkstra algorithm time: O(VE) space: O(VO + EO)
|
|
437
397
|
* /
|
|
438
398
|
|
|
439
399
|
/**
|
|
440
|
-
* Dijkstra algorithm time: O(VE) space: O(
|
|
400
|
+
* Dijkstra algorithm time: O(VE) space: O(VO + EO)
|
|
441
401
|
* The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
|
|
442
402
|
* a graph without using a heap data structure.
|
|
443
|
-
* @param {
|
|
403
|
+
* @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
444
404
|
* vertex object or a vertex ID.
|
|
445
|
-
* @param {
|
|
405
|
+
* @param {VO | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
|
|
446
406
|
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
|
|
447
407
|
* identifier. If no destination is provided, the value is set to `null`.
|
|
448
408
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -451,27 +411,27 @@ export abstract class AbstractGraph<
|
|
|
451
411
|
* @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
|
|
452
412
|
* paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
|
|
453
413
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
454
|
-
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<
|
|
414
|
+
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
|
|
455
415
|
*/
|
|
456
416
|
dijkstraWithoutHeap(
|
|
457
|
-
src:
|
|
458
|
-
dest?:
|
|
417
|
+
src: VO | VertexKey,
|
|
418
|
+
dest?: VO | VertexKey | null,
|
|
459
419
|
getMinDist?: boolean,
|
|
460
420
|
genPaths?: boolean
|
|
461
|
-
): DijkstraResult<
|
|
421
|
+
): DijkstraResult<VO> {
|
|
462
422
|
if (getMinDist === undefined) getMinDist = false;
|
|
463
423
|
if (genPaths === undefined) genPaths = false;
|
|
464
424
|
|
|
465
425
|
if (dest === undefined) dest = null;
|
|
466
426
|
let minDist = Infinity;
|
|
467
|
-
let minDest:
|
|
468
|
-
let minPath:
|
|
469
|
-
const paths:
|
|
427
|
+
let minDest: VO | null = null;
|
|
428
|
+
let minPath: VO[] = [];
|
|
429
|
+
const paths: VO[][] = [];
|
|
470
430
|
|
|
471
431
|
const vertices = this._vertices;
|
|
472
|
-
const distMap: Map<
|
|
473
|
-
const seen: Set<
|
|
474
|
-
const preMap: Map<
|
|
432
|
+
const distMap: Map<VO, number> = new Map();
|
|
433
|
+
const seen: Set<VO> = new Set();
|
|
434
|
+
const preMap: Map<VO, VO | null> = new Map(); // predecessor
|
|
475
435
|
const srcVertex = this._getVertex(src);
|
|
476
436
|
|
|
477
437
|
const destVertex = dest ? this._getVertex(dest) : null;
|
|
@@ -489,11 +449,11 @@ export abstract class AbstractGraph<
|
|
|
489
449
|
|
|
490
450
|
const getMinOfNoSeen = () => {
|
|
491
451
|
let min = Infinity;
|
|
492
|
-
let minV:
|
|
493
|
-
for (const [key,
|
|
452
|
+
let minV: VO | null = null;
|
|
453
|
+
for (const [key, value] of distMap) {
|
|
494
454
|
if (!seen.has(key)) {
|
|
495
|
-
if (
|
|
496
|
-
min =
|
|
455
|
+
if (value < min) {
|
|
456
|
+
min = value;
|
|
497
457
|
minV = key;
|
|
498
458
|
}
|
|
499
459
|
}
|
|
@@ -501,12 +461,12 @@ export abstract class AbstractGraph<
|
|
|
501
461
|
return minV;
|
|
502
462
|
};
|
|
503
463
|
|
|
504
|
-
const getPaths = (minV:
|
|
464
|
+
const getPaths = (minV: VO | null) => {
|
|
505
465
|
for (const vertex of vertices) {
|
|
506
466
|
const vertexOrKey = vertex[1];
|
|
507
467
|
|
|
508
468
|
if (vertexOrKey instanceof AbstractVertex) {
|
|
509
|
-
const path:
|
|
469
|
+
const path: VO[] = [vertexOrKey];
|
|
510
470
|
let parent = preMap.get(vertexOrKey);
|
|
511
471
|
while (parent) {
|
|
512
472
|
path.push(parent);
|
|
@@ -553,14 +513,14 @@ export abstract class AbstractGraph<
|
|
|
553
513
|
}
|
|
554
514
|
|
|
555
515
|
getMinDist &&
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
}
|
|
516
|
+
distMap.forEach((d, v) => {
|
|
517
|
+
if (v !== srcVertex) {
|
|
518
|
+
if (d < minDist) {
|
|
519
|
+
minDist = d;
|
|
520
|
+
if (genPaths) minDest = v;
|
|
562
521
|
}
|
|
563
|
-
}
|
|
522
|
+
}
|
|
523
|
+
});
|
|
564
524
|
|
|
565
525
|
genPaths && getPaths(minDest);
|
|
566
526
|
|
|
@@ -568,11 +528,11 @@ export abstract class AbstractGraph<
|
|
|
568
528
|
}
|
|
569
529
|
|
|
570
530
|
/**
|
|
571
|
-
* Dijkstra algorithm time: O(logVE) space: O(
|
|
531
|
+
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
572
532
|
*
|
|
573
533
|
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
574
534
|
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
|
|
575
|
-
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(
|
|
535
|
+
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
576
536
|
*
|
|
577
537
|
* /
|
|
578
538
|
|
|
@@ -580,9 +540,9 @@ export abstract class AbstractGraph<
|
|
|
580
540
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
581
541
|
* The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
|
|
582
542
|
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
583
|
-
* @param {
|
|
543
|
+
* @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
|
|
584
544
|
* start. It can be either a vertex object or a vertex ID.
|
|
585
|
-
* @param {
|
|
545
|
+
* @param {VO | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
586
546
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
587
547
|
* will calculate the shortest paths to all other vertices from the source vertex.
|
|
588
548
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -591,26 +551,26 @@ export abstract class AbstractGraph<
|
|
|
591
551
|
* @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
|
|
592
552
|
* paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
|
|
593
553
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
594
|
-
* @returns The function `dijkstra` returns an object of type `DijkstraResult<
|
|
554
|
+
* @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
|
|
595
555
|
*/
|
|
596
556
|
dijkstra(
|
|
597
|
-
src:
|
|
598
|
-
dest?:
|
|
557
|
+
src: VO | VertexKey,
|
|
558
|
+
dest?: VO | VertexKey | null,
|
|
599
559
|
getMinDist?: boolean,
|
|
600
560
|
genPaths?: boolean
|
|
601
|
-
): DijkstraResult<
|
|
561
|
+
): DijkstraResult<VO> {
|
|
602
562
|
if (getMinDist === undefined) getMinDist = false;
|
|
603
563
|
if (genPaths === undefined) genPaths = false;
|
|
604
564
|
|
|
605
565
|
if (dest === undefined) dest = null;
|
|
606
566
|
let minDist = Infinity;
|
|
607
|
-
let minDest:
|
|
608
|
-
let minPath:
|
|
609
|
-
const paths:
|
|
567
|
+
let minDest: VO | null = null;
|
|
568
|
+
let minPath: VO[] = [];
|
|
569
|
+
const paths: VO[][] = [];
|
|
610
570
|
const vertices = this._vertices;
|
|
611
|
-
const distMap: Map<
|
|
612
|
-
const seen: Set<
|
|
613
|
-
const preMap: Map<
|
|
571
|
+
const distMap: Map<VO, number> = new Map();
|
|
572
|
+
const seen: Set<VO> = new Set();
|
|
573
|
+
const preMap: Map<VO, VO | null> = new Map(); // predecessor
|
|
614
574
|
|
|
615
575
|
const srcVertex = this._getVertex(src);
|
|
616
576
|
const destVertex = dest ? this._getVertex(dest) : null;
|
|
@@ -622,24 +582,22 @@ export abstract class AbstractGraph<
|
|
|
622
582
|
if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
|
|
623
583
|
}
|
|
624
584
|
|
|
625
|
-
const heap = new PriorityQueue<{key: number;
|
|
626
|
-
|
|
627
|
-
});
|
|
628
|
-
heap.add({key: 0, val: srcVertex});
|
|
585
|
+
const heap = new PriorityQueue<{ key: number; value: VO }>({comparator: (a, b) => a.key - b.key});
|
|
586
|
+
heap.add({key: 0, value: srcVertex});
|
|
629
587
|
|
|
630
588
|
distMap.set(srcVertex, 0);
|
|
631
589
|
preMap.set(srcVertex, null);
|
|
632
590
|
|
|
633
591
|
/**
|
|
634
592
|
* The function `getPaths` retrieves all paths from vertices to a specified minimum vertex.
|
|
635
|
-
* @param {
|
|
593
|
+
* @param {VO | null} minV - The parameter `minV` is of type `VO | null`. It represents the minimum vertex value or
|
|
636
594
|
* null.
|
|
637
595
|
*/
|
|
638
|
-
const getPaths = (minV:
|
|
596
|
+
const getPaths = (minV: VO | null) => {
|
|
639
597
|
for (const vertex of vertices) {
|
|
640
598
|
const vertexOrKey = vertex[1];
|
|
641
599
|
if (vertexOrKey instanceof AbstractVertex) {
|
|
642
|
-
const path:
|
|
600
|
+
const path: VO[] = [vertexOrKey];
|
|
643
601
|
let parent = preMap.get(vertexOrKey);
|
|
644
602
|
while (parent) {
|
|
645
603
|
path.push(parent);
|
|
@@ -655,7 +613,7 @@ export abstract class AbstractGraph<
|
|
|
655
613
|
while (heap.size > 0) {
|
|
656
614
|
const curHeapNode = heap.poll();
|
|
657
615
|
const dist = curHeapNode?.key;
|
|
658
|
-
const cur = curHeapNode?.
|
|
616
|
+
const cur = curHeapNode?.value;
|
|
659
617
|
if (dist !== undefined) {
|
|
660
618
|
if (cur) {
|
|
661
619
|
seen.add(cur);
|
|
@@ -676,7 +634,7 @@ export abstract class AbstractGraph<
|
|
|
676
634
|
const distSrcToNeighbor = distMap.get(neighbor);
|
|
677
635
|
if (distSrcToNeighbor) {
|
|
678
636
|
if (dist + weight < distSrcToNeighbor) {
|
|
679
|
-
heap.add({key: dist + weight,
|
|
637
|
+
heap.add({key: dist + weight, value: neighbor});
|
|
680
638
|
preMap.set(neighbor, cur);
|
|
681
639
|
distMap.set(neighbor, dist + weight);
|
|
682
640
|
}
|
|
@@ -707,17 +665,17 @@ export abstract class AbstractGraph<
|
|
|
707
665
|
}
|
|
708
666
|
|
|
709
667
|
/**
|
|
710
|
-
* BellmanFord time:O(VE) space:O(
|
|
668
|
+
* BellmanFord time:O(VE) space:O(VO)
|
|
711
669
|
* one to rest pairs
|
|
712
670
|
* /
|
|
713
671
|
|
|
714
672
|
/**
|
|
715
|
-
* BellmanFord time:O(VE) space:O(
|
|
673
|
+
* BellmanFord time:O(VE) space:O(VO)
|
|
716
674
|
* one to rest pairs
|
|
717
675
|
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
718
676
|
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
719
677
|
* all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
|
|
720
|
-
* @param {
|
|
678
|
+
* @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
|
|
721
679
|
* start calculating the shortest paths. It can be either a vertex object or a vertex ID.
|
|
722
680
|
* @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
|
|
723
681
|
* @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
|
|
@@ -727,16 +685,16 @@ export abstract class AbstractGraph<
|
|
|
727
685
|
* vertex.
|
|
728
686
|
* @returns The function `bellmanFord` returns an object with the following properties:
|
|
729
687
|
*/
|
|
730
|
-
bellmanFord(src:
|
|
688
|
+
bellmanFord(src: VO | VertexKey, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean) {
|
|
731
689
|
if (getMin === undefined) getMin = false;
|
|
732
690
|
if (genPath === undefined) genPath = false;
|
|
733
691
|
|
|
734
692
|
const srcVertex = this._getVertex(src);
|
|
735
|
-
const paths:
|
|
736
|
-
const distMap: Map<
|
|
737
|
-
const preMap: Map<
|
|
693
|
+
const paths: VO[][] = [];
|
|
694
|
+
const distMap: Map<VO, number> = new Map();
|
|
695
|
+
const preMap: Map<VO, VO> = new Map(); // predecessor
|
|
738
696
|
let min = Infinity;
|
|
739
|
-
let minPath:
|
|
697
|
+
let minPath: VO[] = [];
|
|
740
698
|
// TODO
|
|
741
699
|
let hasNegativeCycle: boolean | undefined;
|
|
742
700
|
if (scanNegativeCycle) hasNegativeCycle = false;
|
|
@@ -771,7 +729,7 @@ export abstract class AbstractGraph<
|
|
|
771
729
|
}
|
|
772
730
|
}
|
|
773
731
|
|
|
774
|
-
let minDest:
|
|
732
|
+
let minDest: VO | null = null;
|
|
775
733
|
if (getMin) {
|
|
776
734
|
distMap.forEach((d, v) => {
|
|
777
735
|
if (v !== srcVertex) {
|
|
@@ -787,7 +745,7 @@ export abstract class AbstractGraph<
|
|
|
787
745
|
for (const vertex of vertices) {
|
|
788
746
|
const vertexOrKey = vertex[1];
|
|
789
747
|
if (vertexOrKey instanceof AbstractVertex) {
|
|
790
|
-
const path:
|
|
748
|
+
const path: VO[] = [vertexOrKey];
|
|
791
749
|
let parent = preMap.get(vertexOrKey);
|
|
792
750
|
while (parent !== undefined) {
|
|
793
751
|
path.push(parent);
|
|
@@ -816,34 +774,34 @@ export abstract class AbstractGraph<
|
|
|
816
774
|
}
|
|
817
775
|
|
|
818
776
|
/**
|
|
819
|
-
* Dijkstra algorithm time: O(logVE) space: O(
|
|
777
|
+
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
820
778
|
* /
|
|
821
779
|
|
|
822
780
|
/**
|
|
823
|
-
* Dijkstra algorithm time: O(logVE) space: O(
|
|
781
|
+
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
824
782
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
825
783
|
*/
|
|
826
784
|
|
|
827
785
|
/**
|
|
828
|
-
* BellmanFord time:O(VE) space:O(
|
|
786
|
+
* BellmanFord time:O(VE) space:O(VO)
|
|
829
787
|
* one to rest pairs
|
|
830
788
|
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
831
789
|
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
832
790
|
*/
|
|
833
791
|
|
|
834
792
|
/**
|
|
835
|
-
* Floyd algorithm time: O(
|
|
793
|
+
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
836
794
|
* all pairs
|
|
837
795
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
838
796
|
*/
|
|
839
797
|
|
|
840
798
|
/**
|
|
841
|
-
* Floyd algorithm time: O(
|
|
799
|
+
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
842
800
|
* all pairs
|
|
843
801
|
* /
|
|
844
802
|
|
|
845
803
|
/**
|
|
846
|
-
* Floyd algorithm time: O(
|
|
804
|
+
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
847
805
|
* all pairs
|
|
848
806
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
849
807
|
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
|
|
@@ -853,12 +811,12 @@ export abstract class AbstractGraph<
|
|
|
853
811
|
* `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
|
|
854
812
|
* path between vertices in the
|
|
855
813
|
*/
|
|
856
|
-
floyd(): {costs: number[][]; predecessor: (
|
|
814
|
+
floyd(): { costs: number[][]; predecessor: (VO | null)[][] } {
|
|
857
815
|
const idAndVertices = [...this._vertices];
|
|
858
816
|
const n = idAndVertices.length;
|
|
859
817
|
|
|
860
818
|
const costs: number[][] = [];
|
|
861
|
-
const predecessor: (
|
|
819
|
+
const predecessor: (VO | null)[][] = [];
|
|
862
820
|
// successors
|
|
863
821
|
|
|
864
822
|
for (let i = 0; i < n; i++) {
|
|
@@ -928,8 +886,8 @@ export abstract class AbstractGraph<
|
|
|
928
886
|
if (needSCCs === undefined) needSCCs = defaultConfig;
|
|
929
887
|
if (needCycles === undefined) needCycles = defaultConfig;
|
|
930
888
|
|
|
931
|
-
const dfnMap: Map<
|
|
932
|
-
const lowMap: Map<
|
|
889
|
+
const dfnMap: Map<VO, number> = new Map();
|
|
890
|
+
const lowMap: Map<VO, number> = new Map();
|
|
933
891
|
const vertices = this._vertices;
|
|
934
892
|
vertices.forEach(v => {
|
|
935
893
|
dfnMap.set(v, -1);
|
|
@@ -938,10 +896,10 @@ export abstract class AbstractGraph<
|
|
|
938
896
|
|
|
939
897
|
const [root] = vertices.values();
|
|
940
898
|
|
|
941
|
-
const articulationPoints:
|
|
942
|
-
const bridges:
|
|
899
|
+
const articulationPoints: VO[] = [];
|
|
900
|
+
const bridges: EO[] = [];
|
|
943
901
|
let dfn = 0;
|
|
944
|
-
const dfs = (cur:
|
|
902
|
+
const dfs = (cur: VO, parent: VO | null) => {
|
|
945
903
|
dfn++;
|
|
946
904
|
dfnMap.set(cur, dfn);
|
|
947
905
|
lowMap.set(cur, dfn);
|
|
@@ -984,10 +942,10 @@ export abstract class AbstractGraph<
|
|
|
984
942
|
|
|
985
943
|
dfs(root, null);
|
|
986
944
|
|
|
987
|
-
let SCCs: Map<number,
|
|
945
|
+
let SCCs: Map<number, VO[]> = new Map();
|
|
988
946
|
|
|
989
947
|
const getSCCs = () => {
|
|
990
|
-
const SCCs: Map<number,
|
|
948
|
+
const SCCs: Map<number, VO[]> = new Map();
|
|
991
949
|
lowMap.forEach((low, vertex) => {
|
|
992
950
|
if (!SCCs.has(low)) {
|
|
993
951
|
SCCs.set(low, [vertex]);
|
|
@@ -1002,9 +960,9 @@ export abstract class AbstractGraph<
|
|
|
1002
960
|
SCCs = getSCCs();
|
|
1003
961
|
}
|
|
1004
962
|
|
|
1005
|
-
const cycles: Map<number,
|
|
963
|
+
const cycles: Map<number, VO[]> = new Map();
|
|
1006
964
|
if (needCycles) {
|
|
1007
|
-
let SCCs: Map<number,
|
|
965
|
+
let SCCs: Map<number, VO[]> = new Map();
|
|
1008
966
|
if (SCCs.size < 1) {
|
|
1009
967
|
SCCs = getSCCs();
|
|
1010
968
|
}
|
|
@@ -1019,9 +977,9 @@ export abstract class AbstractGraph<
|
|
|
1019
977
|
return {dfnMap, lowMap, bridges, articulationPoints, SCCs, cycles};
|
|
1020
978
|
}
|
|
1021
979
|
|
|
1022
|
-
protected abstract _addEdgeOnly(edge:
|
|
980
|
+
protected abstract _addEdgeOnly(edge: EO): boolean;
|
|
1023
981
|
|
|
1024
|
-
protected _addVertexOnly(newVertex:
|
|
982
|
+
protected _addVertexOnly(newVertex: VO): boolean {
|
|
1025
983
|
if (this.hasVertex(newVertex)) {
|
|
1026
984
|
return false;
|
|
1027
985
|
// throw (new Error('Duplicated vertex key is not allowed'));
|
|
@@ -1030,16 +988,13 @@ export abstract class AbstractGraph<
|
|
|
1030
988
|
return true;
|
|
1031
989
|
}
|
|
1032
990
|
|
|
1033
|
-
protected _getVertex(vertexOrKey: VertexKey |
|
|
991
|
+
protected _getVertex(vertexOrKey: VertexKey | VO): VO | null {
|
|
1034
992
|
const vertexKey = this._getVertexKey(vertexOrKey);
|
|
1035
993
|
return this._vertices.get(vertexKey) || null;
|
|
1036
994
|
}
|
|
1037
995
|
|
|
1038
|
-
protected _getVertexKey(vertexOrKey:
|
|
996
|
+
protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey {
|
|
1039
997
|
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
|
|
1040
998
|
}
|
|
1041
999
|
|
|
1042
|
-
protected _setVertices(value: Map<VertexKey, V>) {
|
|
1043
|
-
this._vertices = value;
|
|
1044
|
-
}
|
|
1045
1000
|
}
|