data-structure-typed 1.53.9 → 1.54.1
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/CHANGELOG.md +1 -1
- package/README.md +1 -0
- package/benchmark/report.html +1 -28
- package/benchmark/report.json +17 -326
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts → cjs/data-structures/binary-tree/avl-tree-counter.d.ts} +54 -59
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +408 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -189
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +133 -357
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +108 -78
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +126 -79
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +243 -190
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +273 -229
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +141 -122
- package/dist/cjs/data-structures/binary-tree/bst.js +170 -134
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +84 -80
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +101 -79
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.d.ts → cjs/data-structures/binary-tree/tree-counter.d.ts} +54 -56
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +445 -0
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +78 -186
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +140 -388
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -4
- package/dist/cjs/data-structures/trie/trie.js +0 -4
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +7 -6
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -3
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.js → esm/data-structures/binary-tree/avl-tree-counter.js} +72 -78
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +191 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +234 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/avl-tree.js +126 -80
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.d.ts +243 -190
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.js +276 -234
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.d.ts +141 -122
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.js +171 -140
- package/dist/esm/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js +2 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js.map +1 -1
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.d.ts +84 -80
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.js +100 -79
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.js → esm/data-structures/binary-tree/tree-counter.js} +88 -86
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +106 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +196 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.js +3 -0
- package/dist/esm/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.js +3 -0
- package/dist/esm/data-structures/graph/map-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.js +3 -0
- package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.js +3 -0
- package/dist/esm/data-structures/matrix/matrix.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.js +3 -0
- package/dist/esm/data-structures/matrix/navigator.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/trie/trie.d.ts +0 -4
- package/dist/{mjs → esm}/data-structures/trie/trie.js +0 -4
- package/dist/esm/data-structures/trie/trie.js.map +1 -0
- package/dist/esm/interfaces/binary-tree.d.ts +9 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/esm/types/data-structures/binary-tree/rb-tree.d.ts +3 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/umd/data-structure-typed.js +1407 -913
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +14 -14
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +148 -394
- package/src/data-structures/binary-tree/avl-tree.ts +152 -112
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +446 -379
- package/src/data-structures/binary-tree/bst.ts +224 -201
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +138 -114
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +156 -428
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- package/src/data-structures/trie/trie.ts +0 -4
- package/src/interfaces/binary-tree.ts +10 -11
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -3
- package/src/types/data-structures/binary-tree/index.ts +2 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -4
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -4
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/integration/avl-tree.test.ts +1 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/integration/compile.js +144 -0
- package/test/integration/compile.ts +171 -0
- package/test/integration/index.html +48 -48
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -4
- package/test/performance/data-structures/comparison/comparison.test.ts +2 -2
- package/test/performance/reportor.ts +5 -3
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +877 -0
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +459 -761
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +223 -223
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +474 -492
- package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/overall.test.ts +0 -3
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +87 -90
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +975 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +729 -857
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/{tsconfig-mjs.json → tsconfig-esm.json} +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -204
- package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/map-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix.js.map +0 -1
- package/dist/mjs/data-structures/matrix/navigator.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/trie/trie.js.map +0 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +0 -8
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -4
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -4
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -4
- /package/dist/{mjs → esm}/common/index.d.ts +0 -0
- /package/dist/{mjs → esm}/common/index.js +0 -0
- /package/dist/{mjs → esm}/common/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.js +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.js +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.js +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.js.map +0 -0
- /package/dist/{mjs → esm}/index.d.ts +0 -0
- /package/dist/{mjs → esm}/index.js +0 -0
- /package/dist/{mjs → esm}/index.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/binary-tree.js +0 -0
- /package/dist/{mjs → esm}/interfaces/binary-tree.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.js +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.js +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/index.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/index.js +0 -0
- /package/dist/{mjs → esm}/interfaces/index.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.js +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/common.d.ts +0 -0
- /package/dist/{mjs → esm}/types/common.js +0 -0
- /package/dist/{mjs → esm}/types/common.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/rb-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/rb-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.js.map +0 -0
- /package/dist/{mjs → esm}/types/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/index.js +0 -0
- /package/dist/{mjs → esm}/types/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/index.js +0 -0
- /package/dist/{mjs → esm}/types/utils/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.js +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.js +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.js.map +0 -0
- /package/dist/{mjs → esm}/utils/index.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/index.js +0 -0
- /package/dist/{mjs → esm}/utils/index.js.map +0 -0
- /package/dist/{mjs → esm}/utils/number.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/number.js +0 -0
- /package/dist/{mjs → esm}/utils/number.js.map +0 -0
- /package/dist/{mjs → esm}/utils/utils.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/utils.js +0 -0
- /package/dist/{mjs → esm}/utils/utils.js.map +0 -0
|
@@ -3,119 +3,119 @@ import { AVLTree, AVLTreeNode, BinaryTreeNode, BSTNode } from '../../../../src';
|
|
|
3
3
|
describe('AVL Tree Test', () => {
|
|
4
4
|
it('should perform various operations on a AVL Tree', () => {
|
|
5
5
|
const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
6
|
-
const
|
|
6
|
+
const avlTree = new AVLTree<number>();
|
|
7
7
|
|
|
8
|
-
for (const i of arr)
|
|
8
|
+
for (const i of arr) avlTree.add([i, i]);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
const node6 =
|
|
10
|
+
avlTree.add(null);
|
|
11
|
+
const node6 = avlTree.getNode(6);
|
|
12
12
|
|
|
13
|
-
expect(node6 &&
|
|
14
|
-
expect(node6 &&
|
|
13
|
+
expect(node6 && avlTree.getHeight(node6)).toBe(3);
|
|
14
|
+
expect(node6 && avlTree.getDepth(node6)).toBe(1);
|
|
15
15
|
|
|
16
|
-
const getNodeById =
|
|
16
|
+
const getNodeById = avlTree.getNode(10);
|
|
17
17
|
expect(getNodeById?.key).toBe(10);
|
|
18
18
|
|
|
19
|
-
const getMinNodeByRoot =
|
|
19
|
+
const getMinNodeByRoot = avlTree.getLeftMost();
|
|
20
20
|
expect(getMinNodeByRoot).toBe(1);
|
|
21
21
|
|
|
22
|
-
const node15 =
|
|
23
|
-
const getMinNodeBySpecificNode = node15 &&
|
|
22
|
+
const node15 = avlTree.getNode(15);
|
|
23
|
+
const getMinNodeBySpecificNode = node15 && avlTree.getLeftMost(node => node, node15);
|
|
24
24
|
expect(getMinNodeBySpecificNode?.key).toBe(12);
|
|
25
25
|
|
|
26
26
|
let subTreeSum = 0;
|
|
27
|
-
if (node15)
|
|
27
|
+
if (node15) avlTree.dfs(node => (subTreeSum += node.key), 'PRE', node15);
|
|
28
28
|
expect(subTreeSum).toBe(70);
|
|
29
29
|
|
|
30
30
|
let lesserSum = 0;
|
|
31
|
-
|
|
31
|
+
avlTree.lesserOrGreaterTraverse(node => (lesserSum += node.key), -1, 10);
|
|
32
32
|
expect(lesserSum).toBe(45);
|
|
33
33
|
|
|
34
34
|
// node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class.
|
|
35
35
|
expect(node15?.value).toBe(undefined);
|
|
36
|
-
const dfs =
|
|
36
|
+
const dfs = avlTree.dfs(node => node, 'IN');
|
|
37
37
|
expect(dfs[0].key).toBe(1);
|
|
38
38
|
expect(dfs[dfs.length - 1].key).toBe(16);
|
|
39
|
-
|
|
40
|
-
const bfs =
|
|
41
|
-
expect(
|
|
39
|
+
avlTree.perfectlyBalance();
|
|
40
|
+
const bfs = avlTree.bfs(node => node);
|
|
41
|
+
expect(avlTree.isPerfectlyBalanced()).toBe(true);
|
|
42
42
|
expect(bfs[0].key).toBe(8);
|
|
43
43
|
expect(bfs[bfs.length - 1].key).toBe(16);
|
|
44
44
|
|
|
45
|
-
expect(
|
|
46
|
-
expect(
|
|
47
|
-
expect(node15 &&
|
|
45
|
+
expect(avlTree.delete(avlTree.getNode(11))[0].deleted?.key).toBe(11);
|
|
46
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
47
|
+
expect(node15 && avlTree.getHeight(node15)).toBe(2);
|
|
48
48
|
|
|
49
|
-
expect(
|
|
50
|
-
expect(
|
|
51
|
-
expect(
|
|
49
|
+
expect(avlTree.delete(1)[0].deleted?.key).toBe(1);
|
|
50
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
51
|
+
expect(avlTree.getHeight()).toBe(4);
|
|
52
52
|
|
|
53
|
-
expect(
|
|
54
|
-
expect(
|
|
55
|
-
expect(
|
|
53
|
+
expect(avlTree.delete(4)[0].deleted?.key).toBe(4);
|
|
54
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
55
|
+
expect(avlTree.getHeight()).toBe(4);
|
|
56
56
|
|
|
57
|
-
expect(
|
|
58
|
-
expect(
|
|
59
|
-
expect(
|
|
57
|
+
expect(avlTree.delete(10)[0].deleted?.key).toBe(10);
|
|
58
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
59
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
60
60
|
|
|
61
|
-
expect(
|
|
62
|
-
expect(
|
|
61
|
+
expect(avlTree.delete(15)[0].deleted?.key).toBe(15);
|
|
62
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
63
63
|
|
|
64
|
-
expect(
|
|
64
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
65
65
|
|
|
66
|
-
expect(
|
|
67
|
-
expect(
|
|
68
|
-
expect(
|
|
66
|
+
expect(avlTree.delete(5)[0].deleted?.key).toBe(5);
|
|
67
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
68
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
69
69
|
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
72
|
-
expect(
|
|
70
|
+
expect(avlTree.delete(13)[0].deleted?.key).toBe(13);
|
|
71
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
72
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
73
73
|
|
|
74
|
-
expect(
|
|
75
|
-
expect(
|
|
76
|
-
expect(
|
|
74
|
+
expect(avlTree.delete(3)[0].deleted?.key).toBe(3);
|
|
75
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
76
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
77
77
|
|
|
78
|
-
expect(
|
|
79
|
-
expect(
|
|
80
|
-
expect(
|
|
78
|
+
expect(avlTree.delete(8)[0].deleted?.key).toBe(8);
|
|
79
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
80
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
81
81
|
|
|
82
|
-
expect(
|
|
83
|
-
expect(
|
|
84
|
-
expect(
|
|
85
|
-
expect(
|
|
82
|
+
expect(avlTree.delete(6)[0].deleted?.key).toBe(6);
|
|
83
|
+
expect(avlTree.delete(6).length).toBe(0);
|
|
84
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
85
|
+
expect(avlTree.getHeight()).toBe(2);
|
|
86
86
|
|
|
87
|
-
expect(
|
|
88
|
-
expect(
|
|
89
|
-
expect(
|
|
87
|
+
expect(avlTree.delete(7)[0].deleted?.key).toBe(7);
|
|
88
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
89
|
+
expect(avlTree.getHeight()).toBe(2);
|
|
90
90
|
|
|
91
|
-
expect(
|
|
92
|
-
expect(
|
|
93
|
-
expect(
|
|
94
|
-
expect(
|
|
95
|
-
expect(
|
|
96
|
-
expect(
|
|
91
|
+
expect(avlTree.delete(9)[0].deleted?.key).toBe(9);
|
|
92
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
93
|
+
expect(avlTree.getHeight()).toBe(2);
|
|
94
|
+
expect(avlTree.delete(14)[0].deleted?.key).toBe(14);
|
|
95
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
96
|
+
expect(avlTree.getHeight()).toBe(1);
|
|
97
97
|
|
|
98
|
-
expect(
|
|
99
|
-
const lastBFSIds =
|
|
98
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
99
|
+
const lastBFSIds = avlTree.bfs();
|
|
100
100
|
expect(lastBFSIds[0]).toBe(12);
|
|
101
101
|
expect(lastBFSIds[1]).toBe(2);
|
|
102
102
|
expect(lastBFSIds[2]).toBe(16);
|
|
103
103
|
|
|
104
|
-
const lastBFSNodes =
|
|
104
|
+
const lastBFSNodes = avlTree.bfs(node => node);
|
|
105
105
|
expect(lastBFSNodes[0].key).toBe(12);
|
|
106
106
|
expect(lastBFSNodes[1].key).toBe(2);
|
|
107
107
|
expect(lastBFSNodes[2].key).toBe(16);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it('should replace value', () => {
|
|
111
|
-
const
|
|
112
|
-
expect(
|
|
113
|
-
expect(
|
|
114
|
-
|
|
115
|
-
expect(
|
|
116
|
-
|
|
117
|
-
expect(
|
|
118
|
-
expect(
|
|
111
|
+
const avlTree = new AVLTree<number, string>([4, 5, [1, '1'], 2, 3], { isMapMode: false });
|
|
112
|
+
expect(avlTree.get(1)).toBe('1');
|
|
113
|
+
expect(avlTree.getNode(1)?.value).toBe('1');
|
|
114
|
+
avlTree.add(1, 'a');
|
|
115
|
+
expect(avlTree.get(1)).toBe('a');
|
|
116
|
+
avlTree.add([1, 'b']);
|
|
117
|
+
expect(avlTree.getNode(1)?.value).toBe('b');
|
|
118
|
+
expect(avlTree.get(1)).toBe('b');
|
|
119
119
|
const treeMap = new AVLTree<number>([4, 5, [1, '1'], 2, 3]);
|
|
120
120
|
expect(treeMap.get(1)).toBe('1');
|
|
121
121
|
expect(treeMap.getNode(1)?.value).toBe(undefined);
|
|
@@ -130,106 +130,106 @@ describe('AVL Tree Test', () => {
|
|
|
130
130
|
describe('AVL Tree Test recursively', () => {
|
|
131
131
|
it('should perform various operations on a AVL Tree', () => {
|
|
132
132
|
const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
133
|
-
const
|
|
133
|
+
const avlTree = new AVLTree<number>([], { iterationType: 'RECURSIVE' });
|
|
134
134
|
|
|
135
|
-
for (const i of arr)
|
|
135
|
+
for (const i of arr) avlTree.add([i, i]);
|
|
136
136
|
|
|
137
|
-
const node6 =
|
|
137
|
+
const node6 = avlTree.getNode(6);
|
|
138
138
|
|
|
139
|
-
expect(node6 &&
|
|
140
|
-
expect(node6 &&
|
|
139
|
+
expect(node6 && avlTree.getHeight(node6)).toBe(3);
|
|
140
|
+
expect(node6 && avlTree.getDepth(node6)).toBe(1);
|
|
141
141
|
|
|
142
|
-
const getNodeById =
|
|
142
|
+
const getNodeById = avlTree.getNode(10);
|
|
143
143
|
expect(getNodeById?.key).toBe(10);
|
|
144
144
|
|
|
145
|
-
const getMinNodeByRoot =
|
|
145
|
+
const getMinNodeByRoot = avlTree.getLeftMost();
|
|
146
146
|
expect(getMinNodeByRoot).toBe(1);
|
|
147
147
|
|
|
148
|
-
const node15 =
|
|
149
|
-
const getMinNodeBySpecificNode = node15 &&
|
|
148
|
+
const node15 = avlTree.getNode(15);
|
|
149
|
+
const getMinNodeBySpecificNode = node15 && avlTree.getLeftMost(node => node, node15);
|
|
150
150
|
expect(getMinNodeBySpecificNode?.key).toBe(12);
|
|
151
151
|
|
|
152
152
|
let subTreeSum = 0;
|
|
153
|
-
if (node15)
|
|
153
|
+
if (node15) avlTree.dfs(node => (subTreeSum += node.key), 'PRE', node15);
|
|
154
154
|
expect(subTreeSum).toBe(70);
|
|
155
155
|
|
|
156
156
|
let lesserSum = 0;
|
|
157
|
-
|
|
157
|
+
avlTree.lesserOrGreaterTraverse(node => (lesserSum += node.key), -1, 10);
|
|
158
158
|
expect(lesserSum).toBe(45);
|
|
159
159
|
|
|
160
160
|
// node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class.
|
|
161
161
|
expect(node15?.value).toBe(undefined);
|
|
162
162
|
|
|
163
|
-
const dfs =
|
|
163
|
+
const dfs = avlTree.dfs(node => node, 'IN');
|
|
164
164
|
expect(dfs[0].key).toBe(1);
|
|
165
165
|
expect(dfs[dfs.length - 1].key).toBe(16);
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
const bfs =
|
|
169
|
-
expect(
|
|
167
|
+
avlTree.perfectlyBalance();
|
|
168
|
+
const bfs = avlTree.bfs(node => node);
|
|
169
|
+
expect(avlTree.isPerfectlyBalanced()).toBe(true);
|
|
170
170
|
expect(bfs[0].key).toBe(8);
|
|
171
171
|
expect(bfs[bfs.length - 1].key).toBe(16);
|
|
172
172
|
|
|
173
|
-
expect(
|
|
174
|
-
expect(
|
|
175
|
-
expect(node15 &&
|
|
173
|
+
expect(avlTree.delete(11)[0].deleted?.key).toBe(11);
|
|
174
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
175
|
+
expect(node15 && avlTree.getHeight(node15)).toBe(2);
|
|
176
176
|
|
|
177
|
-
expect(
|
|
178
|
-
expect(
|
|
179
|
-
expect(
|
|
177
|
+
expect(avlTree.delete(1)[0].deleted?.key).toBe(1);
|
|
178
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
179
|
+
expect(avlTree.getHeight()).toBe(4);
|
|
180
180
|
|
|
181
|
-
expect(
|
|
182
|
-
expect(
|
|
183
|
-
expect(
|
|
181
|
+
expect(avlTree.delete(4)[0].deleted?.key).toBe(4);
|
|
182
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
183
|
+
expect(avlTree.getHeight()).toBe(4);
|
|
184
184
|
|
|
185
|
-
expect(
|
|
186
|
-
expect(
|
|
187
|
-
expect(
|
|
185
|
+
expect(avlTree.delete(10)[0].deleted?.key).toBe(10);
|
|
186
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
187
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
188
188
|
|
|
189
|
-
expect(
|
|
190
|
-
expect(
|
|
189
|
+
expect(avlTree.delete(15)[0].deleted?.key).toBe(15);
|
|
190
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
191
191
|
|
|
192
|
-
expect(
|
|
192
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
193
193
|
|
|
194
|
-
expect(
|
|
195
|
-
expect(
|
|
196
|
-
expect(
|
|
194
|
+
expect(avlTree.delete(5)[0].deleted?.key).toBe(5);
|
|
195
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
196
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
197
197
|
|
|
198
|
-
expect(
|
|
199
|
-
expect(
|
|
200
|
-
expect(
|
|
198
|
+
expect(avlTree.delete(13)[0].deleted?.key).toBe(13);
|
|
199
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
200
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
201
201
|
|
|
202
|
-
expect(
|
|
203
|
-
expect(
|
|
204
|
-
expect(
|
|
202
|
+
expect(avlTree.delete(3)[0].deleted?.key).toBe(3);
|
|
203
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
204
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
205
205
|
|
|
206
|
-
expect(
|
|
207
|
-
expect(
|
|
208
|
-
expect(
|
|
206
|
+
expect(avlTree.delete(8)[0].deleted?.key).toBe(8);
|
|
207
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
208
|
+
expect(avlTree.getHeight()).toBe(3);
|
|
209
209
|
|
|
210
|
-
expect(
|
|
211
|
-
expect(
|
|
212
|
-
expect(
|
|
213
|
-
expect(
|
|
210
|
+
expect(avlTree.delete(6)[0].deleted?.key).toBe(6);
|
|
211
|
+
expect(avlTree.delete(6).length).toBe(0);
|
|
212
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
213
|
+
expect(avlTree.getHeight()).toBe(2);
|
|
214
214
|
|
|
215
|
-
expect(
|
|
216
|
-
expect(
|
|
217
|
-
expect(
|
|
215
|
+
expect(avlTree.delete(7)[0].deleted?.key).toBe(7);
|
|
216
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
217
|
+
expect(avlTree.getHeight()).toBe(2);
|
|
218
218
|
|
|
219
|
-
expect(
|
|
220
|
-
expect(
|
|
221
|
-
expect(
|
|
222
|
-
expect(
|
|
223
|
-
expect(
|
|
224
|
-
expect(
|
|
219
|
+
expect(avlTree.delete(9)[0].deleted?.key).toBe(9);
|
|
220
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
221
|
+
expect(avlTree.getHeight()).toBe(2);
|
|
222
|
+
expect(avlTree.delete(14)[0].deleted?.key).toBe(14);
|
|
223
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
224
|
+
expect(avlTree.getHeight()).toBe(1);
|
|
225
225
|
|
|
226
|
-
expect(
|
|
227
|
-
const lastBFSIds =
|
|
226
|
+
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
227
|
+
const lastBFSIds = avlTree.bfs();
|
|
228
228
|
expect(lastBFSIds[0]).toBe(12);
|
|
229
229
|
expect(lastBFSIds[1]).toBe(2);
|
|
230
230
|
expect(lastBFSIds[2]).toBe(16);
|
|
231
231
|
|
|
232
|
-
const lastBFSNodes =
|
|
232
|
+
const lastBFSNodes = avlTree.bfs(node => node);
|
|
233
233
|
expect(lastBFSNodes[0].key).toBe(12);
|
|
234
234
|
expect(lastBFSNodes[1].key).toBe(2);
|
|
235
235
|
expect(lastBFSNodes[2].key).toBe(16);
|
|
@@ -237,66 +237,66 @@ describe('AVL Tree Test recursively', () => {
|
|
|
237
237
|
});
|
|
238
238
|
|
|
239
239
|
describe('AVLTree APIs test', () => {
|
|
240
|
-
const
|
|
240
|
+
const avlTree = new AVLTree<number, { id: number; text: string }>();
|
|
241
241
|
beforeEach(() => {
|
|
242
|
-
|
|
242
|
+
avlTree.clear();
|
|
243
243
|
});
|
|
244
244
|
|
|
245
245
|
it('add', () => {
|
|
246
|
-
|
|
246
|
+
avlTree.add(1);
|
|
247
247
|
const node2 = new AVLTreeNode(2);
|
|
248
|
-
|
|
248
|
+
avlTree.add(node2);
|
|
249
249
|
const node3 = new AVLTreeNode(3, {
|
|
250
250
|
id: 3,
|
|
251
251
|
text: 'text3'
|
|
252
252
|
});
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
avlTree.add(node3);
|
|
254
|
+
avlTree.add([3, { id: 3, text: 'text33' }]);
|
|
255
255
|
|
|
256
|
-
const bfsRes =
|
|
256
|
+
const bfsRes = avlTree.bfs(node => node.key);
|
|
257
257
|
expect(bfsRes[0]).toBe(2);
|
|
258
258
|
});
|
|
259
259
|
|
|
260
260
|
it('should the clone method', () => {
|
|
261
|
-
function checkTreeStructure(
|
|
262
|
-
expect(
|
|
263
|
-
expect(
|
|
264
|
-
expect(
|
|
265
|
-
expect(
|
|
266
|
-
expect(
|
|
267
|
-
expect(
|
|
268
|
-
expect(
|
|
269
|
-
expect(
|
|
261
|
+
function checkTreeStructure(avlTree: AVLTree<string, number>) {
|
|
262
|
+
expect(avlTree.size).toBe(4);
|
|
263
|
+
expect(avlTree.root?.key).toBe('2');
|
|
264
|
+
expect(avlTree.root?.left?.key).toBe('1');
|
|
265
|
+
expect(avlTree.root?.left?.left?.key).toBe(undefined);
|
|
266
|
+
expect(avlTree.root?.left?.right?.key).toBe(undefined);
|
|
267
|
+
expect(avlTree.root?.right?.key).toBe('4');
|
|
268
|
+
expect(avlTree.root?.right?.left?.key).toBe(undefined);
|
|
269
|
+
expect(avlTree.root?.right?.right?.key).toBe('5');
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
const
|
|
273
|
-
|
|
272
|
+
const avlTree = new AVLTree<string, number>();
|
|
273
|
+
avlTree.addMany([
|
|
274
274
|
['2', 2],
|
|
275
275
|
['4', 4],
|
|
276
276
|
['5', 5],
|
|
277
277
|
['3', 3],
|
|
278
278
|
['1', 1]
|
|
279
279
|
]);
|
|
280
|
-
expect(
|
|
281
|
-
expect(
|
|
282
|
-
expect(
|
|
283
|
-
expect(
|
|
284
|
-
expect(
|
|
285
|
-
expect(
|
|
286
|
-
expect(
|
|
287
|
-
expect(
|
|
288
|
-
|
|
289
|
-
checkTreeStructure(
|
|
290
|
-
const cloned =
|
|
280
|
+
expect(avlTree.size).toBe(5);
|
|
281
|
+
expect(avlTree.root?.key).toBe('2');
|
|
282
|
+
expect(avlTree.root?.left?.key).toBe('1');
|
|
283
|
+
expect(avlTree.root?.left?.left?.key).toBe(undefined);
|
|
284
|
+
expect(avlTree.root?.left?.right?.key).toBe(undefined);
|
|
285
|
+
expect(avlTree.root?.right?.key).toBe('4');
|
|
286
|
+
expect(avlTree.root?.right?.left?.key).toBe('3');
|
|
287
|
+
expect(avlTree.root?.right?.right?.key).toBe('5');
|
|
288
|
+
avlTree.delete('3');
|
|
289
|
+
checkTreeStructure(avlTree);
|
|
290
|
+
const cloned = avlTree.clone();
|
|
291
291
|
checkTreeStructure(cloned);
|
|
292
292
|
cloned.delete('1');
|
|
293
|
-
expect(
|
|
293
|
+
expect(avlTree.size).toBe(4);
|
|
294
294
|
expect(cloned.size).toBe(3);
|
|
295
295
|
});
|
|
296
296
|
});
|
|
297
297
|
|
|
298
298
|
describe('AVLTree', () => {
|
|
299
|
-
it('should balance the
|
|
299
|
+
it('should balance the avlTree using _balanceLR when nodes are added', () => {
|
|
300
300
|
const avlTree = new AVLTree();
|
|
301
301
|
avlTree.add([10, 'A']);
|
|
302
302
|
avlTree.add([5, 'B']);
|
|
@@ -307,30 +307,30 @@ describe('AVLTree', () => {
|
|
|
307
307
|
// Adding nodes to trigger _balanceLR
|
|
308
308
|
avlTree.add([12, 'F']);
|
|
309
309
|
|
|
310
|
-
// You can add more specific assertions to check the
|
|
310
|
+
// You can add more specific assertions to check the avlTree's balance and structure.
|
|
311
311
|
});
|
|
312
312
|
|
|
313
313
|
it('should addMany undefined and null', () => {
|
|
314
|
-
const
|
|
315
|
-
const addManyWithUndefined =
|
|
314
|
+
const avlTree = new AVLTree<number, string>();
|
|
315
|
+
const addManyWithUndefined = avlTree.addMany([1, undefined, 3]);
|
|
316
316
|
expect(addManyWithUndefined).toEqual([true, false, true]);
|
|
317
|
-
expect(
|
|
318
|
-
const addManyWithNull =
|
|
317
|
+
expect(avlTree.get(undefined)).toBe(undefined);
|
|
318
|
+
const addManyWithNull = avlTree.addMany([1, null, 3, 4]);
|
|
319
319
|
expect(addManyWithNull).toEqual([true, false, true, true]);
|
|
320
|
-
const addManyEntriesWithNull =
|
|
320
|
+
const addManyEntriesWithNull = avlTree.addMany([
|
|
321
321
|
[1, '1'],
|
|
322
322
|
[null, 'null'],
|
|
323
323
|
[3, '3'],
|
|
324
324
|
[4, '4']
|
|
325
325
|
]);
|
|
326
326
|
expect(addManyEntriesWithNull).toEqual([true, false, true, true]);
|
|
327
|
-
expect(
|
|
328
|
-
const node0 =
|
|
327
|
+
expect(avlTree.get(null)).toBe(undefined);
|
|
328
|
+
const node0 = avlTree.add(0, '0');
|
|
329
329
|
expect(node0).toBe(true);
|
|
330
|
-
expect(
|
|
330
|
+
expect(avlTree.get(0)).toBe('0');
|
|
331
331
|
});
|
|
332
332
|
|
|
333
|
-
it('should balance the
|
|
333
|
+
it('should balance the avlTree using _balanceLR when nodes are deleted', () => {
|
|
334
334
|
const avlTree = new AVLTree();
|
|
335
335
|
avlTree.add([10, 'A']);
|
|
336
336
|
avlTree.add([5, 'B']);
|
|
@@ -342,43 +342,43 @@ describe('AVLTree', () => {
|
|
|
342
342
|
// Deleting nodes to trigger _balanceLR
|
|
343
343
|
avlTree.delete(3);
|
|
344
344
|
|
|
345
|
-
// You can add more specific assertions to check the
|
|
345
|
+
// You can add more specific assertions to check the avlTree's balance and structure.
|
|
346
346
|
});
|
|
347
347
|
|
|
348
|
-
describe('
|
|
349
|
-
const
|
|
348
|
+
describe('AVLTree APIs test', () => {
|
|
349
|
+
const avlTree = new AVLTree<number, { id: number; text: string }>();
|
|
350
350
|
beforeEach(() => {
|
|
351
|
-
|
|
351
|
+
avlTree.clear();
|
|
352
352
|
});
|
|
353
353
|
|
|
354
354
|
it('add', () => {
|
|
355
|
-
|
|
355
|
+
avlTree.add(1);
|
|
356
356
|
const node2 = new AVLTreeNode(2);
|
|
357
|
-
|
|
357
|
+
avlTree.add(node2);
|
|
358
358
|
const node3 = new AVLTreeNode(3, {
|
|
359
359
|
id: 3,
|
|
360
360
|
text: 'text3'
|
|
361
361
|
});
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
avlTree.add(node3);
|
|
363
|
+
avlTree.add([3, { id: 3, text: 'text33' }]);
|
|
364
364
|
|
|
365
|
-
const bfsRes =
|
|
365
|
+
const bfsRes = avlTree.bfs(node => node);
|
|
366
366
|
expect(bfsRes[0]?.key).toBe(2);
|
|
367
367
|
});
|
|
368
368
|
});
|
|
369
369
|
});
|
|
370
370
|
|
|
371
371
|
describe('AVLTree iterative methods test', () => {
|
|
372
|
-
let
|
|
372
|
+
let avlTree: AVLTree<number, string>;
|
|
373
373
|
beforeEach(() => {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
374
|
+
avlTree = new AVLTree();
|
|
375
|
+
avlTree.add([1, 'a']);
|
|
376
|
+
avlTree.add([2, 'b']);
|
|
377
|
+
avlTree.add([3, 'c']);
|
|
378
378
|
});
|
|
379
379
|
|
|
380
380
|
it('The node obtained by get Node should match the node type', () => {
|
|
381
|
-
const node3 =
|
|
381
|
+
const node3 = avlTree.getNode(3);
|
|
382
382
|
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
383
383
|
expect(node3).toBeInstanceOf(BSTNode);
|
|
384
384
|
expect(node3).toBeInstanceOf(AVLTreeNode);
|
|
@@ -386,7 +386,7 @@ describe('AVLTree iterative methods test', () => {
|
|
|
386
386
|
|
|
387
387
|
it('forEach should iterate over all elements', () => {
|
|
388
388
|
const mockCallback = jest.fn();
|
|
389
|
-
|
|
389
|
+
avlTree.forEach((key, value) => {
|
|
390
390
|
mockCallback(key, value);
|
|
391
391
|
});
|
|
392
392
|
|
|
@@ -396,8 +396,8 @@ describe('AVLTree iterative methods test', () => {
|
|
|
396
396
|
expect(mockCallback.mock.calls[2]).toEqual([3, 'c']);
|
|
397
397
|
});
|
|
398
398
|
|
|
399
|
-
it('filter should return a new
|
|
400
|
-
const filteredTree =
|
|
399
|
+
it('filter should return a new avlTree with filtered elements', () => {
|
|
400
|
+
const filteredTree = avlTree.filter(key => key > 1);
|
|
401
401
|
expect(filteredTree.size).toBe(2);
|
|
402
402
|
expect([...filteredTree]).toEqual([
|
|
403
403
|
[2, 'b'],
|
|
@@ -405,8 +405,8 @@ describe('AVLTree iterative methods test', () => {
|
|
|
405
405
|
]);
|
|
406
406
|
});
|
|
407
407
|
|
|
408
|
-
it('map should return a new
|
|
409
|
-
const mappedTree =
|
|
408
|
+
it('map should return a new avlTree with modified elements', () => {
|
|
409
|
+
const mappedTree = avlTree.map((key, value) => [(key * 2).toString(), value]);
|
|
410
410
|
expect(mappedTree.size).toBe(3);
|
|
411
411
|
expect([...mappedTree]).toEqual([
|
|
412
412
|
['2', 'a'],
|
|
@@ -416,13 +416,13 @@ describe('AVLTree iterative methods test', () => {
|
|
|
416
416
|
});
|
|
417
417
|
|
|
418
418
|
it('reduce should accumulate values', () => {
|
|
419
|
-
const sum =
|
|
419
|
+
const sum = avlTree.reduce((acc, value, key) => acc + key, 0);
|
|
420
420
|
expect(sum).toBe(6);
|
|
421
421
|
});
|
|
422
422
|
|
|
423
423
|
it('[Symbol.iterator] should provide an iterator', () => {
|
|
424
424
|
const entries = [];
|
|
425
|
-
for (const entry of
|
|
425
|
+
for (const entry of avlTree) {
|
|
426
426
|
entries.push(entry);
|
|
427
427
|
}
|
|
428
428
|
|
|
@@ -435,23 +435,23 @@ describe('AVLTree iterative methods test', () => {
|
|
|
435
435
|
});
|
|
436
436
|
|
|
437
437
|
it('should clone work well', () => {
|
|
438
|
-
const cloned =
|
|
438
|
+
const cloned = avlTree.clone();
|
|
439
439
|
expect(cloned.root?.left?.key).toBe(1);
|
|
440
440
|
expect(cloned.root?.right?.value).toBe(undefined);
|
|
441
441
|
});
|
|
442
442
|
|
|
443
443
|
it('should keys', () => {
|
|
444
|
-
const keys =
|
|
444
|
+
const keys = avlTree.keys();
|
|
445
445
|
expect([...keys]).toEqual([1, 2, 3]);
|
|
446
446
|
});
|
|
447
447
|
|
|
448
448
|
it('should values', () => {
|
|
449
|
-
const values =
|
|
449
|
+
const values = avlTree.values();
|
|
450
450
|
expect([...values]).toEqual(['a', 'b', 'c']);
|
|
451
451
|
});
|
|
452
452
|
|
|
453
453
|
it('should leaves', () => {
|
|
454
|
-
const leaves =
|
|
454
|
+
const leaves = avlTree.leaves();
|
|
455
455
|
expect(leaves).toEqual([1, 3]);
|
|
456
456
|
});
|
|
457
457
|
});
|
|
@@ -459,85 +459,85 @@ describe('AVLTree iterative methods test', () => {
|
|
|
459
459
|
describe('AVL Tree not map mode', () => {
|
|
460
460
|
it('should perform various operations on a AVL Tree', () => {
|
|
461
461
|
const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
462
|
-
const
|
|
462
|
+
const avlTree = new AVLTree<number>([], { isMapMode: false });
|
|
463
463
|
|
|
464
|
-
for (const i of arr)
|
|
464
|
+
for (const i of arr) avlTree.add([i, i]);
|
|
465
465
|
|
|
466
|
-
|
|
467
|
-
const node6 =
|
|
466
|
+
avlTree.add(null);
|
|
467
|
+
const node6 = avlTree.getNode(6);
|
|
468
468
|
|
|
469
|
-
expect(node6 &&
|
|
470
|
-
expect(node6 &&
|
|
469
|
+
expect(node6 && avlTree.getHeight(node6)).toBe(3);
|
|
470
|
+
expect(node6 && avlTree.getDepth(node6)).toBe(1);
|
|
471
471
|
|
|
472
|
-
const getNodeById =
|
|
472
|
+
const getNodeById = avlTree.getNode(10);
|
|
473
473
|
expect(getNodeById?.key).toBe(10);
|
|
474
474
|
|
|
475
|
-
const getMinNodeByRoot =
|
|
475
|
+
const getMinNodeByRoot = avlTree.getLeftMost();
|
|
476
476
|
expect(getMinNodeByRoot).toBe(1);
|
|
477
477
|
|
|
478
|
-
const node15 =
|
|
479
|
-
const getMinNodeBySpecificNode = node15 &&
|
|
478
|
+
const node15 = avlTree.getNode(15);
|
|
479
|
+
const getMinNodeBySpecificNode = node15 && avlTree.getLeftMost(node => node, node15);
|
|
480
480
|
expect(getMinNodeBySpecificNode?.key).toBe(12);
|
|
481
481
|
|
|
482
482
|
let subTreeSum = 0;
|
|
483
|
-
if (node15)
|
|
483
|
+
if (node15) avlTree.dfs(node => (subTreeSum += node.key), 'PRE', node15);
|
|
484
484
|
expect(subTreeSum).toBe(70);
|
|
485
485
|
|
|
486
486
|
let lesserSum = 0;
|
|
487
|
-
|
|
487
|
+
avlTree.lesserOrGreaterTraverse(node => (lesserSum += node.key), -1, 10);
|
|
488
488
|
expect(lesserSum).toBe(45);
|
|
489
489
|
|
|
490
490
|
// node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class.
|
|
491
|
-
expect(
|
|
491
|
+
expect(avlTree.get(node15)).toBe(15);
|
|
492
492
|
});
|
|
493
493
|
});
|
|
494
494
|
|
|
495
495
|
describe('AVL Tree not map mode test recursively', () => {
|
|
496
496
|
it('should perform various operations on a AVL Tree', () => {
|
|
497
497
|
const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
498
|
-
const
|
|
498
|
+
const avlTree = new AVLTree<number>([], { iterationType: 'RECURSIVE', isMapMode: false });
|
|
499
499
|
|
|
500
|
-
for (const i of arr)
|
|
500
|
+
for (const i of arr) avlTree.add([i, i]);
|
|
501
501
|
|
|
502
|
-
const node6 =
|
|
502
|
+
const node6 = avlTree.getNode(6);
|
|
503
503
|
|
|
504
|
-
expect(node6 &&
|
|
505
|
-
expect(node6 &&
|
|
504
|
+
expect(node6 && avlTree.getHeight(node6)).toBe(3);
|
|
505
|
+
expect(node6 && avlTree.getDepth(node6)).toBe(1);
|
|
506
506
|
|
|
507
|
-
const getNodeById =
|
|
507
|
+
const getNodeById = avlTree.getNode(10);
|
|
508
508
|
expect(getNodeById?.key).toBe(10);
|
|
509
509
|
|
|
510
|
-
const getMinNodeByRoot =
|
|
510
|
+
const getMinNodeByRoot = avlTree.getLeftMost();
|
|
511
511
|
expect(getMinNodeByRoot).toBe(1);
|
|
512
512
|
|
|
513
|
-
const node15 =
|
|
514
|
-
const getMinNodeBySpecificNode = node15 &&
|
|
513
|
+
const node15 = avlTree.getNode(15);
|
|
514
|
+
const getMinNodeBySpecificNode = node15 && avlTree.getLeftMost(node => node, node15);
|
|
515
515
|
expect(getMinNodeBySpecificNode?.key).toBe(12);
|
|
516
516
|
|
|
517
517
|
let subTreeSum = 0;
|
|
518
|
-
if (node15)
|
|
518
|
+
if (node15) avlTree.dfs(node => (subTreeSum += node.key), 'PRE', node15);
|
|
519
519
|
expect(subTreeSum).toBe(70);
|
|
520
520
|
|
|
521
521
|
let lesserSum = 0;
|
|
522
|
-
|
|
522
|
+
avlTree.lesserOrGreaterTraverse(node => (lesserSum += node.key), -1, 10);
|
|
523
523
|
expect(lesserSum).toBe(45);
|
|
524
524
|
|
|
525
525
|
// node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class.
|
|
526
|
-
expect(
|
|
526
|
+
expect(avlTree.get(node15)).toBe(15);
|
|
527
527
|
});
|
|
528
528
|
});
|
|
529
529
|
|
|
530
530
|
describe('AVLTree iterative methods not map mode', () => {
|
|
531
|
-
let
|
|
531
|
+
let avlTree: AVLTree<number, string>;
|
|
532
532
|
beforeEach(() => {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
533
|
+
avlTree = new AVLTree<number, string>([], { isMapMode: false });
|
|
534
|
+
avlTree.add([1, 'a']);
|
|
535
|
+
avlTree.add([2, 'b']);
|
|
536
|
+
avlTree.add([3, 'c']);
|
|
537
537
|
});
|
|
538
538
|
|
|
539
539
|
it('should clone work well', () => {
|
|
540
|
-
const cloned =
|
|
540
|
+
const cloned = avlTree.clone();
|
|
541
541
|
expect(cloned.root?.left?.key).toBe(1);
|
|
542
542
|
expect(cloned.get(cloned.root?.right?.key)).toBe('c');
|
|
543
543
|
});
|