data-structure-typed 1.54.0 → 1.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -0
- package/benchmark/report.html +1 -28
- package/benchmark/report.json +17 -326
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts → cjs/data-structures/binary-tree/avl-tree-counter.d.ts} +54 -47
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +408 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -177
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -340
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +102 -57
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +110 -47
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +240 -190
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +269 -240
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +145 -112
- package/dist/cjs/data-structures/binary-tree/bst.js +180 -129
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +100 -82
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +115 -79
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.d.ts → cjs/data-structures/binary-tree/tree-counter.d.ts} +74 -64
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +445 -0
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +78 -174
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +142 -377
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -4
- package/dist/cjs/data-structures/trie/trie.js +0 -4
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +8 -8
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -4
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -4
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.js → esm/data-structures/binary-tree/avl-tree-counter.js} +73 -60
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +191 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +234 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/avl-tree.js +110 -47
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.d.ts +240 -190
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.js +272 -245
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.d.ts +145 -112
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.js +201 -155
- package/dist/esm/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js +2 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js.map +1 -1
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.d.ts +100 -82
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.js +115 -79
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.js → esm/data-structures/binary-tree/tree-counter.js} +111 -96
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +106 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +196 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.js +3 -0
- package/dist/esm/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.js +3 -0
- package/dist/esm/data-structures/graph/map-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.js +3 -0
- package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.js +3 -0
- package/dist/esm/data-structures/matrix/matrix.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.js +3 -0
- package/dist/esm/data-structures/matrix/navigator.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/trie/trie.d.ts +0 -4
- package/dist/{mjs → esm}/data-structures/trie/trie.js +0 -4
- package/dist/esm/data-structures/trie/trie.js.map +1 -0
- package/dist/esm/interfaces/binary-tree.d.ts +9 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
- package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/esm/types/data-structures/binary-tree/rb-tree.d.ts +3 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/umd/data-structure-typed.js +1464 -895
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +14 -14
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +155 -393
- package/src/data-structures/binary-tree/avl-tree.ts +144 -93
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +433 -405
- package/src/data-structures/binary-tree/bst.ts +261 -239
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +163 -134
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +161 -429
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- package/src/data-structures/trie/trie.ts +0 -4
- package/src/interfaces/binary-tree.ts +10 -24
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -5
- package/src/types/data-structures/binary-tree/index.ts +2 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -6
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -6
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/integration/avl-tree.test.ts +1 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/integration/compile.js +144 -0
- package/test/integration/compile.ts +171 -0
- package/test/integration/index.html +48 -48
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -4
- package/test/performance/data-structures/comparison/comparison.test.ts +2 -2
- package/test/performance/reportor.ts +5 -3
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +877 -0
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +459 -761
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +223 -223
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +474 -492
- package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/overall.test.ts +0 -3
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +87 -90
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +975 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +729 -857
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/{tsconfig-mjs.json → tsconfig-esm.json} +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -189
- package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/map-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix.js.map +0 -1
- package/dist/mjs/data-structures/matrix/navigator.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/trie/trie.js.map +0 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +0 -9
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -6
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -5
- /package/dist/{mjs → esm}/common/index.d.ts +0 -0
- /package/dist/{mjs → esm}/common/index.js +0 -0
- /package/dist/{mjs → esm}/common/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js +0 -0
- /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/graph/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.js +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/hash-map.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/hash/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/max-heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.js +0 -0
- /package/dist/{mjs → esm}/data-structures/heap/min-heap.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/linked-list/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/matrix/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/deque.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.js +0 -0
- /package/dist/{mjs → esm}/data-structures/queue/queue.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.js +0 -0
- /package/dist/{mjs → esm}/data-structures/stack/stack.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/index.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.js +0 -0
- /package/dist/{mjs → esm}/data-structures/tree/tree.js.map +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.d.ts +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.js +0 -0
- /package/dist/{mjs → esm}/data-structures/trie/index.js.map +0 -0
- /package/dist/{mjs → esm}/index.d.ts +0 -0
- /package/dist/{mjs → esm}/index.js +0 -0
- /package/dist/{mjs → esm}/index.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/binary-tree.js +0 -0
- /package/dist/{mjs → esm}/interfaces/binary-tree.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.js +0 -0
- /package/dist/{mjs → esm}/interfaces/graph.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.js +0 -0
- /package/dist/{mjs → esm}/interfaces/heap.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/index.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/index.js +0 -0
- /package/dist/{mjs → esm}/interfaces/index.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.js +0 -0
- /package/dist/{mjs → esm}/interfaces/navigator.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/interfaces/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/interfaces/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/interfaces/singly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/common.d.ts +0 -0
- /package/dist/{mjs → esm}/types/common.js +0 -0
- /package/dist/{mjs → esm}/types/common.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/base.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/base/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/rb-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/rb-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/hash/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/deque.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/queue/queue.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/stack/stack.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/tree/tree.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.d.ts +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.js +0 -0
- /package/dist/{mjs → esm}/types/data-structures/trie/trie.js.map +0 -0
- /package/dist/{mjs → esm}/types/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/index.js +0 -0
- /package/dist/{mjs → esm}/types/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/index.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/index.js +0 -0
- /package/dist/{mjs → esm}/types/utils/index.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.js +0 -0
- /package/dist/{mjs → esm}/types/utils/utils.js.map +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.d.ts +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.js +0 -0
- /package/dist/{mjs → esm}/types/utils/validate-type.js.map +0 -0
- /package/dist/{mjs → esm}/utils/index.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/index.js +0 -0
- /package/dist/{mjs → esm}/utils/index.js.map +0 -0
- /package/dist/{mjs → esm}/utils/number.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/number.js +0 -0
- /package/dist/{mjs → esm}/utils/number.js.map +0 -0
- /package/dist/{mjs → esm}/utils/utils.d.ts +0 -0
- /package/dist/{mjs → esm}/utils/utils.js +0 -0
- /package/dist/{mjs → esm}/utils/utils.js.map +0 -0
|
@@ -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,34 +125,58 @@ 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
|
}
|
|
135
|
+
_comparator = (a, b) => {
|
|
136
|
+
if (isComparable(a) && isComparable(b)) {
|
|
137
|
+
if (a > b)
|
|
138
|
+
return 1;
|
|
139
|
+
if (a < b)
|
|
140
|
+
return -1;
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
if (this._specifyComparable) {
|
|
144
|
+
if (this._specifyComparable(a) > this._specifyComparable(b))
|
|
145
|
+
return 1;
|
|
146
|
+
if (this._specifyComparable(a) < this._specifyComparable(b))
|
|
147
|
+
return -1;
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
if (typeof a === 'object' || typeof b === 'object') {
|
|
151
|
+
throw TypeError(`When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.`);
|
|
152
|
+
}
|
|
153
|
+
return 0;
|
|
154
|
+
};
|
|
155
|
+
get comparator() {
|
|
156
|
+
return this._comparator;
|
|
157
|
+
}
|
|
158
|
+
_specifyComparable;
|
|
159
|
+
get specifyComparable() {
|
|
160
|
+
return this._specifyComparable;
|
|
161
|
+
}
|
|
156
162
|
/**
|
|
163
|
+
* Time Complexity: O(1)
|
|
164
|
+
* Space Complexity: O(1)
|
|
165
|
+
*
|
|
157
166
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
158
167
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
159
168
|
* being created.
|
|
160
169
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
161
170
|
* value associated with the key in the node being created.
|
|
162
|
-
* @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.
|
|
163
172
|
*/
|
|
164
173
|
createNode(key, value) {
|
|
165
174
|
return new BSTNode(key, this._isMapMode ? undefined : value);
|
|
166
175
|
}
|
|
167
176
|
/**
|
|
177
|
+
* Time Complexity: O(1)
|
|
178
|
+
* Space Complexity: O(1)
|
|
179
|
+
*
|
|
168
180
|
* The function creates a new binary search tree with the specified options.
|
|
169
181
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
170
182
|
* behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
|
|
@@ -181,29 +193,14 @@ export class BST extends BinaryTree {
|
|
|
181
193
|
...options
|
|
182
194
|
});
|
|
183
195
|
}
|
|
184
|
-
/**
|
|
185
|
-
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
186
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
|
|
187
|
-
* type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
188
|
-
* element.
|
|
189
|
-
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
190
|
-
* value associated with a key in a key-value pair.
|
|
191
|
-
* @returns either a NODE object or undefined.
|
|
192
|
-
*/
|
|
193
|
-
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
194
|
-
const [node, entryValue] = super._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
195
|
-
if (node === null)
|
|
196
|
-
return [undefined, undefined];
|
|
197
|
-
return [node, value ?? entryValue];
|
|
198
|
-
}
|
|
199
196
|
/**
|
|
200
197
|
* Time Complexity: O(log n)
|
|
201
198
|
* Space Complexity: O(log n)
|
|
202
199
|
*
|
|
203
200
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
204
201
|
* it doesn't exist.
|
|
205
|
-
* @param {BTNRep<K, V,
|
|
206
|
-
* `
|
|
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,
|
|
207
204
|
* entry, or raw element that needs to be ensured in the tree.
|
|
208
205
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
209
206
|
* parameter that specifies the type of iteration to be used when ensuring a node. It has a default
|
|
@@ -211,43 +208,49 @@ export class BST extends BinaryTree {
|
|
|
211
208
|
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
212
209
|
* not be ensured.
|
|
213
210
|
*/
|
|
214
|
-
ensureNode(
|
|
215
|
-
return super.ensureNode(
|
|
211
|
+
ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
|
|
212
|
+
return super.ensureNode(keyNodeOrEntry, iterationType) ?? undefined;
|
|
216
213
|
}
|
|
217
214
|
/**
|
|
215
|
+
* Time Complexity: O(1)
|
|
216
|
+
* Space Complexity: O(1)
|
|
217
|
+
*
|
|
218
218
|
* The function checks if the input is an instance of the BSTNode class.
|
|
219
|
-
* @param {BTNRep<K, V,
|
|
220
|
-
* `
|
|
221
|
-
* @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
|
|
222
222
|
* an instance of the `BSTNode` class.
|
|
223
223
|
*/
|
|
224
|
-
isNode(
|
|
225
|
-
return
|
|
224
|
+
isNode(keyNodeOrEntry) {
|
|
225
|
+
return keyNodeOrEntry instanceof BSTNode;
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
|
-
*
|
|
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.
|
|
229
232
|
* @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
|
|
230
233
|
* type `K`.
|
|
231
|
-
* @returns The `override
|
|
234
|
+
* @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
|
|
232
235
|
* the result of the `isComparable` function with the condition `this._compare !==
|
|
233
236
|
* this._DEFAULT_COMPARATOR`.
|
|
234
237
|
*/
|
|
235
|
-
|
|
238
|
+
isValidKey(key) {
|
|
236
239
|
return isComparable(key, this._specifyComparable !== undefined);
|
|
237
240
|
}
|
|
238
241
|
/**
|
|
239
242
|
* Time Complexity: O(log n)
|
|
240
|
-
* Space Complexity: O(
|
|
243
|
+
* Space Complexity: O(log n)
|
|
241
244
|
*
|
|
242
245
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
243
|
-
* @param {BTNRep<K, V,
|
|
244
|
-
* `
|
|
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>>`.
|
|
245
248
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
246
249
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
247
250
|
* @returns a boolean value.
|
|
248
251
|
*/
|
|
249
|
-
add(
|
|
250
|
-
const [newNode, newValue] = this.
|
|
252
|
+
add(keyNodeOrEntry, value) {
|
|
253
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
251
254
|
if (newNode === undefined)
|
|
252
255
|
return false;
|
|
253
256
|
if (this._root === undefined) {
|
|
@@ -318,8 +321,10 @@ export class BST extends BinaryTree {
|
|
|
318
321
|
valuesIterator = values[Symbol.iterator]();
|
|
319
322
|
}
|
|
320
323
|
if (!isBalanceAdd) {
|
|
321
|
-
for (
|
|
324
|
+
for (let kve of keysNodesEntriesOrRaws) {
|
|
322
325
|
const value = valuesIterator?.next().value;
|
|
326
|
+
if (this.isRaw(kve))
|
|
327
|
+
kve = this._toEntryFn(kve);
|
|
323
328
|
inserted.push(this.add(kve, value));
|
|
324
329
|
}
|
|
325
330
|
return inserted;
|
|
@@ -333,23 +338,21 @@ export class BST extends BinaryTree {
|
|
|
333
338
|
let sorted = [];
|
|
334
339
|
sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
|
|
335
340
|
let keyA, keyB;
|
|
336
|
-
if (this.
|
|
341
|
+
if (this.isRaw(a))
|
|
342
|
+
keyA = this._toEntryFn(a)[0];
|
|
343
|
+
else if (this.isEntry(a))
|
|
337
344
|
keyA = a[0];
|
|
338
345
|
else if (this.isRealNode(a))
|
|
339
346
|
keyA = a.key;
|
|
340
|
-
else if (this._toEntryFn) {
|
|
341
|
-
keyA = this._toEntryFn(a)[0];
|
|
342
|
-
}
|
|
343
347
|
else {
|
|
344
348
|
keyA = a;
|
|
345
349
|
}
|
|
346
|
-
if (this.
|
|
350
|
+
if (this.isRaw(b))
|
|
351
|
+
keyB = this._toEntryFn(b)[0];
|
|
352
|
+
else if (this.isEntry(b))
|
|
347
353
|
keyB = b[0];
|
|
348
354
|
else if (this.isRealNode(b))
|
|
349
355
|
keyB = b.key;
|
|
350
|
-
else if (this._toEntryFn) {
|
|
351
|
-
keyB = this._toEntryFn(b)[0];
|
|
352
|
-
}
|
|
353
356
|
else {
|
|
354
357
|
keyB = b;
|
|
355
358
|
}
|
|
@@ -362,7 +365,13 @@ export class BST extends BinaryTree {
|
|
|
362
365
|
if (arr.length === 0)
|
|
363
366
|
return;
|
|
364
367
|
const mid = Math.floor((arr.length - 1) / 2);
|
|
365
|
-
|
|
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
|
+
}
|
|
366
375
|
inserted[orgIndex] = this.add(key, value);
|
|
367
376
|
_dfs(arr.slice(0, mid));
|
|
368
377
|
_dfs(arr.slice(mid + 1));
|
|
@@ -376,7 +385,13 @@ export class BST extends BinaryTree {
|
|
|
376
385
|
const [l, r] = popped;
|
|
377
386
|
if (l <= r) {
|
|
378
387
|
const m = l + Math.floor((r - l) / 2);
|
|
379
|
-
|
|
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
|
+
}
|
|
380
395
|
inserted[orgIndex] = this.add(key, value);
|
|
381
396
|
stack.push([m + 1, r]);
|
|
382
397
|
stack.push([l, m - 1]);
|
|
@@ -398,17 +413,17 @@ export class BST extends BinaryTree {
|
|
|
398
413
|
*
|
|
399
414
|
* The function `search` in TypeScript overrides the search behavior in a binary tree structure based
|
|
400
415
|
* on specified criteria.
|
|
401
|
-
* @param {BTNRep<K, V,
|
|
402
|
-
* `
|
|
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
|
|
403
418
|
* following types:
|
|
404
419
|
* @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
|
|
405
420
|
* search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
|
|
406
421
|
* search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
|
|
407
422
|
* @param {C} callback - The `callback` parameter in the `override search` function is a function
|
|
408
423
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
409
|
-
* extends `NodeCallback<
|
|
424
|
+
* extends `NodeCallback<BSTNode<K, V>>`. The callback function should accept a node of type `BSTNode<K, V>` as its
|
|
410
425
|
* argument and
|
|
411
|
-
* @param {BTNRep<K, V,
|
|
426
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `override search`
|
|
412
427
|
* method represents the node from which the search operation will begin. It is the starting point
|
|
413
428
|
* for searching within the tree data structure. The method ensures that the `startNode` is a valid
|
|
414
429
|
* node before proceeding with the search operation. If the `
|
|
@@ -420,26 +435,26 @@ export class BST extends BinaryTree {
|
|
|
420
435
|
* structure based on the provided key, predicate, and other options. The search results are
|
|
421
436
|
* collected in an array and returned as the output of the method.
|
|
422
437
|
*/
|
|
423
|
-
search(
|
|
424
|
-
if (
|
|
438
|
+
search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
439
|
+
if (keyNodeEntryOrPredicate === undefined)
|
|
425
440
|
return [];
|
|
426
|
-
if (
|
|
441
|
+
if (keyNodeEntryOrPredicate === null)
|
|
427
442
|
return [];
|
|
428
443
|
startNode = this.ensureNode(startNode);
|
|
429
444
|
if (!startNode)
|
|
430
445
|
return [];
|
|
431
446
|
let predicate;
|
|
432
|
-
const isRange = this.isRange(
|
|
447
|
+
const isRange = this.isRange(keyNodeEntryOrPredicate);
|
|
433
448
|
// Set predicate based on parameter type
|
|
434
449
|
if (isRange) {
|
|
435
|
-
predicate = node =>
|
|
450
|
+
predicate = node => keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
|
|
436
451
|
}
|
|
437
452
|
else {
|
|
438
|
-
predicate = this._ensurePredicate(
|
|
453
|
+
predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
439
454
|
}
|
|
440
455
|
const isToLeftByRange = (cur) => {
|
|
441
456
|
if (isRange) {
|
|
442
|
-
const range =
|
|
457
|
+
const range = keyNodeEntryOrPredicate;
|
|
443
458
|
const leftS = this.isReverse ? range.high : range.low;
|
|
444
459
|
const leftI = this.isReverse ? range.includeHigh : range.includeLow;
|
|
445
460
|
return (leftI && this._compare(cur.key, leftS) >= 0) || (!leftI && this._compare(cur.key, leftS) > 0);
|
|
@@ -448,7 +463,7 @@ export class BST extends BinaryTree {
|
|
|
448
463
|
};
|
|
449
464
|
const isToRightByRange = (cur) => {
|
|
450
465
|
if (isRange) {
|
|
451
|
-
const range =
|
|
466
|
+
const range = keyNodeEntryOrPredicate;
|
|
452
467
|
const rightS = this.isReverse ? range.low : range.high;
|
|
453
468
|
const rightI = this.isReverse ? range.includeLow : range.includeLow;
|
|
454
469
|
return (rightI && this._compare(cur.key, rightS) <= 0) || (!rightI && this._compare(cur.key, rightS) < 0);
|
|
@@ -471,8 +486,8 @@ export class BST extends BinaryTree {
|
|
|
471
486
|
if (this.isRealNode(cur.right) && isToRightByRange(cur))
|
|
472
487
|
dfs(cur.right);
|
|
473
488
|
}
|
|
474
|
-
else if (!this._isPredicate(
|
|
475
|
-
const benchmarkKey = this._extractKey(
|
|
489
|
+
else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
490
|
+
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
476
491
|
if (this.isRealNode(cur.left) &&
|
|
477
492
|
benchmarkKey !== null &&
|
|
478
493
|
benchmarkKey !== undefined &&
|
|
@@ -508,8 +523,8 @@ export class BST extends BinaryTree {
|
|
|
508
523
|
if (this.isRealNode(cur.right) && isToRightByRange(cur))
|
|
509
524
|
stack.push(cur.right);
|
|
510
525
|
}
|
|
511
|
-
else if (!this._isPredicate(
|
|
512
|
-
const benchmarkKey = this._extractKey(
|
|
526
|
+
else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
527
|
+
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
513
528
|
if (this.isRealNode(cur.right) &&
|
|
514
529
|
benchmarkKey !== null &&
|
|
515
530
|
benchmarkKey !== undefined &&
|
|
@@ -533,16 +548,16 @@ export class BST extends BinaryTree {
|
|
|
533
548
|
}
|
|
534
549
|
/**
|
|
535
550
|
* Time Complexity: O(log n)
|
|
536
|
-
* Space Complexity: O(n)
|
|
551
|
+
* Space Complexity: O(k + log n)
|
|
537
552
|
*
|
|
538
553
|
* The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
|
|
539
554
|
* @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
|
|
540
555
|
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
541
556
|
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
542
557
|
* function that is used to process each node that is found within the specified range during the
|
|
543
|
-
* 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
|
|
544
559
|
* data structure.
|
|
545
|
-
* @param {BTNRep<K, V,
|
|
560
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `rangeSearch`
|
|
546
561
|
* function represents the node from which the search for nodes within the specified range will
|
|
547
562
|
* begin. It is the starting point for the range search operation.
|
|
548
563
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
@@ -558,12 +573,12 @@ export class BST extends BinaryTree {
|
|
|
558
573
|
}
|
|
559
574
|
/**
|
|
560
575
|
* Time Complexity: O(log n)
|
|
561
|
-
* Space Complexity: O(
|
|
576
|
+
* Space Complexity: O(log n)
|
|
562
577
|
*
|
|
563
|
-
* This function retrieves a node based on a given
|
|
564
|
-
* @param {BTNRep<K, V,
|
|
565
|
-
* parameter can be of type `BTNRep<K, V,
|
|
566
|
-
* @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
|
|
567
582
|
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
568
583
|
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
569
584
|
* node of the binary search tree.
|
|
@@ -571,13 +586,13 @@ export class BST extends BinaryTree {
|
|
|
571
586
|
* parameter that specifies the type of iteration to be used. It has a default value of
|
|
572
587
|
* `this.iterationType`, which means it will use the iteration type defined in the class instance if
|
|
573
588
|
* no value is provided when calling the method.
|
|
574
|
-
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<
|
|
575
|
-
* 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
|
|
576
591
|
* the specified root node (`startNode`) and using the specified iteration type. The method then
|
|
577
592
|
* returns the first node found or `undefined` if no node is found.
|
|
578
593
|
*/
|
|
579
|
-
getNode(
|
|
580
|
-
return this.getNodes(
|
|
594
|
+
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
595
|
+
return this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0] ?? undefined;
|
|
581
596
|
}
|
|
582
597
|
/**
|
|
583
598
|
* Time complexity: O(n)
|
|
@@ -591,7 +606,7 @@ export class BST extends BinaryTree {
|
|
|
591
606
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
592
607
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
593
608
|
* take one of the following values:
|
|
594
|
-
* @param {BTNRep<K, V,
|
|
609
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
595
610
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
596
611
|
* node entry. If not specified, the default value is the root of the tree.
|
|
597
612
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -611,7 +626,7 @@ export class BST extends BinaryTree {
|
|
|
611
626
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
612
627
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
613
628
|
* node being visited, and it can return a value of any type.
|
|
614
|
-
* @param {BTNRep<K, V,
|
|
629
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
615
630
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
616
631
|
* object. If no value is provided, the default value is the root of the tree.
|
|
617
632
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -629,9 +644,9 @@ export class BST extends BinaryTree {
|
|
|
629
644
|
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
630
645
|
* containing the results of the callback function applied to each level of the tree.
|
|
631
646
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
632
|
-
* `NodeCallback<
|
|
647
|
+
* `NodeCallback<BSTNode<K, V>>`. It represents a callback function that will be called for each node in the
|
|
633
648
|
* tree during the iteration process.
|
|
634
|
-
* @param {BTNRep<K, V,
|
|
649
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
635
650
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
636
651
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
637
652
|
* value is provided, the root of
|
|
@@ -655,7 +670,7 @@ export class BST extends BinaryTree {
|
|
|
655
670
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
656
671
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
657
672
|
* 0, or 1, where:
|
|
658
|
-
* @param {BTNRep<K, V,
|
|
673
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} targetNode - The `targetNode` parameter is the node in
|
|
659
674
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
660
675
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
661
676
|
* `targetNode` is provided,
|
|
@@ -815,46 +830,71 @@ export class BST extends BinaryTree {
|
|
|
815
830
|
}
|
|
816
831
|
return balanced;
|
|
817
832
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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
|
+
*/
|
|
852
|
+
map(callback, options, thisArg) {
|
|
853
|
+
const newTree = new BST([], options);
|
|
854
|
+
let index = 0;
|
|
855
|
+
for (const [key, value] of this) {
|
|
856
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
835
857
|
}
|
|
836
|
-
return
|
|
837
|
-
}
|
|
858
|
+
return newTree;
|
|
859
|
+
}
|
|
838
860
|
/**
|
|
839
|
-
*
|
|
840
|
-
*
|
|
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.
|
|
841
867
|
*/
|
|
842
|
-
|
|
843
|
-
|
|
868
|
+
clone() {
|
|
869
|
+
const cloned = this.createTree();
|
|
870
|
+
this._clone(cloned);
|
|
871
|
+
return cloned;
|
|
844
872
|
}
|
|
845
|
-
_specifyComparable;
|
|
846
873
|
/**
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
874
|
+
* Time Complexity: O(1)
|
|
875
|
+
* Space Complexity: O(1)
|
|
876
|
+
*
|
|
877
|
+
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
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
|
|
880
|
+
* element.
|
|
881
|
+
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
882
|
+
* value associated with a key in a key-value pair.
|
|
883
|
+
* @returns either a BSTNode<K, V> object or undefined.
|
|
850
884
|
*/
|
|
851
|
-
|
|
852
|
-
|
|
885
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
|
|
886
|
+
const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
887
|
+
if (node === null)
|
|
888
|
+
return [undefined, undefined];
|
|
889
|
+
return [node, value ?? entryValue];
|
|
853
890
|
}
|
|
854
891
|
/**
|
|
892
|
+
* Time Complexity: O(1)
|
|
893
|
+
* Space Complexity: O(1)
|
|
894
|
+
*
|
|
855
895
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
856
896
|
* root.
|
|
857
|
-
* @param {OptNode<
|
|
897
|
+
* @param {OptNode<BSTNode<K, V>>} v - v is a parameter of type BSTNode<K, V> or undefined.
|
|
858
898
|
*/
|
|
859
899
|
_setRoot(v) {
|
|
860
900
|
if (v) {
|
|
@@ -862,16 +902,22 @@ export class BST extends BinaryTree {
|
|
|
862
902
|
}
|
|
863
903
|
this._root = v;
|
|
864
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
|
+
*/
|
|
865
919
|
_compare(a, b) {
|
|
866
920
|
return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
|
|
867
921
|
}
|
|
868
|
-
map(callback, options, thisArg) {
|
|
869
|
-
const newTree = new BST([], options);
|
|
870
|
-
let index = 0;
|
|
871
|
-
for (const [key, value] of this) {
|
|
872
|
-
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
873
|
-
}
|
|
874
|
-
return newTree;
|
|
875
|
-
}
|
|
876
922
|
}
|
|
877
923
|
//# sourceMappingURL=bst.js.map
|