data-structure-typed 1.53.9 → 1.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -0
- package/benchmark/report.html +1 -28
- package/benchmark/report.json +17 -326
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts → cjs/data-structures/binary-tree/avl-tree-counter.d.ts} +54 -59
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +408 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -189
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +133 -357
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +108 -78
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +126 -79
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +243 -190
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +273 -229
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +141 -122
- package/dist/cjs/data-structures/binary-tree/bst.js +170 -134
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +84 -80
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +101 -79
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.d.ts → cjs/data-structures/binary-tree/tree-counter.d.ts} +54 -56
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +445 -0
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +78 -186
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +140 -388
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -4
- package/dist/cjs/data-structures/trie/trie.js +0 -4
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +7 -6
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -3
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.js → esm/data-structures/binary-tree/avl-tree-counter.js} +72 -78
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +191 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +234 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/avl-tree.js +126 -80
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.d.ts +243 -190
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.js +276 -234
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.d.ts +141 -122
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.js +171 -140
- package/dist/esm/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js +2 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js.map +1 -1
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.d.ts +84 -80
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.js +100 -79
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.js → esm/data-structures/binary-tree/tree-counter.js} +88 -86
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +106 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +196 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.js +3 -0
- package/dist/esm/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.js +3 -0
- package/dist/esm/data-structures/graph/map-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.js +3 -0
- package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.js +3 -0
- package/dist/esm/data-structures/matrix/matrix.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.js +3 -0
- package/dist/esm/data-structures/matrix/navigator.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/trie/trie.d.ts +0 -4
- package/dist/{mjs → esm}/data-structures/trie/trie.js +0 -4
- package/dist/esm/data-structures/trie/trie.js.map +1 -0
- package/dist/esm/interfaces/binary-tree.d.ts +9 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/esm/types/data-structures/binary-tree/rb-tree.d.ts +3 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/umd/data-structure-typed.js +1407 -913
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +14 -14
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +148 -394
- package/src/data-structures/binary-tree/avl-tree.ts +152 -112
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +446 -379
- package/src/data-structures/binary-tree/bst.ts +224 -201
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +138 -114
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +156 -428
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- package/src/data-structures/trie/trie.ts +0 -4
- package/src/interfaces/binary-tree.ts +10 -11
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -3
- package/src/types/data-structures/binary-tree/index.ts +2 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -4
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -4
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/integration/avl-tree.test.ts +1 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/integration/compile.js +144 -0
- package/test/integration/compile.ts +171 -0
- package/test/integration/index.html +48 -48
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -4
- package/test/performance/data-structures/comparison/comparison.test.ts +2 -2
- package/test/performance/reportor.ts +5 -3
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +877 -0
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +459 -761
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +223 -223
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +474 -492
- package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/overall.test.ts +0 -3
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +87 -90
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +975 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +729 -857
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/{tsconfig-mjs.json → tsconfig-esm.json} +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -204
- package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/map-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix.js.map +0 -1
- package/dist/mjs/data-structures/matrix/navigator.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/trie/trie.js.map +0 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +0 -8
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -4
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -4
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -4
- /package/dist/{mjs → esm}/common/index.d.ts +0 -0
- /package/dist/{mjs → esm}/common/index.js +0 -0
- /package/dist/{mjs → esm}/common/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.js +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.js +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.js +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.js.map +0 -0
- /package/dist/{mjs → esm}/index.d.ts +0 -0
- /package/dist/{mjs → esm}/index.js +0 -0
- /package/dist/{mjs → esm}/index.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/binary-tree.js +0 -0
- /package/dist/{mjs → esm}/interfaces/binary-tree.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.js +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.js +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/index.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/index.js +0 -0
- /package/dist/{mjs → esm}/interfaces/index.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.js +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/common.d.ts +0 -0
- /package/dist/{mjs → esm}/types/common.js +0 -0
- /package/dist/{mjs → esm}/types/common.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/rb-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/rb-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.js.map +0 -0
- /package/dist/{mjs → esm}/types/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/index.js +0 -0
- /package/dist/{mjs → esm}/types/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/index.js +0 -0
- /package/dist/{mjs → esm}/types/utils/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.js +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.js +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.js.map +0 -0
- /package/dist/{mjs → esm}/utils/index.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/index.js +0 -0
- /package/dist/{mjs → esm}/utils/index.js.map +0 -0
- /package/dist/{mjs → esm}/utils/number.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/number.js +0 -0
- /package/dist/{mjs → esm}/utils/number.js.map +0 -0
- /package/dist/{mjs → esm}/utils/utils.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/utils.js +0 -0
- /package/dist/{mjs → esm}/utils/utils.js.map +0 -0
|
@@ -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
|
}
|
|
@@ -42,15 +50,35 @@ export class BinaryTreeNode {
|
|
|
42
50
|
}
|
|
43
51
|
this._right = v;
|
|
44
52
|
}
|
|
53
|
+
_height = 0;
|
|
54
|
+
get height() {
|
|
55
|
+
return this._height;
|
|
56
|
+
}
|
|
57
|
+
set height(value) {
|
|
58
|
+
this._height = value;
|
|
59
|
+
}
|
|
60
|
+
_color = 'BLACK';
|
|
61
|
+
get color() {
|
|
62
|
+
return this._color;
|
|
63
|
+
}
|
|
64
|
+
set color(value) {
|
|
65
|
+
this._color = value;
|
|
66
|
+
}
|
|
67
|
+
_count = 1;
|
|
68
|
+
get count() {
|
|
69
|
+
return this._count;
|
|
70
|
+
}
|
|
71
|
+
set count(value) {
|
|
72
|
+
this._count = value;
|
|
73
|
+
}
|
|
45
74
|
get familyPosition() {
|
|
46
|
-
const that = this;
|
|
47
75
|
if (!this.parent) {
|
|
48
76
|
return this.left || this.right ? 'ROOT' : 'ISOLATED';
|
|
49
77
|
}
|
|
50
|
-
if (this.parent.left ===
|
|
78
|
+
if (this.parent.left === this) {
|
|
51
79
|
return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
|
|
52
80
|
}
|
|
53
|
-
else if (this.parent.right ===
|
|
81
|
+
else if (this.parent.right === this) {
|
|
54
82
|
return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
|
|
55
83
|
}
|
|
56
84
|
return 'MAL_NODE';
|
|
@@ -64,15 +92,14 @@ export class BinaryTreeNode {
|
|
|
64
92
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
65
93
|
*/
|
|
66
94
|
export class BinaryTree extends IterableEntryBase {
|
|
67
|
-
iterationType = 'ITERATIVE';
|
|
68
95
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @param [options] - The `options` parameter in the constructor is an object that can
|
|
75
|
-
* 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:
|
|
76
103
|
*/
|
|
77
104
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
78
105
|
super();
|
|
@@ -90,6 +117,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
90
117
|
if (keysNodesEntriesOrRaws)
|
|
91
118
|
this.addMany(keysNodesEntriesOrRaws);
|
|
92
119
|
}
|
|
120
|
+
iterationType = 'ITERATIVE';
|
|
93
121
|
_isMapMode = true;
|
|
94
122
|
get isMapMode() {
|
|
95
123
|
return this._isMapMode;
|
|
@@ -124,7 +152,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
124
152
|
* not required to be provided when calling the function. If a `value` is provided, it should be of
|
|
125
153
|
* type `V`, which is the type of the value associated with the node.
|
|
126
154
|
* @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
|
|
127
|
-
* as
|
|
155
|
+
* as BinaryTreeNode<K, V>.
|
|
128
156
|
*/
|
|
129
157
|
createNode(key, value) {
|
|
130
158
|
return new BinaryTreeNode(key, this._isMapMode ? undefined : value);
|
|
@@ -133,15 +161,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
133
161
|
* Time Complexity: O(1)
|
|
134
162
|
* Space Complexity: O(1)
|
|
135
163
|
*
|
|
136
|
-
* The
|
|
137
|
-
* @param [options] - The `options` parameter in the `createTree`
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* @returns
|
|
142
|
-
* provided options. The method is creating a new `BinaryTree` object with an empty array as the
|
|
143
|
-
* initial data, and then setting various options such as `iterationType`, `isMapMode`, and
|
|
144
|
-
* `toEntryFn` based on the current object's properties and the provided `options`. Finally, it
|
|
164
|
+
* The function creates a binary tree with the specified options.
|
|
165
|
+
* @param [options] - The `options` parameter in the `createTree` function is an optional parameter
|
|
166
|
+
* that allows you to provide partial configuration options for creating a binary tree. It is of type
|
|
167
|
+
* `Partial<BinaryTreeOptions<K, V, R>>`, which means you can pass in an object containing a subset
|
|
168
|
+
* of properties
|
|
169
|
+
* @returns A new instance of a binary tree with the specified options is being returned.
|
|
145
170
|
*/
|
|
146
171
|
createTree(options) {
|
|
147
172
|
return new BinaryTree([], {
|
|
@@ -157,8 +182,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
157
182
|
*
|
|
158
183
|
* The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
|
|
159
184
|
* value and returns the corresponding node or null.
|
|
160
|
-
* @param {BTNRep<K, V,
|
|
161
|
-
* 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
|
|
162
187
|
* is used to determine whether the input is a key, node, entry, or raw data. The
|
|
163
188
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
|
|
164
189
|
* is used to specify the type of iteration to be performed. It has a default value of
|
|
@@ -166,49 +191,48 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
166
191
|
* @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
|
|
167
192
|
* conditions specified in the code snippet.
|
|
168
193
|
*/
|
|
169
|
-
ensureNode(
|
|
170
|
-
if (
|
|
194
|
+
ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
|
|
195
|
+
if (keyNodeOrEntry === null)
|
|
171
196
|
return null;
|
|
172
|
-
if (
|
|
197
|
+
if (keyNodeOrEntry === undefined)
|
|
173
198
|
return;
|
|
174
|
-
if (
|
|
199
|
+
if (keyNodeOrEntry === this._NIL)
|
|
175
200
|
return;
|
|
176
|
-
if (this.isNode(
|
|
177
|
-
return
|
|
178
|
-
if (this.isEntry(
|
|
179
|
-
const key =
|
|
201
|
+
if (this.isNode(keyNodeOrEntry))
|
|
202
|
+
return keyNodeOrEntry;
|
|
203
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
204
|
+
const key = keyNodeOrEntry[0];
|
|
180
205
|
if (key === null)
|
|
181
206
|
return null;
|
|
182
207
|
if (key === undefined)
|
|
183
208
|
return;
|
|
184
209
|
return this.getNode(key, this._root, iterationType);
|
|
185
210
|
}
|
|
186
|
-
|
|
187
|
-
const [key] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
188
|
-
if (this.isKey(key))
|
|
189
|
-
return this.getNode(key);
|
|
190
|
-
}
|
|
191
|
-
if (this.isKey(keyNodeEntryOrRaw))
|
|
192
|
-
return this.getNode(keyNodeEntryOrRaw, this._root, iterationType);
|
|
193
|
-
return;
|
|
211
|
+
return this.getNode(keyNodeOrEntry, this._root, iterationType);
|
|
194
212
|
}
|
|
195
213
|
/**
|
|
214
|
+
* Time Complexity: O(1)
|
|
215
|
+
* Space Complexity: O(1)
|
|
216
|
+
*
|
|
196
217
|
* The function isNode checks if the input is an instance of BinaryTreeNode.
|
|
197
|
-
* @param {BTNRep<K, V,
|
|
198
|
-
* `
|
|
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
|
|
199
220
|
* checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
|
|
200
221
|
* accordingly.
|
|
201
|
-
* @returns The function `isNode` is checking if the input `
|
|
222
|
+
* @returns The function `isNode` is checking if the input `keyNodeOrEntry` is an instance of
|
|
202
223
|
* `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
|
|
203
224
|
* it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
|
|
204
225
|
* is not a node.
|
|
205
226
|
*/
|
|
206
|
-
isNode(
|
|
207
|
-
return
|
|
227
|
+
isNode(keyNodeOrEntry) {
|
|
228
|
+
return keyNodeOrEntry instanceof BinaryTreeNode;
|
|
208
229
|
}
|
|
209
230
|
/**
|
|
231
|
+
* Time Complexity: O(1)
|
|
232
|
+
* Space Complexity: O(1)
|
|
233
|
+
*
|
|
210
234
|
* The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
|
|
211
|
-
* @param {BTNRep<K, V,
|
|
235
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | R} keyNodeEntryOrRaw - BTNRep<K, V, BinaryTreeNode<K, V>>
|
|
212
236
|
* @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
|
|
213
237
|
* checking if it is an object. If the parameter is an object, the function will return `true`,
|
|
214
238
|
* indicating that it is of type `R`.
|
|
@@ -217,88 +241,117 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
217
241
|
return this._toEntryFn !== undefined && typeof keyNodeEntryOrRaw === 'object';
|
|
218
242
|
}
|
|
219
243
|
/**
|
|
244
|
+
* Time Complexity: O(1)
|
|
245
|
+
* Space Complexity: O(1)
|
|
246
|
+
*
|
|
220
247
|
* The function `isRealNode` checks if a given input is a valid node in a binary tree.
|
|
221
|
-
* @param {BTNRep<K, V,
|
|
222
|
-
* parameter in the `isRealNode` function can be of type `BTNRep<K, V,
|
|
223
|
-
* The function checks if the input parameter is a `
|
|
224
|
-
* @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
|
|
225
252
|
* node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
|
|
226
253
|
* values, it then calls the `isNode` method to further determine if the input is a node. The
|
|
227
254
|
* function will return a boolean value indicating whether the
|
|
228
255
|
*/
|
|
229
|
-
isRealNode(
|
|
230
|
-
if (
|
|
256
|
+
isRealNode(keyNodeOrEntry) {
|
|
257
|
+
if (keyNodeOrEntry === this._NIL || keyNodeOrEntry === null || keyNodeOrEntry === undefined)
|
|
231
258
|
return false;
|
|
232
|
-
return this.isNode(
|
|
259
|
+
return this.isNode(keyNodeOrEntry);
|
|
233
260
|
}
|
|
234
261
|
/**
|
|
262
|
+
* Time Complexity: O(1)
|
|
263
|
+
* Space Complexity: O(1)
|
|
264
|
+
*
|
|
235
265
|
* The function checks if a given input is a valid node or null.
|
|
236
|
-
* @param {BTNRep<K, V,
|
|
237
|
-
* `
|
|
238
|
-
* 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
|
|
239
269
|
* @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
|
|
240
|
-
* `
|
|
270
|
+
* `keyNodeOrEntry` is either `null` or a real node, and returns `true` if it is a node or
|
|
241
271
|
* `null`, and `false` otherwise.
|
|
242
272
|
*/
|
|
243
|
-
isRealNodeOrNull(
|
|
244
|
-
return
|
|
273
|
+
isRealNodeOrNull(keyNodeOrEntry) {
|
|
274
|
+
return keyNodeOrEntry === null || this.isRealNode(keyNodeOrEntry);
|
|
245
275
|
}
|
|
246
276
|
/**
|
|
277
|
+
* Time Complexity: O(1)
|
|
278
|
+
* Space Complexity: O(1)
|
|
279
|
+
*
|
|
247
280
|
* The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
|
|
248
|
-
* @param {BTNRep<K, V,
|
|
249
|
-
*
|
|
250
|
-
* @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`
|
|
251
284
|
* property of the current object and returning a boolean value based on that comparison.
|
|
252
285
|
*/
|
|
253
|
-
isNIL(
|
|
254
|
-
return
|
|
286
|
+
isNIL(keyNodeOrEntry) {
|
|
287
|
+
return keyNodeOrEntry === this._NIL;
|
|
255
288
|
}
|
|
256
|
-
|
|
257
|
-
|
|
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;
|
|
258
305
|
}
|
|
259
306
|
/**
|
|
307
|
+
* Time Complexity: O(1)
|
|
308
|
+
* Space Complexity: O(1)
|
|
309
|
+
*
|
|
260
310
|
* The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
|
|
261
311
|
* tree.
|
|
262
|
-
* @param {BTNRep<K, V,
|
|
263
|
-
* `
|
|
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
|
|
264
314
|
* key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
|
|
265
315
|
* provided
|
|
266
316
|
* @returns The function `isLeaf` returns a boolean value indicating whether the input
|
|
267
|
-
* `
|
|
317
|
+
* `keyNodeOrEntry` is a leaf node in a binary tree.
|
|
268
318
|
*/
|
|
269
|
-
isLeaf(
|
|
270
|
-
|
|
271
|
-
if (
|
|
319
|
+
isLeaf(keyNodeOrEntry) {
|
|
320
|
+
keyNodeOrEntry = this.ensureNode(keyNodeOrEntry);
|
|
321
|
+
if (keyNodeOrEntry === undefined)
|
|
272
322
|
return false;
|
|
273
|
-
if (
|
|
323
|
+
if (keyNodeOrEntry === null)
|
|
274
324
|
return true;
|
|
275
|
-
return !this.isRealNode(
|
|
325
|
+
return !this.isRealNode(keyNodeOrEntry.left) && !this.isRealNode(keyNodeOrEntry.right);
|
|
276
326
|
}
|
|
277
327
|
/**
|
|
328
|
+
* Time Complexity: O(1)
|
|
329
|
+
* Space Complexity: O(1)
|
|
330
|
+
*
|
|
278
331
|
* The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
|
|
279
332
|
* with a length of 2.
|
|
280
|
-
* @param {BTNRep<K, V,
|
|
281
|
-
* parameter in the `isEntry` function can be of type `BTNRep<K, V,
|
|
282
|
-
* The function checks if the provided `
|
|
283
|
-
* @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
|
|
284
337
|
* with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
|
|
285
338
|
* `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
|
|
286
339
|
*/
|
|
287
|
-
isEntry(
|
|
288
|
-
return Array.isArray(
|
|
340
|
+
isEntry(keyNodeOrEntry) {
|
|
341
|
+
return Array.isArray(keyNodeOrEntry) && keyNodeOrEntry.length === 2;
|
|
289
342
|
}
|
|
290
343
|
/**
|
|
291
344
|
* Time Complexity O(1)
|
|
292
345
|
* Space Complexity O(1)
|
|
293
346
|
*
|
|
294
|
-
* The function `
|
|
347
|
+
* The function `isValidKey` checks if a given key is comparable.
|
|
295
348
|
* @param {any} key - The `key` parameter is of type `any`, which means it can be any data type in
|
|
296
349
|
* TypeScript.
|
|
297
|
-
* @returns The function `
|
|
350
|
+
* @returns The function `isValidKey` is checking if the `key` parameter is `null` or if it is comparable.
|
|
298
351
|
* If the `key` is `null`, the function returns `true`. Otherwise, it returns the result of the
|
|
299
352
|
* `isComparable` function, which is not provided in the code snippet.
|
|
300
353
|
*/
|
|
301
|
-
|
|
354
|
+
isValidKey(key) {
|
|
302
355
|
if (key === null)
|
|
303
356
|
return true;
|
|
304
357
|
return isComparable(key);
|
|
@@ -309,8 +362,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
309
362
|
*
|
|
310
363
|
* The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
|
|
311
364
|
* and finding the correct insertion position.
|
|
312
|
-
* @param {BTNRep<K, V,
|
|
313
|
-
* 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`
|
|
314
367
|
* parameter in the method can accept different types of values:
|
|
315
368
|
* @param {V} [value] - The `value` parameter in the `add` method represents the value associated
|
|
316
369
|
* with the key that you want to add to the binary tree. When adding a key-value pair to the binary
|
|
@@ -320,8 +373,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
320
373
|
* node was successful, and `false` if the insertion position could not be found or if a duplicate
|
|
321
374
|
* key was found and the node was replaced instead of inserted.
|
|
322
375
|
*/
|
|
323
|
-
add(
|
|
324
|
-
const [newNode, newValue] = this.
|
|
376
|
+
add(keyNodeOrEntry, value) {
|
|
377
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
325
378
|
if (newNode === undefined)
|
|
326
379
|
return false;
|
|
327
380
|
// If the tree is empty, directly set the new node as the root node
|
|
@@ -376,14 +429,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
376
429
|
}
|
|
377
430
|
/**
|
|
378
431
|
* Time Complexity: O(k * n)
|
|
379
|
-
* Space Complexity: O(
|
|
432
|
+
* Space Complexity: O(k)
|
|
380
433
|
*
|
|
381
434
|
* The `addMany` function takes in multiple keys or nodes or entries or raw values along with
|
|
382
435
|
* optional values, and adds them to a data structure while returning an array indicating whether
|
|
383
436
|
* each insertion was successful.
|
|
384
437
|
* @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
|
|
385
438
|
* mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
|
|
386
|
-
* `BTNRep<K, V,
|
|
439
|
+
* `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
|
|
387
440
|
* @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
|
|
388
441
|
* accepts an iterable of values. These values correspond to the keys or nodes being added in the
|
|
389
442
|
* `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
|
|
@@ -399,7 +452,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
399
452
|
if (values) {
|
|
400
453
|
valuesIterator = values[Symbol.iterator]();
|
|
401
454
|
}
|
|
402
|
-
for (
|
|
455
|
+
for (let keyNodeEntryOrRaw of keysNodesEntriesOrRaws) {
|
|
403
456
|
let value = undefined;
|
|
404
457
|
if (valuesIterator) {
|
|
405
458
|
const valueResult = valuesIterator.next();
|
|
@@ -407,6 +460,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
407
460
|
value = valueResult.value;
|
|
408
461
|
}
|
|
409
462
|
}
|
|
463
|
+
if (this.isRaw(keyNodeEntryOrRaw))
|
|
464
|
+
keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
410
465
|
inserted.push(this.add(keyNodeEntryOrRaw, value));
|
|
411
466
|
}
|
|
412
467
|
return inserted;
|
|
@@ -417,7 +472,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
417
472
|
*
|
|
418
473
|
* The `merge` function in TypeScript merges another binary tree into the current tree by adding all
|
|
419
474
|
* elements from the other tree.
|
|
420
|
-
* @param anotherTree -
|
|
475
|
+
* @param anotherTree - BinaryTree<K, V, R, MK, MV, MR>
|
|
421
476
|
*/
|
|
422
477
|
merge(anotherTree) {
|
|
423
478
|
this.addMany(anotherTree, []);
|
|
@@ -429,7 +484,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
429
484
|
* The `refill` function clears the existing data structure and then adds new key-value pairs based
|
|
430
485
|
* on the provided input.
|
|
431
486
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
|
|
432
|
-
* 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`
|
|
433
488
|
* objects.
|
|
434
489
|
* @param [values] - The `values` parameter in the `refill` method is an optional parameter that
|
|
435
490
|
* accepts an iterable of values of type `V` or `undefined`.
|
|
@@ -444,7 +499,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
444
499
|
*
|
|
445
500
|
* The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
|
|
446
501
|
* the deleted node along with information for tree balancing.
|
|
447
|
-
* @param {BTNRep<K, V,
|
|
502
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry
|
|
448
503
|
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
|
|
449
504
|
* node, entry or raw data. The method returns an array of
|
|
450
505
|
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
|
|
@@ -453,11 +508,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
453
508
|
* the array contains information about the node that was deleted (`deleted`) and the node that may
|
|
454
509
|
* need to be balanced (`needBalanced`).
|
|
455
510
|
*/
|
|
456
|
-
delete(
|
|
511
|
+
delete(keyNodeOrEntry) {
|
|
457
512
|
const deletedResult = [];
|
|
458
513
|
if (!this._root)
|
|
459
514
|
return deletedResult;
|
|
460
|
-
const curr = this.getNode(
|
|
515
|
+
const curr = this.getNode(keyNodeOrEntry);
|
|
461
516
|
if (!curr)
|
|
462
517
|
return deletedResult;
|
|
463
518
|
const parent = curr?.parent;
|
|
@@ -506,15 +561,15 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
506
561
|
*
|
|
507
562
|
* The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
|
|
508
563
|
* structure based on a given predicate or key, with options to return multiple results or just one.
|
|
509
|
-
* @param {BTNRep<K, V,
|
|
510
|
-
* `
|
|
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:
|
|
511
566
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
|
|
512
567
|
* determines whether the search should stop after finding the first matching node. If `onlyOne` is
|
|
513
568
|
* set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
|
|
514
569
|
* @param {C} callback - The `callback` parameter in the `search` function is a callback function
|
|
515
570
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
516
|
-
* extends `NodeCallback<
|
|
517
|
-
* @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
|
|
518
573
|
* used to specify the node from which the search operation should begin. It represents the starting
|
|
519
574
|
* point in the binary tree where the search will be performed. If no specific `startNode` is
|
|
520
575
|
* provided, the search operation will start from the root
|
|
@@ -524,15 +579,15 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
524
579
|
* @returns The `search` function returns an array of values that match the provided criteria based
|
|
525
580
|
* on the search algorithm implemented within the function.
|
|
526
581
|
*/
|
|
527
|
-
search(
|
|
528
|
-
if (
|
|
582
|
+
search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
583
|
+
if (keyNodeEntryOrPredicate === undefined)
|
|
529
584
|
return [];
|
|
530
|
-
if (
|
|
585
|
+
if (keyNodeEntryOrPredicate === null)
|
|
531
586
|
return [];
|
|
532
587
|
startNode = this.ensureNode(startNode);
|
|
533
588
|
if (!startNode)
|
|
534
589
|
return [];
|
|
535
|
-
const predicate = this._ensurePredicate(
|
|
590
|
+
const predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
536
591
|
const ans = [];
|
|
537
592
|
if (iterationType === 'RECURSIVE') {
|
|
538
593
|
const dfs = (cur) => {
|
|
@@ -575,12 +630,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
575
630
|
*
|
|
576
631
|
* The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
|
|
577
632
|
* or predicate, with options for recursive or iterative traversal.
|
|
578
|
-
* @param {BTNRep<K, V,
|
|
633
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
579
634
|
* - The `getNodes` function you provided takes several parameters:
|
|
580
635
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
|
|
581
636
|
* determines whether to return only the first node that matches the criteria specified by the
|
|
582
|
-
* `
|
|
583
|
-
* @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
|
|
584
639
|
* `getNodes` function is used to specify the starting point for traversing the binary tree. It
|
|
585
640
|
* represents the root node of the binary tree or the node from which the traversal should begin. If
|
|
586
641
|
* not provided, the default value is set to `this._root
|
|
@@ -590,19 +645,19 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
590
645
|
* @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
|
|
591
646
|
* based on the input parameters and the iteration type specified.
|
|
592
647
|
*/
|
|
593
|
-
getNodes(
|
|
594
|
-
return this.search(
|
|
648
|
+
getNodes(keyNodeEntryOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
|
|
649
|
+
return this.search(keyNodeEntryOrPredicate, onlyOne, node => node, startNode, iterationType);
|
|
595
650
|
}
|
|
596
651
|
/**
|
|
597
652
|
* Time Complexity: O(n)
|
|
598
|
-
* Space Complexity: O(log n)
|
|
653
|
+
* Space Complexity: O(log n)
|
|
599
654
|
*
|
|
600
655
|
* The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
|
|
601
656
|
* predicate.
|
|
602
|
-
* @param {BTNRep<K, V,
|
|
603
|
-
* - 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,
|
|
604
659
|
* node, entry, raw data, or a predicate function.
|
|
605
|
-
* @param {BTNRep<K, V,
|
|
660
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
606
661
|
* `getNode` function is used to specify the starting point for searching for a node in a binary
|
|
607
662
|
* tree. If no specific starting point is provided, the default value is set to `this._root`, which
|
|
608
663
|
* is typically the root node of the binary tree.
|
|
@@ -613,8 +668,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
613
668
|
* @returns The `getNode` function is returning the first node that matches the specified criteria,
|
|
614
669
|
* or `null` if no matching node is found.
|
|
615
670
|
*/
|
|
616
|
-
getNode(
|
|
617
|
-
return this.search(
|
|
671
|
+
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
672
|
+
return this.search(keyNodeEntryOrPredicate, true, node => node, startNode, iterationType)[0];
|
|
618
673
|
}
|
|
619
674
|
/**
|
|
620
675
|
* Time Complexity: O(n)
|
|
@@ -622,10 +677,10 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
622
677
|
*
|
|
623
678
|
* This function overrides the `get` method to retrieve the value associated with a specified key,
|
|
624
679
|
* node, entry, raw data, or predicate in a data structure.
|
|
625
|
-
* @param {BTNRep<K, V,
|
|
626
|
-
* - 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
|
|
627
682
|
* following types:
|
|
628
|
-
* @param {BTNRep<K, V,
|
|
683
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `get`
|
|
629
684
|
* method is used to specify the starting point for searching for a key or node in the binary tree.
|
|
630
685
|
* If no specific starting point is provided, the default starting point is the root of the binary
|
|
631
686
|
* tree (`this._root`).
|
|
@@ -638,14 +693,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
638
693
|
* the method returns the corresponding value. If the key or node is not found, it returns
|
|
639
694
|
* `undefined`.
|
|
640
695
|
*/
|
|
641
|
-
get(
|
|
696
|
+
get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
642
697
|
if (this._isMapMode) {
|
|
643
|
-
const key = this._extractKey(
|
|
698
|
+
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
644
699
|
if (key === null || key === undefined)
|
|
645
700
|
return;
|
|
646
701
|
return this._store.get(key);
|
|
647
702
|
}
|
|
648
|
-
return this.getNode(
|
|
703
|
+
return this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)?.value;
|
|
649
704
|
}
|
|
650
705
|
/**
|
|
651
706
|
* Time Complexity: O(n)
|
|
@@ -653,10 +708,10 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
653
708
|
*
|
|
654
709
|
* The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
|
|
655
710
|
* exists in the data structure.
|
|
656
|
-
* @param {BTNRep<K, V,
|
|
657
|
-
* - 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
|
|
658
713
|
* the following types:
|
|
659
|
-
* @param {BTNRep<K, V,
|
|
714
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
660
715
|
* `override` method is used to specify the starting point for the search operation within the data
|
|
661
716
|
* structure. It defaults to `this._root` if not provided explicitly.
|
|
662
717
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
|
|
@@ -668,14 +723,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
668
723
|
* are matching nodes, it returns `true`, indicating that the tree contains the specified element.
|
|
669
724
|
* Otherwise, it returns `false`.
|
|
670
725
|
*/
|
|
671
|
-
has(
|
|
672
|
-
return this.search(
|
|
726
|
+
has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
727
|
+
return this.search(keyNodeEntryOrPredicate, true, node => node, startNode, iterationType).length > 0;
|
|
673
728
|
}
|
|
674
729
|
/**
|
|
675
730
|
* Time Complexity: O(1)
|
|
676
731
|
* Space Complexity: O(1)
|
|
677
732
|
*
|
|
678
|
-
* The
|
|
733
|
+
* The clear function removes nodes and values in map mode.
|
|
679
734
|
*/
|
|
680
735
|
clear() {
|
|
681
736
|
this._clearNodes();
|
|
@@ -700,7 +755,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
700
755
|
*
|
|
701
756
|
* The function checks if a binary tree is perfectly balanced by comparing its minimum height with
|
|
702
757
|
* its height.
|
|
703
|
-
* @param {BTNRep<K, V,
|
|
758
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
704
759
|
* point for checking if the binary tree is perfectly balanced. It represents the root node of the
|
|
705
760
|
* binary tree or a specific node from which the balance check should begin.
|
|
706
761
|
* @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
|
|
@@ -714,11 +769,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
714
769
|
}
|
|
715
770
|
/**
|
|
716
771
|
* Time Complexity: O(n)
|
|
717
|
-
* Space Complexity: O(
|
|
772
|
+
* Space Complexity: O(log n)
|
|
718
773
|
*
|
|
719
774
|
* The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
|
|
720
775
|
* or iterative methods.
|
|
721
|
-
* @param {BTNRep<K, V,
|
|
776
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `isBST`
|
|
722
777
|
* function represents the starting point for checking whether a binary search tree (BST) is valid.
|
|
723
778
|
* It can be a node in the BST or a reference to the root of the BST. If no specific node is
|
|
724
779
|
* provided, the function will default to
|
|
@@ -774,13 +829,13 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
774
829
|
}
|
|
775
830
|
/**
|
|
776
831
|
* Time Complexity: O(n)
|
|
777
|
-
* Space Complexity: O(
|
|
832
|
+
* Space Complexity: O(log n)
|
|
778
833
|
*
|
|
779
834
|
* The `getDepth` function calculates the depth between two nodes in a binary tree.
|
|
780
|
-
* @param {BTNRep<K, V,
|
|
835
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} dist - The `dist` parameter in the `getDepth`
|
|
781
836
|
* function represents the node or entry in a binary tree map, or a reference to a node in the tree.
|
|
782
837
|
* It is the target node for which you want to calculate the depth from the `startNode` node.
|
|
783
|
-
* @param {BTNRep<K, V,
|
|
838
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
784
839
|
* `getDepth` function represents the starting point from which you want to calculate the depth of a
|
|
785
840
|
* given node or entry in a binary tree. If no specific starting point is provided, the default value
|
|
786
841
|
* for `startNode` is set to the root of the binary
|
|
@@ -803,11 +858,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
803
858
|
}
|
|
804
859
|
/**
|
|
805
860
|
* Time Complexity: O(n)
|
|
806
|
-
* Space Complexity: O(
|
|
861
|
+
* Space Complexity: O(log n)
|
|
807
862
|
*
|
|
808
863
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
809
864
|
* or iterative approach in TypeScript.
|
|
810
|
-
* @param {BTNRep<K, V,
|
|
865
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
811
866
|
* point from which the height of the binary tree will be calculated. It can be a node in the binary
|
|
812
867
|
* tree or a reference to the root of the tree. If not provided, it defaults to the root of the
|
|
813
868
|
* binary tree data structure.
|
|
@@ -852,7 +907,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
852
907
|
*
|
|
853
908
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
854
909
|
* recursive or iterative approach in TypeScript.
|
|
855
|
-
* @param {BTNRep<K, V,
|
|
910
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
856
911
|
* `getMinHeight` function represents the starting node from which the minimum height of the binary
|
|
857
912
|
* tree will be calculated. It is either a node in the binary tree or a reference to the root of the
|
|
858
913
|
* tree. If not provided, the default value is the root
|
|
@@ -918,7 +973,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
918
973
|
* the path to the root. It is expected to be a function that takes a node as an argument and returns
|
|
919
974
|
* a value based on that node. The return type of the callback function is determined by the generic
|
|
920
975
|
* type `C
|
|
921
|
-
* @param {BTNRep<K, V,
|
|
976
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} beginNode - The `beginNode` parameter in the
|
|
922
977
|
* `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
|
|
923
978
|
* @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
|
|
924
979
|
* whether the resulting path from the given `beginNode` to the root should be in reverse order or
|
|
@@ -943,14 +998,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
943
998
|
}
|
|
944
999
|
/**
|
|
945
1000
|
* Time Complexity: O(log n)
|
|
946
|
-
* Space Complexity: O(
|
|
1001
|
+
* Space Complexity: O(log n)
|
|
947
1002
|
*
|
|
948
1003
|
* The function `getLeftMost` retrieves the leftmost node in a binary tree using either recursive or
|
|
949
1004
|
* tail-recursive iteration.
|
|
950
1005
|
* @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
|
|
951
1006
|
* node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
|
|
952
1007
|
* value of `_DEFAULT_NODE_CALLBACK` if not specified.
|
|
953
|
-
* @param {BTNRep<K, V,
|
|
1008
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
954
1009
|
* `getLeftMost` function represents the starting point for finding the leftmost node in a binary
|
|
955
1010
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
956
1011
|
* starting point is provided, the function will default
|
|
@@ -988,15 +1043,15 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
988
1043
|
}
|
|
989
1044
|
/**
|
|
990
1045
|
* Time Complexity: O(log n)
|
|
991
|
-
* Space Complexity: O(
|
|
1046
|
+
* Space Complexity: O(log n)
|
|
992
1047
|
*
|
|
993
1048
|
* The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
|
|
994
1049
|
* or iterative traversal methods.
|
|
995
1050
|
* @param {C} callback - The `callback` parameter is a function that will be called with the result
|
|
996
|
-
* 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>>>`,
|
|
997
1052
|
* which means it is a callback function that can accept either an optional binary tree node or null
|
|
998
1053
|
* as
|
|
999
|
-
* @param {BTNRep<K, V,
|
|
1054
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1000
1055
|
* `getRightMost` function represents the starting point for finding the rightmost node in a binary
|
|
1001
1056
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
1002
1057
|
* starting point is provided, the function will default
|
|
@@ -1034,14 +1089,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1034
1089
|
}
|
|
1035
1090
|
/**
|
|
1036
1091
|
* Time Complexity: O(log n)
|
|
1037
|
-
* Space Complexity: O(
|
|
1092
|
+
* Space Complexity: O(log n)
|
|
1038
1093
|
*
|
|
1039
1094
|
* The function `getPredecessor` in TypeScript returns the predecessor node of a given node in a
|
|
1040
1095
|
* binary tree.
|
|
1041
|
-
* @param {
|
|
1096
|
+
* @param {BinaryTreeNode<K, V>} node - The `getPredecessor` function you provided seems to be attempting to find the
|
|
1042
1097
|
* predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
|
|
1043
1098
|
* while loop condition that might cause an infinite loop.
|
|
1044
|
-
* @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.
|
|
1045
1100
|
* If the left child of the input node exists, it traverses to the rightmost node of the left subtree
|
|
1046
1101
|
* to find the predecessor. If the left child does not exist, it returns the input node itself.
|
|
1047
1102
|
*/
|
|
@@ -1061,12 +1116,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1061
1116
|
}
|
|
1062
1117
|
/**
|
|
1063
1118
|
* Time Complexity: O(log n)
|
|
1064
|
-
* Space Complexity: O(
|
|
1119
|
+
* Space Complexity: O(log n)
|
|
1065
1120
|
*
|
|
1066
1121
|
* The function `getSuccessor` in TypeScript returns the next node in an in-order traversal of a
|
|
1067
1122
|
* binary tree.
|
|
1068
|
-
* @param {K |
|
|
1069
|
-
* 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`.
|
|
1070
1125
|
* @returns The `getSuccessor` function returns the successor node of the input node `x`. If `x` has
|
|
1071
1126
|
* a right child, the function returns the leftmost node in the right subtree of `x`. If `x` does not
|
|
1072
1127
|
* have a right child, the function traverses up the parent nodes until it finds a node that is not
|
|
@@ -1093,12 +1148,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1093
1148
|
* The function `dfs` performs a depth-first search traversal on a binary tree structure based on the
|
|
1094
1149
|
* specified parameters.
|
|
1095
1150
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends the
|
|
1096
|
-
* `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
|
|
1097
1152
|
* `this._DEFAULT_NODE_CALLBACK as C`.
|
|
1098
1153
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` method specifies the
|
|
1099
1154
|
* order in which the Depth-First Search (DFS) algorithm should traverse the nodes in the tree. The
|
|
1100
1155
|
* possible values for the `pattern` parameter are:
|
|
1101
|
-
* @param {BTNRep<K, V,
|
|
1156
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `dfs`
|
|
1102
1157
|
* method is used to specify the starting point for the Depth-First Search traversal. It can be
|
|
1103
1158
|
* either a `BTNRep` object representing a key, node, or entry in the binary tree map,
|
|
1104
1159
|
* or it can be a
|
|
@@ -1126,8 +1181,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1126
1181
|
* tree, executing a specified callback function on each node visited.
|
|
1127
1182
|
* @param {C} callback - The `callback` parameter in the `bfs` function is a function that will be
|
|
1128
1183
|
* called on each node visited during the breadth-first search traversal. It is a generic type `C`
|
|
1129
|
-
* that extends the `NodeCallback` type, which takes a parameter of type `
|
|
1130
|
-
* @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`
|
|
1131
1186
|
* function represents the starting point for the breadth-first search traversal in a binary tree. It
|
|
1132
1187
|
* can be specified as a key, node, or entry in the binary tree structure. If not provided, the
|
|
1133
1188
|
* default value is the root node of the binary
|
|
@@ -1147,7 +1202,9 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1147
1202
|
return [];
|
|
1148
1203
|
const ans = [];
|
|
1149
1204
|
if (iterationType === 'RECURSIVE') {
|
|
1150
|
-
const queue = new Queue([
|
|
1205
|
+
const queue = new Queue([
|
|
1206
|
+
startNode
|
|
1207
|
+
]);
|
|
1151
1208
|
const dfs = (level) => {
|
|
1152
1209
|
if (queue.size === 0)
|
|
1153
1210
|
return;
|
|
@@ -1201,7 +1258,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1201
1258
|
* structure based on a specified callback and iteration type.
|
|
1202
1259
|
* @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
|
|
1203
1260
|
* in the binary tree. It is optional and defaults to a default callback function if not provided.
|
|
1204
|
-
* @param {BTNRep<K, V,
|
|
1261
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `leaves`
|
|
1205
1262
|
* method is used to specify the starting point for finding and processing the leaves of a binary
|
|
1206
1263
|
* tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
|
|
1207
1264
|
* explicitly provided, the default value
|
|
@@ -1256,7 +1313,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1256
1313
|
* @param {C} callback - The `callback` parameter is a function that will be applied to each node in
|
|
1257
1314
|
* the binary tree during the traversal. It is used to process each node and determine what
|
|
1258
1315
|
* information to include in the output for each level of the tree.
|
|
1259
|
-
* @param {BTNRep<K, V,
|
|
1316
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1260
1317
|
* `listLevels` function represents the starting point for traversing the binary tree. It can be
|
|
1261
1318
|
* either a key, a node, or an entry in the binary tree. If not provided, the default value is the
|
|
1262
1319
|
* root of the binary tree.
|
|
@@ -1328,11 +1385,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1328
1385
|
* Morris Traversal algorithm with different order patterns.
|
|
1329
1386
|
* @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
|
|
1330
1387
|
* called on each node in the binary tree during the traversal. It is of type `C`, which extends the
|
|
1331
|
-
* `NodeCallback<
|
|
1388
|
+
* `NodeCallback<BinaryTreeNode<K, V>>` type. The default value for `callback` is `this._DEFAULT
|
|
1332
1389
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
|
|
1333
1390
|
* the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
|
|
1334
1391
|
* values for the `pattern` parameter are:
|
|
1335
|
-
* @param {BTNRep<K, V,
|
|
1392
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `morris`
|
|
1336
1393
|
* function is the starting point for the Morris traversal algorithm. It represents the root node of
|
|
1337
1394
|
* the binary tree or the node from which the traversal should begin. It can be provided as either a
|
|
1338
1395
|
* key, a node, an entry, or a reference
|
|
@@ -1438,6 +1495,10 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1438
1495
|
*/
|
|
1439
1496
|
clone() {
|
|
1440
1497
|
const cloned = this.createTree();
|
|
1498
|
+
this._clone(cloned);
|
|
1499
|
+
return cloned;
|
|
1500
|
+
}
|
|
1501
|
+
_clone(cloned) {
|
|
1441
1502
|
this.bfs(node => {
|
|
1442
1503
|
if (node === null)
|
|
1443
1504
|
cloned.add(null);
|
|
@@ -1450,7 +1511,6 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1450
1511
|
}, this._root, this.iterationType, true);
|
|
1451
1512
|
if (this._isMapMode)
|
|
1452
1513
|
cloned._store = this._store;
|
|
1453
|
-
return cloned;
|
|
1454
1514
|
}
|
|
1455
1515
|
/**
|
|
1456
1516
|
* Time Complexity: O(n)
|
|
@@ -1511,7 +1571,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1511
1571
|
*
|
|
1512
1572
|
* The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
|
|
1513
1573
|
* customizable options for displaying undefined, null, and sentinel nodes.
|
|
1514
|
-
* @param {BTNRep<K, V,
|
|
1574
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1515
1575
|
* `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
|
|
1516
1576
|
* It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
|
|
1517
1577
|
* the default is set to the root
|
|
@@ -1536,7 +1596,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1536
1596
|
if (opts.isShowRedBlackNIL)
|
|
1537
1597
|
output += `S for Sentinel Node(NIL)\n`;
|
|
1538
1598
|
const display = (root) => {
|
|
1539
|
-
const [lines
|
|
1599
|
+
const [lines] = this._displayAux(root, opts);
|
|
1540
1600
|
let paragraph = '';
|
|
1541
1601
|
for (const line of lines) {
|
|
1542
1602
|
paragraph += line + '\n';
|
|
@@ -1556,7 +1616,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1556
1616
|
* printing options for the binary tree. It is an optional parameter that allows you to customize how
|
|
1557
1617
|
* the binary tree is printed, such as choosing between different traversal orders or formatting
|
|
1558
1618
|
* options.
|
|
1559
|
-
* @param {BTNRep<K, V,
|
|
1619
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
1560
1620
|
* `override print` method is used to specify the starting point for printing the binary tree. It can
|
|
1561
1621
|
* be either a key, a node, an entry, or the root of the tree. If no specific starting point is
|
|
1562
1622
|
* provided, the default value is set to
|
|
@@ -1565,29 +1625,32 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1565
1625
|
console.log(this.toVisual(startNode, options));
|
|
1566
1626
|
}
|
|
1567
1627
|
/**
|
|
1628
|
+
* Time Complexity: O(1)
|
|
1629
|
+
* Space Complexity: O(1)
|
|
1630
|
+
*
|
|
1568
1631
|
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
1569
1632
|
* or returns null.
|
|
1570
|
-
* @param {BTNRep<K, V,
|
|
1571
|
-
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `
|
|
1572
|
-
* can be of type `BTNRep<K, V,
|
|
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
|
|
1573
1636
|
* node, an entry
|
|
1574
1637
|
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
1575
1638
|
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
1576
1639
|
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
1577
1640
|
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
1578
|
-
* (`OptNodeOrNull<
|
|
1579
|
-
* input parameter (`
|
|
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
|
|
1580
1643
|
* value.
|
|
1581
1644
|
*/
|
|
1582
|
-
|
|
1583
|
-
if (
|
|
1645
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
|
|
1646
|
+
if (keyNodeOrEntry === undefined)
|
|
1584
1647
|
return [undefined, undefined];
|
|
1585
|
-
if (
|
|
1648
|
+
if (keyNodeOrEntry === null)
|
|
1586
1649
|
return [null, undefined];
|
|
1587
|
-
if (this.isNode(
|
|
1588
|
-
return [
|
|
1589
|
-
if (this.isEntry(
|
|
1590
|
-
const [key, entryValue] =
|
|
1650
|
+
if (this.isNode(keyNodeOrEntry))
|
|
1651
|
+
return [keyNodeOrEntry, value];
|
|
1652
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
1653
|
+
const [key, entryValue] = keyNodeOrEntry;
|
|
1591
1654
|
if (key === undefined)
|
|
1592
1655
|
return [undefined, undefined];
|
|
1593
1656
|
else if (key === null)
|
|
@@ -1595,15 +1658,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1595
1658
|
const finalValue = value ?? entryValue;
|
|
1596
1659
|
return [this.createNode(key, finalValue), finalValue];
|
|
1597
1660
|
}
|
|
1598
|
-
|
|
1599
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
1600
|
-
const finalValue = value ?? entryValue;
|
|
1601
|
-
if (this.isKey(key))
|
|
1602
|
-
return [this.createNode(key, finalValue), finalValue];
|
|
1603
|
-
}
|
|
1604
|
-
if (this.isKey(keyNodeEntryOrRaw))
|
|
1605
|
-
return [this.createNode(keyNodeEntryOrRaw, value), value];
|
|
1606
|
-
return [undefined, undefined];
|
|
1661
|
+
return [this.createNode(keyNodeOrEntry, value), value];
|
|
1607
1662
|
}
|
|
1608
1663
|
/**
|
|
1609
1664
|
* Time complexity: O(n)
|
|
@@ -1613,11 +1668,11 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1613
1668
|
* the specified order pattern and callback function.
|
|
1614
1669
|
* @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
|
|
1615
1670
|
* called on each node visited during the depth-first search traversal. It is of type `C`, which
|
|
1616
|
-
* extends `NodeCallback<OptNodeOrNull<
|
|
1671
|
+
* extends `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`. The default value for this parameter is `this._DEFAULT
|
|
1617
1672
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
|
|
1618
1673
|
* order in which the nodes are visited during the Depth-First Search traversal. It can have one of
|
|
1619
1674
|
* the following values:
|
|
1620
|
-
* @param {BTNRep<K, V,
|
|
1675
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `_dfs`
|
|
1621
1676
|
* method is used to specify the starting point for the depth-first search traversal in a binary
|
|
1622
1677
|
* tree. It can be provided as either a `BTNRep` object or a reference to the root node
|
|
1623
1678
|
* of the tree. If no specific
|
|
@@ -1860,12 +1915,12 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1860
1915
|
* Space Complexity: O(1)
|
|
1861
1916
|
*
|
|
1862
1917
|
* The _swapProperties function swaps key and value properties between two nodes in a binary tree.
|
|
1863
|
-
* @param {BTNRep<K, V,
|
|
1918
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} srcNode - The `srcNode` parameter in the
|
|
1864
1919
|
* `_swapProperties` method can be either a BTNRep object containing key and value
|
|
1865
1920
|
* properties, or it can be of type R.
|
|
1866
|
-
* @param {BTNRep<K, V,
|
|
1921
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} destNode - The `destNode` parameter in the
|
|
1867
1922
|
* `_swapProperties` method represents the node or entry where the properties will be swapped with
|
|
1868
|
-
* 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
|
|
1869
1924
|
* both `srcNode
|
|
1870
1925
|
* @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
|
|
1871
1926
|
* with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
@@ -1893,9 +1948,9 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1893
1948
|
* Space Complexity: O(1)
|
|
1894
1949
|
*
|
|
1895
1950
|
* The _replaceNode function replaces an old node with a new node in a binary tree structure.
|
|
1896
|
-
* @param {
|
|
1951
|
+
* @param {BinaryTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that you want to replace in a
|
|
1897
1952
|
* tree data structure.
|
|
1898
|
-
* @param {
|
|
1953
|
+
* @param {BinaryTreeNode<K, V>} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
|
|
1899
1954
|
* that will replace the `oldNode` in a tree data structure. This function is responsible for
|
|
1900
1955
|
* updating the parent, left child, right child, and root (if necessary) references when replacing a
|
|
1901
1956
|
* node in the tree.
|
|
@@ -1925,8 +1980,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1925
1980
|
*
|
|
1926
1981
|
* The function _setRoot sets the root node of a data structure while updating the parent reference
|
|
1927
1982
|
* of the previous root node.
|
|
1928
|
-
* @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<
|
|
1929
|
-
* 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`.
|
|
1930
1985
|
*/
|
|
1931
1986
|
_setRoot(v) {
|
|
1932
1987
|
if (v) {
|
|
@@ -1940,30 +1995,24 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1940
1995
|
*
|
|
1941
1996
|
* The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
|
|
1942
1997
|
* predicate function for a binary tree node.
|
|
1943
|
-
* @param {BTNRep<K, V,
|
|
1998
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
1944
1999
|
* `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
|
|
1945
|
-
* parameter `
|
|
2000
|
+
* parameter `keyNodeEntryOrPredicate` is transformed into a valid predicate function that can be
|
|
1946
2001
|
* used for filtering nodes in a binary tree.
|
|
1947
|
-
* @returns A NodePredicate<
|
|
2002
|
+
* @returns A NodePredicate<BinaryTreeNode<K, V>> function is being returned.
|
|
1948
2003
|
*/
|
|
1949
|
-
_ensurePredicate(
|
|
1950
|
-
if (
|
|
2004
|
+
_ensurePredicate(keyNodeEntryOrPredicate) {
|
|
2005
|
+
if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === undefined)
|
|
1951
2006
|
return (node) => (node ? false : false);
|
|
1952
|
-
if (this._isPredicate(
|
|
1953
|
-
return
|
|
1954
|
-
if (this.isRealNode(
|
|
1955
|
-
return (node) => node ===
|
|
1956
|
-
if (this.isEntry(
|
|
1957
|
-
const [key] =
|
|
1958
|
-
return (node) => node.key === key;
|
|
1959
|
-
}
|
|
1960
|
-
if (this.isKey(keyNodeEntryRawOrPredicate))
|
|
1961
|
-
return (node) => node.key === keyNodeEntryRawOrPredicate;
|
|
1962
|
-
if (this._toEntryFn) {
|
|
1963
|
-
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;
|
|
1964
2013
|
return (node) => node.key === key;
|
|
1965
2014
|
}
|
|
1966
|
-
return (node) => node.key ===
|
|
2015
|
+
return (node) => node.key === keyNodeEntryOrPredicate;
|
|
1967
2016
|
}
|
|
1968
2017
|
/**
|
|
1969
2018
|
* Time Complexity: O(1)
|
|
@@ -1972,7 +2021,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1972
2021
|
* The function `_isPredicate` checks if a given parameter is a function.
|
|
1973
2022
|
* @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
|
|
1974
2023
|
* of value. In this context, the function `_isPredicate` is checking if `p` is a function that
|
|
1975
|
-
* satisfies the type `NodePredicate<
|
|
2024
|
+
* satisfies the type `NodePredicate<BinaryTreeNode<K, V>>`.
|
|
1976
2025
|
* @returns The function is checking if the input `p` is a function and returning a boolean value
|
|
1977
2026
|
* based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
|
|
1978
2027
|
* predicate function for a binary tree node. If `p` is not a function, it will return `false`.
|
|
@@ -1986,32 +2035,25 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1986
2035
|
*
|
|
1987
2036
|
* The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
|
|
1988
2037
|
* entry, raw data, or null/undefined.
|
|
1989
|
-
* @param {BTNRep<K, V,
|
|
1990
|
-
* TypeScript method that takes in a parameter `
|
|
1991
|
-
* where `BTNRep` is a generic type with keys `K`, `V`, and `
|
|
1992
|
-
* @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`
|
|
1993
2042
|
* parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
|
|
1994
2043
|
* the conditions checked in the method.
|
|
1995
2044
|
*/
|
|
1996
|
-
_extractKey(
|
|
1997
|
-
if (
|
|
2045
|
+
_extractKey(keyNodeOrEntry) {
|
|
2046
|
+
if (keyNodeOrEntry === null)
|
|
1998
2047
|
return null;
|
|
1999
|
-
if (
|
|
2000
|
-
return;
|
|
2001
|
-
if (keyNodeEntryOrRaw === this._NIL)
|
|
2048
|
+
if (keyNodeOrEntry === undefined)
|
|
2002
2049
|
return;
|
|
2003
|
-
if (this.
|
|
2004
|
-
return keyNodeEntryOrRaw.key;
|
|
2005
|
-
if (this.isEntry(keyNodeEntryOrRaw))
|
|
2006
|
-
return keyNodeEntryOrRaw[0];
|
|
2007
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
2008
|
-
if (this._toEntryFn) {
|
|
2009
|
-
const [key] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
2010
|
-
return key;
|
|
2011
|
-
}
|
|
2050
|
+
if (keyNodeOrEntry === this._NIL)
|
|
2012
2051
|
return;
|
|
2013
|
-
|
|
2014
|
-
|
|
2052
|
+
if (this.isNode(keyNodeOrEntry))
|
|
2053
|
+
return keyNodeOrEntry.key;
|
|
2054
|
+
if (this.isEntry(keyNodeOrEntry))
|
|
2055
|
+
return keyNodeOrEntry[0];
|
|
2056
|
+
return keyNodeOrEntry;
|
|
2015
2057
|
}
|
|
2016
2058
|
/**
|
|
2017
2059
|
* Time Complexity: O(1)
|