data-structure-typed 1.53.9 → 1.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -0
- package/benchmark/report.html +1 -28
- package/benchmark/report.json +17 -326
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts → cjs/data-structures/binary-tree/avl-tree-counter.d.ts} +54 -59
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +408 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -189
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +133 -357
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +108 -78
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +126 -79
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +243 -190
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +273 -229
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +141 -122
- package/dist/cjs/data-structures/binary-tree/bst.js +170 -134
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +84 -80
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +101 -79
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.d.ts → cjs/data-structures/binary-tree/tree-counter.d.ts} +54 -56
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +445 -0
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +78 -186
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +140 -388
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -4
- package/dist/cjs/data-structures/trie/trie.js +0 -4
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +7 -6
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -3
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.js → esm/data-structures/binary-tree/avl-tree-counter.js} +72 -78
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +191 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +234 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/avl-tree.js +126 -80
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.d.ts +243 -190
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.js +276 -234
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.d.ts +141 -122
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.js +171 -140
- package/dist/esm/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js +2 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js.map +1 -1
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.d.ts +84 -80
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.js +100 -79
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.js → esm/data-structures/binary-tree/tree-counter.js} +88 -86
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +106 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +196 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.js +3 -0
- package/dist/esm/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.js +3 -0
- package/dist/esm/data-structures/graph/map-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.js +3 -0
- package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.js +3 -0
- package/dist/esm/data-structures/matrix/matrix.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.js +3 -0
- package/dist/esm/data-structures/matrix/navigator.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/trie/trie.d.ts +0 -4
- package/dist/{mjs → esm}/data-structures/trie/trie.js +0 -4
- package/dist/esm/data-structures/trie/trie.js.map +1 -0
- package/dist/esm/interfaces/binary-tree.d.ts +9 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/esm/types/data-structures/binary-tree/rb-tree.d.ts +3 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/umd/data-structure-typed.js +1407 -913
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +14 -14
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +148 -394
- package/src/data-structures/binary-tree/avl-tree.ts +152 -112
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +446 -379
- package/src/data-structures/binary-tree/bst.ts +224 -201
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +138 -114
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +156 -428
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- package/src/data-structures/trie/trie.ts +0 -4
- package/src/interfaces/binary-tree.ts +10 -11
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -3
- package/src/types/data-structures/binary-tree/index.ts +2 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -4
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -4
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/integration/avl-tree.test.ts +1 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/integration/compile.js +144 -0
- package/test/integration/compile.ts +171 -0
- package/test/integration/index.html +48 -48
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -4
- package/test/performance/data-structures/comparison/comparison.test.ts +2 -2
- package/test/performance/reportor.ts +5 -3
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +877 -0
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +459 -761
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +223 -223
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +474 -492
- package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/overall.test.ts +0 -3
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +87 -90
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +975 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +729 -857
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/{tsconfig-mjs.json → tsconfig-esm.json} +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -204
- package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/map-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix.js.map +0 -1
- package/dist/mjs/data-structures/matrix/navigator.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/trie/trie.js.map +0 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +0 -8
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -4
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -4
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -4
- /package/dist/{mjs → esm}/common/index.d.ts +0 -0
- /package/dist/{mjs → esm}/common/index.js +0 -0
- /package/dist/{mjs → esm}/common/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.js +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.js +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.js +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.js.map +0 -0
- /package/dist/{mjs → esm}/index.d.ts +0 -0
- /package/dist/{mjs → esm}/index.js +0 -0
- /package/dist/{mjs → esm}/index.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/binary-tree.js +0 -0
- /package/dist/{mjs → esm}/interfaces/binary-tree.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.js +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.js +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/index.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/index.js +0 -0
- /package/dist/{mjs → esm}/interfaces/index.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.js +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/common.d.ts +0 -0
- /package/dist/{mjs → esm}/types/common.js +0 -0
- /package/dist/{mjs → esm}/types/common.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/rb-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/rb-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.js.map +0 -0
- /package/dist/{mjs → esm}/types/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/index.js +0 -0
- /package/dist/{mjs → esm}/types/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/index.js +0 -0
- /package/dist/{mjs → esm}/types/utils/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.js +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.js +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.js.map +0 -0
- /package/dist/{mjs → esm}/utils/index.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/index.js +0 -0
- /package/dist/{mjs → esm}/utils/index.js.map +0 -0
- /package/dist/{mjs → esm}/utils/number.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/number.js +0 -0
- /package/dist/{mjs → esm}/utils/number.js.map +0 -0
- /package/dist/{mjs → esm}/utils/utils.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/utils.js +0 -0
- /package/dist/{mjs → esm}/utils/utils.js.map +0 -0
|
@@ -3,46 +3,33 @@ import { Queue } from '../queue';
|
|
|
3
3
|
import { isComparable } from '../../utils';
|
|
4
4
|
import { Range } from '../../common';
|
|
5
5
|
export class BSTNode extends BinaryTreeNode {
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* This TypeScript constructor function initializes an instance with a key and an optional value.
|
|
8
|
+
* @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
|
|
9
|
+
* within a data structure. It serves as a reference or identifier for accessing or manipulating the
|
|
10
|
+
* associated value.
|
|
11
|
+
* @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
|
|
12
|
+
* have to be provided when creating an instance of the class. If a value is not provided, it will
|
|
13
|
+
* default to `undefined`.
|
|
14
|
+
*/
|
|
7
15
|
constructor(key, value) {
|
|
8
16
|
super(key, value);
|
|
9
|
-
this.parent = undefined;
|
|
10
|
-
this._left = undefined;
|
|
11
|
-
this._right = undefined;
|
|
12
17
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* The function returns the value of the `_left` property.
|
|
16
|
-
* @returns The `_left` property of the current object is being returned.
|
|
17
|
-
*/
|
|
18
|
+
parent = undefined;
|
|
19
|
+
_left = undefined;
|
|
18
20
|
get left() {
|
|
19
21
|
return this._left;
|
|
20
22
|
}
|
|
21
|
-
/**
|
|
22
|
-
* The function sets the left child of a node and updates the parent reference of the child.
|
|
23
|
-
* @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be an
|
|
24
|
-
* instance of the `NODE` class or `undefined`.
|
|
25
|
-
*/
|
|
26
23
|
set left(v) {
|
|
27
24
|
if (v) {
|
|
28
25
|
v.parent = this;
|
|
29
26
|
}
|
|
30
27
|
this._left = v;
|
|
31
28
|
}
|
|
32
|
-
_right;
|
|
33
|
-
/**
|
|
34
|
-
* The function returns the right node of a binary tree or undefined if there is no right node.
|
|
35
|
-
* @returns The method is returning the value of the `_right` property, which is of type `NODE` or
|
|
36
|
-
* `undefined`.
|
|
37
|
-
*/
|
|
29
|
+
_right = undefined;
|
|
38
30
|
get right() {
|
|
39
31
|
return this._right;
|
|
40
32
|
}
|
|
41
|
-
/**
|
|
42
|
-
* The function sets the right child of a node and updates the parent reference of the child.
|
|
43
|
-
* @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be a
|
|
44
|
-
* `NODE` object or `undefined`.
|
|
45
|
-
*/
|
|
46
33
|
set right(v) {
|
|
47
34
|
if (v) {
|
|
48
35
|
v.parent = this;
|
|
@@ -117,12 +104,13 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
117
104
|
*/
|
|
118
105
|
export class BST extends BinaryTree {
|
|
119
106
|
/**
|
|
120
|
-
* This
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
107
|
+
* This TypeScript constructor initializes a binary search tree with optional options and adds
|
|
108
|
+
* elements if provided.
|
|
109
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
110
|
+
* iterable that can contain elements of type `BTNRep<K, V, BSTNode<K, V>>` or `R`. It is used to
|
|
111
|
+
* initialize the binary search tree with keys, nodes, entries, or raw data.
|
|
112
|
+
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
113
|
+
* properties:
|
|
126
114
|
*/
|
|
127
115
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
128
116
|
super([], options);
|
|
@@ -137,19 +125,10 @@ export class BST extends BinaryTree {
|
|
|
137
125
|
this.addMany(keysNodesEntriesOrRaws);
|
|
138
126
|
}
|
|
139
127
|
_root = undefined;
|
|
140
|
-
/**
|
|
141
|
-
* The function returns the root node of a tree structure.
|
|
142
|
-
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
143
|
-
*/
|
|
144
128
|
get root() {
|
|
145
129
|
return this._root;
|
|
146
130
|
}
|
|
147
131
|
_isReverse = false;
|
|
148
|
-
/**
|
|
149
|
-
* The above function is a getter method in TypeScript that returns the value of the private property
|
|
150
|
-
* `_isReverse`.
|
|
151
|
-
* @returns The `isReverse` property of the object, which is a boolean value.
|
|
152
|
-
*/
|
|
153
132
|
get isReverse() {
|
|
154
133
|
return this._isReverse;
|
|
155
134
|
}
|
|
@@ -173,29 +152,23 @@ export class BST extends BinaryTree {
|
|
|
173
152
|
}
|
|
174
153
|
return 0;
|
|
175
154
|
};
|
|
176
|
-
/**
|
|
177
|
-
* The function returns the value of the _comparator property.
|
|
178
|
-
* @returns The `_comparator` property is being returned.
|
|
179
|
-
*/
|
|
180
155
|
get comparator() {
|
|
181
156
|
return this._comparator;
|
|
182
157
|
}
|
|
183
158
|
_specifyComparable;
|
|
184
|
-
/**
|
|
185
|
-
* This function returns the value of the `_specifyComparable` property.
|
|
186
|
-
* @returns The method `specifyComparable()` is being returned, which is a getter method for the
|
|
187
|
-
* `_specifyComparable` property.
|
|
188
|
-
*/
|
|
189
159
|
get specifyComparable() {
|
|
190
160
|
return this._specifyComparable;
|
|
191
161
|
}
|
|
192
162
|
/**
|
|
163
|
+
* Time Complexity: O(1)
|
|
164
|
+
* Space Complexity: O(1)
|
|
165
|
+
*
|
|
193
166
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
194
167
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
195
168
|
* being created.
|
|
196
169
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
197
170
|
* value associated with the key in the node being created.
|
|
198
|
-
* @returns The method is returning a new instance of the BSTNode class, casted as the
|
|
171
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the BSTNode<K, V> type.
|
|
199
172
|
*/
|
|
200
173
|
createNode(key, value) {
|
|
201
174
|
return new BSTNode(key, this._isMapMode ? undefined : value);
|
|
@@ -204,14 +177,12 @@ export class BST extends BinaryTree {
|
|
|
204
177
|
* Time Complexity: O(1)
|
|
205
178
|
* Space Complexity: O(1)
|
|
206
179
|
*
|
|
207
|
-
* The
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* @returns
|
|
212
|
-
* and properties inherited from the current instance.
|
|
180
|
+
* The function creates a new binary search tree with the specified options.
|
|
181
|
+
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
182
|
+
* behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
|
|
183
|
+
* following properties:
|
|
184
|
+
* @returns a new instance of the BST class with the provided options.
|
|
213
185
|
*/
|
|
214
|
-
// @ts-ignore
|
|
215
186
|
createTree(options) {
|
|
216
187
|
return new BST([], {
|
|
217
188
|
iterationType: this.iterationType,
|
|
@@ -228,8 +199,8 @@ export class BST extends BinaryTree {
|
|
|
228
199
|
*
|
|
229
200
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
230
201
|
* it doesn't exist.
|
|
231
|
-
* @param {BTNRep<K, V,
|
|
232
|
-
* `
|
|
202
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
203
|
+
* `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
|
|
233
204
|
* entry, or raw element that needs to be ensured in the tree.
|
|
234
205
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
235
206
|
* parameter that specifies the type of iteration to be used when ensuring a node. It has a default
|
|
@@ -237,43 +208,49 @@ export class BST extends BinaryTree {
|
|
|
237
208
|
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
238
209
|
* not be ensured.
|
|
239
210
|
*/
|
|
240
|
-
ensureNode(
|
|
241
|
-
return super.ensureNode(
|
|
211
|
+
ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
|
|
212
|
+
return super.ensureNode(keyNodeOrEntry, iterationType) ?? undefined;
|
|
242
213
|
}
|
|
243
214
|
/**
|
|
215
|
+
* Time Complexity: O(1)
|
|
216
|
+
* Space Complexity: O(1)
|
|
217
|
+
*
|
|
244
218
|
* The function checks if the input is an instance of the BSTNode class.
|
|
245
|
-
* @param {BTNRep<K, V,
|
|
246
|
-
* `
|
|
247
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
219
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
220
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
|
|
221
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
248
222
|
* an instance of the `BSTNode` class.
|
|
249
223
|
*/
|
|
250
|
-
isNode(
|
|
251
|
-
return
|
|
224
|
+
isNode(keyNodeOrEntry) {
|
|
225
|
+
return keyNodeOrEntry instanceof BSTNode;
|
|
252
226
|
}
|
|
253
227
|
/**
|
|
254
|
-
*
|
|
228
|
+
* Time Complexity: O(1)
|
|
229
|
+
* Space Complexity: O(1)
|
|
230
|
+
*
|
|
231
|
+
* The function "override isValidKey" checks if a key is comparable based on a given comparator.
|
|
255
232
|
* @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
|
|
256
233
|
* type `K`.
|
|
257
|
-
* @returns The `override
|
|
234
|
+
* @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
|
|
258
235
|
* the result of the `isComparable` function with the condition `this._compare !==
|
|
259
236
|
* this._DEFAULT_COMPARATOR`.
|
|
260
237
|
*/
|
|
261
|
-
|
|
238
|
+
isValidKey(key) {
|
|
262
239
|
return isComparable(key, this._specifyComparable !== undefined);
|
|
263
240
|
}
|
|
264
241
|
/**
|
|
265
242
|
* Time Complexity: O(log n)
|
|
266
|
-
* Space Complexity: O(
|
|
243
|
+
* Space Complexity: O(log n)
|
|
267
244
|
*
|
|
268
245
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
269
|
-
* @param {BTNRep<K, V,
|
|
270
|
-
* `
|
|
246
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
247
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
|
|
271
248
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
272
249
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
273
250
|
* @returns a boolean value.
|
|
274
251
|
*/
|
|
275
|
-
add(
|
|
276
|
-
const [newNode, newValue] = this.
|
|
252
|
+
add(keyNodeOrEntry, value) {
|
|
253
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
277
254
|
if (newNode === undefined)
|
|
278
255
|
return false;
|
|
279
256
|
if (this._root === undefined) {
|
|
@@ -299,7 +276,8 @@ export class BST extends BinaryTree {
|
|
|
299
276
|
this._size++;
|
|
300
277
|
return true;
|
|
301
278
|
}
|
|
302
|
-
|
|
279
|
+
if (current.left !== null)
|
|
280
|
+
current = current.left;
|
|
303
281
|
}
|
|
304
282
|
else {
|
|
305
283
|
if (current.right === undefined) {
|
|
@@ -309,7 +287,8 @@ export class BST extends BinaryTree {
|
|
|
309
287
|
this._size++;
|
|
310
288
|
return true;
|
|
311
289
|
}
|
|
312
|
-
|
|
290
|
+
if (current.right !== null)
|
|
291
|
+
current = current.right;
|
|
313
292
|
}
|
|
314
293
|
}
|
|
315
294
|
return false;
|
|
@@ -342,8 +321,10 @@ export class BST extends BinaryTree {
|
|
|
342
321
|
valuesIterator = values[Symbol.iterator]();
|
|
343
322
|
}
|
|
344
323
|
if (!isBalanceAdd) {
|
|
345
|
-
for (
|
|
324
|
+
for (let kve of keysNodesEntriesOrRaws) {
|
|
346
325
|
const value = valuesIterator?.next().value;
|
|
326
|
+
if (this.isRaw(kve))
|
|
327
|
+
kve = this._toEntryFn(kve);
|
|
347
328
|
inserted.push(this.add(kve, value));
|
|
348
329
|
}
|
|
349
330
|
return inserted;
|
|
@@ -357,23 +338,21 @@ export class BST extends BinaryTree {
|
|
|
357
338
|
let sorted = [];
|
|
358
339
|
sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
|
|
359
340
|
let keyA, keyB;
|
|
360
|
-
if (this.
|
|
341
|
+
if (this.isRaw(a))
|
|
342
|
+
keyA = this._toEntryFn(a)[0];
|
|
343
|
+
else if (this.isEntry(a))
|
|
361
344
|
keyA = a[0];
|
|
362
345
|
else if (this.isRealNode(a))
|
|
363
346
|
keyA = a.key;
|
|
364
|
-
else if (this._toEntryFn) {
|
|
365
|
-
keyA = this._toEntryFn(a)[0];
|
|
366
|
-
}
|
|
367
347
|
else {
|
|
368
348
|
keyA = a;
|
|
369
349
|
}
|
|
370
|
-
if (this.
|
|
350
|
+
if (this.isRaw(b))
|
|
351
|
+
keyB = this._toEntryFn(b)[0];
|
|
352
|
+
else if (this.isEntry(b))
|
|
371
353
|
keyB = b[0];
|
|
372
354
|
else if (this.isRealNode(b))
|
|
373
355
|
keyB = b.key;
|
|
374
|
-
else if (this._toEntryFn) {
|
|
375
|
-
keyB = this._toEntryFn(b)[0];
|
|
376
|
-
}
|
|
377
356
|
else {
|
|
378
357
|
keyB = b;
|
|
379
358
|
}
|
|
@@ -386,7 +365,13 @@ export class BST extends BinaryTree {
|
|
|
386
365
|
if (arr.length === 0)
|
|
387
366
|
return;
|
|
388
367
|
const mid = Math.floor((arr.length - 1) / 2);
|
|
389
|
-
|
|
368
|
+
let { key, value } = arr[mid];
|
|
369
|
+
const { orgIndex } = arr[mid];
|
|
370
|
+
if (this.isRaw(key)) {
|
|
371
|
+
const entry = this._toEntryFn(key);
|
|
372
|
+
key = entry[0];
|
|
373
|
+
value = entry[1] ?? value;
|
|
374
|
+
}
|
|
390
375
|
inserted[orgIndex] = this.add(key, value);
|
|
391
376
|
_dfs(arr.slice(0, mid));
|
|
392
377
|
_dfs(arr.slice(mid + 1));
|
|
@@ -400,7 +385,13 @@ export class BST extends BinaryTree {
|
|
|
400
385
|
const [l, r] = popped;
|
|
401
386
|
if (l <= r) {
|
|
402
387
|
const m = l + Math.floor((r - l) / 2);
|
|
403
|
-
|
|
388
|
+
let { key, value } = sorted[m];
|
|
389
|
+
const { orgIndex } = sorted[m];
|
|
390
|
+
if (this.isRaw(key)) {
|
|
391
|
+
const entry = this._toEntryFn(key);
|
|
392
|
+
key = entry[0];
|
|
393
|
+
value = entry[1] ?? value;
|
|
394
|
+
}
|
|
404
395
|
inserted[orgIndex] = this.add(key, value);
|
|
405
396
|
stack.push([m + 1, r]);
|
|
406
397
|
stack.push([l, m - 1]);
|
|
@@ -416,35 +407,23 @@ export class BST extends BinaryTree {
|
|
|
416
407
|
}
|
|
417
408
|
return inserted;
|
|
418
409
|
}
|
|
419
|
-
/**
|
|
420
|
-
* Time Complexity: O(n)
|
|
421
|
-
* Space Complexity: O(1)
|
|
422
|
-
*
|
|
423
|
-
* The `merge` function overrides the base class method by adding elements from another
|
|
424
|
-
* binary search tree.
|
|
425
|
-
* @param anotherTree - `anotherTree` is an instance of a Binary Search Tree (BST) with key type `K`,
|
|
426
|
-
* value type `V`, return type `R`, node type `NODE`, and tree type `TREE`.
|
|
427
|
-
*/
|
|
428
|
-
merge(anotherTree) {
|
|
429
|
-
this.addMany(anotherTree, [], false);
|
|
430
|
-
}
|
|
431
410
|
/**
|
|
432
411
|
* Time Complexity: O(log n)
|
|
433
412
|
* Space Complexity: O(k + log n)
|
|
434
413
|
*
|
|
435
414
|
* The function `search` in TypeScript overrides the search behavior in a binary tree structure based
|
|
436
415
|
* on specified criteria.
|
|
437
|
-
* @param {BTNRep<K, V,
|
|
438
|
-
* `
|
|
416
|
+
* @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
417
|
+
* `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
|
|
439
418
|
* following types:
|
|
440
419
|
* @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
|
|
441
420
|
* search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
|
|
442
421
|
* search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
|
|
443
422
|
* @param {C} callback - The `callback` parameter in the `override search` function is a function
|
|
444
423
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
445
|
-
* extends `NodeCallback<
|
|
424
|
+
* extends `NodeCallback<BSTNode<K, V>>`. The callback function should accept a node of type `BSTNode<K, V>` as its
|
|
446
425
|
* argument and
|
|
447
|
-
* @param {BTNRep<K, V,
|
|
426
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `override search`
|
|
448
427
|
* method represents the node from which the search operation will begin. It is the starting point
|
|
449
428
|
* for searching within the tree data structure. The method ensures that the `startNode` is a valid
|
|
450
429
|
* node before proceeding with the search operation. If the `
|
|
@@ -456,26 +435,26 @@ export class BST extends BinaryTree {
|
|
|
456
435
|
* structure based on the provided key, predicate, and other options. The search results are
|
|
457
436
|
* collected in an array and returned as the output of the method.
|
|
458
437
|
*/
|
|
459
|
-
search(
|
|
460
|
-
if (
|
|
438
|
+
search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
439
|
+
if (keyNodeEntryOrPredicate === undefined)
|
|
461
440
|
return [];
|
|
462
|
-
if (
|
|
441
|
+
if (keyNodeEntryOrPredicate === null)
|
|
463
442
|
return [];
|
|
464
443
|
startNode = this.ensureNode(startNode);
|
|
465
444
|
if (!startNode)
|
|
466
445
|
return [];
|
|
467
446
|
let predicate;
|
|
468
|
-
const isRange = this.isRange(
|
|
447
|
+
const isRange = this.isRange(keyNodeEntryOrPredicate);
|
|
469
448
|
// Set predicate based on parameter type
|
|
470
449
|
if (isRange) {
|
|
471
|
-
predicate = node =>
|
|
450
|
+
predicate = node => keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
|
|
472
451
|
}
|
|
473
452
|
else {
|
|
474
|
-
predicate = this._ensurePredicate(
|
|
453
|
+
predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
475
454
|
}
|
|
476
455
|
const isToLeftByRange = (cur) => {
|
|
477
456
|
if (isRange) {
|
|
478
|
-
const range =
|
|
457
|
+
const range = keyNodeEntryOrPredicate;
|
|
479
458
|
const leftS = this.isReverse ? range.high : range.low;
|
|
480
459
|
const leftI = this.isReverse ? range.includeHigh : range.includeLow;
|
|
481
460
|
return (leftI && this._compare(cur.key, leftS) >= 0) || (!leftI && this._compare(cur.key, leftS) > 0);
|
|
@@ -484,7 +463,7 @@ export class BST extends BinaryTree {
|
|
|
484
463
|
};
|
|
485
464
|
const isToRightByRange = (cur) => {
|
|
486
465
|
if (isRange) {
|
|
487
|
-
const range =
|
|
466
|
+
const range = keyNodeEntryOrPredicate;
|
|
488
467
|
const rightS = this.isReverse ? range.low : range.high;
|
|
489
468
|
const rightI = this.isReverse ? range.includeLow : range.includeLow;
|
|
490
469
|
return (rightI && this._compare(cur.key, rightS) <= 0) || (!rightI && this._compare(cur.key, rightS) < 0);
|
|
@@ -507,8 +486,8 @@ export class BST extends BinaryTree {
|
|
|
507
486
|
if (this.isRealNode(cur.right) && isToRightByRange(cur))
|
|
508
487
|
dfs(cur.right);
|
|
509
488
|
}
|
|
510
|
-
else if (!this._isPredicate(
|
|
511
|
-
const benchmarkKey = this._extractKey(
|
|
489
|
+
else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
490
|
+
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
512
491
|
if (this.isRealNode(cur.left) &&
|
|
513
492
|
benchmarkKey !== null &&
|
|
514
493
|
benchmarkKey !== undefined &&
|
|
@@ -544,8 +523,8 @@ export class BST extends BinaryTree {
|
|
|
544
523
|
if (this.isRealNode(cur.right) && isToRightByRange(cur))
|
|
545
524
|
stack.push(cur.right);
|
|
546
525
|
}
|
|
547
|
-
else if (!this._isPredicate(
|
|
548
|
-
const benchmarkKey = this._extractKey(
|
|
526
|
+
else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
527
|
+
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
549
528
|
if (this.isRealNode(cur.right) &&
|
|
550
529
|
benchmarkKey !== null &&
|
|
551
530
|
benchmarkKey !== undefined &&
|
|
@@ -569,16 +548,16 @@ export class BST extends BinaryTree {
|
|
|
569
548
|
}
|
|
570
549
|
/**
|
|
571
550
|
* Time Complexity: O(log n)
|
|
572
|
-
* Space Complexity: O(n)
|
|
551
|
+
* Space Complexity: O(k + log n)
|
|
573
552
|
*
|
|
574
553
|
* The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
|
|
575
554
|
* @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
|
|
576
555
|
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
577
556
|
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
578
557
|
* function that is used to process each node that is found within the specified range during the
|
|
579
|
-
* search operation. It is of type `NodeCallback<
|
|
558
|
+
* search operation. It is of type `NodeCallback<BSTNode<K, V>>`, where `BSTNode<K, V>` is the type of nodes in the
|
|
580
559
|
* data structure.
|
|
581
|
-
* @param {BTNRep<K, V,
|
|
560
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `rangeSearch`
|
|
582
561
|
* function represents the node from which the search for nodes within the specified range will
|
|
583
562
|
* begin. It is the starting point for the range search operation.
|
|
584
563
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
@@ -594,12 +573,12 @@ export class BST extends BinaryTree {
|
|
|
594
573
|
}
|
|
595
574
|
/**
|
|
596
575
|
* Time Complexity: O(log n)
|
|
597
|
-
* Space Complexity: O(
|
|
576
|
+
* Space Complexity: O(log n)
|
|
598
577
|
*
|
|
599
|
-
* This function retrieves a node based on a given
|
|
600
|
-
* @param {BTNRep<K, V,
|
|
601
|
-
* parameter can be of type `BTNRep<K, V,
|
|
602
|
-
* @param {
|
|
578
|
+
* This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
|
|
579
|
+
* @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
|
|
580
|
+
* parameter can be of type `BTNRep<K, V, BSTNode<K, V>>`, `R`, or `NodePredicate<BSTNode<K, V>>`.
|
|
581
|
+
* @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
|
|
603
582
|
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
604
583
|
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
605
584
|
* node of the binary search tree.
|
|
@@ -607,13 +586,13 @@ export class BST extends BinaryTree {
|
|
|
607
586
|
* parameter that specifies the type of iteration to be used. It has a default value of
|
|
608
587
|
* `this.iterationType`, which means it will use the iteration type defined in the class instance if
|
|
609
588
|
* no value is provided when calling the method.
|
|
610
|
-
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<
|
|
611
|
-
* It is using the `getNodes` method to find the node based on the provided
|
|
589
|
+
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<BSTNode<K, V>>`).
|
|
590
|
+
* It is using the `getNodes` method to find the node based on the provided keyNodeEntryOrPredicate, beginning at
|
|
612
591
|
* the specified root node (`startNode`) and using the specified iteration type. The method then
|
|
613
592
|
* returns the first node found or `undefined` if no node is found.
|
|
614
593
|
*/
|
|
615
|
-
getNode(
|
|
616
|
-
return this.getNodes(
|
|
594
|
+
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
595
|
+
return this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0] ?? undefined;
|
|
617
596
|
}
|
|
618
597
|
/**
|
|
619
598
|
* Time complexity: O(n)
|
|
@@ -627,7 +606,7 @@ export class BST extends BinaryTree {
|
|
|
627
606
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
628
607
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
629
608
|
* take one of the following values:
|
|
630
|
-
* @param {BTNRep<K, V,
|
|
609
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
631
610
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
632
611
|
* node entry. If not specified, the default value is the root of the tree.
|
|
633
612
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -647,7 +626,7 @@ export class BST extends BinaryTree {
|
|
|
647
626
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
648
627
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
649
628
|
* node being visited, and it can return a value of any type.
|
|
650
|
-
* @param {BTNRep<K, V,
|
|
629
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
651
630
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
652
631
|
* object. If no value is provided, the default value is the root of the tree.
|
|
653
632
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -665,9 +644,9 @@ export class BST extends BinaryTree {
|
|
|
665
644
|
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
666
645
|
* containing the results of the callback function applied to each level of the tree.
|
|
667
646
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
668
|
-
* `NodeCallback<
|
|
647
|
+
* `NodeCallback<BSTNode<K, V>>`. It represents a callback function that will be called for each node in the
|
|
669
648
|
* tree during the iteration process.
|
|
670
|
-
* @param {BTNRep<K, V,
|
|
649
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
671
650
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
672
651
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
673
652
|
* value is provided, the root of
|
|
@@ -691,7 +670,7 @@ export class BST extends BinaryTree {
|
|
|
691
670
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
692
671
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
693
672
|
* 0, or 1, where:
|
|
694
|
-
* @param {BTNRep<K, V,
|
|
673
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} targetNode - The `targetNode` parameter is the node in
|
|
695
674
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
696
675
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
697
676
|
* `targetNode` is provided,
|
|
@@ -827,7 +806,8 @@ export class BST extends BinaryTree {
|
|
|
827
806
|
while (stack.length > 0 || node) {
|
|
828
807
|
if (node) {
|
|
829
808
|
stack.push(node);
|
|
830
|
-
|
|
809
|
+
if (node.left !== null)
|
|
810
|
+
node = node.left;
|
|
831
811
|
}
|
|
832
812
|
else {
|
|
833
813
|
node = stack[stack.length - 1];
|
|
@@ -850,7 +830,25 @@ export class BST extends BinaryTree {
|
|
|
850
830
|
}
|
|
851
831
|
return balanced;
|
|
852
832
|
}
|
|
853
|
-
|
|
833
|
+
/**
|
|
834
|
+
* Time complexity: O(n)
|
|
835
|
+
* Space complexity: O(n)
|
|
836
|
+
*
|
|
837
|
+
* The `map` function in TypeScript overrides the default map behavior for a binary search tree by
|
|
838
|
+
* applying a callback function to each entry and creating a new tree with the results.
|
|
839
|
+
* @param callback - A function that will be called for each entry in the BST. It takes four
|
|
840
|
+
* arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
|
|
841
|
+
* the BST itself.
|
|
842
|
+
* @param [options] - The `options` parameter in the `override map` method is of type `BSTOptions<MK,
|
|
843
|
+
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the Binary
|
|
844
|
+
* Search Tree (BST) being created in the `map` method. These options could include configuration
|
|
845
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` method is used to specify
|
|
846
|
+
* the value of `this` that should be used when executing the `callback` function. It allows you to
|
|
847
|
+
* set the context or scope in which the callback function will be called. This can be useful when
|
|
848
|
+
* you want
|
|
849
|
+
* @returns The `map` method is returning a new Binary Search Tree (`BST`) instance with the entries
|
|
850
|
+
* transformed by the provided callback function.
|
|
851
|
+
*/
|
|
854
852
|
map(callback, options, thisArg) {
|
|
855
853
|
const newTree = new BST([], options);
|
|
856
854
|
let index = 0;
|
|
@@ -860,24 +858,43 @@ export class BST extends BinaryTree {
|
|
|
860
858
|
return newTree;
|
|
861
859
|
}
|
|
862
860
|
/**
|
|
861
|
+
* Time complexity: O(n)
|
|
862
|
+
* Space complexity: O(n)
|
|
863
|
+
*
|
|
864
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
865
|
+
* structure.
|
|
866
|
+
* @returns The `cloned` object is being returned.
|
|
867
|
+
*/
|
|
868
|
+
clone() {
|
|
869
|
+
const cloned = this.createTree();
|
|
870
|
+
this._clone(cloned);
|
|
871
|
+
return cloned;
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Time Complexity: O(1)
|
|
875
|
+
* Space Complexity: O(1)
|
|
876
|
+
*
|
|
863
877
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
864
|
-
* @param {BTNRep<K, V,
|
|
865
|
-
* type R or BTNRep<K, V,
|
|
878
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - A variable that can be of
|
|
879
|
+
* type R or BTNRep<K, V, BSTNode<K, V>>. It represents either a key, a node, an entry, or a raw
|
|
866
880
|
* element.
|
|
867
881
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
868
882
|
* value associated with a key in a key-value pair.
|
|
869
|
-
* @returns either a
|
|
883
|
+
* @returns either a BSTNode<K, V> object or undefined.
|
|
870
884
|
*/
|
|
871
|
-
|
|
872
|
-
const [node, entryValue] = super.
|
|
885
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
|
|
886
|
+
const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
873
887
|
if (node === null)
|
|
874
888
|
return [undefined, undefined];
|
|
875
889
|
return [node, value ?? entryValue];
|
|
876
890
|
}
|
|
877
891
|
/**
|
|
892
|
+
* Time Complexity: O(1)
|
|
893
|
+
* Space Complexity: O(1)
|
|
894
|
+
*
|
|
878
895
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
879
896
|
* root.
|
|
880
|
-
* @param {OptNode<
|
|
897
|
+
* @param {OptNode<BSTNode<K, V>>} v - v is a parameter of type BSTNode<K, V> or undefined.
|
|
881
898
|
*/
|
|
882
899
|
_setRoot(v) {
|
|
883
900
|
if (v) {
|
|
@@ -885,6 +902,20 @@ export class BST extends BinaryTree {
|
|
|
885
902
|
}
|
|
886
903
|
this._root = v;
|
|
887
904
|
}
|
|
905
|
+
/**
|
|
906
|
+
* Time Complexity: O(1)
|
|
907
|
+
* Space Complexity: O(1)
|
|
908
|
+
*
|
|
909
|
+
* The _compare function compares two values using a specified comparator function and optionally
|
|
910
|
+
* reverses the result.
|
|
911
|
+
* @param {K} a - The parameter `a` is of type `K`, which is used as an input for comparison in the
|
|
912
|
+
* `_compare` method.
|
|
913
|
+
* @param {K} b - The parameter `b` in the `_compare` function is of type `K`.
|
|
914
|
+
* @returns The `_compare` method is returning the result of the ternary expression. If `_isReverse`
|
|
915
|
+
* is true, it returns the negation of the result of calling the `_comparator` function with
|
|
916
|
+
* arguments `a` and `b`. If `_isReverse` is false, it returns the result of calling the
|
|
917
|
+
* `_comparator` function with arguments `a` and `b`.
|
|
918
|
+
*/
|
|
888
919
|
_compare(a, b) {
|
|
889
920
|
return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
|
|
890
921
|
}
|