data-structure-typed 1.54.0 → 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 -47
- 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 -177
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -340
- 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 +102 -57
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +110 -47
- 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 +240 -190
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +269 -240
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +145 -112
- package/dist/cjs/data-structures/binary-tree/bst.js +180 -129
- 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 +100 -82
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +115 -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} +74 -64
- 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 -174
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +142 -377
- 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 +8 -8
- 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 -4
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -3
- 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 -4
- 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 -4
- 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} +73 -60
- 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 +110 -47
- 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 +240 -190
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.js +272 -245
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.d.ts +145 -112
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.js +201 -155
- 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 +100 -82
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.js +115 -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} +111 -96
- 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 -3
- package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.d.ts +3 -3
- 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 +1464 -895
- 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 +155 -393
- package/src/data-structures/binary-tree/avl-tree.ts +144 -93
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +433 -405
- package/src/data-structures/binary-tree/bst.ts +261 -239
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +163 -134
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +161 -429
- 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 -24
- 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 -6
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -5
- package/src/types/data-structures/binary-tree/index.ts +2 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -6
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -6
- 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 -189
- 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 -9
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -6
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -5
- /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
|
@@ -12,17 +12,25 @@ import { DFSOperation, Range } from '../../common';
|
|
|
12
12
|
/**
|
|
13
13
|
* Represents a node in a binary tree.
|
|
14
14
|
* @template V - The type of data stored in the node.
|
|
15
|
-
* @template
|
|
15
|
+
* @template BinaryTreeNode<K, V> - The type of the family relationship in the binary tree.
|
|
16
16
|
*/
|
|
17
17
|
export class BinaryTreeNode {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The constructor function initializes an object with a key and an optional value in TypeScript.
|
|
20
|
+
* @param {K} key - The `key` parameter in the constructor function is used to store the key value
|
|
21
|
+
* for the key-value pair.
|
|
22
|
+
* @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
|
|
23
|
+
* have to be provided when creating an instance of the class. If a `value` is not provided, it will
|
|
24
|
+
* default to `undefined`.
|
|
25
|
+
*/
|
|
21
26
|
constructor(key, value) {
|
|
22
27
|
this.key = key;
|
|
23
28
|
this.value = value;
|
|
24
29
|
}
|
|
25
|
-
|
|
30
|
+
key;
|
|
31
|
+
value;
|
|
32
|
+
parent = undefined;
|
|
33
|
+
_left = undefined;
|
|
26
34
|
get left() {
|
|
27
35
|
return this._left;
|
|
28
36
|
}
|
|
@@ -32,7 +40,7 @@ export class BinaryTreeNode {
|
|
|
32
40
|
}
|
|
33
41
|
this._left = v;
|
|
34
42
|
}
|
|
35
|
-
_right;
|
|
43
|
+
_right = undefined;
|
|
36
44
|
get right() {
|
|
37
45
|
return this._right;
|
|
38
46
|
}
|
|
@@ -64,14 +72,13 @@ export class BinaryTreeNode {
|
|
|
64
72
|
this._count = value;
|
|
65
73
|
}
|
|
66
74
|
get familyPosition() {
|
|
67
|
-
const that = this;
|
|
68
75
|
if (!this.parent) {
|
|
69
76
|
return this.left || this.right ? 'ROOT' : 'ISOLATED';
|
|
70
77
|
}
|
|
71
|
-
if (this.parent.left ===
|
|
78
|
+
if (this.parent.left === this) {
|
|
72
79
|
return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
|
|
73
80
|
}
|
|
74
|
-
else if (this.parent.right ===
|
|
81
|
+
else if (this.parent.right === this) {
|
|
75
82
|
return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
|
|
76
83
|
}
|
|
77
84
|
return 'MAL_NODE';
|
|
@@ -85,15 +92,14 @@ export class BinaryTreeNode {
|
|
|
85
92
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
86
93
|
*/
|
|
87
94
|
export class BinaryTree extends IterableEntryBase {
|
|
88
|
-
iterationType = 'ITERATIVE';
|
|
89
95
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* @param [options] - The `options` parameter in the constructor is an object that can
|
|
96
|
-
* following properties:
|
|
96
|
+
* This TypeScript constructor function initializes a binary tree with optional options and adds
|
|
97
|
+
* elements based on the provided input.
|
|
98
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
99
|
+
* iterable that can contain either objects of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
|
|
100
|
+
* is used to initialize the binary tree with keys, nodes, entries, or raw data.
|
|
101
|
+
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
102
|
+
* contain the following properties:
|
|
97
103
|
*/
|
|
98
104
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
99
105
|
super();
|
|
@@ -111,6 +117,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
111
117
|
if (keysNodesEntriesOrRaws)
|
|
112
118
|
this.addMany(keysNodesEntriesOrRaws);
|
|
113
119
|
}
|
|
120
|
+
iterationType = 'ITERATIVE';
|
|
114
121
|
_isMapMode = true;
|
|
115
122
|
get isMapMode() {
|
|
116
123
|
return this._isMapMode;
|
|
@@ -145,12 +152,15 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
145
152
|
* not required to be provided when calling the function. If a `value` is provided, it should be of
|
|
146
153
|
* type `V`, which is the type of the value associated with the node.
|
|
147
154
|
* @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
|
|
148
|
-
* as
|
|
155
|
+
* as BinaryTreeNode<K, V>.
|
|
149
156
|
*/
|
|
150
157
|
createNode(key, value) {
|
|
151
158
|
return new BinaryTreeNode(key, this._isMapMode ? undefined : value);
|
|
152
159
|
}
|
|
153
160
|
/**
|
|
161
|
+
* Time Complexity: O(1)
|
|
162
|
+
* Space Complexity: O(1)
|
|
163
|
+
*
|
|
154
164
|
* The function creates a binary tree with the specified options.
|
|
155
165
|
* @param [options] - The `options` parameter in the `createTree` function is an optional parameter
|
|
156
166
|
* that allows you to provide partial configuration options for creating a binary tree. It is of type
|
|
@@ -166,55 +176,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
166
176
|
...options
|
|
167
177
|
});
|
|
168
178
|
}
|
|
169
|
-
/**
|
|
170
|
-
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
171
|
-
* or returns null.
|
|
172
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
173
|
-
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
174
|
-
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
175
|
-
* node, an entry
|
|
176
|
-
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
177
|
-
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
178
|
-
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
179
|
-
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
180
|
-
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
181
|
-
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
182
|
-
* value.
|
|
183
|
-
*/
|
|
184
|
-
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
185
|
-
if (keyNodeEntryOrRaw === undefined)
|
|
186
|
-
return [undefined, undefined];
|
|
187
|
-
if (keyNodeEntryOrRaw === null)
|
|
188
|
-
return [null, undefined];
|
|
189
|
-
if (this.isNode(keyNodeEntryOrRaw))
|
|
190
|
-
return [keyNodeEntryOrRaw, value];
|
|
191
|
-
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
192
|
-
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
193
|
-
if (key === undefined)
|
|
194
|
-
return [undefined, undefined];
|
|
195
|
-
else if (key === null)
|
|
196
|
-
return [null, undefined];
|
|
197
|
-
const finalValue = value ?? entryValue;
|
|
198
|
-
return [this.createNode(key, finalValue), finalValue];
|
|
199
|
-
}
|
|
200
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
201
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
202
|
-
const finalValue = value ?? entryValue;
|
|
203
|
-
if (this.isKey(key))
|
|
204
|
-
return [this.createNode(key, finalValue), finalValue];
|
|
205
|
-
}
|
|
206
|
-
if (this.isKey(keyNodeEntryOrRaw))
|
|
207
|
-
return [this.createNode(keyNodeEntryOrRaw, value), value];
|
|
208
|
-
return [undefined, undefined];
|
|
209
|
-
}
|
|
210
179
|
/**
|
|
211
180
|
* Time Complexity: O(n)
|
|
212
181
|
* Space Complexity: O(log n)
|
|
213
182
|
*
|
|
214
183
|
* The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
|
|
215
184
|
* value and returns the corresponding node or null.
|
|
216
|
-
* @param {BTNRep<K, V,
|
|
217
|
-
* parameter in the `ensureNode` function can be of type `BTNRep<K, V,
|
|
185
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
186
|
+
* parameter in the `ensureNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
|
|
218
187
|
* is used to determine whether the input is a key, node, entry, or raw data. The
|
|
219
188
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
|
|
220
189
|
* is used to specify the type of iteration to be performed. It has a default value of
|
|
@@ -222,49 +191,48 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
222
191
|
* @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
|
|
223
192
|
* conditions specified in the code snippet.
|
|
224
193
|
*/
|
|
225
|
-
ensureNode(
|
|
226
|
-
if (
|
|
194
|
+
ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
|
|
195
|
+
if (keyNodeOrEntry === null)
|
|
227
196
|
return null;
|
|
228
|
-
if (
|
|
197
|
+
if (keyNodeOrEntry === undefined)
|
|
229
198
|
return;
|
|
230
|
-
if (
|
|
199
|
+
if (keyNodeOrEntry === this._NIL)
|
|
231
200
|
return;
|
|
232
|
-
if (this.isNode(
|
|
233
|
-
return
|
|
234
|
-
if (this.isEntry(
|
|
235
|
-
const key =
|
|
201
|
+
if (this.isNode(keyNodeOrEntry))
|
|
202
|
+
return keyNodeOrEntry;
|
|
203
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
204
|
+
const key = keyNodeOrEntry[0];
|
|
236
205
|
if (key === null)
|
|
237
206
|
return null;
|
|
238
207
|
if (key === undefined)
|
|
239
208
|
return;
|
|
240
209
|
return this.getNode(key, this._root, iterationType);
|
|
241
210
|
}
|
|
242
|
-
|
|
243
|
-
const [key] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
244
|
-
if (this.isKey(key))
|
|
245
|
-
return this.getNode(key);
|
|
246
|
-
}
|
|
247
|
-
if (this.isKey(keyNodeEntryOrRaw))
|
|
248
|
-
return this.getNode(keyNodeEntryOrRaw, this._root, iterationType);
|
|
249
|
-
return;
|
|
211
|
+
return this.getNode(keyNodeOrEntry, this._root, iterationType);
|
|
250
212
|
}
|
|
251
213
|
/**
|
|
214
|
+
* Time Complexity: O(1)
|
|
215
|
+
* Space Complexity: O(1)
|
|
216
|
+
*
|
|
252
217
|
* The function isNode checks if the input is an instance of BinaryTreeNode.
|
|
253
|
-
* @param {BTNRep<K, V,
|
|
254
|
-
* `
|
|
218
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
219
|
+
* `keyNodeOrEntry` can be either a key, a node, an entry, or raw data. The function is
|
|
255
220
|
* checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
|
|
256
221
|
* accordingly.
|
|
257
|
-
* @returns The function `isNode` is checking if the input `
|
|
222
|
+
* @returns The function `isNode` is checking if the input `keyNodeOrEntry` is an instance of
|
|
258
223
|
* `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
|
|
259
224
|
* it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
|
|
260
225
|
* is not a node.
|
|
261
226
|
*/
|
|
262
|
-
isNode(
|
|
263
|
-
return
|
|
227
|
+
isNode(keyNodeOrEntry) {
|
|
228
|
+
return keyNodeOrEntry instanceof BinaryTreeNode;
|
|
264
229
|
}
|
|
265
230
|
/**
|
|
231
|
+
* Time Complexity: O(1)
|
|
232
|
+
* Space Complexity: O(1)
|
|
233
|
+
*
|
|
266
234
|
* The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
|
|
267
|
-
* @param {BTNRep<K, V,
|
|
235
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | R} keyNodeEntryOrRaw - BTNRep<K, V, BinaryTreeNode<K, V>>
|
|
268
236
|
* @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
|
|
269
237
|
* checking if it is an object. If the parameter is an object, the function will return `true`,
|
|
270
238
|
* indicating that it is of type `R`.
|
|
@@ -273,88 +241,117 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
273
241
|
return this._toEntryFn !== undefined && typeof keyNodeEntryOrRaw === 'object';
|
|
274
242
|
}
|
|
275
243
|
/**
|
|
244
|
+
* Time Complexity: O(1)
|
|
245
|
+
* Space Complexity: O(1)
|
|
246
|
+
*
|
|
276
247
|
* The function `isRealNode` checks if a given input is a valid node in a binary tree.
|
|
277
|
-
* @param {BTNRep<K, V,
|
|
278
|
-
* parameter in the `isRealNode` function can be of type `BTNRep<K, V,
|
|
279
|
-
* The function checks if the input parameter is a `
|
|
280
|
-
* @returns The function `isRealNode` is checking if the input `
|
|
248
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
249
|
+
* parameter in the `isRealNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
|
|
250
|
+
* The function checks if the input parameter is a `BinaryTreeNode<K, V>` type by verifying if it is not equal
|
|
251
|
+
* @returns The function `isRealNode` is checking if the input `keyNodeOrEntry` is a valid
|
|
281
252
|
* node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
|
|
282
253
|
* values, it then calls the `isNode` method to further determine if the input is a node. The
|
|
283
254
|
* function will return a boolean value indicating whether the
|
|
284
255
|
*/
|
|
285
|
-
isRealNode(
|
|
286
|
-
if (
|
|
256
|
+
isRealNode(keyNodeOrEntry) {
|
|
257
|
+
if (keyNodeOrEntry === this._NIL || keyNodeOrEntry === null || keyNodeOrEntry === undefined)
|
|
287
258
|
return false;
|
|
288
|
-
return this.isNode(
|
|
259
|
+
return this.isNode(keyNodeOrEntry);
|
|
289
260
|
}
|
|
290
261
|
/**
|
|
262
|
+
* Time Complexity: O(1)
|
|
263
|
+
* Space Complexity: O(1)
|
|
264
|
+
*
|
|
291
265
|
* The function checks if a given input is a valid node or null.
|
|
292
|
-
* @param {BTNRep<K, V,
|
|
293
|
-
* `
|
|
294
|
-
* V,
|
|
266
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
267
|
+
* `keyNodeOrEntry` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
|
|
268
|
+
* V, BinaryTreeNode<K, V>>` or `R`. It is a union type that can either be a key, a node, an entry, or
|
|
295
269
|
* @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
|
|
296
|
-
* `
|
|
270
|
+
* `keyNodeOrEntry` is either `null` or a real node, and returns `true` if it is a node or
|
|
297
271
|
* `null`, and `false` otherwise.
|
|
298
272
|
*/
|
|
299
|
-
isRealNodeOrNull(
|
|
300
|
-
return
|
|
273
|
+
isRealNodeOrNull(keyNodeOrEntry) {
|
|
274
|
+
return keyNodeOrEntry === null || this.isRealNode(keyNodeOrEntry);
|
|
301
275
|
}
|
|
302
276
|
/**
|
|
277
|
+
* Time Complexity: O(1)
|
|
278
|
+
* Space Complexity: O(1)
|
|
279
|
+
*
|
|
303
280
|
* The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
|
|
304
|
-
* @param {BTNRep<K, V,
|
|
305
|
-
*
|
|
306
|
-
* @returns The function is checking if the `
|
|
281
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - BTNRep<K, V,
|
|
282
|
+
* BinaryTreeNode<K, V>>
|
|
283
|
+
* @returns The function is checking if the `keyNodeOrEntry` parameter is equal to the `_NIL`
|
|
307
284
|
* property of the current object and returning a boolean value based on that comparison.
|
|
308
285
|
*/
|
|
309
|
-
isNIL(
|
|
310
|
-
return
|
|
286
|
+
isNIL(keyNodeOrEntry) {
|
|
287
|
+
return keyNodeOrEntry === this._NIL;
|
|
311
288
|
}
|
|
312
|
-
|
|
313
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Time Complexity: O(1)
|
|
291
|
+
* Space Complexity: O(1)
|
|
292
|
+
*
|
|
293
|
+
* The function `isRange` checks if the input parameter is an instance of the `Range` class.
|
|
294
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>> | Range<K>}
|
|
295
|
+
* keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
|
|
296
|
+
* of type `BTNRep<K, V, BinaryTreeNode<K, V>>`, `NodePredicate<BinaryTreeNode<K, V>>`, or
|
|
297
|
+
* `Range<K>`. The function checks if the `keyNodeEntry
|
|
298
|
+
* @returns The `isRange` function is checking if the `keyNodeEntryOrPredicate` parameter is an
|
|
299
|
+
* instance of the `Range` class. If it is an instance of `Range`, the function will return `true`,
|
|
300
|
+
* indicating that the parameter is a `Range<K>`. If it is not an instance of `Range`, the function
|
|
301
|
+
* will return `false`.
|
|
302
|
+
*/
|
|
303
|
+
isRange(keyNodeEntryOrPredicate) {
|
|
304
|
+
return keyNodeEntryOrPredicate instanceof Range;
|
|
314
305
|
}
|
|
315
306
|
/**
|
|
307
|
+
* Time Complexity: O(1)
|
|
308
|
+
* Space Complexity: O(1)
|
|
309
|
+
*
|
|
316
310
|
* The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
|
|
317
311
|
* tree.
|
|
318
|
-
* @param {BTNRep<K, V,
|
|
319
|
-
* `
|
|
312
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
313
|
+
* `keyNodeOrEntry` can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It represents a
|
|
320
314
|
* key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
|
|
321
315
|
* provided
|
|
322
316
|
* @returns The function `isLeaf` returns a boolean value indicating whether the input
|
|
323
|
-
* `
|
|
317
|
+
* `keyNodeOrEntry` is a leaf node in a binary tree.
|
|
324
318
|
*/
|
|
325
|
-
isLeaf(
|
|
326
|
-
|
|
327
|
-
if (
|
|
319
|
+
isLeaf(keyNodeOrEntry) {
|
|
320
|
+
keyNodeOrEntry = this.ensureNode(keyNodeOrEntry);
|
|
321
|
+
if (keyNodeOrEntry === undefined)
|
|
328
322
|
return false;
|
|
329
|
-
if (
|
|
323
|
+
if (keyNodeOrEntry === null)
|
|
330
324
|
return true;
|
|
331
|
-
return !this.isRealNode(
|
|
325
|
+
return !this.isRealNode(keyNodeOrEntry.left) && !this.isRealNode(keyNodeOrEntry.right);
|
|
332
326
|
}
|
|
333
327
|
/**
|
|
328
|
+
* Time Complexity: O(1)
|
|
329
|
+
* Space Complexity: O(1)
|
|
330
|
+
*
|
|
334
331
|
* The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
|
|
335
332
|
* with a length of 2.
|
|
336
|
-
* @param {BTNRep<K, V,
|
|
337
|
-
* parameter in the `isEntry` function can be of type `BTNRep<K, V,
|
|
338
|
-
* The function checks if the provided `
|
|
339
|
-
* @returns The `isEntry` function is checking if the `
|
|
333
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
334
|
+
* parameter in the `isEntry` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or type `R`.
|
|
335
|
+
* The function checks if the provided `keyNodeOrEntry` is of type `BTN
|
|
336
|
+
* @returns The `isEntry` function is checking if the `keyNodeOrEntry` parameter is an array
|
|
340
337
|
* with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
|
|
341
338
|
* `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
|
|
342
339
|
*/
|
|
343
|
-
isEntry(
|
|
344
|
-
return Array.isArray(
|
|
340
|
+
isEntry(keyNodeOrEntry) {
|
|
341
|
+
return Array.isArray(keyNodeOrEntry) && keyNodeOrEntry.length === 2;
|
|
345
342
|
}
|
|
346
343
|
/**
|
|
347
344
|
* Time Complexity O(1)
|
|
348
345
|
* Space Complexity O(1)
|
|
349
346
|
*
|
|
350
|
-
* The function `
|
|
347
|
+
* The function `isValidKey` checks if a given key is comparable.
|
|
351
348
|
* @param {any} key - The `key` parameter is of type `any`, which means it can be any data type in
|
|
352
349
|
* TypeScript.
|
|
353
|
-
* @returns The function `
|
|
350
|
+
* @returns The function `isValidKey` is checking if the `key` parameter is `null` or if it is comparable.
|
|
354
351
|
* If the `key` is `null`, the function returns `true`. Otherwise, it returns the result of the
|
|
355
352
|
* `isComparable` function, which is not provided in the code snippet.
|
|
356
353
|
*/
|
|
357
|
-
|
|
354
|
+
isValidKey(key) {
|
|
358
355
|
if (key === null)
|
|
359
356
|
return true;
|
|
360
357
|
return isComparable(key);
|
|
@@ -365,8 +362,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
365
362
|
*
|
|
366
363
|
* The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
|
|
367
364
|
* and finding the correct insertion position.
|
|
368
|
-
* @param {BTNRep<K, V,
|
|
369
|
-
* seems to be for adding a new node to a binary tree structure. The `
|
|
365
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `add` method you provided
|
|
366
|
+
* seems to be for adding a new node to a binary tree structure. The `keyNodeOrEntry`
|
|
370
367
|
* parameter in the method can accept different types of values:
|
|
371
368
|
* @param {V} [value] - The `value` parameter in the `add` method represents the value associated
|
|
372
369
|
* with the key that you want to add to the binary tree. When adding a key-value pair to the binary
|
|
@@ -376,8 +373,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
376
373
|
* node was successful, and `false` if the insertion position could not be found or if a duplicate
|
|
377
374
|
* key was found and the node was replaced instead of inserted.
|
|
378
375
|
*/
|
|
379
|
-
add(
|
|
380
|
-
const [newNode, newValue] = this.
|
|
376
|
+
add(keyNodeOrEntry, value) {
|
|
377
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
381
378
|
if (newNode === undefined)
|
|
382
379
|
return false;
|
|
383
380
|
// If the tree is empty, directly set the new node as the root node
|
|
@@ -432,14 +429,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
432
429
|
}
|
|
433
430
|
/**
|
|
434
431
|
* Time Complexity: O(k * n)
|
|
435
|
-
* Space Complexity: O(
|
|
432
|
+
* Space Complexity: O(k)
|
|
436
433
|
*
|
|
437
434
|
* The `addMany` function takes in multiple keys or nodes or entries or raw values along with
|
|
438
435
|
* optional values, and adds them to a data structure while returning an array indicating whether
|
|
439
436
|
* each insertion was successful.
|
|
440
437
|
* @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
|
|
441
438
|
* mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
|
|
442
|
-
* `BTNRep<K, V,
|
|
439
|
+
* `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
|
|
443
440
|
* @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
|
|
444
441
|
* accepts an iterable of values. These values correspond to the keys or nodes being added in the
|
|
445
442
|
* `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
|
|
@@ -455,7 +452,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
455
452
|
if (values) {
|
|
456
453
|
valuesIterator = values[Symbol.iterator]();
|
|
457
454
|
}
|
|
458
|
-
for (
|
|
455
|
+
for (let keyNodeEntryOrRaw of keysNodesEntriesOrRaws) {
|
|
459
456
|
let value = undefined;
|
|
460
457
|
if (valuesIterator) {
|
|
461
458
|
const valueResult = valuesIterator.next();
|
|
@@ -463,6 +460,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
463
460
|
value = valueResult.value;
|
|
464
461
|
}
|
|
465
462
|
}
|
|
463
|
+
if (this.isRaw(keyNodeEntryOrRaw))
|
|
464
|
+
keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
466
465
|
inserted.push(this.add(keyNodeEntryOrRaw, value));
|
|
467
466
|
}
|
|
468
467
|
return inserted;
|
|
@@ -473,7 +472,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
473
472
|
*
|
|
474
473
|
* The `merge` function in TypeScript merges another binary tree into the current tree by adding all
|
|
475
474
|
* elements from the other tree.
|
|
476
|
-
* @param anotherTree -
|
|
475
|
+
* @param anotherTree - BinaryTree<K, V, R, MK, MV, MR>
|
|
477
476
|
*/
|
|
478
477
|
merge(anotherTree) {
|
|
479
478
|
this.addMany(anotherTree, []);
|
|
@@ -485,7 +484,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
485
484
|
* The `refill` function clears the existing data structure and then adds new key-value pairs based
|
|
486
485
|
* on the provided input.
|
|
487
486
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
|
|
488
|
-
* method can accept an iterable containing a mix of `BTNRep<K, V,
|
|
487
|
+
* method can accept an iterable containing a mix of `BTNRep<K, V, BinaryTreeNode<K, V>>` objects or `R`
|
|
489
488
|
* objects.
|
|
490
489
|
* @param [values] - The `values` parameter in the `refill` method is an optional parameter that
|
|
491
490
|
* accepts an iterable of values of type `V` or `undefined`.
|
|
@@ -500,7 +499,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
500
499
|
*
|
|
501
500
|
* The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
|
|
502
501
|
* the deleted node along with information for tree balancing.
|
|
503
|
-
* @param {BTNRep<K, V,
|
|
502
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry
|
|
504
503
|
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
|
|
505
504
|
* node, entry or raw data. The method returns an array of
|
|
506
505
|
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
|
|
@@ -509,11 +508,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
509
508
|
* the array contains information about the node that was deleted (`deleted`) and the node that may
|
|
510
509
|
* need to be balanced (`needBalanced`).
|
|
511
510
|
*/
|
|
512
|
-
delete(
|
|
511
|
+
delete(keyNodeOrEntry) {
|
|
513
512
|
const deletedResult = [];
|
|
514
513
|
if (!this._root)
|
|
515
514
|
return deletedResult;
|
|
516
|
-
const curr = this.getNode(
|
|
515
|
+
const curr = this.getNode(keyNodeOrEntry);
|
|
517
516
|
if (!curr)
|
|
518
517
|
return deletedResult;
|
|
519
518
|
const parent = curr?.parent;
|
|
@@ -562,15 +561,15 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
562
561
|
*
|
|
563
562
|
* The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
|
|
564
563
|
* structure based on a given predicate or key, with options to return multiple results or just one.
|
|
565
|
-
* @param {BTNRep<K, V,
|
|
566
|
-
* `
|
|
564
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
565
|
+
* `keyNodeEntryOrPredicate` parameter in the `search` function can accept three types of values:
|
|
567
566
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
|
|
568
567
|
* determines whether the search should stop after finding the first matching node. If `onlyOne` is
|
|
569
568
|
* set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
|
|
570
569
|
* @param {C} callback - The `callback` parameter in the `search` function is a callback function
|
|
571
570
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
572
|
-
* extends `NodeCallback<
|
|
573
|
-
* @param {BTNRep<K, V,
|
|
571
|
+
* extends `NodeCallback<BinaryTreeNode<K, V>>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
|
|
572
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `search` function is
|
|
574
573
|
* used to specify the node from which the search operation should begin. It represents the starting
|
|
575
574
|
* point in the binary tree where the search will be performed. If no specific `startNode` is
|
|
576
575
|
* provided, the search operation will start from the root
|
|
@@ -580,15 +579,15 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
580
579
|
* @returns The `search` function returns an array of values that match the provided criteria based
|
|
581
580
|
* on the search algorithm implemented within the function.
|
|
582
581
|
*/
|
|
583
|
-
search(
|
|
584
|
-
if (
|
|
582
|
+
search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
583
|
+
if (keyNodeEntryOrPredicate === undefined)
|
|
585
584
|
return [];
|
|
586
|
-
if (
|
|
585
|
+
if (keyNodeEntryOrPredicate === null)
|
|
587
586
|
return [];
|
|
588
587
|
startNode = this.ensureNode(startNode);
|
|
589
588
|
if (!startNode)
|
|
590
589
|
return [];
|
|
591
|
-
const predicate = this._ensurePredicate(
|
|
590
|
+
const predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
592
591
|
const ans = [];
|
|
593
592
|
if (iterationType === 'RECURSIVE') {
|
|
594
593
|
const dfs = (cur) => {
|
|
@@ -631,12 +630,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
631
630
|
*
|
|
632
631
|
* The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
|
|
633
632
|
* or predicate, with options for recursive or iterative traversal.
|
|
634
|
-
* @param {BTNRep<K, V,
|
|
633
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
635
634
|
* - The `getNodes` function you provided takes several parameters:
|
|
636
635
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
|
|
637
636
|
* determines whether to return only the first node that matches the criteria specified by the
|
|
638
|
-
* `
|
|
639
|
-
* @param {BTNRep<K, V,
|
|
637
|
+
* `keyNodeEntryOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
|
|
638
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
640
639
|
* `getNodes` function is used to specify the starting point for traversing the binary tree. It
|
|
641
640
|
* represents the root node of the binary tree or the node from which the traversal should begin. If
|
|
642
641
|
* not provided, the default value is set to `this._root
|
|
@@ -646,19 +645,19 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
646
645
|
* @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
|
|
647
646
|
* based on the input parameters and the iteration type specified.
|
|
648
647
|
*/
|
|
649
|
-
getNodes(
|
|
650
|
-
return this.search(
|
|
648
|
+
getNodes(keyNodeEntryOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
|
|
649
|
+
return this.search(keyNodeEntryOrPredicate, onlyOne, node => node, startNode, iterationType);
|
|
651
650
|
}
|
|
652
651
|
/**
|
|
653
652
|
* Time Complexity: O(n)
|
|
654
|
-
* Space Complexity: O(log n)
|
|
653
|
+
* Space Complexity: O(log n)
|
|
655
654
|
*
|
|
656
655
|
* The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
|
|
657
656
|
* predicate.
|
|
658
|
-
* @param {BTNRep<K, V,
|
|
659
|
-
* - The `
|
|
657
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
658
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `getNode` function can accept a key,
|
|
660
659
|
* node, entry, raw data, or a predicate function.
|
|
661
|
-
* @param {BTNRep<K, V,
|
|
660
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
662
661
|
* `getNode` function is used to specify the starting point for searching for a node in a binary
|
|
663
662
|
* tree. If no specific starting point is provided, the default value is set to `this._root`, which
|
|
664
663
|
* is typically the root node of the binary tree.
|
|
@@ -669,8 +668,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
669
668
|
* @returns The `getNode` function is returning the first node that matches the specified criteria,
|
|
670
669
|
* or `null` if no matching node is found.
|
|
671
670
|
*/
|
|
672
|
-
getNode(
|
|
673
|
-
return this.search(
|
|
671
|
+
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
672
|
+
return this.search(keyNodeEntryOrPredicate, true, node => node, startNode, iterationType)[0];
|
|
674
673
|
}
|
|
675
674
|
/**
|
|
676
675
|
* Time Complexity: O(n)
|
|
@@ -678,10 +677,10 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
678
677
|
*
|
|
679
678
|
* This function overrides the `get` method to retrieve the value associated with a specified key,
|
|
680
679
|
* node, entry, raw data, or predicate in a data structure.
|
|
681
|
-
* @param {BTNRep<K, V,
|
|
682
|
-
* - The `
|
|
680
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
681
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `get` method can accept one of the
|
|
683
682
|
* following types:
|
|
684
|
-
* @param {BTNRep<K, V,
|
|
683
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `get`
|
|
685
684
|
* method is used to specify the starting point for searching for a key or node in the binary tree.
|
|
686
685
|
* If no specific starting point is provided, the default starting point is the root of the binary
|
|
687
686
|
* tree (`this._root`).
|
|
@@ -694,14 +693,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
694
693
|
* the method returns the corresponding value. If the key or node is not found, it returns
|
|
695
694
|
* `undefined`.
|
|
696
695
|
*/
|
|
697
|
-
get(
|
|
696
|
+
get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
698
697
|
if (this._isMapMode) {
|
|
699
|
-
const key = this._extractKey(
|
|
698
|
+
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
700
699
|
if (key === null || key === undefined)
|
|
701
700
|
return;
|
|
702
701
|
return this._store.get(key);
|
|
703
702
|
}
|
|
704
|
-
return this.getNode(
|
|
703
|
+
return this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)?.value;
|
|
705
704
|
}
|
|
706
705
|
/**
|
|
707
706
|
* Time Complexity: O(n)
|
|
@@ -709,10 +708,10 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
709
708
|
*
|
|
710
709
|
* The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
|
|
711
710
|
* exists in the data structure.
|
|
712
|
-
* @param {BTNRep<K, V,
|
|
713
|
-
* - The `
|
|
711
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
712
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `override has` method can accept one of
|
|
714
713
|
* the following types:
|
|
715
|
-
* @param {BTNRep<K, V,
|
|
714
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
716
715
|
* `override` method is used to specify the starting point for the search operation within the data
|
|
717
716
|
* structure. It defaults to `this._root` if not provided explicitly.
|
|
718
717
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
|
|
@@ -724,14 +723,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
724
723
|
* are matching nodes, it returns `true`, indicating that the tree contains the specified element.
|
|
725
724
|
* Otherwise, it returns `false`.
|
|
726
725
|
*/
|
|
727
|
-
has(
|
|
728
|
-
return this.search(
|
|
726
|
+
has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
727
|
+
return this.search(keyNodeEntryOrPredicate, true, node => node, startNode, iterationType).length > 0;
|
|
729
728
|
}
|
|
730
729
|
/**
|
|
731
730
|
* Time Complexity: O(1)
|
|
732
731
|
* Space Complexity: O(1)
|
|
733
732
|
*
|
|
734
|
-
* The
|
|
733
|
+
* The clear function removes nodes and values in map mode.
|
|
735
734
|
*/
|
|
736
735
|
clear() {
|
|
737
736
|
this._clearNodes();
|
|
@@ -756,7 +755,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
756
755
|
*
|
|
757
756
|
* The function checks if a binary tree is perfectly balanced by comparing its minimum height with
|
|
758
757
|
* its height.
|
|
759
|
-
* @param {BTNRep<K, V,
|
|
758
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
760
759
|
* point for checking if the binary tree is perfectly balanced. It represents the root node of the
|
|
761
760
|
* binary tree or a specific node from which the balance check should begin.
|
|
762
761
|
* @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
|
|
@@ -770,11 +769,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
770
769
|
}
|
|
771
770
|
/**
|
|
772
771
|
* Time Complexity: O(n)
|
|
773
|
-
* Space Complexity: O(
|
|
772
|
+
* Space Complexity: O(log n)
|
|
774
773
|
*
|
|
775
774
|
* The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
|
|
776
775
|
* or iterative methods.
|
|
777
|
-
* @param {BTNRep<K, V,
|
|
776
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `isBST`
|
|
778
777
|
* function represents the starting point for checking whether a binary search tree (BST) is valid.
|
|
779
778
|
* It can be a node in the BST or a reference to the root of the BST. If no specific node is
|
|
780
779
|
* provided, the function will default to
|
|
@@ -830,13 +829,13 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
830
829
|
}
|
|
831
830
|
/**
|
|
832
831
|
* Time Complexity: O(n)
|
|
833
|
-
* Space Complexity: O(
|
|
832
|
+
* Space Complexity: O(log n)
|
|
834
833
|
*
|
|
835
834
|
* The `getDepth` function calculates the depth between two nodes in a binary tree.
|
|
836
|
-
* @param {BTNRep<K, V,
|
|
835
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} dist - The `dist` parameter in the `getDepth`
|
|
837
836
|
* function represents the node or entry in a binary tree map, or a reference to a node in the tree.
|
|
838
837
|
* It is the target node for which you want to calculate the depth from the `startNode` node.
|
|
839
|
-
* @param {BTNRep<K, V,
|
|
838
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
840
839
|
* `getDepth` function represents the starting point from which you want to calculate the depth of a
|
|
841
840
|
* given node or entry in a binary tree. If no specific starting point is provided, the default value
|
|
842
841
|
* for `startNode` is set to the root of the binary
|
|
@@ -859,11 +858,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
859
858
|
}
|
|
860
859
|
/**
|
|
861
860
|
* Time Complexity: O(n)
|
|
862
|
-
* Space Complexity: O(
|
|
861
|
+
* Space Complexity: O(log n)
|
|
863
862
|
*
|
|
864
863
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
865
864
|
* or iterative approach in TypeScript.
|
|
866
|
-
* @param {BTNRep<K, V,
|
|
865
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
867
866
|
* point from which the height of the binary tree will be calculated. It can be a node in the binary
|
|
868
867
|
* tree or a reference to the root of the tree. If not provided, it defaults to the root of the
|
|
869
868
|
* binary tree data structure.
|
|
@@ -908,7 +907,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
908
907
|
*
|
|
909
908
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
910
909
|
* recursive or iterative approach in TypeScript.
|
|
911
|
-
* @param {BTNRep<K, V,
|
|
910
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
912
911
|
* `getMinHeight` function represents the starting node from which the minimum height of the binary
|
|
913
912
|
* tree will be calculated. It is either a node in the binary tree or a reference to the root of the
|
|
914
913
|
* tree. If not provided, the default value is the root
|
|
@@ -974,7 +973,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
974
973
|
* the path to the root. It is expected to be a function that takes a node as an argument and returns
|
|
975
974
|
* a value based on that node. The return type of the callback function is determined by the generic
|
|
976
975
|
* type `C
|
|
977
|
-
* @param {BTNRep<K, V,
|
|
976
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} beginNode - The `beginNode` parameter in the
|
|
978
977
|
* `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
|
|
979
978
|
* @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
|
|
980
979
|
* whether the resulting path from the given `beginNode` to the root should be in reverse order or
|
|
@@ -999,14 +998,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
999
998
|
}
|
|
1000
999
|
/**
|
|
1001
1000
|
* Time Complexity: O(log n)
|
|
1002
|
-
* Space Complexity: O(
|
|
1001
|
+
* Space Complexity: O(log n)
|
|
1003
1002
|
*
|
|
1004
1003
|
* The function `getLeftMost` retrieves the leftmost node in a binary tree using either recursive or
|
|
1005
1004
|
* tail-recursive iteration.
|
|
1006
1005
|
* @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
|
|
1007
1006
|
* node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
|
|
1008
1007
|
* value of `_DEFAULT_NODE_CALLBACK` if not specified.
|
|
1009
|
-
* @param {BTNRep<K, V,
|
|
1008
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1010
1009
|
* `getLeftMost` function represents the starting point for finding the leftmost node in a binary
|
|
1011
1010
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
1012
1011
|
* starting point is provided, the function will default
|
|
@@ -1044,15 +1043,15 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1044
1043
|
}
|
|
1045
1044
|
/**
|
|
1046
1045
|
* Time Complexity: O(log n)
|
|
1047
|
-
* Space Complexity: O(
|
|
1046
|
+
* Space Complexity: O(log n)
|
|
1048
1047
|
*
|
|
1049
1048
|
* The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
|
|
1050
1049
|
* or iterative traversal methods.
|
|
1051
1050
|
* @param {C} callback - The `callback` parameter is a function that will be called with the result
|
|
1052
|
-
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<
|
|
1051
|
+
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`,
|
|
1053
1052
|
* which means it is a callback function that can accept either an optional binary tree node or null
|
|
1054
1053
|
* as
|
|
1055
|
-
* @param {BTNRep<K, V,
|
|
1054
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1056
1055
|
* `getRightMost` function represents the starting point for finding the rightmost node in a binary
|
|
1057
1056
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
1058
1057
|
* starting point is provided, the function will default
|
|
@@ -1090,14 +1089,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1090
1089
|
}
|
|
1091
1090
|
/**
|
|
1092
1091
|
* Time Complexity: O(log n)
|
|
1093
|
-
* Space Complexity: O(
|
|
1092
|
+
* Space Complexity: O(log n)
|
|
1094
1093
|
*
|
|
1095
1094
|
* The function `getPredecessor` in TypeScript returns the predecessor node of a given node in a
|
|
1096
1095
|
* binary tree.
|
|
1097
|
-
* @param {
|
|
1096
|
+
* @param {BinaryTreeNode<K, V>} node - The `getPredecessor` function you provided seems to be attempting to find the
|
|
1098
1097
|
* predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
|
|
1099
1098
|
* while loop condition that might cause an infinite loop.
|
|
1100
|
-
* @returns The `getPredecessor` function returns the predecessor node of the input `
|
|
1099
|
+
* @returns The `getPredecessor` function returns the predecessor node of the input `BinaryTreeNode<K, V>` parameter.
|
|
1101
1100
|
* If the left child of the input node exists, it traverses to the rightmost node of the left subtree
|
|
1102
1101
|
* to find the predecessor. If the left child does not exist, it returns the input node itself.
|
|
1103
1102
|
*/
|
|
@@ -1117,12 +1116,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1117
1116
|
}
|
|
1118
1117
|
/**
|
|
1119
1118
|
* Time Complexity: O(log n)
|
|
1120
|
-
* Space Complexity: O(
|
|
1119
|
+
* Space Complexity: O(log n)
|
|
1121
1120
|
*
|
|
1122
1121
|
* The function `getSuccessor` in TypeScript returns the next node in an in-order traversal of a
|
|
1123
1122
|
* binary tree.
|
|
1124
|
-
* @param {K |
|
|
1125
|
-
* type `K`, `
|
|
1123
|
+
* @param {K | BinaryTreeNode<K, V> | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
|
|
1124
|
+
* type `K`, `BinaryTreeNode<K, V>`, or `null`.
|
|
1126
1125
|
* @returns The `getSuccessor` function returns the successor node of the input node `x`. If `x` has
|
|
1127
1126
|
* a right child, the function returns the leftmost node in the right subtree of `x`. If `x` does not
|
|
1128
1127
|
* have a right child, the function traverses up the parent nodes until it finds a node that is not
|
|
@@ -1149,12 +1148,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1149
1148
|
* The function `dfs` performs a depth-first search traversal on a binary tree structure based on the
|
|
1150
1149
|
* specified parameters.
|
|
1151
1150
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends the
|
|
1152
|
-
* `NodeCallback` interface with a type parameter of `OptNodeOrNull<
|
|
1151
|
+
* `NodeCallback` interface with a type parameter of `OptNodeOrNull<BinaryTreeNode<K, V>>`. It has a default value of
|
|
1153
1152
|
* `this._DEFAULT_NODE_CALLBACK as C`.
|
|
1154
1153
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` method specifies the
|
|
1155
1154
|
* order in which the Depth-First Search (DFS) algorithm should traverse the nodes in the tree. The
|
|
1156
1155
|
* possible values for the `pattern` parameter are:
|
|
1157
|
-
* @param {BTNRep<K, V,
|
|
1156
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `dfs`
|
|
1158
1157
|
* method is used to specify the starting point for the Depth-First Search traversal. It can be
|
|
1159
1158
|
* either a `BTNRep` object representing a key, node, or entry in the binary tree map,
|
|
1160
1159
|
* or it can be a
|
|
@@ -1182,8 +1181,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1182
1181
|
* tree, executing a specified callback function on each node visited.
|
|
1183
1182
|
* @param {C} callback - The `callback` parameter in the `bfs` function is a function that will be
|
|
1184
1183
|
* called on each node visited during the breadth-first search traversal. It is a generic type `C`
|
|
1185
|
-
* that extends the `NodeCallback` type, which takes a parameter of type `
|
|
1186
|
-
* @param {BTNRep<K, V,
|
|
1184
|
+
* that extends the `NodeCallback` type, which takes a parameter of type `BinaryTreeNode<K, V>` or `null`.
|
|
1185
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `bfs`
|
|
1187
1186
|
* function represents the starting point for the breadth-first search traversal in a binary tree. It
|
|
1188
1187
|
* can be specified as a key, node, or entry in the binary tree structure. If not provided, the
|
|
1189
1188
|
* default value is the root node of the binary
|
|
@@ -1203,7 +1202,9 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1203
1202
|
return [];
|
|
1204
1203
|
const ans = [];
|
|
1205
1204
|
if (iterationType === 'RECURSIVE') {
|
|
1206
|
-
const queue = new Queue([
|
|
1205
|
+
const queue = new Queue([
|
|
1206
|
+
startNode
|
|
1207
|
+
]);
|
|
1207
1208
|
const dfs = (level) => {
|
|
1208
1209
|
if (queue.size === 0)
|
|
1209
1210
|
return;
|
|
@@ -1257,7 +1258,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1257
1258
|
* structure based on a specified callback and iteration type.
|
|
1258
1259
|
* @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
|
|
1259
1260
|
* in the binary tree. It is optional and defaults to a default callback function if not provided.
|
|
1260
|
-
* @param {BTNRep<K, V,
|
|
1261
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `leaves`
|
|
1261
1262
|
* method is used to specify the starting point for finding and processing the leaves of a binary
|
|
1262
1263
|
* tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
|
|
1263
1264
|
* explicitly provided, the default value
|
|
@@ -1312,7 +1313,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1312
1313
|
* @param {C} callback - The `callback` parameter is a function that will be applied to each node in
|
|
1313
1314
|
* the binary tree during the traversal. It is used to process each node and determine what
|
|
1314
1315
|
* information to include in the output for each level of the tree.
|
|
1315
|
-
* @param {BTNRep<K, V,
|
|
1316
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1316
1317
|
* `listLevels` function represents the starting point for traversing the binary tree. It can be
|
|
1317
1318
|
* either a key, a node, or an entry in the binary tree. If not provided, the default value is the
|
|
1318
1319
|
* root of the binary tree.
|
|
@@ -1384,11 +1385,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1384
1385
|
* Morris Traversal algorithm with different order patterns.
|
|
1385
1386
|
* @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
|
|
1386
1387
|
* called on each node in the binary tree during the traversal. It is of type `C`, which extends the
|
|
1387
|
-
* `NodeCallback<
|
|
1388
|
+
* `NodeCallback<BinaryTreeNode<K, V>>` type. The default value for `callback` is `this._DEFAULT
|
|
1388
1389
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
|
|
1389
1390
|
* the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
|
|
1390
1391
|
* values for the `pattern` parameter are:
|
|
1391
|
-
* @param {BTNRep<K, V,
|
|
1392
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `morris`
|
|
1392
1393
|
* function is the starting point for the Morris traversal algorithm. It represents the root node of
|
|
1393
1394
|
* the binary tree or the node from which the traversal should begin. It can be provided as either a
|
|
1394
1395
|
* key, a node, an entry, or a reference
|
|
@@ -1494,6 +1495,10 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1494
1495
|
*/
|
|
1495
1496
|
clone() {
|
|
1496
1497
|
const cloned = this.createTree();
|
|
1498
|
+
this._clone(cloned);
|
|
1499
|
+
return cloned;
|
|
1500
|
+
}
|
|
1501
|
+
_clone(cloned) {
|
|
1497
1502
|
this.bfs(node => {
|
|
1498
1503
|
if (node === null)
|
|
1499
1504
|
cloned.add(null);
|
|
@@ -1506,7 +1511,6 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1506
1511
|
}, this._root, this.iterationType, true);
|
|
1507
1512
|
if (this._isMapMode)
|
|
1508
1513
|
cloned._store = this._store;
|
|
1509
|
-
return cloned;
|
|
1510
1514
|
}
|
|
1511
1515
|
/**
|
|
1512
1516
|
* Time Complexity: O(n)
|
|
@@ -1567,7 +1571,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1567
1571
|
*
|
|
1568
1572
|
* The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
|
|
1569
1573
|
* customizable options for displaying undefined, null, and sentinel nodes.
|
|
1570
|
-
* @param {BTNRep<K, V,
|
|
1574
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1571
1575
|
* `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
|
|
1572
1576
|
* It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
|
|
1573
1577
|
* the default is set to the root
|
|
@@ -1592,7 +1596,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1592
1596
|
if (opts.isShowRedBlackNIL)
|
|
1593
1597
|
output += `S for Sentinel Node(NIL)\n`;
|
|
1594
1598
|
const display = (root) => {
|
|
1595
|
-
const [lines
|
|
1599
|
+
const [lines] = this._displayAux(root, opts);
|
|
1596
1600
|
let paragraph = '';
|
|
1597
1601
|
for (const line of lines) {
|
|
1598
1602
|
paragraph += line + '\n';
|
|
@@ -1612,7 +1616,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1612
1616
|
* printing options for the binary tree. It is an optional parameter that allows you to customize how
|
|
1613
1617
|
* the binary tree is printed, such as choosing between different traversal orders or formatting
|
|
1614
1618
|
* options.
|
|
1615
|
-
* @param {BTNRep<K, V,
|
|
1619
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1616
1620
|
* `override print` method is used to specify the starting point for printing the binary tree. It can
|
|
1617
1621
|
* be either a key, a node, an entry, or the root of the tree. If no specific starting point is
|
|
1618
1622
|
* provided, the default value is set to
|
|
@@ -1620,6 +1624,42 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1620
1624
|
print(options, startNode = this._root) {
|
|
1621
1625
|
console.log(this.toVisual(startNode, options));
|
|
1622
1626
|
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Time Complexity: O(1)
|
|
1629
|
+
* Space Complexity: O(1)
|
|
1630
|
+
*
|
|
1631
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
1632
|
+
* or returns null.
|
|
1633
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The
|
|
1634
|
+
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeOrEntry`, which
|
|
1635
|
+
* can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. This parameter represents either a key, a
|
|
1636
|
+
* node, an entry
|
|
1637
|
+
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
1638
|
+
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
1639
|
+
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
1640
|
+
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
1641
|
+
* (`OptNodeOrNull<BinaryTreeNode<K, V>>`) based on the input parameters provided. The function checks the type of the
|
|
1642
|
+
* input parameter (`keyNodeOrEntry`) and processes it accordingly to return a node or null
|
|
1643
|
+
* value.
|
|
1644
|
+
*/
|
|
1645
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
|
|
1646
|
+
if (keyNodeOrEntry === undefined)
|
|
1647
|
+
return [undefined, undefined];
|
|
1648
|
+
if (keyNodeOrEntry === null)
|
|
1649
|
+
return [null, undefined];
|
|
1650
|
+
if (this.isNode(keyNodeOrEntry))
|
|
1651
|
+
return [keyNodeOrEntry, value];
|
|
1652
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
1653
|
+
const [key, entryValue] = keyNodeOrEntry;
|
|
1654
|
+
if (key === undefined)
|
|
1655
|
+
return [undefined, undefined];
|
|
1656
|
+
else if (key === null)
|
|
1657
|
+
return [null, undefined];
|
|
1658
|
+
const finalValue = value ?? entryValue;
|
|
1659
|
+
return [this.createNode(key, finalValue), finalValue];
|
|
1660
|
+
}
|
|
1661
|
+
return [this.createNode(keyNodeOrEntry, value), value];
|
|
1662
|
+
}
|
|
1623
1663
|
/**
|
|
1624
1664
|
* Time complexity: O(n)
|
|
1625
1665
|
* Space complexity: O(n)
|
|
@@ -1628,11 +1668,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1628
1668
|
* the specified order pattern and callback function.
|
|
1629
1669
|
* @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
|
|
1630
1670
|
* called on each node visited during the depth-first search traversal. It is of type `C`, which
|
|
1631
|
-
* extends `NodeCallback<OptNodeOrNull<
|
|
1671
|
+
* extends `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`. The default value for this parameter is `this._DEFAULT
|
|
1632
1672
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
|
|
1633
1673
|
* order in which the nodes are visited during the Depth-First Search traversal. It can have one of
|
|
1634
1674
|
* the following values:
|
|
1635
|
-
* @param {BTNRep<K, V,
|
|
1675
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `_dfs`
|
|
1636
1676
|
* method is used to specify the starting point for the depth-first search traversal in a binary
|
|
1637
1677
|
* tree. It can be provided as either a `BTNRep` object or a reference to the root node
|
|
1638
1678
|
* of the tree. If no specific
|
|
@@ -1875,12 +1915,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1875
1915
|
* Space Complexity: O(1)
|
|
1876
1916
|
*
|
|
1877
1917
|
* The _swapProperties function swaps key and value properties between two nodes in a binary tree.
|
|
1878
|
-
* @param {BTNRep<K, V,
|
|
1918
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} srcNode - The `srcNode` parameter in the
|
|
1879
1919
|
* `_swapProperties` method can be either a BTNRep object containing key and value
|
|
1880
1920
|
* properties, or it can be of type R.
|
|
1881
|
-
* @param {BTNRep<K, V,
|
|
1921
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} destNode - The `destNode` parameter in the
|
|
1882
1922
|
* `_swapProperties` method represents the node or entry where the properties will be swapped with
|
|
1883
|
-
* the `srcNode`. It can be of type `BTNRep<K, V,
|
|
1923
|
+
* the `srcNode`. It can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. The method ensures that
|
|
1884
1924
|
* both `srcNode
|
|
1885
1925
|
* @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
|
|
1886
1926
|
* with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
@@ -1908,9 +1948,9 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1908
1948
|
* Space Complexity: O(1)
|
|
1909
1949
|
*
|
|
1910
1950
|
* The _replaceNode function replaces an old node with a new node in a binary tree structure.
|
|
1911
|
-
* @param {
|
|
1951
|
+
* @param {BinaryTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that you want to replace in a
|
|
1912
1952
|
* tree data structure.
|
|
1913
|
-
* @param {
|
|
1953
|
+
* @param {BinaryTreeNode<K, V>} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
|
|
1914
1954
|
* that will replace the `oldNode` in a tree data structure. This function is responsible for
|
|
1915
1955
|
* updating the parent, left child, right child, and root (if necessary) references when replacing a
|
|
1916
1956
|
* node in the tree.
|
|
@@ -1940,8 +1980,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1940
1980
|
*
|
|
1941
1981
|
* The function _setRoot sets the root node of a data structure while updating the parent reference
|
|
1942
1982
|
* of the previous root node.
|
|
1943
|
-
* @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<
|
|
1944
|
-
* it can either be an optional `
|
|
1983
|
+
* @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<BinaryTreeNode<K, V>>`, which means
|
|
1984
|
+
* it can either be an optional `BinaryTreeNode<K, V>` type or `null`.
|
|
1945
1985
|
*/
|
|
1946
1986
|
_setRoot(v) {
|
|
1947
1987
|
if (v) {
|
|
@@ -1955,30 +1995,24 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1955
1995
|
*
|
|
1956
1996
|
* The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
|
|
1957
1997
|
* predicate function for a binary tree node.
|
|
1958
|
-
* @param {BTNRep<K, V,
|
|
1998
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
1959
1999
|
* `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
|
|
1960
|
-
* parameter `
|
|
2000
|
+
* parameter `keyNodeEntryOrPredicate` is transformed into a valid predicate function that can be
|
|
1961
2001
|
* used for filtering nodes in a binary tree.
|
|
1962
|
-
* @returns A NodePredicate<
|
|
2002
|
+
* @returns A NodePredicate<BinaryTreeNode<K, V>> function is being returned.
|
|
1963
2003
|
*/
|
|
1964
|
-
_ensurePredicate(
|
|
1965
|
-
if (
|
|
2004
|
+
_ensurePredicate(keyNodeEntryOrPredicate) {
|
|
2005
|
+
if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === undefined)
|
|
1966
2006
|
return (node) => (node ? false : false);
|
|
1967
|
-
if (this._isPredicate(
|
|
1968
|
-
return
|
|
1969
|
-
if (this.isRealNode(
|
|
1970
|
-
return (node) => node ===
|
|
1971
|
-
if (this.isEntry(
|
|
1972
|
-
const [key] =
|
|
1973
|
-
return (node) => node.key === key;
|
|
1974
|
-
}
|
|
1975
|
-
if (this.isKey(keyNodeEntryRawOrPredicate))
|
|
1976
|
-
return (node) => node.key === keyNodeEntryRawOrPredicate;
|
|
1977
|
-
if (this._toEntryFn) {
|
|
1978
|
-
const [key] = this._toEntryFn(keyNodeEntryRawOrPredicate);
|
|
2007
|
+
if (this._isPredicate(keyNodeEntryOrPredicate))
|
|
2008
|
+
return keyNodeEntryOrPredicate;
|
|
2009
|
+
if (this.isRealNode(keyNodeEntryOrPredicate))
|
|
2010
|
+
return (node) => node === keyNodeEntryOrPredicate;
|
|
2011
|
+
if (this.isEntry(keyNodeEntryOrPredicate)) {
|
|
2012
|
+
const [key] = keyNodeEntryOrPredicate;
|
|
1979
2013
|
return (node) => node.key === key;
|
|
1980
2014
|
}
|
|
1981
|
-
return (node) => node.key ===
|
|
2015
|
+
return (node) => node.key === keyNodeEntryOrPredicate;
|
|
1982
2016
|
}
|
|
1983
2017
|
/**
|
|
1984
2018
|
* Time Complexity: O(1)
|
|
@@ -1987,7 +2021,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1987
2021
|
* The function `_isPredicate` checks if a given parameter is a function.
|
|
1988
2022
|
* @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
|
|
1989
2023
|
* of value. In this context, the function `_isPredicate` is checking if `p` is a function that
|
|
1990
|
-
* satisfies the type `NodePredicate<
|
|
2024
|
+
* satisfies the type `NodePredicate<BinaryTreeNode<K, V>>`.
|
|
1991
2025
|
* @returns The function is checking if the input `p` is a function and returning a boolean value
|
|
1992
2026
|
* based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
|
|
1993
2027
|
* predicate function for a binary tree node. If `p` is not a function, it will return `false`.
|
|
@@ -2001,32 +2035,25 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
2001
2035
|
*
|
|
2002
2036
|
* The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
|
|
2003
2037
|
* entry, raw data, or null/undefined.
|
|
2004
|
-
* @param {BTNRep<K, V,
|
|
2005
|
-
* TypeScript method that takes in a parameter `
|
|
2006
|
-
* where `BTNRep` is a generic type with keys `K`, `V`, and `
|
|
2007
|
-
* @returns The `_extractKey` method returns the key value extracted from the `
|
|
2038
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `_extractKey` method you provided is a
|
|
2039
|
+
* TypeScript method that takes in a parameter `keyNodeOrEntry` of type `BTNRep<K, V, BinaryTreeNode<K, V>>`,
|
|
2040
|
+
* where `BTNRep` is a generic type with keys `K`, `V`, and `BinaryTreeNode<K, V>`, and `
|
|
2041
|
+
* @returns The `_extractKey` method returns the key value extracted from the `keyNodeOrEntry`
|
|
2008
2042
|
* parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
|
|
2009
2043
|
* the conditions checked in the method.
|
|
2010
2044
|
*/
|
|
2011
|
-
_extractKey(
|
|
2012
|
-
if (
|
|
2045
|
+
_extractKey(keyNodeOrEntry) {
|
|
2046
|
+
if (keyNodeOrEntry === null)
|
|
2013
2047
|
return null;
|
|
2014
|
-
if (
|
|
2048
|
+
if (keyNodeOrEntry === undefined)
|
|
2015
2049
|
return;
|
|
2016
|
-
if (
|
|
2050
|
+
if (keyNodeOrEntry === this._NIL)
|
|
2017
2051
|
return;
|
|
2018
|
-
if (this.isNode(
|
|
2019
|
-
return
|
|
2020
|
-
if (this.isEntry(
|
|
2021
|
-
return
|
|
2022
|
-
|
|
2023
|
-
if (this._toEntryFn) {
|
|
2024
|
-
const [key] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
2025
|
-
return key;
|
|
2026
|
-
}
|
|
2027
|
-
return;
|
|
2028
|
-
}
|
|
2029
|
-
return keyNodeEntryOrRaw;
|
|
2052
|
+
if (this.isNode(keyNodeOrEntry))
|
|
2053
|
+
return keyNodeOrEntry.key;
|
|
2054
|
+
if (this.isEntry(keyNodeOrEntry))
|
|
2055
|
+
return keyNodeOrEntry[0];
|
|
2056
|
+
return keyNodeOrEntry;
|
|
2030
2057
|
}
|
|
2031
2058
|
/**
|
|
2032
2059
|
* Time Complexity: O(1)
|