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
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var dataStructureTyped = (() => {
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
8
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -22,6 +24,7 @@ var dataStructureTyped = (() => {
|
|
|
22
24
|
}
|
|
23
25
|
return a;
|
|
24
26
|
};
|
|
27
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
28
|
var __export = (target, all) => {
|
|
26
29
|
for (var name in all)
|
|
27
30
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -93,6 +96,8 @@ var dataStructureTyped = (() => {
|
|
|
93
96
|
var src_exports = {};
|
|
94
97
|
__export(src_exports, {
|
|
95
98
|
AVLTree: () => AVLTree,
|
|
99
|
+
AVLTreeCounter: () => AVLTreeCounter,
|
|
100
|
+
AVLTreeCounterNode: () => AVLTreeCounterNode,
|
|
96
101
|
AVLTreeMultiMap: () => AVLTreeMultiMap,
|
|
97
102
|
AVLTreeMultiMapNode: () => AVLTreeMultiMapNode,
|
|
98
103
|
AVLTreeNode: () => AVLTreeNode,
|
|
@@ -142,6 +147,8 @@ var dataStructureTyped = (() => {
|
|
|
142
147
|
SkipListNode: () => SkipListNode,
|
|
143
148
|
Stack: () => Stack,
|
|
144
149
|
THUNK_SYMBOL: () => THUNK_SYMBOL,
|
|
150
|
+
TreeCounter: () => TreeCounter,
|
|
151
|
+
TreeCounterNode: () => TreeCounterNode,
|
|
145
152
|
TreeMultiMap: () => TreeMultiMap,
|
|
146
153
|
TreeMultiMapNode: () => TreeMultiMapNode,
|
|
147
154
|
TreeNode: () => TreeNode,
|
|
@@ -7383,12 +7390,23 @@ var dataStructureTyped = (() => {
|
|
|
7383
7390
|
|
|
7384
7391
|
// src/data-structures/binary-tree/binary-tree.ts
|
|
7385
7392
|
var BinaryTreeNode = class {
|
|
7393
|
+
/**
|
|
7394
|
+
* The constructor function initializes an object with a key and an optional value in TypeScript.
|
|
7395
|
+
* @param {K} key - The `key` parameter in the constructor function is used to store the key value
|
|
7396
|
+
* for the key-value pair.
|
|
7397
|
+
* @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
|
|
7398
|
+
* have to be provided when creating an instance of the class. If a `value` is not provided, it will
|
|
7399
|
+
* default to `undefined`.
|
|
7400
|
+
*/
|
|
7386
7401
|
constructor(key, value) {
|
|
7387
7402
|
__publicField(this, "key");
|
|
7388
7403
|
__publicField(this, "value");
|
|
7389
7404
|
__publicField(this, "parent");
|
|
7390
7405
|
__publicField(this, "_left");
|
|
7391
7406
|
__publicField(this, "_right");
|
|
7407
|
+
__publicField(this, "_height", 0);
|
|
7408
|
+
__publicField(this, "_color", "BLACK");
|
|
7409
|
+
__publicField(this, "_count", 1);
|
|
7392
7410
|
this.key = key;
|
|
7393
7411
|
this.value = value;
|
|
7394
7412
|
}
|
|
@@ -7410,14 +7428,31 @@ var dataStructureTyped = (() => {
|
|
|
7410
7428
|
}
|
|
7411
7429
|
this._right = v;
|
|
7412
7430
|
}
|
|
7431
|
+
get height() {
|
|
7432
|
+
return this._height;
|
|
7433
|
+
}
|
|
7434
|
+
set height(value) {
|
|
7435
|
+
this._height = value;
|
|
7436
|
+
}
|
|
7437
|
+
get color() {
|
|
7438
|
+
return this._color;
|
|
7439
|
+
}
|
|
7440
|
+
set color(value) {
|
|
7441
|
+
this._color = value;
|
|
7442
|
+
}
|
|
7443
|
+
get count() {
|
|
7444
|
+
return this._count;
|
|
7445
|
+
}
|
|
7446
|
+
set count(value) {
|
|
7447
|
+
this._count = value;
|
|
7448
|
+
}
|
|
7413
7449
|
get familyPosition() {
|
|
7414
|
-
const that = this;
|
|
7415
7450
|
if (!this.parent) {
|
|
7416
7451
|
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
7417
7452
|
}
|
|
7418
|
-
if (this.parent.left ===
|
|
7453
|
+
if (this.parent.left === this) {
|
|
7419
7454
|
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
7420
|
-
} else if (this.parent.right ===
|
|
7455
|
+
} else if (this.parent.right === this) {
|
|
7421
7456
|
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
7422
7457
|
}
|
|
7423
7458
|
return "MAL_NODE";
|
|
@@ -7425,13 +7460,13 @@ var dataStructureTyped = (() => {
|
|
|
7425
7460
|
};
|
|
7426
7461
|
var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
7427
7462
|
/**
|
|
7428
|
-
*
|
|
7429
|
-
*
|
|
7430
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor
|
|
7431
|
-
*
|
|
7432
|
-
*
|
|
7433
|
-
* @param [options] - The `options` parameter in the constructor is an object that can
|
|
7434
|
-
* following properties:
|
|
7463
|
+
* This TypeScript constructor function initializes a binary tree with optional options and adds
|
|
7464
|
+
* elements based on the provided input.
|
|
7465
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
7466
|
+
* iterable that can contain either objects of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
|
|
7467
|
+
* is used to initialize the binary tree with keys, nodes, entries, or raw data.
|
|
7468
|
+
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
7469
|
+
* contain the following properties:
|
|
7435
7470
|
*/
|
|
7436
7471
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
7437
7472
|
super();
|
|
@@ -7480,7 +7515,7 @@ var dataStructureTyped = (() => {
|
|
|
7480
7515
|
* not required to be provided when calling the function. If a `value` is provided, it should be of
|
|
7481
7516
|
* type `V`, which is the type of the value associated with the node.
|
|
7482
7517
|
* @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
|
|
7483
|
-
* as
|
|
7518
|
+
* as BinaryTreeNode<K, V>.
|
|
7484
7519
|
*/
|
|
7485
7520
|
createNode(key, value) {
|
|
7486
7521
|
return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
|
|
@@ -7489,15 +7524,12 @@ var dataStructureTyped = (() => {
|
|
|
7489
7524
|
* Time Complexity: O(1)
|
|
7490
7525
|
* Space Complexity: O(1)
|
|
7491
7526
|
*
|
|
7492
|
-
* The
|
|
7493
|
-
* @param [options] - The `options` parameter in the `createTree`
|
|
7494
|
-
*
|
|
7495
|
-
*
|
|
7496
|
-
*
|
|
7497
|
-
* @returns
|
|
7498
|
-
* provided options. The method is creating a new `BinaryTree` object with an empty array as the
|
|
7499
|
-
* initial data, and then setting various options such as `iterationType`, `isMapMode`, and
|
|
7500
|
-
* `toEntryFn` based on the current object's properties and the provided `options`. Finally, it
|
|
7527
|
+
* The function creates a binary tree with the specified options.
|
|
7528
|
+
* @param [options] - The `options` parameter in the `createTree` function is an optional parameter
|
|
7529
|
+
* that allows you to provide partial configuration options for creating a binary tree. It is of type
|
|
7530
|
+
* `Partial<BinaryTreeOptions<K, V, R>>`, which means you can pass in an object containing a subset
|
|
7531
|
+
* of properties
|
|
7532
|
+
* @returns A new instance of a binary tree with the specified options is being returned.
|
|
7501
7533
|
*/
|
|
7502
7534
|
createTree(options) {
|
|
7503
7535
|
return new _BinaryTree([], __spreadValues({
|
|
@@ -7512,8 +7544,8 @@ var dataStructureTyped = (() => {
|
|
|
7512
7544
|
*
|
|
7513
7545
|
* The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
|
|
7514
7546
|
* value and returns the corresponding node or null.
|
|
7515
|
-
* @param {BTNRep<K, V,
|
|
7516
|
-
* parameter in the `ensureNode` function can be of type `BTNRep<K, V,
|
|
7547
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
7548
|
+
* parameter in the `ensureNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
|
|
7517
7549
|
* is used to determine whether the input is a key, node, entry, or raw data. The
|
|
7518
7550
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
|
|
7519
7551
|
* is used to specify the type of iteration to be performed. It has a default value of
|
|
@@ -7521,41 +7553,42 @@ var dataStructureTyped = (() => {
|
|
|
7521
7553
|
* @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
|
|
7522
7554
|
* conditions specified in the code snippet.
|
|
7523
7555
|
*/
|
|
7524
|
-
ensureNode(
|
|
7525
|
-
if (
|
|
7526
|
-
if (
|
|
7527
|
-
if (
|
|
7528
|
-
if (this.isNode(
|
|
7529
|
-
if (this.isEntry(
|
|
7530
|
-
const key =
|
|
7556
|
+
ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
|
|
7557
|
+
if (keyNodeOrEntry === null) return null;
|
|
7558
|
+
if (keyNodeOrEntry === void 0) return;
|
|
7559
|
+
if (keyNodeOrEntry === this._NIL) return;
|
|
7560
|
+
if (this.isNode(keyNodeOrEntry)) return keyNodeOrEntry;
|
|
7561
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
7562
|
+
const key = keyNodeOrEntry[0];
|
|
7531
7563
|
if (key === null) return null;
|
|
7532
7564
|
if (key === void 0) return;
|
|
7533
7565
|
return this.getNode(key, this._root, iterationType);
|
|
7534
7566
|
}
|
|
7535
|
-
|
|
7536
|
-
const [key] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
7537
|
-
if (this.isKey(key)) return this.getNode(key);
|
|
7538
|
-
}
|
|
7539
|
-
if (this.isKey(keyNodeEntryOrRaw)) return this.getNode(keyNodeEntryOrRaw, this._root, iterationType);
|
|
7540
|
-
return;
|
|
7567
|
+
return this.getNode(keyNodeOrEntry, this._root, iterationType);
|
|
7541
7568
|
}
|
|
7542
7569
|
/**
|
|
7570
|
+
* Time Complexity: O(1)
|
|
7571
|
+
* Space Complexity: O(1)
|
|
7572
|
+
*
|
|
7543
7573
|
* The function isNode checks if the input is an instance of BinaryTreeNode.
|
|
7544
|
-
* @param {BTNRep<K, V,
|
|
7545
|
-
* `
|
|
7574
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
7575
|
+
* `keyNodeOrEntry` can be either a key, a node, an entry, or raw data. The function is
|
|
7546
7576
|
* checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
|
|
7547
7577
|
* accordingly.
|
|
7548
|
-
* @returns The function `isNode` is checking if the input `
|
|
7578
|
+
* @returns The function `isNode` is checking if the input `keyNodeOrEntry` is an instance of
|
|
7549
7579
|
* `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
|
|
7550
7580
|
* it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
|
|
7551
7581
|
* is not a node.
|
|
7552
7582
|
*/
|
|
7553
|
-
isNode(
|
|
7554
|
-
return
|
|
7583
|
+
isNode(keyNodeOrEntry) {
|
|
7584
|
+
return keyNodeOrEntry instanceof BinaryTreeNode;
|
|
7555
7585
|
}
|
|
7556
7586
|
/**
|
|
7587
|
+
* Time Complexity: O(1)
|
|
7588
|
+
* Space Complexity: O(1)
|
|
7589
|
+
*
|
|
7557
7590
|
* The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
|
|
7558
|
-
* @param {BTNRep<K, V,
|
|
7591
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | R} keyNodeEntryOrRaw - BTNRep<K, V, BinaryTreeNode<K, V>>
|
|
7559
7592
|
* @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
|
|
7560
7593
|
* checking if it is an object. If the parameter is an object, the function will return `true`,
|
|
7561
7594
|
* indicating that it is of type `R`.
|
|
@@ -7564,85 +7597,114 @@ var dataStructureTyped = (() => {
|
|
|
7564
7597
|
return this._toEntryFn !== void 0 && typeof keyNodeEntryOrRaw === "object";
|
|
7565
7598
|
}
|
|
7566
7599
|
/**
|
|
7600
|
+
* Time Complexity: O(1)
|
|
7601
|
+
* Space Complexity: O(1)
|
|
7602
|
+
*
|
|
7567
7603
|
* The function `isRealNode` checks if a given input is a valid node in a binary tree.
|
|
7568
|
-
* @param {BTNRep<K, V,
|
|
7569
|
-
* parameter in the `isRealNode` function can be of type `BTNRep<K, V,
|
|
7570
|
-
* The function checks if the input parameter is a `
|
|
7571
|
-
* @returns The function `isRealNode` is checking if the input `
|
|
7604
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
7605
|
+
* parameter in the `isRealNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
|
|
7606
|
+
* The function checks if the input parameter is a `BinaryTreeNode<K, V>` type by verifying if it is not equal
|
|
7607
|
+
* @returns The function `isRealNode` is checking if the input `keyNodeOrEntry` is a valid
|
|
7572
7608
|
* node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
|
|
7573
7609
|
* values, it then calls the `isNode` method to further determine if the input is a node. The
|
|
7574
7610
|
* function will return a boolean value indicating whether the
|
|
7575
7611
|
*/
|
|
7576
|
-
isRealNode(
|
|
7577
|
-
if (
|
|
7578
|
-
return this.isNode(
|
|
7612
|
+
isRealNode(keyNodeOrEntry) {
|
|
7613
|
+
if (keyNodeOrEntry === this._NIL || keyNodeOrEntry === null || keyNodeOrEntry === void 0) return false;
|
|
7614
|
+
return this.isNode(keyNodeOrEntry);
|
|
7579
7615
|
}
|
|
7580
7616
|
/**
|
|
7617
|
+
* Time Complexity: O(1)
|
|
7618
|
+
* Space Complexity: O(1)
|
|
7619
|
+
*
|
|
7581
7620
|
* The function checks if a given input is a valid node or null.
|
|
7582
|
-
* @param {BTNRep<K, V,
|
|
7583
|
-
* `
|
|
7584
|
-
* V,
|
|
7621
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
7622
|
+
* `keyNodeOrEntry` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
|
|
7623
|
+
* V, BinaryTreeNode<K, V>>` or `R`. It is a union type that can either be a key, a node, an entry, or
|
|
7585
7624
|
* @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
|
|
7586
|
-
* `
|
|
7625
|
+
* `keyNodeOrEntry` is either `null` or a real node, and returns `true` if it is a node or
|
|
7587
7626
|
* `null`, and `false` otherwise.
|
|
7588
7627
|
*/
|
|
7589
|
-
isRealNodeOrNull(
|
|
7590
|
-
return
|
|
7628
|
+
isRealNodeOrNull(keyNodeOrEntry) {
|
|
7629
|
+
return keyNodeOrEntry === null || this.isRealNode(keyNodeOrEntry);
|
|
7591
7630
|
}
|
|
7592
7631
|
/**
|
|
7632
|
+
* Time Complexity: O(1)
|
|
7633
|
+
* Space Complexity: O(1)
|
|
7634
|
+
*
|
|
7593
7635
|
* The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
|
|
7594
|
-
* @param {BTNRep<K, V,
|
|
7595
|
-
*
|
|
7596
|
-
* @returns The function is checking if the `
|
|
7636
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - BTNRep<K, V,
|
|
7637
|
+
* BinaryTreeNode<K, V>>
|
|
7638
|
+
* @returns The function is checking if the `keyNodeOrEntry` parameter is equal to the `_NIL`
|
|
7597
7639
|
* property of the current object and returning a boolean value based on that comparison.
|
|
7598
7640
|
*/
|
|
7599
|
-
isNIL(
|
|
7600
|
-
return
|
|
7641
|
+
isNIL(keyNodeOrEntry) {
|
|
7642
|
+
return keyNodeOrEntry === this._NIL;
|
|
7601
7643
|
}
|
|
7602
|
-
|
|
7603
|
-
|
|
7644
|
+
/**
|
|
7645
|
+
* Time Complexity: O(1)
|
|
7646
|
+
* Space Complexity: O(1)
|
|
7647
|
+
*
|
|
7648
|
+
* The function `isRange` checks if the input parameter is an instance of the `Range` class.
|
|
7649
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>> | Range<K>}
|
|
7650
|
+
* keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
|
|
7651
|
+
* of type `BTNRep<K, V, BinaryTreeNode<K, V>>`, `NodePredicate<BinaryTreeNode<K, V>>`, or
|
|
7652
|
+
* `Range<K>`. The function checks if the `keyNodeEntry
|
|
7653
|
+
* @returns The `isRange` function is checking if the `keyNodeEntryOrPredicate` parameter is an
|
|
7654
|
+
* instance of the `Range` class. If it is an instance of `Range`, the function will return `true`,
|
|
7655
|
+
* indicating that the parameter is a `Range<K>`. If it is not an instance of `Range`, the function
|
|
7656
|
+
* will return `false`.
|
|
7657
|
+
*/
|
|
7658
|
+
isRange(keyNodeEntryOrPredicate) {
|
|
7659
|
+
return keyNodeEntryOrPredicate instanceof Range;
|
|
7604
7660
|
}
|
|
7605
7661
|
/**
|
|
7662
|
+
* Time Complexity: O(1)
|
|
7663
|
+
* Space Complexity: O(1)
|
|
7664
|
+
*
|
|
7606
7665
|
* The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
|
|
7607
7666
|
* tree.
|
|
7608
|
-
* @param {BTNRep<K, V,
|
|
7609
|
-
* `
|
|
7667
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
7668
|
+
* `keyNodeOrEntry` can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It represents a
|
|
7610
7669
|
* key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
|
|
7611
7670
|
* provided
|
|
7612
7671
|
* @returns The function `isLeaf` returns a boolean value indicating whether the input
|
|
7613
|
-
* `
|
|
7672
|
+
* `keyNodeOrEntry` is a leaf node in a binary tree.
|
|
7614
7673
|
*/
|
|
7615
|
-
isLeaf(
|
|
7616
|
-
|
|
7617
|
-
if (
|
|
7618
|
-
if (
|
|
7619
|
-
return !this.isRealNode(
|
|
7674
|
+
isLeaf(keyNodeOrEntry) {
|
|
7675
|
+
keyNodeOrEntry = this.ensureNode(keyNodeOrEntry);
|
|
7676
|
+
if (keyNodeOrEntry === void 0) return false;
|
|
7677
|
+
if (keyNodeOrEntry === null) return true;
|
|
7678
|
+
return !this.isRealNode(keyNodeOrEntry.left) && !this.isRealNode(keyNodeOrEntry.right);
|
|
7620
7679
|
}
|
|
7621
7680
|
/**
|
|
7681
|
+
* Time Complexity: O(1)
|
|
7682
|
+
* Space Complexity: O(1)
|
|
7683
|
+
*
|
|
7622
7684
|
* The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
|
|
7623
7685
|
* with a length of 2.
|
|
7624
|
-
* @param {BTNRep<K, V,
|
|
7625
|
-
* parameter in the `isEntry` function can be of type `BTNRep<K, V,
|
|
7626
|
-
* The function checks if the provided `
|
|
7627
|
-
* @returns The `isEntry` function is checking if the `
|
|
7686
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
7687
|
+
* parameter in the `isEntry` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or type `R`.
|
|
7688
|
+
* The function checks if the provided `keyNodeOrEntry` is of type `BTN
|
|
7689
|
+
* @returns The `isEntry` function is checking if the `keyNodeOrEntry` parameter is an array
|
|
7628
7690
|
* with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
|
|
7629
7691
|
* `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
|
|
7630
7692
|
*/
|
|
7631
|
-
isEntry(
|
|
7632
|
-
return Array.isArray(
|
|
7693
|
+
isEntry(keyNodeOrEntry) {
|
|
7694
|
+
return Array.isArray(keyNodeOrEntry) && keyNodeOrEntry.length === 2;
|
|
7633
7695
|
}
|
|
7634
7696
|
/**
|
|
7635
7697
|
* Time Complexity O(1)
|
|
7636
7698
|
* Space Complexity O(1)
|
|
7637
7699
|
*
|
|
7638
|
-
* The function `
|
|
7700
|
+
* The function `isValidKey` checks if a given key is comparable.
|
|
7639
7701
|
* @param {any} key - The `key` parameter is of type `any`, which means it can be any data type in
|
|
7640
7702
|
* TypeScript.
|
|
7641
|
-
* @returns The function `
|
|
7703
|
+
* @returns The function `isValidKey` is checking if the `key` parameter is `null` or if it is comparable.
|
|
7642
7704
|
* If the `key` is `null`, the function returns `true`. Otherwise, it returns the result of the
|
|
7643
7705
|
* `isComparable` function, which is not provided in the code snippet.
|
|
7644
7706
|
*/
|
|
7645
|
-
|
|
7707
|
+
isValidKey(key) {
|
|
7646
7708
|
if (key === null) return true;
|
|
7647
7709
|
return isComparable(key);
|
|
7648
7710
|
}
|
|
@@ -7652,8 +7714,8 @@ var dataStructureTyped = (() => {
|
|
|
7652
7714
|
*
|
|
7653
7715
|
* The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
|
|
7654
7716
|
* and finding the correct insertion position.
|
|
7655
|
-
* @param {BTNRep<K, V,
|
|
7656
|
-
* seems to be for adding a new node to a binary tree structure. The `
|
|
7717
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `add` method you provided
|
|
7718
|
+
* seems to be for adding a new node to a binary tree structure. The `keyNodeOrEntry`
|
|
7657
7719
|
* parameter in the method can accept different types of values:
|
|
7658
7720
|
* @param {V} [value] - The `value` parameter in the `add` method represents the value associated
|
|
7659
7721
|
* with the key that you want to add to the binary tree. When adding a key-value pair to the binary
|
|
@@ -7663,8 +7725,8 @@ var dataStructureTyped = (() => {
|
|
|
7663
7725
|
* node was successful, and `false` if the insertion position could not be found or if a duplicate
|
|
7664
7726
|
* key was found and the node was replaced instead of inserted.
|
|
7665
7727
|
*/
|
|
7666
|
-
add(
|
|
7667
|
-
const [newNode, newValue] = this.
|
|
7728
|
+
add(keyNodeOrEntry, value) {
|
|
7729
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
7668
7730
|
if (newNode === void 0) return false;
|
|
7669
7731
|
if (!this._root) {
|
|
7670
7732
|
this._setRoot(newNode);
|
|
@@ -7706,14 +7768,14 @@ var dataStructureTyped = (() => {
|
|
|
7706
7768
|
}
|
|
7707
7769
|
/**
|
|
7708
7770
|
* Time Complexity: O(k * n)
|
|
7709
|
-
* Space Complexity: O(
|
|
7771
|
+
* Space Complexity: O(k)
|
|
7710
7772
|
*
|
|
7711
7773
|
* The `addMany` function takes in multiple keys or nodes or entries or raw values along with
|
|
7712
7774
|
* optional values, and adds them to a data structure while returning an array indicating whether
|
|
7713
7775
|
* each insertion was successful.
|
|
7714
7776
|
* @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
|
|
7715
7777
|
* mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
|
|
7716
|
-
* `BTNRep<K, V,
|
|
7778
|
+
* `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
|
|
7717
7779
|
* @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
|
|
7718
7780
|
* accepts an iterable of values. These values correspond to the keys or nodes being added in the
|
|
7719
7781
|
* `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
|
|
@@ -7728,7 +7790,7 @@ var dataStructureTyped = (() => {
|
|
|
7728
7790
|
if (values) {
|
|
7729
7791
|
valuesIterator = values[Symbol.iterator]();
|
|
7730
7792
|
}
|
|
7731
|
-
for (
|
|
7793
|
+
for (let keyNodeEntryOrRaw of keysNodesEntriesOrRaws) {
|
|
7732
7794
|
let value = void 0;
|
|
7733
7795
|
if (valuesIterator) {
|
|
7734
7796
|
const valueResult = valuesIterator.next();
|
|
@@ -7736,6 +7798,7 @@ var dataStructureTyped = (() => {
|
|
|
7736
7798
|
value = valueResult.value;
|
|
7737
7799
|
}
|
|
7738
7800
|
}
|
|
7801
|
+
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
7739
7802
|
inserted.push(this.add(keyNodeEntryOrRaw, value));
|
|
7740
7803
|
}
|
|
7741
7804
|
return inserted;
|
|
@@ -7746,7 +7809,7 @@ var dataStructureTyped = (() => {
|
|
|
7746
7809
|
*
|
|
7747
7810
|
* The `merge` function in TypeScript merges another binary tree into the current tree by adding all
|
|
7748
7811
|
* elements from the other tree.
|
|
7749
|
-
* @param anotherTree -
|
|
7812
|
+
* @param anotherTree - BinaryTree<K, V, R, MK, MV, MR>
|
|
7750
7813
|
*/
|
|
7751
7814
|
merge(anotherTree) {
|
|
7752
7815
|
this.addMany(anotherTree, []);
|
|
@@ -7758,7 +7821,7 @@ var dataStructureTyped = (() => {
|
|
|
7758
7821
|
* The `refill` function clears the existing data structure and then adds new key-value pairs based
|
|
7759
7822
|
* on the provided input.
|
|
7760
7823
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
|
|
7761
|
-
* method can accept an iterable containing a mix of `BTNRep<K, V,
|
|
7824
|
+
* method can accept an iterable containing a mix of `BTNRep<K, V, BinaryTreeNode<K, V>>` objects or `R`
|
|
7762
7825
|
* objects.
|
|
7763
7826
|
* @param [values] - The `values` parameter in the `refill` method is an optional parameter that
|
|
7764
7827
|
* accepts an iterable of values of type `V` or `undefined`.
|
|
@@ -7773,7 +7836,7 @@ var dataStructureTyped = (() => {
|
|
|
7773
7836
|
*
|
|
7774
7837
|
* The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
|
|
7775
7838
|
* the deleted node along with information for tree balancing.
|
|
7776
|
-
* @param {BTNRep<K, V,
|
|
7839
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry
|
|
7777
7840
|
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
|
|
7778
7841
|
* node, entry or raw data. The method returns an array of
|
|
7779
7842
|
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
|
|
@@ -7782,10 +7845,10 @@ var dataStructureTyped = (() => {
|
|
|
7782
7845
|
* the array contains information about the node that was deleted (`deleted`) and the node that may
|
|
7783
7846
|
* need to be balanced (`needBalanced`).
|
|
7784
7847
|
*/
|
|
7785
|
-
delete(
|
|
7848
|
+
delete(keyNodeOrEntry) {
|
|
7786
7849
|
const deletedResult = [];
|
|
7787
7850
|
if (!this._root) return deletedResult;
|
|
7788
|
-
const curr = this.getNode(
|
|
7851
|
+
const curr = this.getNode(keyNodeOrEntry);
|
|
7789
7852
|
if (!curr) return deletedResult;
|
|
7790
7853
|
const parent = curr == null ? void 0 : curr.parent;
|
|
7791
7854
|
let needBalanced;
|
|
@@ -7827,15 +7890,15 @@ var dataStructureTyped = (() => {
|
|
|
7827
7890
|
*
|
|
7828
7891
|
* The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
|
|
7829
7892
|
* structure based on a given predicate or key, with options to return multiple results or just one.
|
|
7830
|
-
* @param {BTNRep<K, V,
|
|
7831
|
-
* `
|
|
7893
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
7894
|
+
* `keyNodeEntryOrPredicate` parameter in the `search` function can accept three types of values:
|
|
7832
7895
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
|
|
7833
7896
|
* determines whether the search should stop after finding the first matching node. If `onlyOne` is
|
|
7834
7897
|
* set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
|
|
7835
7898
|
* @param {C} callback - The `callback` parameter in the `search` function is a callback function
|
|
7836
7899
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
7837
|
-
* extends `NodeCallback<
|
|
7838
|
-
* @param {BTNRep<K, V,
|
|
7900
|
+
* extends `NodeCallback<BinaryTreeNode<K, V>>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
|
|
7901
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `search` function is
|
|
7839
7902
|
* used to specify the node from which the search operation should begin. It represents the starting
|
|
7840
7903
|
* point in the binary tree where the search will be performed. If no specific `startNode` is
|
|
7841
7904
|
* provided, the search operation will start from the root
|
|
@@ -7845,12 +7908,12 @@ var dataStructureTyped = (() => {
|
|
|
7845
7908
|
* @returns The `search` function returns an array of values that match the provided criteria based
|
|
7846
7909
|
* on the search algorithm implemented within the function.
|
|
7847
7910
|
*/
|
|
7848
|
-
search(
|
|
7849
|
-
if (
|
|
7850
|
-
if (
|
|
7911
|
+
search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
7912
|
+
if (keyNodeEntryOrPredicate === void 0) return [];
|
|
7913
|
+
if (keyNodeEntryOrPredicate === null) return [];
|
|
7851
7914
|
startNode = this.ensureNode(startNode);
|
|
7852
7915
|
if (!startNode) return [];
|
|
7853
|
-
const predicate = this._ensurePredicate(
|
|
7916
|
+
const predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
7854
7917
|
const ans = [];
|
|
7855
7918
|
if (iterationType === "RECURSIVE") {
|
|
7856
7919
|
const dfs = (cur) => {
|
|
@@ -7885,12 +7948,12 @@ var dataStructureTyped = (() => {
|
|
|
7885
7948
|
*
|
|
7886
7949
|
* The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
|
|
7887
7950
|
* or predicate, with options for recursive or iterative traversal.
|
|
7888
|
-
* @param {BTNRep<K, V,
|
|
7951
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
7889
7952
|
* - The `getNodes` function you provided takes several parameters:
|
|
7890
7953
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
|
|
7891
7954
|
* determines whether to return only the first node that matches the criteria specified by the
|
|
7892
|
-
* `
|
|
7893
|
-
* @param {BTNRep<K, V,
|
|
7955
|
+
* `keyNodeEntryOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
|
|
7956
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
7894
7957
|
* `getNodes` function is used to specify the starting point for traversing the binary tree. It
|
|
7895
7958
|
* represents the root node of the binary tree or the node from which the traversal should begin. If
|
|
7896
7959
|
* not provided, the default value is set to `this._root
|
|
@@ -7900,19 +7963,19 @@ var dataStructureTyped = (() => {
|
|
|
7900
7963
|
* @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
|
|
7901
7964
|
* based on the input parameters and the iteration type specified.
|
|
7902
7965
|
*/
|
|
7903
|
-
getNodes(
|
|
7904
|
-
return this.search(
|
|
7966
|
+
getNodes(keyNodeEntryOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
|
|
7967
|
+
return this.search(keyNodeEntryOrPredicate, onlyOne, (node) => node, startNode, iterationType);
|
|
7905
7968
|
}
|
|
7906
7969
|
/**
|
|
7907
7970
|
* Time Complexity: O(n)
|
|
7908
|
-
* Space Complexity: O(log n)
|
|
7971
|
+
* Space Complexity: O(log n)
|
|
7909
7972
|
*
|
|
7910
7973
|
* The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
|
|
7911
7974
|
* predicate.
|
|
7912
|
-
* @param {BTNRep<K, V,
|
|
7913
|
-
* - The `
|
|
7975
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
7976
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `getNode` function can accept a key,
|
|
7914
7977
|
* node, entry, raw data, or a predicate function.
|
|
7915
|
-
* @param {BTNRep<K, V,
|
|
7978
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
7916
7979
|
* `getNode` function is used to specify the starting point for searching for a node in a binary
|
|
7917
7980
|
* tree. If no specific starting point is provided, the default value is set to `this._root`, which
|
|
7918
7981
|
* is typically the root node of the binary tree.
|
|
@@ -7923,9 +7986,8 @@ var dataStructureTyped = (() => {
|
|
|
7923
7986
|
* @returns The `getNode` function is returning the first node that matches the specified criteria,
|
|
7924
7987
|
* or `null` if no matching node is found.
|
|
7925
7988
|
*/
|
|
7926
|
-
getNode(
|
|
7927
|
-
|
|
7928
|
-
return (_a = this.search(keyNodeEntryRawOrPredicate, true, (node) => node, startNode, iterationType)[0]) != null ? _a : null;
|
|
7989
|
+
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7990
|
+
return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType)[0];
|
|
7929
7991
|
}
|
|
7930
7992
|
/**
|
|
7931
7993
|
* Time Complexity: O(n)
|
|
@@ -7933,10 +7995,10 @@ var dataStructureTyped = (() => {
|
|
|
7933
7995
|
*
|
|
7934
7996
|
* This function overrides the `get` method to retrieve the value associated with a specified key,
|
|
7935
7997
|
* node, entry, raw data, or predicate in a data structure.
|
|
7936
|
-
* @param {BTNRep<K, V,
|
|
7937
|
-
* - The `
|
|
7998
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
7999
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `get` method can accept one of the
|
|
7938
8000
|
* following types:
|
|
7939
|
-
* @param {BTNRep<K, V,
|
|
8001
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `get`
|
|
7940
8002
|
* method is used to specify the starting point for searching for a key or node in the binary tree.
|
|
7941
8003
|
* If no specific starting point is provided, the default starting point is the root of the binary
|
|
7942
8004
|
* tree (`this._root`).
|
|
@@ -7949,14 +8011,14 @@ var dataStructureTyped = (() => {
|
|
|
7949
8011
|
* the method returns the corresponding value. If the key or node is not found, it returns
|
|
7950
8012
|
* `undefined`.
|
|
7951
8013
|
*/
|
|
7952
|
-
get(
|
|
8014
|
+
get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7953
8015
|
var _a;
|
|
7954
8016
|
if (this._isMapMode) {
|
|
7955
|
-
const key = this._extractKey(
|
|
8017
|
+
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
7956
8018
|
if (key === null || key === void 0) return;
|
|
7957
8019
|
return this._store.get(key);
|
|
7958
8020
|
}
|
|
7959
|
-
return (_a = this.getNode(
|
|
8021
|
+
return (_a = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
|
|
7960
8022
|
}
|
|
7961
8023
|
/**
|
|
7962
8024
|
* Time Complexity: O(n)
|
|
@@ -7964,10 +8026,10 @@ var dataStructureTyped = (() => {
|
|
|
7964
8026
|
*
|
|
7965
8027
|
* The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
|
|
7966
8028
|
* exists in the data structure.
|
|
7967
|
-
* @param {BTNRep<K, V,
|
|
7968
|
-
* - The `
|
|
8029
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
8030
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `override has` method can accept one of
|
|
7969
8031
|
* the following types:
|
|
7970
|
-
* @param {BTNRep<K, V,
|
|
8032
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
7971
8033
|
* `override` method is used to specify the starting point for the search operation within the data
|
|
7972
8034
|
* structure. It defaults to `this._root` if not provided explicitly.
|
|
7973
8035
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
|
|
@@ -7979,14 +8041,14 @@ var dataStructureTyped = (() => {
|
|
|
7979
8041
|
* are matching nodes, it returns `true`, indicating that the tree contains the specified element.
|
|
7980
8042
|
* Otherwise, it returns `false`.
|
|
7981
8043
|
*/
|
|
7982
|
-
has(
|
|
7983
|
-
return this.search(
|
|
8044
|
+
has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
8045
|
+
return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
|
|
7984
8046
|
}
|
|
7985
8047
|
/**
|
|
7986
8048
|
* Time Complexity: O(1)
|
|
7987
8049
|
* Space Complexity: O(1)
|
|
7988
8050
|
*
|
|
7989
|
-
* The
|
|
8051
|
+
* The clear function removes nodes and values in map mode.
|
|
7990
8052
|
*/
|
|
7991
8053
|
clear() {
|
|
7992
8054
|
this._clearNodes();
|
|
@@ -8010,7 +8072,7 @@ var dataStructureTyped = (() => {
|
|
|
8010
8072
|
*
|
|
8011
8073
|
* The function checks if a binary tree is perfectly balanced by comparing its minimum height with
|
|
8012
8074
|
* its height.
|
|
8013
|
-
* @param {BTNRep<K, V,
|
|
8075
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
8014
8076
|
* point for checking if the binary tree is perfectly balanced. It represents the root node of the
|
|
8015
8077
|
* binary tree or a specific node from which the balance check should begin.
|
|
8016
8078
|
* @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
|
|
@@ -8024,11 +8086,11 @@ var dataStructureTyped = (() => {
|
|
|
8024
8086
|
}
|
|
8025
8087
|
/**
|
|
8026
8088
|
* Time Complexity: O(n)
|
|
8027
|
-
* Space Complexity: O(
|
|
8089
|
+
* Space Complexity: O(log n)
|
|
8028
8090
|
*
|
|
8029
8091
|
* The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
|
|
8030
8092
|
* or iterative methods.
|
|
8031
|
-
* @param {BTNRep<K, V,
|
|
8093
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `isBST`
|
|
8032
8094
|
* function represents the starting point for checking whether a binary search tree (BST) is valid.
|
|
8033
8095
|
* It can be a node in the BST or a reference to the root of the BST. If no specific node is
|
|
8034
8096
|
* provided, the function will default to
|
|
@@ -8077,13 +8139,13 @@ var dataStructureTyped = (() => {
|
|
|
8077
8139
|
}
|
|
8078
8140
|
/**
|
|
8079
8141
|
* Time Complexity: O(n)
|
|
8080
|
-
* Space Complexity: O(
|
|
8142
|
+
* Space Complexity: O(log n)
|
|
8081
8143
|
*
|
|
8082
8144
|
* The `getDepth` function calculates the depth between two nodes in a binary tree.
|
|
8083
|
-
* @param {BTNRep<K, V,
|
|
8145
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} dist - The `dist` parameter in the `getDepth`
|
|
8084
8146
|
* function represents the node or entry in a binary tree map, or a reference to a node in the tree.
|
|
8085
8147
|
* It is the target node for which you want to calculate the depth from the `startNode` node.
|
|
8086
|
-
* @param {BTNRep<K, V,
|
|
8148
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
8087
8149
|
* `getDepth` function represents the starting point from which you want to calculate the depth of a
|
|
8088
8150
|
* given node or entry in a binary tree. If no specific starting point is provided, the default value
|
|
8089
8151
|
* for `startNode` is set to the root of the binary
|
|
@@ -8106,11 +8168,11 @@ var dataStructureTyped = (() => {
|
|
|
8106
8168
|
}
|
|
8107
8169
|
/**
|
|
8108
8170
|
* Time Complexity: O(n)
|
|
8109
|
-
* Space Complexity: O(
|
|
8171
|
+
* Space Complexity: O(log n)
|
|
8110
8172
|
*
|
|
8111
8173
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
8112
8174
|
* or iterative approach in TypeScript.
|
|
8113
|
-
* @param {BTNRep<K, V,
|
|
8175
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
8114
8176
|
* point from which the height of the binary tree will be calculated. It can be a node in the binary
|
|
8115
8177
|
* tree or a reference to the root of the tree. If not provided, it defaults to the root of the
|
|
8116
8178
|
* binary tree data structure.
|
|
@@ -8150,7 +8212,7 @@ var dataStructureTyped = (() => {
|
|
|
8150
8212
|
*
|
|
8151
8213
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
8152
8214
|
* recursive or iterative approach in TypeScript.
|
|
8153
|
-
* @param {BTNRep<K, V,
|
|
8215
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
8154
8216
|
* `getMinHeight` function represents the starting node from which the minimum height of the binary
|
|
8155
8217
|
* tree will be calculated. It is either a node in the binary tree or a reference to the root of the
|
|
8156
8218
|
* tree. If not provided, the default value is the root
|
|
@@ -8209,7 +8271,7 @@ var dataStructureTyped = (() => {
|
|
|
8209
8271
|
* the path to the root. It is expected to be a function that takes a node as an argument and returns
|
|
8210
8272
|
* a value based on that node. The return type of the callback function is determined by the generic
|
|
8211
8273
|
* type `C
|
|
8212
|
-
* @param {BTNRep<K, V,
|
|
8274
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} beginNode - The `beginNode` parameter in the
|
|
8213
8275
|
* `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
|
|
8214
8276
|
* @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
|
|
8215
8277
|
* whether the resulting path from the given `beginNode` to the root should be in reverse order or
|
|
@@ -8232,14 +8294,14 @@ var dataStructureTyped = (() => {
|
|
|
8232
8294
|
}
|
|
8233
8295
|
/**
|
|
8234
8296
|
* Time Complexity: O(log n)
|
|
8235
|
-
* Space Complexity: O(
|
|
8297
|
+
* Space Complexity: O(log n)
|
|
8236
8298
|
*
|
|
8237
8299
|
* The function `getLeftMost` retrieves the leftmost node in a binary tree using either recursive or
|
|
8238
8300
|
* tail-recursive iteration.
|
|
8239
8301
|
* @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
|
|
8240
8302
|
* node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
|
|
8241
8303
|
* value of `_DEFAULT_NODE_CALLBACK` if not specified.
|
|
8242
|
-
* @param {BTNRep<K, V,
|
|
8304
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
8243
8305
|
* `getLeftMost` function represents the starting point for finding the leftmost node in a binary
|
|
8244
8306
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
8245
8307
|
* starting point is provided, the function will default
|
|
@@ -8271,15 +8333,15 @@ var dataStructureTyped = (() => {
|
|
|
8271
8333
|
}
|
|
8272
8334
|
/**
|
|
8273
8335
|
* Time Complexity: O(log n)
|
|
8274
|
-
* Space Complexity: O(
|
|
8336
|
+
* Space Complexity: O(log n)
|
|
8275
8337
|
*
|
|
8276
8338
|
* The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
|
|
8277
8339
|
* or iterative traversal methods.
|
|
8278
8340
|
* @param {C} callback - The `callback` parameter is a function that will be called with the result
|
|
8279
|
-
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<
|
|
8341
|
+
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`,
|
|
8280
8342
|
* which means it is a callback function that can accept either an optional binary tree node or null
|
|
8281
8343
|
* as
|
|
8282
|
-
* @param {BTNRep<K, V,
|
|
8344
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
8283
8345
|
* `getRightMost` function represents the starting point for finding the rightmost node in a binary
|
|
8284
8346
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
8285
8347
|
* starting point is provided, the function will default
|
|
@@ -8311,14 +8373,14 @@ var dataStructureTyped = (() => {
|
|
|
8311
8373
|
}
|
|
8312
8374
|
/**
|
|
8313
8375
|
* Time Complexity: O(log n)
|
|
8314
|
-
* Space Complexity: O(
|
|
8376
|
+
* Space Complexity: O(log n)
|
|
8315
8377
|
*
|
|
8316
8378
|
* The function `getPredecessor` in TypeScript returns the predecessor node of a given node in a
|
|
8317
8379
|
* binary tree.
|
|
8318
|
-
* @param {
|
|
8380
|
+
* @param {BinaryTreeNode<K, V>} node - The `getPredecessor` function you provided seems to be attempting to find the
|
|
8319
8381
|
* predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
|
|
8320
8382
|
* while loop condition that might cause an infinite loop.
|
|
8321
|
-
* @returns The `getPredecessor` function returns the predecessor node of the input `
|
|
8383
|
+
* @returns The `getPredecessor` function returns the predecessor node of the input `BinaryTreeNode<K, V>` parameter.
|
|
8322
8384
|
* If the left child of the input node exists, it traverses to the rightmost node of the left subtree
|
|
8323
8385
|
* to find the predecessor. If the left child does not exist, it returns the input node itself.
|
|
8324
8386
|
*/
|
|
@@ -8337,12 +8399,12 @@ var dataStructureTyped = (() => {
|
|
|
8337
8399
|
}
|
|
8338
8400
|
/**
|
|
8339
8401
|
* Time Complexity: O(log n)
|
|
8340
|
-
* Space Complexity: O(
|
|
8402
|
+
* Space Complexity: O(log n)
|
|
8341
8403
|
*
|
|
8342
8404
|
* The function `getSuccessor` in TypeScript returns the next node in an in-order traversal of a
|
|
8343
8405
|
* binary tree.
|
|
8344
|
-
* @param {K |
|
|
8345
|
-
* type `K`, `
|
|
8406
|
+
* @param {K | BinaryTreeNode<K, V> | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
|
|
8407
|
+
* type `K`, `BinaryTreeNode<K, V>`, or `null`.
|
|
8346
8408
|
* @returns The `getSuccessor` function returns the successor node of the input node `x`. If `x` has
|
|
8347
8409
|
* a right child, the function returns the leftmost node in the right subtree of `x`. If `x` does not
|
|
8348
8410
|
* have a right child, the function traverses up the parent nodes until it finds a node that is not
|
|
@@ -8368,12 +8430,12 @@ var dataStructureTyped = (() => {
|
|
|
8368
8430
|
* The function `dfs` performs a depth-first search traversal on a binary tree structure based on the
|
|
8369
8431
|
* specified parameters.
|
|
8370
8432
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends the
|
|
8371
|
-
* `NodeCallback` interface with a type parameter of `OptNodeOrNull<
|
|
8433
|
+
* `NodeCallback` interface with a type parameter of `OptNodeOrNull<BinaryTreeNode<K, V>>`. It has a default value of
|
|
8372
8434
|
* `this._DEFAULT_NODE_CALLBACK as C`.
|
|
8373
8435
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` method specifies the
|
|
8374
8436
|
* order in which the Depth-First Search (DFS) algorithm should traverse the nodes in the tree. The
|
|
8375
8437
|
* possible values for the `pattern` parameter are:
|
|
8376
|
-
* @param {BTNRep<K, V,
|
|
8438
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `dfs`
|
|
8377
8439
|
* method is used to specify the starting point for the Depth-First Search traversal. It can be
|
|
8378
8440
|
* either a `BTNRep` object representing a key, node, or entry in the binary tree map,
|
|
8379
8441
|
* or it can be a
|
|
@@ -8400,8 +8462,8 @@ var dataStructureTyped = (() => {
|
|
|
8400
8462
|
* tree, executing a specified callback function on each node visited.
|
|
8401
8463
|
* @param {C} callback - The `callback` parameter in the `bfs` function is a function that will be
|
|
8402
8464
|
* called on each node visited during the breadth-first search traversal. It is a generic type `C`
|
|
8403
|
-
* that extends the `NodeCallback` type, which takes a parameter of type `
|
|
8404
|
-
* @param {BTNRep<K, V,
|
|
8465
|
+
* that extends the `NodeCallback` type, which takes a parameter of type `BinaryTreeNode<K, V>` or `null`.
|
|
8466
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `bfs`
|
|
8405
8467
|
* function represents the starting point for the breadth-first search traversal in a binary tree. It
|
|
8406
8468
|
* can be specified as a key, node, or entry in the binary tree structure. If not provided, the
|
|
8407
8469
|
* default value is the root node of the binary
|
|
@@ -8420,7 +8482,9 @@ var dataStructureTyped = (() => {
|
|
|
8420
8482
|
if (!startNode) return [];
|
|
8421
8483
|
const ans = [];
|
|
8422
8484
|
if (iterationType === "RECURSIVE") {
|
|
8423
|
-
const queue = new Queue([
|
|
8485
|
+
const queue = new Queue([
|
|
8486
|
+
startNode
|
|
8487
|
+
]);
|
|
8424
8488
|
const dfs = (level) => {
|
|
8425
8489
|
if (queue.size === 0) return;
|
|
8426
8490
|
const current = queue.shift();
|
|
@@ -8462,7 +8526,7 @@ var dataStructureTyped = (() => {
|
|
|
8462
8526
|
* structure based on a specified callback and iteration type.
|
|
8463
8527
|
* @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
|
|
8464
8528
|
* in the binary tree. It is optional and defaults to a default callback function if not provided.
|
|
8465
|
-
* @param {BTNRep<K, V,
|
|
8529
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `leaves`
|
|
8466
8530
|
* method is used to specify the starting point for finding and processing the leaves of a binary
|
|
8467
8531
|
* tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
|
|
8468
8532
|
* explicitly provided, the default value
|
|
@@ -8510,7 +8574,7 @@ var dataStructureTyped = (() => {
|
|
|
8510
8574
|
* @param {C} callback - The `callback` parameter is a function that will be applied to each node in
|
|
8511
8575
|
* the binary tree during the traversal. It is used to process each node and determine what
|
|
8512
8576
|
* information to include in the output for each level of the tree.
|
|
8513
|
-
* @param {BTNRep<K, V,
|
|
8577
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
8514
8578
|
* `listLevels` function represents the starting point for traversing the binary tree. It can be
|
|
8515
8579
|
* either a key, a node, or an entry in the binary tree. If not provided, the default value is the
|
|
8516
8580
|
* root of the binary tree.
|
|
@@ -8568,11 +8632,11 @@ var dataStructureTyped = (() => {
|
|
|
8568
8632
|
* Morris Traversal algorithm with different order patterns.
|
|
8569
8633
|
* @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
|
|
8570
8634
|
* called on each node in the binary tree during the traversal. It is of type `C`, which extends the
|
|
8571
|
-
* `NodeCallback<
|
|
8635
|
+
* `NodeCallback<BinaryTreeNode<K, V>>` type. The default value for `callback` is `this._DEFAULT
|
|
8572
8636
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
|
|
8573
8637
|
* the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
|
|
8574
8638
|
* values for the `pattern` parameter are:
|
|
8575
|
-
* @param {BTNRep<K, V,
|
|
8639
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `morris`
|
|
8576
8640
|
* function is the starting point for the Morris traversal algorithm. It represents the root node of
|
|
8577
8641
|
* the binary tree or the node from which the traversal should begin. It can be provided as either a
|
|
8578
8642
|
* key, a node, an entry, or a reference
|
|
@@ -8673,6 +8737,10 @@ var dataStructureTyped = (() => {
|
|
|
8673
8737
|
*/
|
|
8674
8738
|
clone() {
|
|
8675
8739
|
const cloned = this.createTree();
|
|
8740
|
+
this._clone(cloned);
|
|
8741
|
+
return cloned;
|
|
8742
|
+
}
|
|
8743
|
+
_clone(cloned) {
|
|
8676
8744
|
this.bfs(
|
|
8677
8745
|
(node) => {
|
|
8678
8746
|
if (node === null) cloned.add(null);
|
|
@@ -8686,7 +8754,6 @@ var dataStructureTyped = (() => {
|
|
|
8686
8754
|
true
|
|
8687
8755
|
);
|
|
8688
8756
|
if (this._isMapMode) cloned._store = this._store;
|
|
8689
|
-
return cloned;
|
|
8690
8757
|
}
|
|
8691
8758
|
/**
|
|
8692
8759
|
* Time Complexity: O(n)
|
|
@@ -8747,7 +8814,7 @@ var dataStructureTyped = (() => {
|
|
|
8747
8814
|
*
|
|
8748
8815
|
* The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
|
|
8749
8816
|
* customizable options for displaying undefined, null, and sentinel nodes.
|
|
8750
|
-
* @param {BTNRep<K, V,
|
|
8817
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
8751
8818
|
* `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
|
|
8752
8819
|
* It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
|
|
8753
8820
|
* the default is set to the root
|
|
@@ -8771,7 +8838,7 @@ var dataStructureTyped = (() => {
|
|
|
8771
8838
|
if (opts.isShowRedBlackNIL) output += `S for Sentinel Node(NIL)
|
|
8772
8839
|
`;
|
|
8773
8840
|
const display = (root) => {
|
|
8774
|
-
const [lines
|
|
8841
|
+
const [lines] = this._displayAux(root, opts);
|
|
8775
8842
|
let paragraph = "";
|
|
8776
8843
|
for (const line of lines) {
|
|
8777
8844
|
paragraph += line + "\n";
|
|
@@ -8791,7 +8858,7 @@ var dataStructureTyped = (() => {
|
|
|
8791
8858
|
* printing options for the binary tree. It is an optional parameter that allows you to customize how
|
|
8792
8859
|
* the binary tree is printed, such as choosing between different traversal orders or formatting
|
|
8793
8860
|
* options.
|
|
8794
|
-
* @param {BTNRep<K, V,
|
|
8861
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
8795
8862
|
* `override print` method is used to specify the starting point for printing the binary tree. It can
|
|
8796
8863
|
* be either a key, a node, an entry, or the root of the tree. If no specific starting point is
|
|
8797
8864
|
* provided, the default value is set to
|
|
@@ -8800,38 +8867,35 @@ var dataStructureTyped = (() => {
|
|
|
8800
8867
|
console.log(this.toVisual(startNode, options));
|
|
8801
8868
|
}
|
|
8802
8869
|
/**
|
|
8870
|
+
* Time Complexity: O(1)
|
|
8871
|
+
* Space Complexity: O(1)
|
|
8872
|
+
*
|
|
8803
8873
|
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
8804
8874
|
* or returns null.
|
|
8805
|
-
* @param {BTNRep<K, V,
|
|
8806
|
-
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `
|
|
8807
|
-
* can be of type `BTNRep<K, V,
|
|
8875
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The
|
|
8876
|
+
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeOrEntry`, which
|
|
8877
|
+
* can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. This parameter represents either a key, a
|
|
8808
8878
|
* node, an entry
|
|
8809
8879
|
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
8810
8880
|
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
8811
8881
|
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
8812
8882
|
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
8813
|
-
* (`OptNodeOrNull<
|
|
8814
|
-
* input parameter (`
|
|
8883
|
+
* (`OptNodeOrNull<BinaryTreeNode<K, V>>`) based on the input parameters provided. The function checks the type of the
|
|
8884
|
+
* input parameter (`keyNodeOrEntry`) and processes it accordingly to return a node or null
|
|
8815
8885
|
* value.
|
|
8816
8886
|
*/
|
|
8817
|
-
|
|
8818
|
-
if (
|
|
8819
|
-
if (
|
|
8820
|
-
if (this.isNode(
|
|
8821
|
-
if (this.isEntry(
|
|
8822
|
-
const [key, entryValue] =
|
|
8887
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
|
|
8888
|
+
if (keyNodeOrEntry === void 0) return [void 0, void 0];
|
|
8889
|
+
if (keyNodeOrEntry === null) return [null, void 0];
|
|
8890
|
+
if (this.isNode(keyNodeOrEntry)) return [keyNodeOrEntry, value];
|
|
8891
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
8892
|
+
const [key, entryValue] = keyNodeOrEntry;
|
|
8823
8893
|
if (key === void 0) return [void 0, void 0];
|
|
8824
8894
|
else if (key === null) return [null, void 0];
|
|
8825
8895
|
const finalValue = value != null ? value : entryValue;
|
|
8826
8896
|
return [this.createNode(key, finalValue), finalValue];
|
|
8827
8897
|
}
|
|
8828
|
-
|
|
8829
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
8830
|
-
const finalValue = value != null ? value : entryValue;
|
|
8831
|
-
if (this.isKey(key)) return [this.createNode(key, finalValue), finalValue];
|
|
8832
|
-
}
|
|
8833
|
-
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value), value];
|
|
8834
|
-
return [void 0, void 0];
|
|
8898
|
+
return [this.createNode(keyNodeOrEntry, value), value];
|
|
8835
8899
|
}
|
|
8836
8900
|
/**
|
|
8837
8901
|
* Time complexity: O(n)
|
|
@@ -8841,11 +8905,11 @@ var dataStructureTyped = (() => {
|
|
|
8841
8905
|
* the specified order pattern and callback function.
|
|
8842
8906
|
* @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
|
|
8843
8907
|
* called on each node visited during the depth-first search traversal. It is of type `C`, which
|
|
8844
|
-
* extends `NodeCallback<OptNodeOrNull<
|
|
8908
|
+
* extends `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`. The default value for this parameter is `this._DEFAULT
|
|
8845
8909
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
|
|
8846
8910
|
* order in which the nodes are visited during the Depth-First Search traversal. It can have one of
|
|
8847
8911
|
* the following values:
|
|
8848
|
-
* @param {BTNRep<K, V,
|
|
8912
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `_dfs`
|
|
8849
8913
|
* method is used to specify the starting point for the depth-first search traversal in a binary
|
|
8850
8914
|
* tree. It can be provided as either a `BTNRep` object or a reference to the root node
|
|
8851
8915
|
* of the tree. If no specific
|
|
@@ -9055,12 +9119,12 @@ var dataStructureTyped = (() => {
|
|
|
9055
9119
|
* Space Complexity: O(1)
|
|
9056
9120
|
*
|
|
9057
9121
|
* The _swapProperties function swaps key and value properties between two nodes in a binary tree.
|
|
9058
|
-
* @param {BTNRep<K, V,
|
|
9122
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} srcNode - The `srcNode` parameter in the
|
|
9059
9123
|
* `_swapProperties` method can be either a BTNRep object containing key and value
|
|
9060
9124
|
* properties, or it can be of type R.
|
|
9061
|
-
* @param {BTNRep<K, V,
|
|
9125
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} destNode - The `destNode` parameter in the
|
|
9062
9126
|
* `_swapProperties` method represents the node or entry where the properties will be swapped with
|
|
9063
|
-
* the `srcNode`. It can be of type `BTNRep<K, V,
|
|
9127
|
+
* the `srcNode`. It can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. The method ensures that
|
|
9064
9128
|
* both `srcNode
|
|
9065
9129
|
* @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
|
|
9066
9130
|
* with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
@@ -9086,9 +9150,9 @@ var dataStructureTyped = (() => {
|
|
|
9086
9150
|
* Space Complexity: O(1)
|
|
9087
9151
|
*
|
|
9088
9152
|
* The _replaceNode function replaces an old node with a new node in a binary tree structure.
|
|
9089
|
-
* @param {
|
|
9153
|
+
* @param {BinaryTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that you want to replace in a
|
|
9090
9154
|
* tree data structure.
|
|
9091
|
-
* @param {
|
|
9155
|
+
* @param {BinaryTreeNode<K, V>} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
|
|
9092
9156
|
* that will replace the `oldNode` in a tree data structure. This function is responsible for
|
|
9093
9157
|
* updating the parent, left child, right child, and root (if necessary) references when replacing a
|
|
9094
9158
|
* node in the tree.
|
|
@@ -9117,8 +9181,8 @@ var dataStructureTyped = (() => {
|
|
|
9117
9181
|
*
|
|
9118
9182
|
* The function _setRoot sets the root node of a data structure while updating the parent reference
|
|
9119
9183
|
* of the previous root node.
|
|
9120
|
-
* @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<
|
|
9121
|
-
* it can either be an optional `
|
|
9184
|
+
* @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<BinaryTreeNode<K, V>>`, which means
|
|
9185
|
+
* it can either be an optional `BinaryTreeNode<K, V>` type or `null`.
|
|
9122
9186
|
*/
|
|
9123
9187
|
_setRoot(v) {
|
|
9124
9188
|
if (v) {
|
|
@@ -9132,27 +9196,23 @@ var dataStructureTyped = (() => {
|
|
|
9132
9196
|
*
|
|
9133
9197
|
* The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
|
|
9134
9198
|
* predicate function for a binary tree node.
|
|
9135
|
-
* @param {BTNRep<K, V,
|
|
9199
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
9136
9200
|
* `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
|
|
9137
|
-
* parameter `
|
|
9201
|
+
* parameter `keyNodeEntryOrPredicate` is transformed into a valid predicate function that can be
|
|
9138
9202
|
* used for filtering nodes in a binary tree.
|
|
9139
|
-
* @returns A NodePredicate<
|
|
9203
|
+
* @returns A NodePredicate<BinaryTreeNode<K, V>> function is being returned.
|
|
9140
9204
|
*/
|
|
9141
|
-
_ensurePredicate(
|
|
9142
|
-
if (
|
|
9205
|
+
_ensurePredicate(keyNodeEntryOrPredicate) {
|
|
9206
|
+
if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0)
|
|
9143
9207
|
return (node) => node ? false : false;
|
|
9144
|
-
if (this._isPredicate(
|
|
9145
|
-
if (this.isRealNode(
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
}
|
|
9150
|
-
if (this.isKey(keyNodeEntryRawOrPredicate)) return (node) => node.key === keyNodeEntryRawOrPredicate;
|
|
9151
|
-
if (this._toEntryFn) {
|
|
9152
|
-
const [key] = this._toEntryFn(keyNodeEntryRawOrPredicate);
|
|
9208
|
+
if (this._isPredicate(keyNodeEntryOrPredicate)) return keyNodeEntryOrPredicate;
|
|
9209
|
+
if (this.isRealNode(keyNodeEntryOrPredicate))
|
|
9210
|
+
return (node) => node === keyNodeEntryOrPredicate;
|
|
9211
|
+
if (this.isEntry(keyNodeEntryOrPredicate)) {
|
|
9212
|
+
const [key] = keyNodeEntryOrPredicate;
|
|
9153
9213
|
return (node) => node.key === key;
|
|
9154
9214
|
}
|
|
9155
|
-
return (node) => node.key ===
|
|
9215
|
+
return (node) => node.key === keyNodeEntryOrPredicate;
|
|
9156
9216
|
}
|
|
9157
9217
|
/**
|
|
9158
9218
|
* Time Complexity: O(1)
|
|
@@ -9161,7 +9221,7 @@ var dataStructureTyped = (() => {
|
|
|
9161
9221
|
* The function `_isPredicate` checks if a given parameter is a function.
|
|
9162
9222
|
* @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
|
|
9163
9223
|
* of value. In this context, the function `_isPredicate` is checking if `p` is a function that
|
|
9164
|
-
* satisfies the type `NodePredicate<
|
|
9224
|
+
* satisfies the type `NodePredicate<BinaryTreeNode<K, V>>`.
|
|
9165
9225
|
* @returns The function is checking if the input `p` is a function and returning a boolean value
|
|
9166
9226
|
* based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
|
|
9167
9227
|
* predicate function for a binary tree node. If `p` is not a function, it will return `false`.
|
|
@@ -9175,27 +9235,20 @@ var dataStructureTyped = (() => {
|
|
|
9175
9235
|
*
|
|
9176
9236
|
* The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
|
|
9177
9237
|
* entry, raw data, or null/undefined.
|
|
9178
|
-
* @param {BTNRep<K, V,
|
|
9179
|
-
* TypeScript method that takes in a parameter `
|
|
9180
|
-
* where `BTNRep` is a generic type with keys `K`, `V`, and `
|
|
9181
|
-
* @returns The `_extractKey` method returns the key value extracted from the `
|
|
9238
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `_extractKey` method you provided is a
|
|
9239
|
+
* TypeScript method that takes in a parameter `keyNodeOrEntry` of type `BTNRep<K, V, BinaryTreeNode<K, V>>`,
|
|
9240
|
+
* where `BTNRep` is a generic type with keys `K`, `V`, and `BinaryTreeNode<K, V>`, and `
|
|
9241
|
+
* @returns The `_extractKey` method returns the key value extracted from the `keyNodeOrEntry`
|
|
9182
9242
|
* parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
|
|
9183
9243
|
* the conditions checked in the method.
|
|
9184
9244
|
*/
|
|
9185
|
-
_extractKey(
|
|
9186
|
-
if (
|
|
9187
|
-
if (
|
|
9188
|
-
if (
|
|
9189
|
-
if (this.isNode(
|
|
9190
|
-
if (this.isEntry(
|
|
9191
|
-
|
|
9192
|
-
if (this._toEntryFn) {
|
|
9193
|
-
const [key] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
9194
|
-
return key;
|
|
9195
|
-
}
|
|
9196
|
-
return;
|
|
9197
|
-
}
|
|
9198
|
-
return keyNodeEntryOrRaw;
|
|
9245
|
+
_extractKey(keyNodeOrEntry) {
|
|
9246
|
+
if (keyNodeOrEntry === null) return null;
|
|
9247
|
+
if (keyNodeOrEntry === void 0) return;
|
|
9248
|
+
if (keyNodeOrEntry === this._NIL) return;
|
|
9249
|
+
if (this.isNode(keyNodeOrEntry)) return keyNodeOrEntry.key;
|
|
9250
|
+
if (this.isEntry(keyNodeOrEntry)) return keyNodeOrEntry[0];
|
|
9251
|
+
return keyNodeOrEntry;
|
|
9199
9252
|
}
|
|
9200
9253
|
/**
|
|
9201
9254
|
* Time Complexity: O(1)
|
|
@@ -9239,46 +9292,33 @@ var dataStructureTyped = (() => {
|
|
|
9239
9292
|
|
|
9240
9293
|
// src/data-structures/binary-tree/bst.ts
|
|
9241
9294
|
var BSTNode = class extends BinaryTreeNode {
|
|
9295
|
+
/**
|
|
9296
|
+
* This TypeScript constructor function initializes an instance with a key and an optional value.
|
|
9297
|
+
* @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
|
|
9298
|
+
* within a data structure. It serves as a reference or identifier for accessing or manipulating the
|
|
9299
|
+
* associated value.
|
|
9300
|
+
* @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
|
|
9301
|
+
* have to be provided when creating an instance of the class. If a value is not provided, it will
|
|
9302
|
+
* default to `undefined`.
|
|
9303
|
+
*/
|
|
9242
9304
|
constructor(key, value) {
|
|
9243
9305
|
super(key, value);
|
|
9244
9306
|
__publicField(this, "parent");
|
|
9245
9307
|
__publicField(this, "_left");
|
|
9246
9308
|
__publicField(this, "_right");
|
|
9247
|
-
this.parent = void 0;
|
|
9248
|
-
this._left = void 0;
|
|
9249
|
-
this._right = void 0;
|
|
9250
9309
|
}
|
|
9251
|
-
/**
|
|
9252
|
-
* The function returns the value of the `_left` property.
|
|
9253
|
-
* @returns The `_left` property of the current object is being returned.
|
|
9254
|
-
*/
|
|
9255
9310
|
get left() {
|
|
9256
9311
|
return this._left;
|
|
9257
9312
|
}
|
|
9258
|
-
/**
|
|
9259
|
-
* The function sets the left child of a node and updates the parent reference of the child.
|
|
9260
|
-
* @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be an
|
|
9261
|
-
* instance of the `NODE` class or `undefined`.
|
|
9262
|
-
*/
|
|
9263
9313
|
set left(v) {
|
|
9264
9314
|
if (v) {
|
|
9265
9315
|
v.parent = this;
|
|
9266
9316
|
}
|
|
9267
9317
|
this._left = v;
|
|
9268
9318
|
}
|
|
9269
|
-
/**
|
|
9270
|
-
* The function returns the right node of a binary tree or undefined if there is no right node.
|
|
9271
|
-
* @returns The method is returning the value of the `_right` property, which is of type `NODE` or
|
|
9272
|
-
* `undefined`.
|
|
9273
|
-
*/
|
|
9274
9319
|
get right() {
|
|
9275
9320
|
return this._right;
|
|
9276
9321
|
}
|
|
9277
|
-
/**
|
|
9278
|
-
* The function sets the right child of a node and updates the parent reference of the child.
|
|
9279
|
-
* @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be a
|
|
9280
|
-
* `NODE` object or `undefined`.
|
|
9281
|
-
*/
|
|
9282
9322
|
set right(v) {
|
|
9283
9323
|
if (v) {
|
|
9284
9324
|
v.parent = this;
|
|
@@ -9288,12 +9328,13 @@ var dataStructureTyped = (() => {
|
|
|
9288
9328
|
};
|
|
9289
9329
|
var BST = class _BST extends BinaryTree {
|
|
9290
9330
|
/**
|
|
9291
|
-
* This
|
|
9292
|
-
*
|
|
9293
|
-
*
|
|
9294
|
-
*
|
|
9295
|
-
*
|
|
9296
|
-
*
|
|
9331
|
+
* This TypeScript constructor initializes a binary search tree with optional options and adds
|
|
9332
|
+
* elements if provided.
|
|
9333
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
9334
|
+
* iterable that can contain elements of type `BTNRep<K, V, BSTNode<K, V>>` or `R`. It is used to
|
|
9335
|
+
* initialize the binary search tree with keys, nodes, entries, or raw data.
|
|
9336
|
+
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
9337
|
+
* properties:
|
|
9297
9338
|
*/
|
|
9298
9339
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
9299
9340
|
super([], options);
|
|
@@ -9325,43 +9366,28 @@ var dataStructureTyped = (() => {
|
|
|
9325
9366
|
}
|
|
9326
9367
|
if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
|
|
9327
9368
|
}
|
|
9328
|
-
/**
|
|
9329
|
-
* The function returns the root node of a tree structure.
|
|
9330
|
-
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
9331
|
-
*/
|
|
9332
9369
|
get root() {
|
|
9333
9370
|
return this._root;
|
|
9334
9371
|
}
|
|
9335
|
-
/**
|
|
9336
|
-
* The above function is a getter method in TypeScript that returns the value of the private property
|
|
9337
|
-
* `_isReverse`.
|
|
9338
|
-
* @returns The `isReverse` property of the object, which is a boolean value.
|
|
9339
|
-
*/
|
|
9340
9372
|
get isReverse() {
|
|
9341
9373
|
return this._isReverse;
|
|
9342
9374
|
}
|
|
9343
|
-
/**
|
|
9344
|
-
* The function returns the value of the _comparator property.
|
|
9345
|
-
* @returns The `_comparator` property is being returned.
|
|
9346
|
-
*/
|
|
9347
9375
|
get comparator() {
|
|
9348
9376
|
return this._comparator;
|
|
9349
9377
|
}
|
|
9350
|
-
/**
|
|
9351
|
-
* This function returns the value of the `_specifyComparable` property.
|
|
9352
|
-
* @returns The method `specifyComparable()` is being returned, which is a getter method for the
|
|
9353
|
-
* `_specifyComparable` property.
|
|
9354
|
-
*/
|
|
9355
9378
|
get specifyComparable() {
|
|
9356
9379
|
return this._specifyComparable;
|
|
9357
9380
|
}
|
|
9358
9381
|
/**
|
|
9382
|
+
* Time Complexity: O(1)
|
|
9383
|
+
* Space Complexity: O(1)
|
|
9384
|
+
*
|
|
9359
9385
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
9360
9386
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
9361
9387
|
* being created.
|
|
9362
9388
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
9363
9389
|
* value associated with the key in the node being created.
|
|
9364
|
-
* @returns The method is returning a new instance of the BSTNode class, casted as the
|
|
9390
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the BSTNode<K, V> type.
|
|
9365
9391
|
*/
|
|
9366
9392
|
createNode(key, value) {
|
|
9367
9393
|
return new BSTNode(key, this._isMapMode ? void 0 : value);
|
|
@@ -9370,14 +9396,12 @@ var dataStructureTyped = (() => {
|
|
|
9370
9396
|
* Time Complexity: O(1)
|
|
9371
9397
|
* Space Complexity: O(1)
|
|
9372
9398
|
*
|
|
9373
|
-
* The
|
|
9374
|
-
*
|
|
9375
|
-
*
|
|
9376
|
-
*
|
|
9377
|
-
* @returns
|
|
9378
|
-
* and properties inherited from the current instance.
|
|
9399
|
+
* The function creates a new binary search tree with the specified options.
|
|
9400
|
+
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
9401
|
+
* behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
|
|
9402
|
+
* following properties:
|
|
9403
|
+
* @returns a new instance of the BST class with the provided options.
|
|
9379
9404
|
*/
|
|
9380
|
-
// @ts-ignore
|
|
9381
9405
|
createTree(options) {
|
|
9382
9406
|
return new _BST([], __spreadValues({
|
|
9383
9407
|
iterationType: this.iterationType,
|
|
@@ -9393,8 +9417,8 @@ var dataStructureTyped = (() => {
|
|
|
9393
9417
|
*
|
|
9394
9418
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
9395
9419
|
* it doesn't exist.
|
|
9396
|
-
* @param {BTNRep<K, V,
|
|
9397
|
-
* `
|
|
9420
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
9421
|
+
* `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
|
|
9398
9422
|
* entry, or raw element that needs to be ensured in the tree.
|
|
9399
9423
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
9400
9424
|
* parameter that specifies the type of iteration to be used when ensuring a node. It has a default
|
|
@@ -9402,44 +9426,50 @@ var dataStructureTyped = (() => {
|
|
|
9402
9426
|
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
9403
9427
|
* not be ensured.
|
|
9404
9428
|
*/
|
|
9405
|
-
ensureNode(
|
|
9429
|
+
ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
|
|
9406
9430
|
var _a;
|
|
9407
|
-
return (_a = super.ensureNode(
|
|
9431
|
+
return (_a = super.ensureNode(keyNodeOrEntry, iterationType)) != null ? _a : void 0;
|
|
9408
9432
|
}
|
|
9409
9433
|
/**
|
|
9434
|
+
* Time Complexity: O(1)
|
|
9435
|
+
* Space Complexity: O(1)
|
|
9436
|
+
*
|
|
9410
9437
|
* The function checks if the input is an instance of the BSTNode class.
|
|
9411
|
-
* @param {BTNRep<K, V,
|
|
9412
|
-
* `
|
|
9413
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
9438
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
9439
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
|
|
9440
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
9414
9441
|
* an instance of the `BSTNode` class.
|
|
9415
9442
|
*/
|
|
9416
|
-
isNode(
|
|
9417
|
-
return
|
|
9443
|
+
isNode(keyNodeOrEntry) {
|
|
9444
|
+
return keyNodeOrEntry instanceof BSTNode;
|
|
9418
9445
|
}
|
|
9419
9446
|
/**
|
|
9420
|
-
*
|
|
9447
|
+
* Time Complexity: O(1)
|
|
9448
|
+
* Space Complexity: O(1)
|
|
9449
|
+
*
|
|
9450
|
+
* The function "override isValidKey" checks if a key is comparable based on a given comparator.
|
|
9421
9451
|
* @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
|
|
9422
9452
|
* type `K`.
|
|
9423
|
-
* @returns The `override
|
|
9453
|
+
* @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
|
|
9424
9454
|
* the result of the `isComparable` function with the condition `this._compare !==
|
|
9425
9455
|
* this._DEFAULT_COMPARATOR`.
|
|
9426
9456
|
*/
|
|
9427
|
-
|
|
9457
|
+
isValidKey(key) {
|
|
9428
9458
|
return isComparable(key, this._specifyComparable !== void 0);
|
|
9429
9459
|
}
|
|
9430
9460
|
/**
|
|
9431
9461
|
* Time Complexity: O(log n)
|
|
9432
|
-
* Space Complexity: O(
|
|
9462
|
+
* Space Complexity: O(log n)
|
|
9433
9463
|
*
|
|
9434
9464
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
9435
|
-
* @param {BTNRep<K, V,
|
|
9436
|
-
* `
|
|
9465
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
9466
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
|
|
9437
9467
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
9438
9468
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
9439
9469
|
* @returns a boolean value.
|
|
9440
9470
|
*/
|
|
9441
|
-
add(
|
|
9442
|
-
const [newNode, newValue] = this.
|
|
9471
|
+
add(keyNodeOrEntry, value) {
|
|
9472
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
9443
9473
|
if (newNode === void 0) return false;
|
|
9444
9474
|
if (this._root === void 0) {
|
|
9445
9475
|
this._setRoot(newNode);
|
|
@@ -9460,7 +9490,7 @@ var dataStructureTyped = (() => {
|
|
|
9460
9490
|
this._size++;
|
|
9461
9491
|
return true;
|
|
9462
9492
|
}
|
|
9463
|
-
current = current.left;
|
|
9493
|
+
if (current.left !== null) current = current.left;
|
|
9464
9494
|
} else {
|
|
9465
9495
|
if (current.right === void 0) {
|
|
9466
9496
|
current.right = newNode;
|
|
@@ -9468,7 +9498,7 @@ var dataStructureTyped = (() => {
|
|
|
9468
9498
|
this._size++;
|
|
9469
9499
|
return true;
|
|
9470
9500
|
}
|
|
9471
|
-
current = current.right;
|
|
9501
|
+
if (current.right !== null) current = current.right;
|
|
9472
9502
|
}
|
|
9473
9503
|
}
|
|
9474
9504
|
return false;
|
|
@@ -9501,8 +9531,9 @@ var dataStructureTyped = (() => {
|
|
|
9501
9531
|
valuesIterator = values[Symbol.iterator]();
|
|
9502
9532
|
}
|
|
9503
9533
|
if (!isBalanceAdd) {
|
|
9504
|
-
for (
|
|
9534
|
+
for (let kve of keysNodesEntriesOrRaws) {
|
|
9505
9535
|
const value = valuesIterator == null ? void 0 : valuesIterator.next().value;
|
|
9536
|
+
if (this.isRaw(kve)) kve = this._toEntryFn(kve);
|
|
9506
9537
|
inserted.push(this.add(kve, value));
|
|
9507
9538
|
}
|
|
9508
9539
|
return inserted;
|
|
@@ -9516,18 +9547,16 @@ var dataStructureTyped = (() => {
|
|
|
9516
9547
|
let sorted = [];
|
|
9517
9548
|
sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
|
|
9518
9549
|
let keyA, keyB;
|
|
9519
|
-
if (this.
|
|
9550
|
+
if (this.isRaw(a)) keyA = this._toEntryFn(a)[0];
|
|
9551
|
+
else if (this.isEntry(a)) keyA = a[0];
|
|
9520
9552
|
else if (this.isRealNode(a)) keyA = a.key;
|
|
9521
|
-
else
|
|
9522
|
-
keyA = this._toEntryFn(a)[0];
|
|
9523
|
-
} else {
|
|
9553
|
+
else {
|
|
9524
9554
|
keyA = a;
|
|
9525
9555
|
}
|
|
9526
|
-
if (this.
|
|
9556
|
+
if (this.isRaw(b)) keyB = this._toEntryFn(b)[0];
|
|
9557
|
+
else if (this.isEntry(b)) keyB = b[0];
|
|
9527
9558
|
else if (this.isRealNode(b)) keyB = b.key;
|
|
9528
|
-
else
|
|
9529
|
-
keyB = this._toEntryFn(b)[0];
|
|
9530
|
-
} else {
|
|
9559
|
+
else {
|
|
9531
9560
|
keyB = b;
|
|
9532
9561
|
}
|
|
9533
9562
|
if (keyA !== void 0 && keyA !== null && keyB !== void 0 && keyB !== null) {
|
|
@@ -9536,14 +9565,22 @@ var dataStructureTyped = (() => {
|
|
|
9536
9565
|
return 0;
|
|
9537
9566
|
});
|
|
9538
9567
|
const _dfs = (arr) => {
|
|
9568
|
+
var _a;
|
|
9539
9569
|
if (arr.length === 0) return;
|
|
9540
9570
|
const mid = Math.floor((arr.length - 1) / 2);
|
|
9541
|
-
|
|
9571
|
+
let { key, value } = arr[mid];
|
|
9572
|
+
const { orgIndex } = arr[mid];
|
|
9573
|
+
if (this.isRaw(key)) {
|
|
9574
|
+
const entry = this._toEntryFn(key);
|
|
9575
|
+
key = entry[0];
|
|
9576
|
+
value = (_a = entry[1]) != null ? _a : value;
|
|
9577
|
+
}
|
|
9542
9578
|
inserted[orgIndex] = this.add(key, value);
|
|
9543
9579
|
_dfs(arr.slice(0, mid));
|
|
9544
9580
|
_dfs(arr.slice(mid + 1));
|
|
9545
9581
|
};
|
|
9546
9582
|
const _iterate = () => {
|
|
9583
|
+
var _a;
|
|
9547
9584
|
const n = sorted.length;
|
|
9548
9585
|
const stack = [[0, n - 1]];
|
|
9549
9586
|
while (stack.length > 0) {
|
|
@@ -9552,7 +9589,13 @@ var dataStructureTyped = (() => {
|
|
|
9552
9589
|
const [l, r] = popped;
|
|
9553
9590
|
if (l <= r) {
|
|
9554
9591
|
const m = l + Math.floor((r - l) / 2);
|
|
9555
|
-
|
|
9592
|
+
let { key, value } = sorted[m];
|
|
9593
|
+
const { orgIndex } = sorted[m];
|
|
9594
|
+
if (this.isRaw(key)) {
|
|
9595
|
+
const entry = this._toEntryFn(key);
|
|
9596
|
+
key = entry[0];
|
|
9597
|
+
value = (_a = entry[1]) != null ? _a : value;
|
|
9598
|
+
}
|
|
9556
9599
|
inserted[orgIndex] = this.add(key, value);
|
|
9557
9600
|
stack.push([m + 1, r]);
|
|
9558
9601
|
stack.push([l, m - 1]);
|
|
@@ -9567,35 +9610,23 @@ var dataStructureTyped = (() => {
|
|
|
9567
9610
|
}
|
|
9568
9611
|
return inserted;
|
|
9569
9612
|
}
|
|
9570
|
-
/**
|
|
9571
|
-
* Time Complexity: O(n)
|
|
9572
|
-
* Space Complexity: O(1)
|
|
9573
|
-
*
|
|
9574
|
-
* The `merge` function overrides the base class method by adding elements from another
|
|
9575
|
-
* binary search tree.
|
|
9576
|
-
* @param anotherTree - `anotherTree` is an instance of a Binary Search Tree (BST) with key type `K`,
|
|
9577
|
-
* value type `V`, return type `R`, node type `NODE`, and tree type `TREE`.
|
|
9578
|
-
*/
|
|
9579
|
-
merge(anotherTree) {
|
|
9580
|
-
this.addMany(anotherTree, [], false);
|
|
9581
|
-
}
|
|
9582
9613
|
/**
|
|
9583
9614
|
* Time Complexity: O(log n)
|
|
9584
9615
|
* Space Complexity: O(k + log n)
|
|
9585
9616
|
*
|
|
9586
9617
|
* The function `search` in TypeScript overrides the search behavior in a binary tree structure based
|
|
9587
9618
|
* on specified criteria.
|
|
9588
|
-
* @param {BTNRep<K, V,
|
|
9589
|
-
* `
|
|
9619
|
+
* @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
9620
|
+
* `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
|
|
9590
9621
|
* following types:
|
|
9591
9622
|
* @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
|
|
9592
9623
|
* search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
|
|
9593
9624
|
* search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
|
|
9594
9625
|
* @param {C} callback - The `callback` parameter in the `override search` function is a function
|
|
9595
9626
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
9596
|
-
* extends `NodeCallback<
|
|
9627
|
+
* extends `NodeCallback<BSTNode<K, V>>`. The callback function should accept a node of type `BSTNode<K, V>` as its
|
|
9597
9628
|
* argument and
|
|
9598
|
-
* @param {BTNRep<K, V,
|
|
9629
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `override search`
|
|
9599
9630
|
* method represents the node from which the search operation will begin. It is the starting point
|
|
9600
9631
|
* for searching within the tree data structure. The method ensures that the `startNode` is a valid
|
|
9601
9632
|
* node before proceeding with the search operation. If the `
|
|
@@ -9607,21 +9638,21 @@ var dataStructureTyped = (() => {
|
|
|
9607
9638
|
* structure based on the provided key, predicate, and other options. The search results are
|
|
9608
9639
|
* collected in an array and returned as the output of the method.
|
|
9609
9640
|
*/
|
|
9610
|
-
search(
|
|
9611
|
-
if (
|
|
9612
|
-
if (
|
|
9641
|
+
search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
9642
|
+
if (keyNodeEntryOrPredicate === void 0) return [];
|
|
9643
|
+
if (keyNodeEntryOrPredicate === null) return [];
|
|
9613
9644
|
startNode = this.ensureNode(startNode);
|
|
9614
9645
|
if (!startNode) return [];
|
|
9615
9646
|
let predicate;
|
|
9616
|
-
const isRange = this.isRange(
|
|
9647
|
+
const isRange = this.isRange(keyNodeEntryOrPredicate);
|
|
9617
9648
|
if (isRange) {
|
|
9618
|
-
predicate = (node) =>
|
|
9649
|
+
predicate = (node) => keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
|
|
9619
9650
|
} else {
|
|
9620
|
-
predicate = this._ensurePredicate(
|
|
9651
|
+
predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
9621
9652
|
}
|
|
9622
9653
|
const isToLeftByRange = (cur) => {
|
|
9623
9654
|
if (isRange) {
|
|
9624
|
-
const range =
|
|
9655
|
+
const range = keyNodeEntryOrPredicate;
|
|
9625
9656
|
const leftS = this.isReverse ? range.high : range.low;
|
|
9626
9657
|
const leftI = this.isReverse ? range.includeHigh : range.includeLow;
|
|
9627
9658
|
return leftI && this._compare(cur.key, leftS) >= 0 || !leftI && this._compare(cur.key, leftS) > 0;
|
|
@@ -9630,7 +9661,7 @@ var dataStructureTyped = (() => {
|
|
|
9630
9661
|
};
|
|
9631
9662
|
const isToRightByRange = (cur) => {
|
|
9632
9663
|
if (isRange) {
|
|
9633
|
-
const range =
|
|
9664
|
+
const range = keyNodeEntryOrPredicate;
|
|
9634
9665
|
const rightS = this.isReverse ? range.low : range.high;
|
|
9635
9666
|
const rightI = this.isReverse ? range.includeLow : range.includeLow;
|
|
9636
9667
|
return rightI && this._compare(cur.key, rightS) <= 0 || !rightI && this._compare(cur.key, rightS) < 0;
|
|
@@ -9648,8 +9679,8 @@ var dataStructureTyped = (() => {
|
|
|
9648
9679
|
if (isRange) {
|
|
9649
9680
|
if (this.isRealNode(cur.left) && isToLeftByRange(cur)) dfs(cur.left);
|
|
9650
9681
|
if (this.isRealNode(cur.right) && isToRightByRange(cur)) dfs(cur.right);
|
|
9651
|
-
} else if (!this._isPredicate(
|
|
9652
|
-
const benchmarkKey = this._extractKey(
|
|
9682
|
+
} else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
9683
|
+
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
9653
9684
|
if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0)
|
|
9654
9685
|
dfs(cur.left);
|
|
9655
9686
|
if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0)
|
|
@@ -9671,8 +9702,8 @@ var dataStructureTyped = (() => {
|
|
|
9671
9702
|
if (isRange) {
|
|
9672
9703
|
if (this.isRealNode(cur.left) && isToLeftByRange(cur)) stack.push(cur.left);
|
|
9673
9704
|
if (this.isRealNode(cur.right) && isToRightByRange(cur)) stack.push(cur.right);
|
|
9674
|
-
} else if (!this._isPredicate(
|
|
9675
|
-
const benchmarkKey = this._extractKey(
|
|
9705
|
+
} else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
9706
|
+
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
9676
9707
|
if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0)
|
|
9677
9708
|
stack.push(cur.right);
|
|
9678
9709
|
if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0)
|
|
@@ -9687,16 +9718,16 @@ var dataStructureTyped = (() => {
|
|
|
9687
9718
|
}
|
|
9688
9719
|
/**
|
|
9689
9720
|
* Time Complexity: O(log n)
|
|
9690
|
-
* Space Complexity: O(n)
|
|
9721
|
+
* Space Complexity: O(k + log n)
|
|
9691
9722
|
*
|
|
9692
9723
|
* The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
|
|
9693
9724
|
* @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
|
|
9694
9725
|
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
9695
9726
|
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
9696
9727
|
* function that is used to process each node that is found within the specified range during the
|
|
9697
|
-
* search operation. It is of type `NodeCallback<
|
|
9728
|
+
* search operation. It is of type `NodeCallback<BSTNode<K, V>>`, where `BSTNode<K, V>` is the type of nodes in the
|
|
9698
9729
|
* data structure.
|
|
9699
|
-
* @param {BTNRep<K, V,
|
|
9730
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `rangeSearch`
|
|
9700
9731
|
* function represents the node from which the search for nodes within the specified range will
|
|
9701
9732
|
* begin. It is the starting point for the range search operation.
|
|
9702
9733
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
@@ -9712,12 +9743,12 @@ var dataStructureTyped = (() => {
|
|
|
9712
9743
|
}
|
|
9713
9744
|
/**
|
|
9714
9745
|
* Time Complexity: O(log n)
|
|
9715
|
-
* Space Complexity: O(
|
|
9746
|
+
* Space Complexity: O(log n)
|
|
9716
9747
|
*
|
|
9717
|
-
* This function retrieves a node based on a given
|
|
9718
|
-
* @param {BTNRep<K, V,
|
|
9719
|
-
* parameter can be of type `BTNRep<K, V,
|
|
9720
|
-
* @param {
|
|
9748
|
+
* This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
|
|
9749
|
+
* @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
|
|
9750
|
+
* parameter can be of type `BTNRep<K, V, BSTNode<K, V>>`, `R`, or `NodePredicate<BSTNode<K, V>>`.
|
|
9751
|
+
* @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
|
|
9721
9752
|
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
9722
9753
|
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
9723
9754
|
* node of the binary search tree.
|
|
@@ -9725,14 +9756,14 @@ var dataStructureTyped = (() => {
|
|
|
9725
9756
|
* parameter that specifies the type of iteration to be used. It has a default value of
|
|
9726
9757
|
* `this.iterationType`, which means it will use the iteration type defined in the class instance if
|
|
9727
9758
|
* no value is provided when calling the method.
|
|
9728
|
-
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<
|
|
9729
|
-
* It is using the `getNodes` method to find the node based on the provided
|
|
9759
|
+
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<BSTNode<K, V>>`).
|
|
9760
|
+
* It is using the `getNodes` method to find the node based on the provided keyNodeEntryOrPredicate, beginning at
|
|
9730
9761
|
* the specified root node (`startNode`) and using the specified iteration type. The method then
|
|
9731
9762
|
* returns the first node found or `undefined` if no node is found.
|
|
9732
9763
|
*/
|
|
9733
|
-
getNode(
|
|
9764
|
+
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
9734
9765
|
var _a;
|
|
9735
|
-
return (_a = this.getNodes(
|
|
9766
|
+
return (_a = this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0]) != null ? _a : void 0;
|
|
9736
9767
|
}
|
|
9737
9768
|
/**
|
|
9738
9769
|
* Time complexity: O(n)
|
|
@@ -9746,7 +9777,7 @@ var dataStructureTyped = (() => {
|
|
|
9746
9777
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
9747
9778
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
9748
9779
|
* take one of the following values:
|
|
9749
|
-
* @param {BTNRep<K, V,
|
|
9780
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
9750
9781
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
9751
9782
|
* node entry. If not specified, the default value is the root of the tree.
|
|
9752
9783
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -9766,7 +9797,7 @@ var dataStructureTyped = (() => {
|
|
|
9766
9797
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
9767
9798
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
9768
9799
|
* node being visited, and it can return a value of any type.
|
|
9769
|
-
* @param {BTNRep<K, V,
|
|
9800
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
9770
9801
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
9771
9802
|
* object. If no value is provided, the default value is the root of the tree.
|
|
9772
9803
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -9784,9 +9815,9 @@ var dataStructureTyped = (() => {
|
|
|
9784
9815
|
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
9785
9816
|
* containing the results of the callback function applied to each level of the tree.
|
|
9786
9817
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
9787
|
-
* `NodeCallback<
|
|
9818
|
+
* `NodeCallback<BSTNode<K, V>>`. It represents a callback function that will be called for each node in the
|
|
9788
9819
|
* tree during the iteration process.
|
|
9789
|
-
* @param {BTNRep<K, V,
|
|
9820
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
9790
9821
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
9791
9822
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
9792
9823
|
* value is provided, the root of
|
|
@@ -9810,7 +9841,7 @@ var dataStructureTyped = (() => {
|
|
|
9810
9841
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
9811
9842
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
9812
9843
|
* 0, or 1, where:
|
|
9813
|
-
* @param {BTNRep<K, V,
|
|
9844
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} targetNode - The `targetNode` parameter is the node in
|
|
9814
9845
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
9815
9846
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
9816
9847
|
* `targetNode` is provided,
|
|
@@ -9925,7 +9956,7 @@ var dataStructureTyped = (() => {
|
|
|
9925
9956
|
while (stack.length > 0 || node) {
|
|
9926
9957
|
if (node) {
|
|
9927
9958
|
stack.push(node);
|
|
9928
|
-
node = node.left;
|
|
9959
|
+
if (node.left !== null) node = node.left;
|
|
9929
9960
|
} else {
|
|
9930
9961
|
node = stack[stack.length - 1];
|
|
9931
9962
|
if (!node.right || last === node.right) {
|
|
@@ -9944,7 +9975,25 @@ var dataStructureTyped = (() => {
|
|
|
9944
9975
|
}
|
|
9945
9976
|
return balanced;
|
|
9946
9977
|
}
|
|
9947
|
-
|
|
9978
|
+
/**
|
|
9979
|
+
* Time complexity: O(n)
|
|
9980
|
+
* Space complexity: O(n)
|
|
9981
|
+
*
|
|
9982
|
+
* The `map` function in TypeScript overrides the default map behavior for a binary search tree by
|
|
9983
|
+
* applying a callback function to each entry and creating a new tree with the results.
|
|
9984
|
+
* @param callback - A function that will be called for each entry in the BST. It takes four
|
|
9985
|
+
* arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
|
|
9986
|
+
* the BST itself.
|
|
9987
|
+
* @param [options] - The `options` parameter in the `override map` method is of type `BSTOptions<MK,
|
|
9988
|
+
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the Binary
|
|
9989
|
+
* Search Tree (BST) being created in the `map` method. These options could include configuration
|
|
9990
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` method is used to specify
|
|
9991
|
+
* the value of `this` that should be used when executing the `callback` function. It allows you to
|
|
9992
|
+
* set the context or scope in which the callback function will be called. This can be useful when
|
|
9993
|
+
* you want
|
|
9994
|
+
* @returns The `map` method is returning a new Binary Search Tree (`BST`) instance with the entries
|
|
9995
|
+
* transformed by the provided callback function.
|
|
9996
|
+
*/
|
|
9948
9997
|
map(callback, options, thisArg) {
|
|
9949
9998
|
const newTree = new _BST([], options);
|
|
9950
9999
|
let index = 0;
|
|
@@ -9954,23 +10003,42 @@ var dataStructureTyped = (() => {
|
|
|
9954
10003
|
return newTree;
|
|
9955
10004
|
}
|
|
9956
10005
|
/**
|
|
10006
|
+
* Time complexity: O(n)
|
|
10007
|
+
* Space complexity: O(n)
|
|
10008
|
+
*
|
|
10009
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
10010
|
+
* structure.
|
|
10011
|
+
* @returns The `cloned` object is being returned.
|
|
10012
|
+
*/
|
|
10013
|
+
clone() {
|
|
10014
|
+
const cloned = this.createTree();
|
|
10015
|
+
this._clone(cloned);
|
|
10016
|
+
return cloned;
|
|
10017
|
+
}
|
|
10018
|
+
/**
|
|
10019
|
+
* Time Complexity: O(1)
|
|
10020
|
+
* Space Complexity: O(1)
|
|
10021
|
+
*
|
|
9957
10022
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
9958
|
-
* @param {BTNRep<K, V,
|
|
9959
|
-
* type R or BTNRep<K, V,
|
|
10023
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - A variable that can be of
|
|
10024
|
+
* type R or BTNRep<K, V, BSTNode<K, V>>. It represents either a key, a node, an entry, or a raw
|
|
9960
10025
|
* element.
|
|
9961
10026
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
9962
10027
|
* value associated with a key in a key-value pair.
|
|
9963
|
-
* @returns either a
|
|
10028
|
+
* @returns either a BSTNode<K, V> object or undefined.
|
|
9964
10029
|
*/
|
|
9965
|
-
|
|
9966
|
-
const [node, entryValue] = super.
|
|
10030
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
|
|
10031
|
+
const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
9967
10032
|
if (node === null) return [void 0, void 0];
|
|
9968
10033
|
return [node, value != null ? value : entryValue];
|
|
9969
10034
|
}
|
|
9970
10035
|
/**
|
|
10036
|
+
* Time Complexity: O(1)
|
|
10037
|
+
* Space Complexity: O(1)
|
|
10038
|
+
*
|
|
9971
10039
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
9972
10040
|
* root.
|
|
9973
|
-
* @param {OptNode<
|
|
10041
|
+
* @param {OptNode<BSTNode<K, V>>} v - v is a parameter of type BSTNode<K, V> or undefined.
|
|
9974
10042
|
*/
|
|
9975
10043
|
_setRoot(v) {
|
|
9976
10044
|
if (v) {
|
|
@@ -9978,6 +10046,20 @@ var dataStructureTyped = (() => {
|
|
|
9978
10046
|
}
|
|
9979
10047
|
this._root = v;
|
|
9980
10048
|
}
|
|
10049
|
+
/**
|
|
10050
|
+
* Time Complexity: O(1)
|
|
10051
|
+
* Space Complexity: O(1)
|
|
10052
|
+
*
|
|
10053
|
+
* The _compare function compares two values using a specified comparator function and optionally
|
|
10054
|
+
* reverses the result.
|
|
10055
|
+
* @param {K} a - The parameter `a` is of type `K`, which is used as an input for comparison in the
|
|
10056
|
+
* `_compare` method.
|
|
10057
|
+
* @param {K} b - The parameter `b` in the `_compare` function is of type `K`.
|
|
10058
|
+
* @returns The `_compare` method is returning the result of the ternary expression. If `_isReverse`
|
|
10059
|
+
* is true, it returns the negation of the result of calling the `_comparator` function with
|
|
10060
|
+
* arguments `a` and `b`. If `_isReverse` is false, it returns the result of calling the
|
|
10061
|
+
* `_comparator` function with arguments `a` and `b`.
|
|
10062
|
+
*/
|
|
9981
10063
|
_compare(a, b) {
|
|
9982
10064
|
return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
|
|
9983
10065
|
}
|
|
@@ -10549,73 +10631,80 @@ var dataStructureTyped = (() => {
|
|
|
10549
10631
|
// src/data-structures/binary-tree/avl-tree.ts
|
|
10550
10632
|
var AVLTreeNode = class extends BSTNode {
|
|
10551
10633
|
/**
|
|
10552
|
-
*
|
|
10553
|
-
*
|
|
10554
|
-
*
|
|
10555
|
-
*
|
|
10556
|
-
* @param {V} [value] - The
|
|
10557
|
-
*
|
|
10634
|
+
* This TypeScript constructor function initializes an instance with a key and an optional value.
|
|
10635
|
+
* @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
|
|
10636
|
+
* within a data structure. It serves as a reference or identifier for accessing or manipulating the
|
|
10637
|
+
* associated value or data.
|
|
10638
|
+
* @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
|
|
10639
|
+
* have to be provided when creating an instance of the class. If a value is not provided, it will
|
|
10640
|
+
* default to `undefined`.
|
|
10558
10641
|
*/
|
|
10559
10642
|
constructor(key, value) {
|
|
10560
10643
|
super(key, value);
|
|
10561
|
-
__publicField(this, "
|
|
10562
|
-
this
|
|
10644
|
+
__publicField(this, "parent");
|
|
10645
|
+
__publicField(this, "_left");
|
|
10646
|
+
__publicField(this, "_right");
|
|
10563
10647
|
}
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
* @returns The height of the object.
|
|
10567
|
-
*/
|
|
10568
|
-
get height() {
|
|
10569
|
-
return this._height;
|
|
10648
|
+
get left() {
|
|
10649
|
+
return this._left;
|
|
10570
10650
|
}
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10651
|
+
set left(v) {
|
|
10652
|
+
if (v) {
|
|
10653
|
+
v.parent = this;
|
|
10654
|
+
}
|
|
10655
|
+
this._left = v;
|
|
10656
|
+
}
|
|
10657
|
+
get right() {
|
|
10658
|
+
return this._right;
|
|
10659
|
+
}
|
|
10660
|
+
set right(v) {
|
|
10661
|
+
if (v) {
|
|
10662
|
+
v.parent = this;
|
|
10663
|
+
}
|
|
10664
|
+
this._right = v;
|
|
10578
10665
|
}
|
|
10579
10666
|
};
|
|
10580
10667
|
var AVLTree = class _AVLTree extends BST {
|
|
10581
10668
|
/**
|
|
10582
|
-
* This
|
|
10583
|
-
*
|
|
10584
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
10585
|
-
* iterable
|
|
10586
|
-
*
|
|
10587
|
-
* @param [options] - The `options` parameter
|
|
10588
|
-
*
|
|
10589
|
-
*
|
|
10590
|
-
*
|
|
10669
|
+
* This TypeScript constructor initializes an AVLTree with keys, nodes, entries, or raw data provided
|
|
10670
|
+
* in an iterable format.
|
|
10671
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
10672
|
+
* iterable that can contain either `BTNRep<K, V, AVLTreeNode<K, V>>` objects or `R` objects. It is
|
|
10673
|
+
* used to initialize the AVLTree with key-value pairs or raw data entries. If provided
|
|
10674
|
+
* @param [options] - The `options` parameter in the constructor is of type `AVLTreeOptions<K, V,
|
|
10675
|
+
* R>`. It is an optional parameter that allows you to specify additional options for configuring the
|
|
10676
|
+
* AVL tree. These options could include things like custom comparators, initial capacity, or any
|
|
10677
|
+
* other configuration settings specific
|
|
10591
10678
|
*/
|
|
10592
10679
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
10593
10680
|
super([], options);
|
|
10594
10681
|
if (keysNodesEntriesOrRaws) super.addMany(keysNodesEntriesOrRaws);
|
|
10595
10682
|
}
|
|
10596
10683
|
/**
|
|
10684
|
+
* Time Complexity: O(1)
|
|
10685
|
+
* Space Complexity: O(1)
|
|
10686
|
+
*
|
|
10597
10687
|
* The function creates a new AVL tree node with the given key and value.
|
|
10598
10688
|
* @param {K} key - The key parameter is of type K, which represents the key of the node being
|
|
10599
10689
|
* created.
|
|
10600
10690
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
10601
10691
|
* value associated with the key in the node being created.
|
|
10602
10692
|
* @returns The method is returning a new instance of the AVLTreeNode class, casted as the generic
|
|
10603
|
-
* type
|
|
10693
|
+
* type AVLTreeNode<K, V>.
|
|
10604
10694
|
*/
|
|
10605
10695
|
createNode(key, value) {
|
|
10606
10696
|
return new AVLTreeNode(key, this._isMapMode ? void 0 : value);
|
|
10607
10697
|
}
|
|
10608
10698
|
/**
|
|
10609
|
-
*
|
|
10610
|
-
*
|
|
10611
|
-
*
|
|
10612
|
-
*
|
|
10613
|
-
*
|
|
10614
|
-
*
|
|
10615
|
-
*
|
|
10616
|
-
*
|
|
10617
|
-
*/
|
|
10618
|
-
// @ts-ignore
|
|
10699
|
+
* Time Complexity: O(1)
|
|
10700
|
+
* Space Complexity: O(1)
|
|
10701
|
+
*
|
|
10702
|
+
* The function creates a new AVL tree with the specified options and returns it.
|
|
10703
|
+
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
|
|
10704
|
+
* passed to the `createTree` function. It is used to customize the behavior of the AVL tree that is
|
|
10705
|
+
* being created.
|
|
10706
|
+
* @returns a new AVLTree object.
|
|
10707
|
+
*/
|
|
10619
10708
|
createTree(options) {
|
|
10620
10709
|
return new _AVLTree([], __spreadValues({
|
|
10621
10710
|
iterationType: this.iterationType,
|
|
@@ -10626,49 +10715,51 @@ var dataStructureTyped = (() => {
|
|
|
10626
10715
|
}, options));
|
|
10627
10716
|
}
|
|
10628
10717
|
/**
|
|
10718
|
+
* Time Complexity: O(1)
|
|
10719
|
+
* Space Complexity: O(1)
|
|
10720
|
+
*
|
|
10629
10721
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
10630
|
-
* @param {BTNRep<K, V,
|
|
10631
|
-
* `
|
|
10632
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
10722
|
+
* @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
10723
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, AVLTreeNode<K, V>>`.
|
|
10724
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
10633
10725
|
* an instance of the `AVLTreeNode` class.
|
|
10634
10726
|
*/
|
|
10635
|
-
isNode(
|
|
10636
|
-
return
|
|
10727
|
+
isNode(keyNodeOrEntry) {
|
|
10728
|
+
return keyNodeOrEntry instanceof AVLTreeNode;
|
|
10637
10729
|
}
|
|
10638
10730
|
/**
|
|
10639
10731
|
* Time Complexity: O(log n)
|
|
10640
|
-
* Space Complexity: O(
|
|
10732
|
+
* Space Complexity: O(log n)
|
|
10641
10733
|
*
|
|
10642
10734
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
10643
10735
|
* structure, then balances the path.
|
|
10644
|
-
* @param {BTNRep<K, V,
|
|
10645
|
-
* `
|
|
10646
|
-
* `RawElement`.
|
|
10736
|
+
* @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
10737
|
+
* `keyNodeOrEntry` can accept values of type `R`, `BTNRep<K, V, AVLTreeNode<K, V>>`
|
|
10647
10738
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
10648
10739
|
* the key or node being added to the data structure.
|
|
10649
10740
|
* @returns The method is returning a boolean value.
|
|
10650
10741
|
*/
|
|
10651
|
-
add(
|
|
10652
|
-
if (
|
|
10653
|
-
const inserted = super.add(
|
|
10654
|
-
if (inserted) this._balancePath(
|
|
10742
|
+
add(keyNodeOrEntry, value) {
|
|
10743
|
+
if (keyNodeOrEntry === null) return false;
|
|
10744
|
+
const inserted = super.add(keyNodeOrEntry, value);
|
|
10745
|
+
if (inserted) this._balancePath(keyNodeOrEntry);
|
|
10655
10746
|
return inserted;
|
|
10656
10747
|
}
|
|
10657
10748
|
/**
|
|
10658
10749
|
* Time Complexity: O(log n)
|
|
10659
|
-
* Space Complexity: O(
|
|
10750
|
+
* Space Complexity: O(log n)
|
|
10660
10751
|
*
|
|
10661
10752
|
* The function overrides the delete method in a TypeScript class, performs deletion, and then
|
|
10662
10753
|
* balances the tree if necessary.
|
|
10663
|
-
* @param {BTNRep<K, V,
|
|
10754
|
+
* @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
10664
10755
|
* parameter in the `override delete` method can be one of the following types:
|
|
10665
10756
|
* @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
|
|
10666
10757
|
* method from the superclass (presumably a parent class) with the provided `predicate`, which could
|
|
10667
10758
|
* be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
|
|
10668
10759
|
* `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
|
|
10669
10760
|
*/
|
|
10670
|
-
delete(
|
|
10671
|
-
const deletedResults = super.delete(
|
|
10761
|
+
delete(keyNodeOrEntry) {
|
|
10762
|
+
const deletedResults = super.delete(keyNodeOrEntry);
|
|
10672
10763
|
for (const { needBalanced } of deletedResults) {
|
|
10673
10764
|
if (needBalanced) {
|
|
10674
10765
|
this._balancePath(needBalanced);
|
|
@@ -10676,7 +10767,26 @@ var dataStructureTyped = (() => {
|
|
|
10676
10767
|
}
|
|
10677
10768
|
return deletedResults;
|
|
10678
10769
|
}
|
|
10679
|
-
|
|
10770
|
+
/**
|
|
10771
|
+
* Time Complexity: O(n)
|
|
10772
|
+
* Space Complexity: O(n)
|
|
10773
|
+
*
|
|
10774
|
+
* The `map` function in TypeScript overrides the default map behavior of an AVLTree data structure
|
|
10775
|
+
* by applying a callback function to each entry and creating a new AVLTree with the results.
|
|
10776
|
+
* @param callback - A function that will be called for each entry in the AVLTree. It takes four
|
|
10777
|
+
* arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
|
|
10778
|
+
* the AVLTree itself.
|
|
10779
|
+
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
10780
|
+
* `AVLTreeOptions<MK, MV, MR>`. It is an optional parameter that allows you to specify additional
|
|
10781
|
+
* options for the AVL tree being created during the mapping process. These options could include
|
|
10782
|
+
* custom comparators, initial
|
|
10783
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
10784
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
10785
|
+
* (value of `this`) within the callback function. This can be useful when you want to access
|
|
10786
|
+
* properties or
|
|
10787
|
+
* @returns The `map` method is returning a new AVLTree instance (`newTree`) with the entries
|
|
10788
|
+
* modified by the provided callback function.
|
|
10789
|
+
*/
|
|
10680
10790
|
map(callback, options, thisArg) {
|
|
10681
10791
|
const newTree = new _AVLTree([], options);
|
|
10682
10792
|
let index = 0;
|
|
@@ -10685,16 +10795,29 @@ var dataStructureTyped = (() => {
|
|
|
10685
10795
|
}
|
|
10686
10796
|
return newTree;
|
|
10687
10797
|
}
|
|
10798
|
+
/**
|
|
10799
|
+
* Time Complexity: O(n)
|
|
10800
|
+
* Space Complexity: O(n)
|
|
10801
|
+
*
|
|
10802
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
10803
|
+
* structure.
|
|
10804
|
+
* @returns A cloned tree object is being returned.
|
|
10805
|
+
*/
|
|
10806
|
+
clone() {
|
|
10807
|
+
const cloned = this.createTree();
|
|
10808
|
+
this._clone(cloned);
|
|
10809
|
+
return cloned;
|
|
10810
|
+
}
|
|
10688
10811
|
/**
|
|
10689
10812
|
* Time Complexity: O(1)
|
|
10690
10813
|
* Space Complexity: O(1)
|
|
10691
10814
|
*
|
|
10692
10815
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
|
|
10693
10816
|
* binary search tree.
|
|
10694
|
-
* @param {
|
|
10695
|
-
* object (`
|
|
10696
|
-
* @param {
|
|
10697
|
-
* `R` or an instance of `BSTNOptKeyOrNode<K,
|
|
10817
|
+
* @param {BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>} srcNode - The `srcNode` parameter represents either a node
|
|
10818
|
+
* object (`AVLTreeNode<K, V>`) or a key-value pair (`R`) that is being swapped with another node.
|
|
10819
|
+
* @param {BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>} destNode - The `destNode` parameter is either an instance of
|
|
10820
|
+
* `R` or an instance of `BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>`.
|
|
10698
10821
|
* @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
|
|
10699
10822
|
* `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
|
|
10700
10823
|
*/
|
|
@@ -10722,7 +10845,7 @@ var dataStructureTyped = (() => {
|
|
|
10722
10845
|
* Space Complexity: O(1)
|
|
10723
10846
|
*
|
|
10724
10847
|
* The function calculates the balance factor of a node in a binary tree.
|
|
10725
|
-
* @param {
|
|
10848
|
+
* @param {AVLTreeNode<K, V>} node - The parameter "node" is of type "AVLTreeNode<K, V>", which likely represents a node in a
|
|
10726
10849
|
* binary tree data structure.
|
|
10727
10850
|
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
10728
10851
|
* height of the left subtree from the height of the right subtree.
|
|
@@ -10740,7 +10863,7 @@ var dataStructureTyped = (() => {
|
|
|
10740
10863
|
*
|
|
10741
10864
|
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
10742
10865
|
* right children.
|
|
10743
|
-
* @param {
|
|
10866
|
+
* @param {AVLTreeNode<K, V>} node - The parameter "node" represents a node in a binary tree data structure.
|
|
10744
10867
|
*/
|
|
10745
10868
|
_updateHeight(node) {
|
|
10746
10869
|
if (!node.left && !node.right) node.height = 0;
|
|
@@ -10755,12 +10878,12 @@ var dataStructureTyped = (() => {
|
|
|
10755
10878
|
* Space Complexity: O(1)
|
|
10756
10879
|
*
|
|
10757
10880
|
* The `_balanceLL` function performs a left-left rotation to balance a binary search tree.
|
|
10758
|
-
* @param {
|
|
10881
|
+
* @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
|
|
10759
10882
|
*/
|
|
10760
10883
|
_balanceLL(A) {
|
|
10761
10884
|
const parentOfA = A.parent;
|
|
10762
10885
|
const B = A.left;
|
|
10763
|
-
A.parent = B;
|
|
10886
|
+
if (B !== null) A.parent = B;
|
|
10764
10887
|
if (B && B.right) {
|
|
10765
10888
|
B.right.parent = A;
|
|
10766
10889
|
}
|
|
@@ -10786,7 +10909,7 @@ var dataStructureTyped = (() => {
|
|
|
10786
10909
|
* Space Complexity: O(1)
|
|
10787
10910
|
*
|
|
10788
10911
|
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
10789
|
-
* @param {
|
|
10912
|
+
* @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
|
|
10790
10913
|
*/
|
|
10791
10914
|
_balanceLR(A) {
|
|
10792
10915
|
const parentOfA = A.parent;
|
|
@@ -10795,11 +10918,11 @@ var dataStructureTyped = (() => {
|
|
|
10795
10918
|
if (B) {
|
|
10796
10919
|
C = B.right;
|
|
10797
10920
|
}
|
|
10798
|
-
if (A) A.parent = C;
|
|
10799
|
-
if (B) B.parent = C;
|
|
10921
|
+
if (A && C !== null) A.parent = C;
|
|
10922
|
+
if (B && C !== null) B.parent = C;
|
|
10800
10923
|
if (C) {
|
|
10801
10924
|
if (C.left) {
|
|
10802
|
-
C.left.parent = B;
|
|
10925
|
+
if (B !== null) C.left.parent = B;
|
|
10803
10926
|
}
|
|
10804
10927
|
if (C.right) {
|
|
10805
10928
|
C.right.parent = A;
|
|
@@ -10832,12 +10955,12 @@ var dataStructureTyped = (() => {
|
|
|
10832
10955
|
* Space Complexity: O(1)
|
|
10833
10956
|
*
|
|
10834
10957
|
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
10835
|
-
* @param {
|
|
10958
|
+
* @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
|
|
10836
10959
|
*/
|
|
10837
10960
|
_balanceRR(A) {
|
|
10838
10961
|
const parentOfA = A.parent;
|
|
10839
10962
|
const B = A.right;
|
|
10840
|
-
A.parent = B;
|
|
10963
|
+
if (B !== null) A.parent = B;
|
|
10841
10964
|
if (B) {
|
|
10842
10965
|
if (B.left) {
|
|
10843
10966
|
B.left.parent = A;
|
|
@@ -10867,7 +10990,7 @@ var dataStructureTyped = (() => {
|
|
|
10867
10990
|
* Space Complexity: O(1)
|
|
10868
10991
|
*
|
|
10869
10992
|
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
10870
|
-
* @param {
|
|
10993
|
+
* @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
|
|
10871
10994
|
*/
|
|
10872
10995
|
_balanceRL(A) {
|
|
10873
10996
|
const parentOfA = A.parent;
|
|
@@ -10876,14 +10999,14 @@ var dataStructureTyped = (() => {
|
|
|
10876
10999
|
if (B) {
|
|
10877
11000
|
C = B.left;
|
|
10878
11001
|
}
|
|
10879
|
-
A.parent = C;
|
|
10880
|
-
if (B) B.parent = C;
|
|
11002
|
+
if (C !== null) A.parent = C;
|
|
11003
|
+
if (B && C !== null) B.parent = C;
|
|
10881
11004
|
if (C) {
|
|
10882
11005
|
if (C.left) {
|
|
10883
11006
|
C.left.parent = A;
|
|
10884
11007
|
}
|
|
10885
11008
|
if (C.right) {
|
|
10886
|
-
C.right.parent = B;
|
|
11009
|
+
if (B !== null) C.right.parent = B;
|
|
10887
11010
|
}
|
|
10888
11011
|
C.parent = parentOfA;
|
|
10889
11012
|
}
|
|
@@ -10912,8 +11035,8 @@ var dataStructureTyped = (() => {
|
|
|
10912
11035
|
*
|
|
10913
11036
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
10914
11037
|
* to restore balance in an AVL tree after inserting a node.
|
|
10915
|
-
* @param {BTNRep<K, V,
|
|
10916
|
-
* `BTNRep<K, V,
|
|
11038
|
+
* @param {BTNRep<K, V, AVLTreeNode<K, V>>} node - The `node` parameter can be of type `R` or
|
|
11039
|
+
* `BTNRep<K, V, AVLTreeNode<K, V>>`.
|
|
10917
11040
|
*/
|
|
10918
11041
|
_balancePath(node) {
|
|
10919
11042
|
node = this.ensureNode(node);
|
|
@@ -10950,9 +11073,9 @@ var dataStructureTyped = (() => {
|
|
|
10950
11073
|
*
|
|
10951
11074
|
* The function replaces an old node with a new node and sets the height of the new node to be the
|
|
10952
11075
|
* same as the old node.
|
|
10953
|
-
* @param {
|
|
11076
|
+
* @param {AVLTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
10954
11077
|
* the data structure.
|
|
10955
|
-
* @param {
|
|
11078
|
+
* @param {AVLTreeNode<K, V>} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
|
|
10956
11079
|
* the data structure.
|
|
10957
11080
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
10958
11081
|
* superclass, with the `oldNode` and `newNode` as arguments.
|
|
@@ -10966,63 +11089,68 @@ var dataStructureTyped = (() => {
|
|
|
10966
11089
|
// src/data-structures/binary-tree/red-black-tree.ts
|
|
10967
11090
|
var RedBlackTreeNode = class extends BSTNode {
|
|
10968
11091
|
/**
|
|
10969
|
-
* The constructor
|
|
10970
|
-
*
|
|
10971
|
-
*
|
|
10972
|
-
*
|
|
10973
|
-
*
|
|
10974
|
-
*
|
|
10975
|
-
*
|
|
10976
|
-
*
|
|
10977
|
-
* Tree Node. It is an optional parameter with a default value of `'BLACK'`.
|
|
11092
|
+
* The constructor initializes a node with a key, value, and color for a Red-Black Tree.
|
|
11093
|
+
* @param {K} key - The `key` parameter is a key of type `K` that is used to identify the node in a
|
|
11094
|
+
* Red-Black Tree data structure.
|
|
11095
|
+
* @param {V} [value] - The `value` parameter in the constructor is an optional parameter of type
|
|
11096
|
+
* `V`. It represents the value associated with the key in the data structure being constructed.
|
|
11097
|
+
* @param {RBTNColor} [color=BLACK] - The `color` parameter in the constructor is used to specify the
|
|
11098
|
+
* color of the node in a Red-Black Tree. It has a default value of 'BLACK' if not provided
|
|
11099
|
+
* explicitly.
|
|
10978
11100
|
*/
|
|
10979
11101
|
constructor(key, value, color = "BLACK") {
|
|
10980
11102
|
super(key, value);
|
|
10981
|
-
__publicField(this, "
|
|
11103
|
+
__publicField(this, "parent");
|
|
11104
|
+
__publicField(this, "_left");
|
|
11105
|
+
__publicField(this, "_right");
|
|
10982
11106
|
this._color = color;
|
|
10983
11107
|
}
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
* @returns The color value stored in the private variable `_color`.
|
|
10987
|
-
*/
|
|
10988
|
-
get color() {
|
|
10989
|
-
return this._color;
|
|
11108
|
+
get left() {
|
|
11109
|
+
return this._left;
|
|
10990
11110
|
}
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
this._color = value;
|
|
11111
|
+
set left(v) {
|
|
11112
|
+
if (v) {
|
|
11113
|
+
v.parent = this;
|
|
11114
|
+
}
|
|
11115
|
+
this._left = v;
|
|
10997
11116
|
}
|
|
10998
|
-
|
|
10999
|
-
|
|
11000
|
-
|
|
11001
|
-
|
|
11002
|
-
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11117
|
+
get right() {
|
|
11118
|
+
return this._right;
|
|
11119
|
+
}
|
|
11120
|
+
set right(v) {
|
|
11121
|
+
if (v) {
|
|
11122
|
+
v.parent = this;
|
|
11123
|
+
}
|
|
11124
|
+
this._right = v;
|
|
11125
|
+
}
|
|
11126
|
+
};
|
|
11127
|
+
var RedBlackTree = class _RedBlackTree extends BST {
|
|
11128
|
+
/**
|
|
11129
|
+
* This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
|
|
11130
|
+
* raw data.
|
|
11131
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
11132
|
+
* iterable that can contain either `BTNRep<K, V, RedBlackTreeNode<K, V>>` objects or `R` objects. It
|
|
11133
|
+
* is used to initialize the Red-Black Tree with keys, nodes, entries, or
|
|
11134
|
+
* @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
|
|
11135
|
+
* V, R>`. It is an optional parameter that allows you to specify additional options for the
|
|
11136
|
+
* RedBlackTree class. These options could include configuration settings, behavior customization, or
|
|
11137
|
+
* any other parameters that are specific to
|
|
11138
|
+
*/
|
|
11139
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11140
|
+
super([], options);
|
|
11012
11141
|
__publicField(this, "_root");
|
|
11013
11142
|
this._root = this.NIL;
|
|
11014
11143
|
if (keysNodesEntriesOrRaws) {
|
|
11015
11144
|
this.addMany(keysNodesEntriesOrRaws);
|
|
11016
11145
|
}
|
|
11017
11146
|
}
|
|
11018
|
-
/**
|
|
11019
|
-
* The function returns the root node of a tree or undefined if there is no root.
|
|
11020
|
-
* @returns The root node of the tree structure, or undefined if there is no root node.
|
|
11021
|
-
*/
|
|
11022
11147
|
get root() {
|
|
11023
11148
|
return this._root;
|
|
11024
11149
|
}
|
|
11025
11150
|
/**
|
|
11151
|
+
* Time Complexity: O(1)
|
|
11152
|
+
* Space Complexity: O(1)
|
|
11153
|
+
*
|
|
11026
11154
|
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
11027
11155
|
* @param {K} key - The key parameter represents the key value of the node being created. It is of
|
|
11028
11156
|
* type K, which is a generic type that can be replaced with any specific type when using the
|
|
@@ -11040,15 +11168,14 @@ var dataStructureTyped = (() => {
|
|
|
11040
11168
|
return new RedBlackTreeNode(key, this._isMapMode ? void 0 : value, color);
|
|
11041
11169
|
}
|
|
11042
11170
|
/**
|
|
11043
|
-
*
|
|
11044
|
-
*
|
|
11045
|
-
*
|
|
11046
|
-
*
|
|
11047
|
-
*
|
|
11048
|
-
*
|
|
11049
|
-
*
|
|
11171
|
+
* Time Complexity: O(1)
|
|
11172
|
+
* Space Complexity: O(1)
|
|
11173
|
+
*
|
|
11174
|
+
* The function creates a new Red-Black Tree with the specified options.
|
|
11175
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
11176
|
+
* configuration options for creating the Red-Black Tree. It has the following properties:
|
|
11177
|
+
* @returns a new instance of a RedBlackTree object.
|
|
11050
11178
|
*/
|
|
11051
|
-
// @ts-ignore
|
|
11052
11179
|
createTree(options) {
|
|
11053
11180
|
return new _RedBlackTree([], __spreadValues({
|
|
11054
11181
|
iterationType: this.iterationType,
|
|
@@ -11062,13 +11189,13 @@ var dataStructureTyped = (() => {
|
|
|
11062
11189
|
* Space Complexity: O(1)
|
|
11063
11190
|
*
|
|
11064
11191
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
11065
|
-
* @param {BTNRep<K, V,
|
|
11066
|
-
* `
|
|
11067
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
11192
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
11193
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
|
|
11194
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
11068
11195
|
* an instance of the `RedBlackTreeNode` class.
|
|
11069
11196
|
*/
|
|
11070
|
-
isNode(
|
|
11071
|
-
return
|
|
11197
|
+
isNode(keyNodeOrEntry) {
|
|
11198
|
+
return keyNodeOrEntry instanceof RedBlackTreeNode;
|
|
11072
11199
|
}
|
|
11073
11200
|
/**
|
|
11074
11201
|
* Time Complexity: O(1)
|
|
@@ -11083,12 +11210,12 @@ var dataStructureTyped = (() => {
|
|
|
11083
11210
|
}
|
|
11084
11211
|
/**
|
|
11085
11212
|
* Time Complexity: O(log n)
|
|
11086
|
-
* Space Complexity: O(
|
|
11213
|
+
* Space Complexity: O(log n)
|
|
11087
11214
|
*
|
|
11088
11215
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
11089
11216
|
* added.
|
|
11090
|
-
* @param {BTNRep<K, V,
|
|
11091
|
-
* `
|
|
11217
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
11218
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
|
|
11092
11219
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
11093
11220
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
11094
11221
|
* structure.
|
|
@@ -11096,8 +11223,8 @@ var dataStructureTyped = (() => {
|
|
|
11096
11223
|
* the method returns true. If the node already exists and its value is updated, the method also
|
|
11097
11224
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
11098
11225
|
*/
|
|
11099
|
-
add(
|
|
11100
|
-
const [newNode, newValue] = this.
|
|
11226
|
+
add(keyNodeOrEntry, value) {
|
|
11227
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
11101
11228
|
if (!this.isRealNode(newNode)) return false;
|
|
11102
11229
|
const insertStatus = this._insert(newNode);
|
|
11103
11230
|
if (insertStatus === "CREATED") {
|
|
@@ -11118,32 +11245,34 @@ var dataStructureTyped = (() => {
|
|
|
11118
11245
|
}
|
|
11119
11246
|
/**
|
|
11120
11247
|
* Time Complexity: O(log n)
|
|
11121
|
-
* Space Complexity: O(
|
|
11248
|
+
* Space Complexity: O(log n)
|
|
11122
11249
|
*
|
|
11123
11250
|
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
11124
11251
|
* a given predicate and maintain the binary search tree properties.
|
|
11125
|
-
* @param {BTNRep<K, V,
|
|
11252
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11126
11253
|
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
11127
11254
|
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
11128
11255
|
* function that determines which node(s) should be deleted.
|
|
11129
|
-
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<
|
|
11256
|
+
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>`
|
|
11130
11257
|
* objects. Each object in the array contains information about the deleted node and whether
|
|
11131
11258
|
* balancing is needed.
|
|
11132
11259
|
*/
|
|
11133
|
-
delete(
|
|
11134
|
-
if (
|
|
11260
|
+
delete(keyNodeOrEntry) {
|
|
11261
|
+
if (keyNodeOrEntry === null) return [];
|
|
11135
11262
|
const results = [];
|
|
11136
11263
|
let nodeToDelete;
|
|
11137
|
-
if (this._isPredicate(
|
|
11138
|
-
else nodeToDelete = this.isRealNode(
|
|
11264
|
+
if (this._isPredicate(keyNodeOrEntry)) nodeToDelete = this.getNode(keyNodeOrEntry);
|
|
11265
|
+
else nodeToDelete = this.isRealNode(keyNodeOrEntry) ? keyNodeOrEntry : this.getNode(keyNodeOrEntry);
|
|
11139
11266
|
if (!nodeToDelete) {
|
|
11140
11267
|
return results;
|
|
11141
11268
|
}
|
|
11142
11269
|
let originalColor = nodeToDelete.color;
|
|
11143
11270
|
let replacementNode;
|
|
11144
11271
|
if (!this.isRealNode(nodeToDelete.left)) {
|
|
11145
|
-
|
|
11146
|
-
|
|
11272
|
+
if (nodeToDelete.right !== null) {
|
|
11273
|
+
replacementNode = nodeToDelete.right;
|
|
11274
|
+
this._transplant(nodeToDelete, nodeToDelete.right);
|
|
11275
|
+
}
|
|
11147
11276
|
} else if (!this.isRealNode(nodeToDelete.right)) {
|
|
11148
11277
|
replacementNode = nodeToDelete.left;
|
|
11149
11278
|
this._transplant(nodeToDelete, nodeToDelete.left);
|
|
@@ -11151,14 +11280,16 @@ var dataStructureTyped = (() => {
|
|
|
11151
11280
|
const successor = this.getLeftMost((node) => node, nodeToDelete.right);
|
|
11152
11281
|
if (successor) {
|
|
11153
11282
|
originalColor = successor.color;
|
|
11154
|
-
replacementNode = successor.right;
|
|
11283
|
+
if (successor.right !== null) replacementNode = successor.right;
|
|
11155
11284
|
if (successor.parent === nodeToDelete) {
|
|
11156
11285
|
if (this.isRealNode(replacementNode)) {
|
|
11157
11286
|
replacementNode.parent = successor;
|
|
11158
11287
|
}
|
|
11159
11288
|
} else {
|
|
11160
|
-
|
|
11161
|
-
|
|
11289
|
+
if (successor.right !== null) {
|
|
11290
|
+
this._transplant(successor, successor.right);
|
|
11291
|
+
successor.right = nodeToDelete.right;
|
|
11292
|
+
}
|
|
11162
11293
|
if (this.isRealNode(successor.right)) {
|
|
11163
11294
|
successor.right.parent = successor;
|
|
11164
11295
|
}
|
|
@@ -11199,7 +11330,6 @@ var dataStructureTyped = (() => {
|
|
|
11199
11330
|
* @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
|
|
11200
11331
|
* provided callback function.
|
|
11201
11332
|
*/
|
|
11202
|
-
// @ts-ignore
|
|
11203
11333
|
map(callback, options, thisArg) {
|
|
11204
11334
|
const newTree = new _RedBlackTree([], options);
|
|
11205
11335
|
let index = 0;
|
|
@@ -11208,13 +11338,26 @@ var dataStructureTyped = (() => {
|
|
|
11208
11338
|
}
|
|
11209
11339
|
return newTree;
|
|
11210
11340
|
}
|
|
11341
|
+
/**
|
|
11342
|
+
* Time Complexity: O(n)
|
|
11343
|
+
* Space Complexity: O(n)
|
|
11344
|
+
*
|
|
11345
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
11346
|
+
* structure.
|
|
11347
|
+
* @returns The `cloned` object is being returned.
|
|
11348
|
+
*/
|
|
11349
|
+
clone() {
|
|
11350
|
+
const cloned = this.createTree();
|
|
11351
|
+
this._clone(cloned);
|
|
11352
|
+
return cloned;
|
|
11353
|
+
}
|
|
11211
11354
|
/**
|
|
11212
11355
|
* Time Complexity: O(1)
|
|
11213
11356
|
* Space Complexity: O(1)
|
|
11214
11357
|
*
|
|
11215
11358
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
11216
11359
|
* root.
|
|
11217
|
-
* @param {
|
|
11360
|
+
* @param {RedBlackTreeNode<K, V> | undefined} v - v is a parameter of type RedBlackTreeNode<K, V> or undefined.
|
|
11218
11361
|
*/
|
|
11219
11362
|
_setRoot(v) {
|
|
11220
11363
|
if (v) {
|
|
@@ -11227,9 +11370,9 @@ var dataStructureTyped = (() => {
|
|
|
11227
11370
|
* Space Complexity: O(1)
|
|
11228
11371
|
*
|
|
11229
11372
|
* The function replaces an old node with a new node while preserving the color of the old node.
|
|
11230
|
-
* @param {
|
|
11373
|
+
* @param {RedBlackTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
11231
11374
|
* the data structure.
|
|
11232
|
-
* @param {
|
|
11375
|
+
* @param {RedBlackTreeNode<K, V>} newNode - The `newNode` parameter is of type `RedBlackTreeNode<K, V>`, which represents a node in a
|
|
11233
11376
|
* data structure.
|
|
11234
11377
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
11235
11378
|
* superclass, with the `oldNode` and `newNode` parameters.
|
|
@@ -11240,11 +11383,11 @@ var dataStructureTyped = (() => {
|
|
|
11240
11383
|
}
|
|
11241
11384
|
/**
|
|
11242
11385
|
* Time Complexity: O(log n)
|
|
11243
|
-
* Space Complexity: O(
|
|
11386
|
+
* Space Complexity: O(log n)
|
|
11244
11387
|
*
|
|
11245
11388
|
* The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
|
|
11246
11389
|
* maintain the red-black tree properties.
|
|
11247
|
-
* @param {
|
|
11390
|
+
* @param {RedBlackTreeNode<K, V>} node - The `node` parameter represents the node that needs to be inserted into the
|
|
11248
11391
|
* binary search tree.
|
|
11249
11392
|
* @returns a string value indicating the result of the insertion operation. It can return either
|
|
11250
11393
|
* 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
|
|
@@ -11285,9 +11428,9 @@ var dataStructureTyped = (() => {
|
|
|
11285
11428
|
* Space Complexity: O(1)
|
|
11286
11429
|
*
|
|
11287
11430
|
* The function `_transplant` is used to replace a node `u` with another node `v` in a binary tree.
|
|
11288
|
-
* @param {
|
|
11289
|
-
* @param {
|
|
11290
|
-
* either be a `
|
|
11431
|
+
* @param {RedBlackTreeNode<K, V>} u - The parameter "u" represents a node in a binary tree.
|
|
11432
|
+
* @param {RedBlackTreeNode<K, V> | undefined} v - The parameter `v` is of type `RedBlackTreeNode<K, V> | undefined`, which means it can
|
|
11433
|
+
* either be a `RedBlackTreeNode<K, V>` object or `undefined`.
|
|
11291
11434
|
*/
|
|
11292
11435
|
_transplant(u, v) {
|
|
11293
11436
|
if (!u.parent) {
|
|
@@ -11306,11 +11449,11 @@ var dataStructureTyped = (() => {
|
|
|
11306
11449
|
* Space Complexity: O(1)
|
|
11307
11450
|
*
|
|
11308
11451
|
* The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
|
|
11309
|
-
* @param {
|
|
11452
|
+
* @param {RedBlackTreeNode<K, V> | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
|
|
11310
11453
|
* structure. It can either be a valid node or `undefined`.
|
|
11311
11454
|
*/
|
|
11312
11455
|
_insertFixup(z) {
|
|
11313
|
-
var _a, _b, _c, _d;
|
|
11456
|
+
var _a, _b, _c, _d, _e;
|
|
11314
11457
|
while (((_a = z == null ? void 0 : z.parent) == null ? void 0 : _a.color) === "RED") {
|
|
11315
11458
|
if (z.parent === ((_b = z.parent.parent) == null ? void 0 : _b.left)) {
|
|
11316
11459
|
const y = z.parent.parent.right;
|
|
@@ -11331,7 +11474,7 @@ var dataStructureTyped = (() => {
|
|
|
11331
11474
|
}
|
|
11332
11475
|
}
|
|
11333
11476
|
} else {
|
|
11334
|
-
const y = (_d = (_c = z == null ? void 0 : z.parent) == null ? void 0 : _c.parent) == null ? void 0 : _d.left;
|
|
11477
|
+
const y = (_e = (_d = (_c = z == null ? void 0 : z.parent) == null ? void 0 : _c.parent) == null ? void 0 : _d.left) != null ? _e : void 0;
|
|
11335
11478
|
if ((y == null ? void 0 : y.color) === "RED") {
|
|
11336
11479
|
z.parent.color = "BLACK";
|
|
11337
11480
|
y.color = "BLACK";
|
|
@@ -11358,7 +11501,7 @@ var dataStructureTyped = (() => {
|
|
|
11358
11501
|
*
|
|
11359
11502
|
* The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
|
|
11360
11503
|
* the colors and performing rotations.
|
|
11361
|
-
* @param {
|
|
11504
|
+
* @param {RedBlackTreeNode<K, V> | undefined} node - The `node` parameter represents a node in a binary tree. It can
|
|
11362
11505
|
* be either a valid node object or `undefined`.
|
|
11363
11506
|
* @returns The function does not return any value. It has a return type of `void`, which means it
|
|
11364
11507
|
* does not return anything.
|
|
@@ -11423,7 +11566,7 @@ var dataStructureTyped = (() => {
|
|
|
11423
11566
|
* Space Complexity: O(1)
|
|
11424
11567
|
*
|
|
11425
11568
|
* The `_leftRotate` function performs a left rotation on a given node in a binary tree.
|
|
11426
|
-
* @param {
|
|
11569
|
+
* @param {RedBlackTreeNode<K, V> | undefined} x - The parameter `x` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
11427
11570
|
* node in a binary tree or `undefined` if there is no node.
|
|
11428
11571
|
* @returns void, which means it does not return any value.
|
|
11429
11572
|
*/
|
|
@@ -11452,7 +11595,7 @@ var dataStructureTyped = (() => {
|
|
|
11452
11595
|
* Space Complexity: O(1)
|
|
11453
11596
|
*
|
|
11454
11597
|
* The `_rightRotate` function performs a right rotation on a given node in a binary tree.
|
|
11455
|
-
* @param {
|
|
11598
|
+
* @param {RedBlackTreeNode<K, V> | undefined} y - The parameter `y` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
11456
11599
|
* node in a binary tree or `undefined` if there is no node.
|
|
11457
11600
|
* @returns void, which means it does not return any value.
|
|
11458
11601
|
*/
|
|
@@ -11481,388 +11624,360 @@ var dataStructureTyped = (() => {
|
|
|
11481
11624
|
// src/data-structures/binary-tree/avl-tree-multi-map.ts
|
|
11482
11625
|
var AVLTreeMultiMapNode = class extends AVLTreeNode {
|
|
11483
11626
|
/**
|
|
11484
|
-
*
|
|
11485
|
-
*
|
|
11486
|
-
*
|
|
11487
|
-
*
|
|
11488
|
-
*
|
|
11489
|
-
* @param {
|
|
11490
|
-
*
|
|
11491
|
-
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
11627
|
+
* This TypeScript constructor initializes an object with a key of type K and an array of values of
|
|
11628
|
+
* type V.
|
|
11629
|
+
* @param {K} key - The `key` parameter is typically used to store a unique identifier or key for the
|
|
11630
|
+
* data being stored in the data structure. It helps in quickly accessing or retrieving the
|
|
11631
|
+
* associated value in the data structure.
|
|
11632
|
+
* @param {V[]} value - The `value` parameter in the constructor represents an array of values of
|
|
11633
|
+
* type `V`.
|
|
11492
11634
|
*/
|
|
11493
|
-
constructor(key, value
|
|
11635
|
+
constructor(key, value) {
|
|
11494
11636
|
super(key, value);
|
|
11495
|
-
__publicField(this, "
|
|
11496
|
-
this
|
|
11637
|
+
__publicField(this, "parent");
|
|
11638
|
+
__publicField(this, "_left");
|
|
11639
|
+
__publicField(this, "_right");
|
|
11497
11640
|
}
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
* @returns The count property of the object, which is of type number.
|
|
11501
|
-
*/
|
|
11502
|
-
get count() {
|
|
11503
|
-
return this._count;
|
|
11641
|
+
get left() {
|
|
11642
|
+
return this._left;
|
|
11504
11643
|
}
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11644
|
+
set left(v) {
|
|
11645
|
+
if (v) {
|
|
11646
|
+
v.parent = this;
|
|
11647
|
+
}
|
|
11648
|
+
this._left = v;
|
|
11649
|
+
}
|
|
11650
|
+
get right() {
|
|
11651
|
+
return this._right;
|
|
11652
|
+
}
|
|
11653
|
+
set right(v) {
|
|
11654
|
+
if (v) {
|
|
11655
|
+
v.parent = this;
|
|
11656
|
+
}
|
|
11657
|
+
this._right = v;
|
|
11512
11658
|
}
|
|
11513
11659
|
};
|
|
11514
11660
|
var AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
11515
11661
|
/**
|
|
11516
|
-
* The constructor initializes
|
|
11517
|
-
*
|
|
11518
|
-
*
|
|
11519
|
-
*
|
|
11520
|
-
*
|
|
11521
|
-
*
|
|
11662
|
+
* The constructor initializes an AVLTreeMultiMap with the provided keys, nodes, entries, or raw data
|
|
11663
|
+
* and options.
|
|
11664
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
11665
|
+
* iterable that can contain either key-value pairs represented as `BTNRep<K, V[],
|
|
11666
|
+
* AVLTreeMultiMapNode<K, V>>` or raw data represented as `R`. This parameter is used to initialize
|
|
11667
|
+
* the AVLTreeMulti
|
|
11668
|
+
* @param [options] - The `options` parameter in the constructor is of type
|
|
11669
|
+
* `AVLTreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
|
|
11670
|
+
* additional options for configuring the AVLTreeMultiMap instance.
|
|
11522
11671
|
*/
|
|
11523
11672
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11524
|
-
super([], options);
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
/**
|
|
11529
|
-
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
11530
|
-
* search.
|
|
11531
|
-
* @returns the sum of the count property of all nodes in the tree.
|
|
11532
|
-
*/
|
|
11533
|
-
get count() {
|
|
11534
|
-
return this._count;
|
|
11673
|
+
super([], __spreadProps(__spreadValues({}, options), { isMapMode: true }));
|
|
11674
|
+
if (keysNodesEntriesOrRaws) {
|
|
11675
|
+
this.addMany(keysNodesEntriesOrRaws);
|
|
11676
|
+
}
|
|
11535
11677
|
}
|
|
11536
11678
|
/**
|
|
11537
|
-
* Time Complexity: O(
|
|
11679
|
+
* Time Complexity: O(1)
|
|
11538
11680
|
* Space Complexity: O(1)
|
|
11539
11681
|
*
|
|
11540
|
-
* The function
|
|
11541
|
-
*
|
|
11542
|
-
* @
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
return sum;
|
|
11548
|
-
}
|
|
11549
|
-
/**
|
|
11550
|
-
* The function creates a new AVLTreeMultiMapNode with the specified key, value, and count.
|
|
11551
|
-
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
11552
|
-
* which is a generic type that can be replaced with any specific type when using the function.
|
|
11553
|
-
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
11554
|
-
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
11555
|
-
* @param {number} [count] - The `count` parameter represents the number of occurrences of a
|
|
11556
|
-
* key-value pair in the AVLTreeMultiMapNode. It is an optional parameter, so it can be omitted when
|
|
11557
|
-
* calling the `createNode` method. If provided, it specifies the initial count for the node.
|
|
11558
|
-
* @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
|
|
11559
|
-
*/
|
|
11560
|
-
createNode(key, value, count) {
|
|
11561
|
-
return new AVLTreeMultiMapNode(key, this._isMapMode ? void 0 : value, count);
|
|
11562
|
-
}
|
|
11563
|
-
/**
|
|
11564
|
-
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
11565
|
-
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
11566
|
-
* configuration options for creating the AVLTreeMultiMap. It can have the following properties:
|
|
11567
|
-
* @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
|
|
11568
|
-
* object.
|
|
11682
|
+
* The function `createTree` in TypeScript overrides the creation of an AVLTreeMultiMap with
|
|
11683
|
+
* specified options.
|
|
11684
|
+
* @param [options] - The `options` parameter in the `createTree` function is of type
|
|
11685
|
+
* `AVLTreeMultiMapOptions<K, V[], R>`. This means it is an object that can have properties of type
|
|
11686
|
+
* `K`, `V[]`, and `R`. The function creates a new `AVL
|
|
11687
|
+
* @returns The `createTree` method is returning a new instance of `AVLTreeMultiMap` with the
|
|
11688
|
+
* provided options.
|
|
11569
11689
|
*/
|
|
11570
|
-
// @ts-ignore
|
|
11571
11690
|
createTree(options) {
|
|
11572
11691
|
return new _AVLTreeMultiMap([], __spreadValues({
|
|
11573
11692
|
iterationType: this.iterationType,
|
|
11574
|
-
isMapMode: this._isMapMode,
|
|
11575
11693
|
specifyComparable: this._specifyComparable,
|
|
11576
11694
|
toEntryFn: this._toEntryFn,
|
|
11577
11695
|
isReverse: this._isReverse
|
|
11578
11696
|
}, options));
|
|
11579
11697
|
}
|
|
11580
11698
|
/**
|
|
11581
|
-
*
|
|
11582
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
11583
|
-
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
11584
|
-
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
11585
|
-
* an instance of the `AVLTreeMultiMapNode` class.
|
|
11586
|
-
*/
|
|
11587
|
-
isNode(keyNodeEntryOrRaw) {
|
|
11588
|
-
return keyNodeEntryOrRaw instanceof AVLTreeMultiMapNode;
|
|
11589
|
-
}
|
|
11590
|
-
/**
|
|
11591
|
-
* Time Complexity: O(log n)
|
|
11699
|
+
* Time Complexity: O(1)
|
|
11592
11700
|
* Space Complexity: O(1)
|
|
11593
11701
|
*
|
|
11594
|
-
* The function overrides the
|
|
11595
|
-
* and
|
|
11596
|
-
* @param {
|
|
11597
|
-
*
|
|
11598
|
-
*
|
|
11599
|
-
*
|
|
11600
|
-
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
11601
|
-
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
11602
|
-
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
11603
|
-
* be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
|
|
11604
|
-
* be added once. However, you can specify a different value for `count` if you want to add
|
|
11605
|
-
* @returns a boolean value.
|
|
11702
|
+
* The function `createNode` overrides the method to create a new AVLTreeMultiMapNode with a
|
|
11703
|
+
* specified key and an empty array of values.
|
|
11704
|
+
* @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
|
|
11705
|
+
* that will be created in the AVLTreeMultiMap.
|
|
11706
|
+
* @returns An AVLTreeMultiMapNode object is being returned, initialized with the provided key and an
|
|
11707
|
+
* empty array.
|
|
11606
11708
|
*/
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
if (newNode === void 0) return false;
|
|
11610
|
-
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
11611
|
-
const inserted = super.add(newNode, newValue);
|
|
11612
|
-
if (inserted) {
|
|
11613
|
-
this._count += orgNodeCount;
|
|
11614
|
-
}
|
|
11615
|
-
return true;
|
|
11709
|
+
createNode(key) {
|
|
11710
|
+
return new AVLTreeMultiMapNode(key, []);
|
|
11616
11711
|
}
|
|
11617
11712
|
/**
|
|
11618
11713
|
* Time Complexity: O(log n)
|
|
11619
|
-
* Space Complexity: O(
|
|
11714
|
+
* Space Complexity: O(log n)
|
|
11620
11715
|
*
|
|
11621
|
-
* The function overrides the
|
|
11622
|
-
*
|
|
11623
|
-
* @param {BTNRep<K, V,
|
|
11624
|
-
* parameter in the `
|
|
11625
|
-
*
|
|
11626
|
-
*
|
|
11627
|
-
* @param [
|
|
11628
|
-
*
|
|
11629
|
-
*
|
|
11630
|
-
* `
|
|
11631
|
-
*
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
|
|
11636
|
-
|
|
11637
|
-
|
|
11638
|
-
|
|
11639
|
-
|
|
11640
|
-
|
|
11641
|
-
|
|
11642
|
-
|
|
11643
|
-
|
|
11644
|
-
|
|
11645
|
-
|
|
11646
|
-
|
|
11647
|
-
|
|
11648
|
-
|
|
11649
|
-
|
|
11650
|
-
|
|
11716
|
+
* The function `add` in TypeScript overrides the superclass method to add key-value pairs to an AVL
|
|
11717
|
+
* tree multi-map.
|
|
11718
|
+
* @param {BTNRep<K, V[], AVLTreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11719
|
+
* parameter in the `override add` method can be either a key-value pair entry or just a key. If it
|
|
11720
|
+
* is a key-value pair entry, it will be in the format `[key, values]`, where `key` is the key and
|
|
11721
|
+
* `values`
|
|
11722
|
+
* @param {V} [value] - The `value` parameter in the `override add` method represents the value that
|
|
11723
|
+
* you want to add to the AVLTreeMultiMap. It can be a single value or an array of values associated
|
|
11724
|
+
* with a specific key.
|
|
11725
|
+
* @returns The `override add` method is returning a boolean value, which indicates whether the
|
|
11726
|
+
* addition operation was successful or not.
|
|
11727
|
+
*/
|
|
11728
|
+
add(keyNodeOrEntry, value) {
|
|
11729
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
|
|
11730
|
+
const _commonAdd = (key, values) => {
|
|
11731
|
+
if (key === void 0 || key === null) return false;
|
|
11732
|
+
const existingValues = this.get(key);
|
|
11733
|
+
if (existingValues !== void 0 && values !== void 0) {
|
|
11734
|
+
for (const value2 of values) existingValues.push(value2);
|
|
11735
|
+
return true;
|
|
11736
|
+
}
|
|
11737
|
+
const existingNode = this.getNode(key);
|
|
11738
|
+
if (this.isRealNode(existingNode)) {
|
|
11739
|
+
if (existingValues === void 0) {
|
|
11740
|
+
super.add(key, values);
|
|
11741
|
+
return true;
|
|
11742
|
+
}
|
|
11743
|
+
if (values !== void 0) {
|
|
11744
|
+
for (const value2 of values) existingValues.push(value2);
|
|
11745
|
+
return true;
|
|
11651
11746
|
} else {
|
|
11652
|
-
|
|
11653
|
-
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
11654
|
-
parent.left = curr.right;
|
|
11655
|
-
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
11656
|
-
parent.right = curr.right;
|
|
11657
|
-
}
|
|
11658
|
-
needBalanced = parent;
|
|
11747
|
+
return false;
|
|
11659
11748
|
}
|
|
11660
11749
|
} else {
|
|
11661
|
-
|
|
11662
|
-
if (leftSubTreeRightMost) {
|
|
11663
|
-
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
11664
|
-
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
11665
|
-
if (parentOfLeftSubTreeMax) {
|
|
11666
|
-
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
|
|
11667
|
-
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
11668
|
-
} else {
|
|
11669
|
-
parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
11670
|
-
}
|
|
11671
|
-
needBalanced = parentOfLeftSubTreeMax;
|
|
11672
|
-
}
|
|
11673
|
-
}
|
|
11750
|
+
return super.add(key, values);
|
|
11674
11751
|
}
|
|
11675
|
-
|
|
11676
|
-
|
|
11752
|
+
};
|
|
11753
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
11754
|
+
const [key, values] = keyNodeOrEntry;
|
|
11755
|
+
return _commonAdd(key, value !== void 0 ? [value] : values);
|
|
11677
11756
|
}
|
|
11678
|
-
|
|
11679
|
-
|
|
11680
|
-
|
|
11757
|
+
return _commonAdd(keyNodeOrEntry, value !== void 0 ? [value] : void 0);
|
|
11758
|
+
}
|
|
11759
|
+
/**
|
|
11760
|
+
* Time Complexity: O(log n)
|
|
11761
|
+
* Space Complexity: O(log n)
|
|
11762
|
+
*
|
|
11763
|
+
* The function `deleteValue` removes a specific value from a key in an AVLTreeMultiMap data
|
|
11764
|
+
* structure and deletes the entire node if no values are left for that key.
|
|
11765
|
+
* @param {BTNRep<K, V[], AVLTreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11766
|
+
* parameter in the `deleteValue` function can be either a `BTNRep` object representing a key-value
|
|
11767
|
+
* pair in the AVLTreeMultiMapNode, or just the key itself.
|
|
11768
|
+
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
11769
|
+
* value that you want to delete from the multi-map data structure associated with a particular key.
|
|
11770
|
+
* The function checks if the value exists in the array of values associated with the key, and if
|
|
11771
|
+
* found, removes it from the array.
|
|
11772
|
+
* @returns The `deleteValue` function returns a boolean value. It returns `true` if the specified
|
|
11773
|
+
* `value` was successfully deleted from the array of values associated with the `keyNodeOrEntry`. If
|
|
11774
|
+
* the value was not found in the array, it returns `false`.
|
|
11775
|
+
*/
|
|
11776
|
+
deleteValue(keyNodeOrEntry, value) {
|
|
11777
|
+
const values = this.get(keyNodeOrEntry);
|
|
11778
|
+
if (Array.isArray(values)) {
|
|
11779
|
+
const index = values.indexOf(value);
|
|
11780
|
+
if (index === -1) return false;
|
|
11781
|
+
values.splice(index, 1);
|
|
11782
|
+
if (values.length === 0) this.delete(keyNodeOrEntry);
|
|
11783
|
+
return true;
|
|
11681
11784
|
}
|
|
11682
|
-
return
|
|
11785
|
+
return false;
|
|
11683
11786
|
}
|
|
11684
11787
|
/**
|
|
11685
|
-
* Time Complexity: O(
|
|
11686
|
-
* Space Complexity: O(
|
|
11788
|
+
* Time Complexity: O(n)
|
|
11789
|
+
* Space Complexity: O(n)
|
|
11687
11790
|
*
|
|
11688
|
-
* The
|
|
11689
|
-
*
|
|
11791
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
11792
|
+
* structure.
|
|
11793
|
+
* @returns A cloned tree object is being returned.
|
|
11690
11794
|
*/
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
this.
|
|
11795
|
+
clone() {
|
|
11796
|
+
const cloned = this.createTree();
|
|
11797
|
+
this._clone(cloned);
|
|
11798
|
+
return cloned;
|
|
11694
11799
|
}
|
|
11800
|
+
};
|
|
11801
|
+
|
|
11802
|
+
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
11803
|
+
var TreeMultiMapNode = class extends RedBlackTreeNode {
|
|
11695
11804
|
/**
|
|
11696
|
-
*
|
|
11697
|
-
*
|
|
11698
|
-
* The `
|
|
11699
|
-
*
|
|
11700
|
-
*
|
|
11701
|
-
*
|
|
11702
|
-
*
|
|
11703
|
-
* the object.
|
|
11704
|
-
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
11705
|
-
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
11805
|
+
* This TypeScript constructor initializes an object with a key of type K and an array of values of
|
|
11806
|
+
* type V.
|
|
11807
|
+
* @param {K} key - The `key` parameter is typically used to store a unique identifier or key for the
|
|
11808
|
+
* data being stored in the data structure. It helps in quickly accessing or retrieving the
|
|
11809
|
+
* associated value in the data structure.
|
|
11810
|
+
* @param {V[]} value - The `value` parameter in the constructor represents an array of values of
|
|
11811
|
+
* type `V`.
|
|
11706
11812
|
*/
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11710
|
-
this
|
|
11711
|
-
|
|
11712
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
|
|
11718
|
-
|
|
11719
|
-
buildBalanceBST(m + 1, r);
|
|
11720
|
-
};
|
|
11721
|
-
buildBalanceBST(0, n - 1);
|
|
11722
|
-
return true;
|
|
11723
|
-
} else {
|
|
11724
|
-
const stack = [[0, n - 1]];
|
|
11725
|
-
while (stack.length > 0) {
|
|
11726
|
-
const popped = stack.pop();
|
|
11727
|
-
if (popped) {
|
|
11728
|
-
const [l, r] = popped;
|
|
11729
|
-
if (l <= r) {
|
|
11730
|
-
const m = l + Math.floor((r - l) / 2);
|
|
11731
|
-
const midNode = sorted[m];
|
|
11732
|
-
if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
|
|
11733
|
-
else this.add(midNode.key, midNode.value, midNode.count);
|
|
11734
|
-
stack.push([m + 1, r]);
|
|
11735
|
-
stack.push([l, m - 1]);
|
|
11736
|
-
}
|
|
11737
|
-
}
|
|
11738
|
-
}
|
|
11739
|
-
return true;
|
|
11813
|
+
constructor(key, value) {
|
|
11814
|
+
super(key, value);
|
|
11815
|
+
__publicField(this, "parent");
|
|
11816
|
+
__publicField(this, "_left");
|
|
11817
|
+
__publicField(this, "_right");
|
|
11818
|
+
}
|
|
11819
|
+
get left() {
|
|
11820
|
+
return this._left;
|
|
11821
|
+
}
|
|
11822
|
+
set left(v) {
|
|
11823
|
+
if (v) {
|
|
11824
|
+
v.parent = this;
|
|
11740
11825
|
}
|
|
11826
|
+
this._left = v;
|
|
11741
11827
|
}
|
|
11742
|
-
|
|
11743
|
-
|
|
11744
|
-
|
|
11745
|
-
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
|
|
11749
|
-
|
|
11750
|
-
clone() {
|
|
11751
|
-
const cloned = this.createTree();
|
|
11752
|
-
if (this._isMapMode) this.bfs((node) => cloned.add(node.key, void 0, node.count));
|
|
11753
|
-
else this.bfs((node) => cloned.add(node.key, node.value, node.count));
|
|
11754
|
-
if (this._isMapMode) cloned._store = this._store;
|
|
11755
|
-
return cloned;
|
|
11828
|
+
get right() {
|
|
11829
|
+
return this._right;
|
|
11830
|
+
}
|
|
11831
|
+
set right(v) {
|
|
11832
|
+
if (v) {
|
|
11833
|
+
v.parent = this;
|
|
11834
|
+
}
|
|
11835
|
+
this._right = v;
|
|
11756
11836
|
}
|
|
11837
|
+
};
|
|
11838
|
+
var TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
11757
11839
|
/**
|
|
11758
|
-
* The
|
|
11759
|
-
*
|
|
11760
|
-
* @param
|
|
11761
|
-
*
|
|
11762
|
-
*
|
|
11763
|
-
*
|
|
11764
|
-
*
|
|
11765
|
-
*
|
|
11766
|
-
*
|
|
11767
|
-
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
11768
|
-
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
11769
|
-
* or
|
|
11770
|
-
* @returns The `map` method is returning a new `AVLTreeMultiMap` instance with the entries
|
|
11771
|
-
* transformed by the provided `callback` function. Each entry in the original tree is passed to the
|
|
11772
|
-
* `callback` function along with the index and the original tree itself. The transformed entries are
|
|
11773
|
-
* then added to the new `AVLTreeMultiMap` instance, which is returned at the end.
|
|
11840
|
+
* The constructor initializes an TreeMultiMap with the provided keys, nodes, entries, or raw data
|
|
11841
|
+
* and options.
|
|
11842
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
11843
|
+
* iterable that can contain either key-value pairs represented as `BTNRep<K, V[],
|
|
11844
|
+
* TreeMultiMapNode<K, V>>` or raw data represented as `R`. This parameter is used to initialize
|
|
11845
|
+
* the RedBlackTreeMulti
|
|
11846
|
+
* @param [options] - The `options` parameter in the constructor is of type
|
|
11847
|
+
* `TreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
|
|
11848
|
+
* additional options for configuring the TreeMultiMap instance.
|
|
11774
11849
|
*/
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
for (const [key, value] of this) {
|
|
11780
|
-
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
11850
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11851
|
+
super([], __spreadProps(__spreadValues({}, options), { isMapMode: true }));
|
|
11852
|
+
if (keysNodesEntriesOrRaws) {
|
|
11853
|
+
this.addMany(keysNodesEntriesOrRaws);
|
|
11781
11854
|
}
|
|
11782
|
-
return newTree;
|
|
11783
11855
|
}
|
|
11784
11856
|
/**
|
|
11785
|
-
*
|
|
11786
|
-
*
|
|
11787
|
-
*
|
|
11788
|
-
* `
|
|
11789
|
-
*
|
|
11790
|
-
*
|
|
11791
|
-
*
|
|
11792
|
-
*
|
|
11793
|
-
*
|
|
11794
|
-
* @returns
|
|
11857
|
+
* Time Complexity: O(1)
|
|
11858
|
+
* Space Complexity: O(1)
|
|
11859
|
+
*
|
|
11860
|
+
* The `createTree` function in TypeScript overrides the default implementation to create a new
|
|
11861
|
+
* TreeMultiMap with specified options.
|
|
11862
|
+
* @param [options] - The `options` parameter in the `createTree` method is of type
|
|
11863
|
+
* `TreeMultiMapOptions<K, V[], R>`. This parameter allows you to pass additional configuration
|
|
11864
|
+
* options when creating a new `TreeMultiMap` instance. It includes properties such as
|
|
11865
|
+
* `iterationType`, `specifyComparable
|
|
11866
|
+
* @returns A new instance of `TreeMultiMap` is being returned, with an empty array as the initial
|
|
11867
|
+
* data and the provided options merged with the existing properties of the current object.
|
|
11795
11868
|
*/
|
|
11796
|
-
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
11802
|
-
|
|
11803
|
-
return [this.createNode(key, finalValue, count), finalValue];
|
|
11804
|
-
}
|
|
11805
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
11806
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
11807
|
-
const finalValue = value != null ? value : entryValue;
|
|
11808
|
-
if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
|
|
11809
|
-
}
|
|
11810
|
-
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
|
|
11811
|
-
return [void 0, void 0];
|
|
11869
|
+
createTree(options) {
|
|
11870
|
+
return new _TreeMultiMap([], __spreadValues({
|
|
11871
|
+
iterationType: this.iterationType,
|
|
11872
|
+
specifyComparable: this._specifyComparable,
|
|
11873
|
+
toEntryFn: this._toEntryFn,
|
|
11874
|
+
isReverse: this._isReverse
|
|
11875
|
+
}, options));
|
|
11812
11876
|
}
|
|
11813
11877
|
/**
|
|
11814
11878
|
* Time Complexity: O(1)
|
|
11815
11879
|
* Space Complexity: O(1)
|
|
11816
11880
|
*
|
|
11817
|
-
* The `
|
|
11818
|
-
*
|
|
11819
|
-
* @param {
|
|
11820
|
-
* that will be
|
|
11821
|
-
* @
|
|
11822
|
-
*
|
|
11823
|
-
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
11824
|
-
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
11881
|
+
* The function `createNode` overrides the method to create a new `TreeMultiMapNode` with a specified
|
|
11882
|
+
* key and an empty array of values.
|
|
11883
|
+
* @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
|
|
11884
|
+
* that will be created in the TreeMultiMap data structure.
|
|
11885
|
+
* @returns A new instance of `TreeMultiMapNode<K, V>` is being returned, with the specified key and
|
|
11886
|
+
* an empty array as its value.
|
|
11825
11887
|
*/
|
|
11826
|
-
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
|
|
11831
|
-
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
|
|
11837
|
-
|
|
11838
|
-
|
|
11839
|
-
|
|
11840
|
-
|
|
11841
|
-
|
|
11888
|
+
createNode(key) {
|
|
11889
|
+
return new TreeMultiMapNode(key, []);
|
|
11890
|
+
}
|
|
11891
|
+
/**
|
|
11892
|
+
* Time Complexity: O(log n)
|
|
11893
|
+
* Space Complexity: O(log n)
|
|
11894
|
+
*
|
|
11895
|
+
* The function `add` in TypeScript overrides the superclass method to add key-value pairs to a
|
|
11896
|
+
* TreeMultiMapNode, handling different input types and scenarios.
|
|
11897
|
+
* @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11898
|
+
* parameter in the `override add` method can be either a `BTNRep` object containing a key, an array
|
|
11899
|
+
* of values, and a `TreeMultiMapNode`, or just a key.
|
|
11900
|
+
* @param {V} [value] - The `value` parameter in the `override add` method represents the value that
|
|
11901
|
+
* you want to add to the TreeMultiMap. If the key is already present in the map, the new value will
|
|
11902
|
+
* be added to the existing list of values associated with that key. If the key is not present,
|
|
11903
|
+
* @returns The `add` method is returning a boolean value, which indicates whether the operation was
|
|
11904
|
+
* successful or not.
|
|
11905
|
+
*/
|
|
11906
|
+
add(keyNodeOrEntry, value) {
|
|
11907
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
|
|
11908
|
+
const _commonAdd = (key, values) => {
|
|
11909
|
+
if (key === void 0 || key === null) return false;
|
|
11910
|
+
const existingValues = this.get(key);
|
|
11911
|
+
if (existingValues !== void 0 && values !== void 0) {
|
|
11912
|
+
for (const value2 of values) existingValues.push(value2);
|
|
11913
|
+
return true;
|
|
11842
11914
|
}
|
|
11843
|
-
|
|
11915
|
+
const existingNode = this.getNode(key);
|
|
11916
|
+
if (this.isRealNode(existingNode)) {
|
|
11917
|
+
if (existingValues === void 0) {
|
|
11918
|
+
super.add(key, values);
|
|
11919
|
+
return true;
|
|
11920
|
+
}
|
|
11921
|
+
if (values !== void 0) {
|
|
11922
|
+
for (const value2 of values) existingValues.push(value2);
|
|
11923
|
+
return true;
|
|
11924
|
+
} else {
|
|
11925
|
+
return false;
|
|
11926
|
+
}
|
|
11927
|
+
} else {
|
|
11928
|
+
return super.add(key, values);
|
|
11929
|
+
}
|
|
11930
|
+
};
|
|
11931
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
11932
|
+
const [key, values] = keyNodeOrEntry;
|
|
11933
|
+
return _commonAdd(key, value !== void 0 ? [value] : values);
|
|
11844
11934
|
}
|
|
11845
|
-
return void 0;
|
|
11935
|
+
return _commonAdd(keyNodeOrEntry, value !== void 0 ? [value] : void 0);
|
|
11846
11936
|
}
|
|
11847
11937
|
/**
|
|
11848
|
-
* Time Complexity: O(
|
|
11849
|
-
* Space Complexity: O(
|
|
11938
|
+
* Time Complexity: O(log n)
|
|
11939
|
+
* Space Complexity: O(log n)
|
|
11850
11940
|
*
|
|
11851
|
-
* The function
|
|
11852
|
-
*
|
|
11853
|
-
*
|
|
11854
|
-
*
|
|
11855
|
-
*
|
|
11856
|
-
*
|
|
11941
|
+
* The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
|
|
11942
|
+
* and deletes the entire node if no values are left for that key.
|
|
11943
|
+
* @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11944
|
+
* parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
|
|
11945
|
+
* array of values, or just a key itself.
|
|
11946
|
+
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
11947
|
+
* value that you want to remove from the multi-map data structure associated with a particular key.
|
|
11948
|
+
* The function checks if the value exists in the array of values associated with the key, and if
|
|
11949
|
+
* found, removes it from the array.
|
|
11950
|
+
* @returns The `deleteValue` function returns a boolean value - `true` if the specified `value` was
|
|
11951
|
+
* successfully deleted from the values associated with the `keyNodeOrEntry`, and `false` otherwise.
|
|
11952
|
+
*/
|
|
11953
|
+
deleteValue(keyNodeOrEntry, value) {
|
|
11954
|
+
const values = this.get(keyNodeOrEntry);
|
|
11955
|
+
if (Array.isArray(values)) {
|
|
11956
|
+
const index = values.indexOf(value);
|
|
11957
|
+
if (index === -1) return false;
|
|
11958
|
+
values.splice(index, 1);
|
|
11959
|
+
if (values.length === 0) this.delete(keyNodeOrEntry);
|
|
11960
|
+
return true;
|
|
11961
|
+
}
|
|
11962
|
+
return false;
|
|
11963
|
+
}
|
|
11964
|
+
/**
|
|
11965
|
+
* Time Complexity: O(n)
|
|
11966
|
+
* Space Complexity: O(n)
|
|
11967
|
+
*
|
|
11968
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
11969
|
+
* structure.
|
|
11970
|
+
* @returns The `cloned` object is being returned.
|
|
11857
11971
|
*/
|
|
11858
|
-
|
|
11859
|
-
|
|
11860
|
-
|
|
11972
|
+
clone() {
|
|
11973
|
+
const cloned = this.createTree();
|
|
11974
|
+
this._clone(cloned);
|
|
11975
|
+
return cloned;
|
|
11861
11976
|
}
|
|
11862
11977
|
};
|
|
11863
11978
|
|
|
11864
|
-
// src/data-structures/binary-tree/tree-
|
|
11865
|
-
var
|
|
11979
|
+
// src/data-structures/binary-tree/tree-counter.ts
|
|
11980
|
+
var TreeCounterNode = class extends RedBlackTreeNode {
|
|
11866
11981
|
/**
|
|
11867
11982
|
* The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
|
|
11868
11983
|
* @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
|
|
@@ -11877,33 +11992,38 @@ var dataStructureTyped = (() => {
|
|
|
11877
11992
|
*/
|
|
11878
11993
|
constructor(key, value, count = 1, color = "BLACK") {
|
|
11879
11994
|
super(key, value, color);
|
|
11880
|
-
__publicField(this, "
|
|
11995
|
+
__publicField(this, "parent");
|
|
11996
|
+
__publicField(this, "_left");
|
|
11997
|
+
__publicField(this, "_right");
|
|
11881
11998
|
this.count = count;
|
|
11882
11999
|
}
|
|
11883
|
-
|
|
11884
|
-
|
|
11885
|
-
* @returns The count property of the object, which is of type number.
|
|
11886
|
-
*/
|
|
11887
|
-
get count() {
|
|
11888
|
-
return this._count;
|
|
12000
|
+
get left() {
|
|
12001
|
+
return this._left;
|
|
11889
12002
|
}
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
12003
|
+
set left(v) {
|
|
12004
|
+
if (v) {
|
|
12005
|
+
v.parent = this;
|
|
12006
|
+
}
|
|
12007
|
+
this._left = v;
|
|
12008
|
+
}
|
|
12009
|
+
get right() {
|
|
12010
|
+
return this._right;
|
|
12011
|
+
}
|
|
12012
|
+
set right(v) {
|
|
12013
|
+
if (v) {
|
|
12014
|
+
v.parent = this;
|
|
12015
|
+
}
|
|
12016
|
+
this._right = v;
|
|
11897
12017
|
}
|
|
11898
12018
|
};
|
|
11899
|
-
var
|
|
12019
|
+
var TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
11900
12020
|
/**
|
|
11901
|
-
* The constructor function initializes a
|
|
12021
|
+
* The constructor function initializes a TreeCounter object with optional initial data.
|
|
11902
12022
|
* @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
|
|
11903
12023
|
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
11904
|
-
*
|
|
12024
|
+
* TreeCounter with initial data.
|
|
11905
12025
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
11906
|
-
* behavior of the `
|
|
12026
|
+
* behavior of the `TreeCounter` constructor. It can include properties such as `compareKeys` and
|
|
11907
12027
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
11908
12028
|
*/
|
|
11909
12029
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -11933,7 +12053,7 @@ var dataStructureTyped = (() => {
|
|
|
11933
12053
|
return sum;
|
|
11934
12054
|
}
|
|
11935
12055
|
/**
|
|
11936
|
-
* The function creates a new
|
|
12056
|
+
* The function creates a new TreeCounterNode with the specified key, value, color, and count.
|
|
11937
12057
|
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
11938
12058
|
* which is a generic type representing the type of keys in the tree.
|
|
11939
12059
|
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
@@ -11943,37 +12063,36 @@ var dataStructureTyped = (() => {
|
|
|
11943
12063
|
* @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
|
|
11944
12064
|
* the tree. It is an optional parameter and is used to keep track of the number of values associated
|
|
11945
12065
|
* with a key in the tree.
|
|
11946
|
-
* @returns A new instance of the
|
|
12066
|
+
* @returns A new instance of the TreeCounterNode class, casted as TreeCounterNode<K, V>.
|
|
11947
12067
|
*/
|
|
11948
12068
|
createNode(key, value, color = "BLACK", count) {
|
|
11949
|
-
return new
|
|
12069
|
+
return new TreeCounterNode(key, this._isMapMode ? void 0 : value, count, color);
|
|
11950
12070
|
}
|
|
11951
12071
|
/**
|
|
11952
|
-
* The function creates a new instance of a
|
|
12072
|
+
* The function creates a new instance of a TreeCounter with the specified options and returns it.
|
|
11953
12073
|
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
11954
|
-
* configuration options for creating the `
|
|
12074
|
+
* configuration options for creating the `TreeCounter`. It is of type `TreeCounterOptions<K, V,
|
|
11955
12075
|
* R>`.
|
|
11956
|
-
* @returns a new instance of the `
|
|
12076
|
+
* @returns a new instance of the `TreeCounter` class, with the provided options merged with the
|
|
11957
12077
|
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
11958
12078
|
*/
|
|
11959
|
-
// @ts-ignore
|
|
11960
12079
|
createTree(options) {
|
|
11961
|
-
return new
|
|
12080
|
+
return new _TreeCounter([], __spreadValues({
|
|
11962
12081
|
iterationType: this.iterationType,
|
|
11963
|
-
isMapMode: this._isMapMode,
|
|
11964
12082
|
specifyComparable: this._specifyComparable,
|
|
12083
|
+
isMapMode: this._isMapMode,
|
|
11965
12084
|
toEntryFn: this._toEntryFn
|
|
11966
12085
|
}, options));
|
|
11967
12086
|
}
|
|
11968
12087
|
/**
|
|
11969
|
-
* The function checks if the input is an instance of the
|
|
11970
|
-
* @param {BTNRep<K, V,
|
|
11971
|
-
* `
|
|
11972
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
11973
|
-
* an instance of the `
|
|
12088
|
+
* The function checks if the input is an instance of the TreeCounterNode class.
|
|
12089
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
|
|
12090
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
|
|
12091
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
12092
|
+
* an instance of the `TreeCounterNode` class.
|
|
11974
12093
|
*/
|
|
11975
|
-
isNode(
|
|
11976
|
-
return
|
|
12094
|
+
isNode(keyNodeOrEntry) {
|
|
12095
|
+
return keyNodeOrEntry instanceof TreeCounterNode;
|
|
11977
12096
|
}
|
|
11978
12097
|
/**
|
|
11979
12098
|
* Time Complexity: O(log n)
|
|
@@ -11981,8 +12100,8 @@ var dataStructureTyped = (() => {
|
|
|
11981
12100
|
*
|
|
11982
12101
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
11983
12102
|
* the count and returning a boolean indicating success.
|
|
11984
|
-
* @param {BTNRep<K, V,
|
|
11985
|
-
* `
|
|
12103
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The
|
|
12104
|
+
* `keyNodeOrEntry` parameter can accept one of the following types:
|
|
11986
12105
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
11987
12106
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
11988
12107
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
@@ -11991,8 +12110,8 @@ var dataStructureTyped = (() => {
|
|
|
11991
12110
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
11992
12111
|
* was successful, and false otherwise.
|
|
11993
12112
|
*/
|
|
11994
|
-
add(
|
|
11995
|
-
const [newNode, newValue] = this.
|
|
12113
|
+
add(keyNodeOrEntry, value, count = 1) {
|
|
12114
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
11996
12115
|
const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
11997
12116
|
const isSuccessAdded = super.add(newNode, newValue);
|
|
11998
12117
|
if (isSuccessAdded) {
|
|
@@ -12008,31 +12127,33 @@ var dataStructureTyped = (() => {
|
|
|
12008
12127
|
*
|
|
12009
12128
|
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
12010
12129
|
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
12011
|
-
* @param {BTNRep<K, V,
|
|
12130
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
|
|
12012
12131
|
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
12013
12132
|
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
12014
12133
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
12015
12134
|
* boolean flag that determines whether to ignore the count of nodes when performing deletion. If
|
|
12016
12135
|
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
12017
12136
|
* `ignoreCount` is `false
|
|
12018
|
-
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<
|
|
12137
|
+
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
|
|
12019
12138
|
*/
|
|
12020
|
-
delete(
|
|
12021
|
-
if (
|
|
12139
|
+
delete(keyNodeOrEntry, ignoreCount = false) {
|
|
12140
|
+
if (keyNodeOrEntry === null) return [];
|
|
12022
12141
|
const results = [];
|
|
12023
12142
|
let nodeToDelete;
|
|
12024
|
-
if (this._isPredicate(
|
|
12025
|
-
else nodeToDelete = this.isRealNode(
|
|
12143
|
+
if (this._isPredicate(keyNodeOrEntry)) nodeToDelete = this.getNode(keyNodeOrEntry);
|
|
12144
|
+
else nodeToDelete = this.isRealNode(keyNodeOrEntry) ? keyNodeOrEntry : this.getNode(keyNodeOrEntry);
|
|
12026
12145
|
if (!nodeToDelete) {
|
|
12027
12146
|
return results;
|
|
12028
12147
|
}
|
|
12029
12148
|
let originalColor = nodeToDelete.color;
|
|
12030
12149
|
let replacementNode;
|
|
12031
12150
|
if (!this.isRealNode(nodeToDelete.left)) {
|
|
12032
|
-
replacementNode = nodeToDelete.right;
|
|
12151
|
+
if (nodeToDelete.right !== null) replacementNode = nodeToDelete.right;
|
|
12033
12152
|
if (ignoreCount || nodeToDelete.count <= 1) {
|
|
12034
|
-
|
|
12035
|
-
|
|
12153
|
+
if (nodeToDelete.right !== null) {
|
|
12154
|
+
this._transplant(nodeToDelete, nodeToDelete.right);
|
|
12155
|
+
this._count -= nodeToDelete.count;
|
|
12156
|
+
}
|
|
12036
12157
|
} else {
|
|
12037
12158
|
nodeToDelete.count--;
|
|
12038
12159
|
this._count--;
|
|
@@ -12054,15 +12175,17 @@ var dataStructureTyped = (() => {
|
|
|
12054
12175
|
const successor = this.getLeftMost((node) => node, nodeToDelete.right);
|
|
12055
12176
|
if (successor) {
|
|
12056
12177
|
originalColor = successor.color;
|
|
12057
|
-
replacementNode = successor.right;
|
|
12178
|
+
if (successor.right !== null) replacementNode = successor.right;
|
|
12058
12179
|
if (successor.parent === nodeToDelete) {
|
|
12059
12180
|
if (this.isRealNode(replacementNode)) {
|
|
12060
12181
|
replacementNode.parent = successor;
|
|
12061
12182
|
}
|
|
12062
12183
|
} else {
|
|
12063
12184
|
if (ignoreCount || nodeToDelete.count <= 1) {
|
|
12064
|
-
|
|
12065
|
-
|
|
12185
|
+
if (successor.right !== null) {
|
|
12186
|
+
this._transplant(successor, successor.right);
|
|
12187
|
+
this._count -= nodeToDelete.count;
|
|
12188
|
+
}
|
|
12066
12189
|
} else {
|
|
12067
12190
|
nodeToDelete.count--;
|
|
12068
12191
|
this._count--;
|
|
@@ -12163,7 +12286,6 @@ var dataStructureTyped = (() => {
|
|
|
12163
12286
|
* The function overrides the clone method to create a deep copy of a tree object.
|
|
12164
12287
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
12165
12288
|
*/
|
|
12166
|
-
// @ts-ignore
|
|
12167
12289
|
clone() {
|
|
12168
12290
|
const cloned = this.createTree();
|
|
12169
12291
|
this.bfs((node) => cloned.add(node.key, void 0, node.count));
|
|
@@ -12171,23 +12293,22 @@ var dataStructureTyped = (() => {
|
|
|
12171
12293
|
return cloned;
|
|
12172
12294
|
}
|
|
12173
12295
|
/**
|
|
12174
|
-
* The `map` function in TypeScript overrides the default behavior to create a new
|
|
12296
|
+
* The `map` function in TypeScript overrides the default behavior to create a new TreeCounter with
|
|
12175
12297
|
* modified entries based on a provided callback.
|
|
12176
12298
|
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
12177
12299
|
* map. It takes four arguments:
|
|
12178
12300
|
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
12179
|
-
* `
|
|
12180
|
-
* options when creating a new `
|
|
12301
|
+
* `TreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
|
|
12302
|
+
* options when creating a new `TreeCounter` instance within the `map` function. These options could
|
|
12181
12303
|
* include things like
|
|
12182
12304
|
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
12183
12305
|
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
12184
12306
|
* (value of `this`) for the callback function when it is called within the `map` function. This
|
|
12185
|
-
* @returns A new
|
|
12307
|
+
* @returns A new TreeCounter instance is being returned, which is populated with entries generated
|
|
12186
12308
|
* by the provided callback function.
|
|
12187
12309
|
*/
|
|
12188
|
-
// @ts-ignore
|
|
12189
12310
|
map(callback, options, thisArg) {
|
|
12190
|
-
const newTree = new
|
|
12311
|
+
const newTree = new _TreeCounter([], options);
|
|
12191
12312
|
let index = 0;
|
|
12192
12313
|
for (const [key, value] of this) {
|
|
12193
12314
|
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
@@ -12197,31 +12318,25 @@ var dataStructureTyped = (() => {
|
|
|
12197
12318
|
/**
|
|
12198
12319
|
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
12199
12320
|
* node based on the input.
|
|
12200
|
-
* @param {BTNRep<K, V,
|
|
12201
|
-
* `
|
|
12321
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
|
|
12322
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
|
|
12202
12323
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
12203
12324
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
12204
12325
|
* an existing node.
|
|
12205
12326
|
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
12206
12327
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
12207
|
-
* @returns either a
|
|
12328
|
+
* @returns either a TreeCounterNode<K, V> object or undefined.
|
|
12208
12329
|
*/
|
|
12209
|
-
|
|
12210
|
-
if (
|
|
12211
|
-
if (this.isNode(
|
|
12212
|
-
if (this.isEntry(
|
|
12213
|
-
const [key, entryValue] =
|
|
12330
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count = 1) {
|
|
12331
|
+
if (keyNodeOrEntry === void 0 || keyNodeOrEntry === null) return [void 0, void 0];
|
|
12332
|
+
if (this.isNode(keyNodeOrEntry)) return [keyNodeOrEntry, value];
|
|
12333
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
12334
|
+
const [key, entryValue] = keyNodeOrEntry;
|
|
12214
12335
|
if (key === void 0 || key === null) return [void 0, void 0];
|
|
12215
12336
|
const finalValue = value != null ? value : entryValue;
|
|
12216
|
-
|
|
12217
|
-
}
|
|
12218
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
12219
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
12220
|
-
const finalValue = value != null ? value : entryValue;
|
|
12221
|
-
if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
12337
|
+
return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
12222
12338
|
}
|
|
12223
|
-
|
|
12224
|
-
return [void 0, void 0];
|
|
12339
|
+
return [this.createNode(keyNodeOrEntry, value, "BLACK", count), value];
|
|
12225
12340
|
}
|
|
12226
12341
|
/**
|
|
12227
12342
|
* Time Complexity: O(1)
|
|
@@ -12229,10 +12344,10 @@ var dataStructureTyped = (() => {
|
|
|
12229
12344
|
*
|
|
12230
12345
|
* The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
|
|
12231
12346
|
* in a binary search tree.
|
|
12232
|
-
* @param {R | BSTNOptKeyOrNode<K,
|
|
12347
|
+
* @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
|
|
12233
12348
|
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
12234
|
-
* instance of the `BSTNOptKeyOrNode<K,
|
|
12235
|
-
* @param {R | BSTNOptKeyOrNode<K,
|
|
12349
|
+
* instance of the `BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>` class.
|
|
12350
|
+
* @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
|
|
12236
12351
|
* node where the properties will be swapped with the source node.
|
|
12237
12352
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
12238
12353
|
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
@@ -12263,11 +12378,390 @@ var dataStructureTyped = (() => {
|
|
|
12263
12378
|
* Space Complexity: O(1)
|
|
12264
12379
|
*
|
|
12265
12380
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
12266
|
-
* @param {
|
|
12381
|
+
* @param {TreeCounterNode<K, V>} oldNode - The `oldNode` parameter is the node that you want to replace in the data
|
|
12267
12382
|
* structure.
|
|
12268
|
-
* @param {
|
|
12383
|
+
* @param {TreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `TreeCounterNode<K, V>` class.
|
|
12384
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
12385
|
+
* superclass, which is of type `TreeCounterNode<K, V>`.
|
|
12386
|
+
*/
|
|
12387
|
+
_replaceNode(oldNode, newNode) {
|
|
12388
|
+
newNode.count = oldNode.count + newNode.count;
|
|
12389
|
+
return super._replaceNode(oldNode, newNode);
|
|
12390
|
+
}
|
|
12391
|
+
};
|
|
12392
|
+
|
|
12393
|
+
// src/data-structures/binary-tree/avl-tree-counter.ts
|
|
12394
|
+
var AVLTreeCounterNode = class extends AVLTreeNode {
|
|
12395
|
+
/**
|
|
12396
|
+
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
12397
|
+
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
12398
|
+
* of the binary tree node.
|
|
12399
|
+
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
|
|
12400
|
+
* tree node. If no value is provided, it will be `undefined`.
|
|
12401
|
+
* @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
|
|
12402
|
+
* occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
|
|
12403
|
+
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
12404
|
+
*/
|
|
12405
|
+
constructor(key, value, count = 1) {
|
|
12406
|
+
super(key, value);
|
|
12407
|
+
__publicField(this, "parent");
|
|
12408
|
+
__publicField(this, "_left");
|
|
12409
|
+
__publicField(this, "_right");
|
|
12410
|
+
this.count = count;
|
|
12411
|
+
}
|
|
12412
|
+
get left() {
|
|
12413
|
+
return this._left;
|
|
12414
|
+
}
|
|
12415
|
+
set left(v) {
|
|
12416
|
+
if (v) {
|
|
12417
|
+
v.parent = this;
|
|
12418
|
+
}
|
|
12419
|
+
this._left = v;
|
|
12420
|
+
}
|
|
12421
|
+
get right() {
|
|
12422
|
+
return this._right;
|
|
12423
|
+
}
|
|
12424
|
+
set right(v) {
|
|
12425
|
+
if (v) {
|
|
12426
|
+
v.parent = this;
|
|
12427
|
+
}
|
|
12428
|
+
this._right = v;
|
|
12429
|
+
}
|
|
12430
|
+
};
|
|
12431
|
+
var AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
12432
|
+
/**
|
|
12433
|
+
* The constructor initializes a new AVLTreeCounter object with optional initial elements.
|
|
12434
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
12435
|
+
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
12436
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
12437
|
+
* behavior of the AVLTreeCounter. It can include properties such as `compareKeys` and
|
|
12438
|
+
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
12439
|
+
*/
|
|
12440
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
12441
|
+
super([], options);
|
|
12442
|
+
__publicField(this, "_count", 0);
|
|
12443
|
+
if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
|
|
12444
|
+
}
|
|
12445
|
+
/**
|
|
12446
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
12447
|
+
* search.
|
|
12448
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
12449
|
+
*/
|
|
12450
|
+
get count() {
|
|
12451
|
+
return this._count;
|
|
12452
|
+
}
|
|
12453
|
+
/**
|
|
12454
|
+
* Time Complexity: O(n)
|
|
12455
|
+
* Space Complexity: O(1)
|
|
12456
|
+
*
|
|
12457
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
12458
|
+
* search.
|
|
12459
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
12460
|
+
*/
|
|
12461
|
+
getComputedCount() {
|
|
12462
|
+
let sum = 0;
|
|
12463
|
+
this.dfs((node) => sum += node.count);
|
|
12464
|
+
return sum;
|
|
12465
|
+
}
|
|
12466
|
+
/**
|
|
12467
|
+
* The function creates a new AVLTreeCounterNode with the specified key, value, and count.
|
|
12468
|
+
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
12469
|
+
* which is a generic type that can be replaced with any specific type when using the function.
|
|
12470
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
12471
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
12472
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of a
|
|
12473
|
+
* key-value pair in the AVLTreeCounterNode. It is an optional parameter, so it can be omitted when
|
|
12474
|
+
* calling the `createNode` method. If provided, it specifies the initial count for the node.
|
|
12475
|
+
* @returns a new instance of the AVLTreeCounterNode class, casted as AVLTreeCounterNode<K, V>.
|
|
12476
|
+
*/
|
|
12477
|
+
createNode(key, value, count) {
|
|
12478
|
+
return new AVLTreeCounterNode(key, this._isMapMode ? void 0 : value, count);
|
|
12479
|
+
}
|
|
12480
|
+
/**
|
|
12481
|
+
* The function creates a new AVLTreeCounter object with the specified options and returns it.
|
|
12482
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
12483
|
+
* configuration options for creating the AVLTreeCounter. It can have the following properties:
|
|
12484
|
+
* @returns a new instance of the AVLTreeCounter class, with the specified options, as a TREE
|
|
12485
|
+
* object.
|
|
12486
|
+
*/
|
|
12487
|
+
createTree(options) {
|
|
12488
|
+
return new _AVLTreeCounter([], __spreadValues({
|
|
12489
|
+
iterationType: this.iterationType,
|
|
12490
|
+
isMapMode: this._isMapMode,
|
|
12491
|
+
specifyComparable: this._specifyComparable,
|
|
12492
|
+
toEntryFn: this._toEntryFn,
|
|
12493
|
+
isReverse: this._isReverse
|
|
12494
|
+
}, options));
|
|
12495
|
+
}
|
|
12496
|
+
/**
|
|
12497
|
+
* The function checks if the input is an instance of AVLTreeCounterNode.
|
|
12498
|
+
* @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
|
|
12499
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, AVLTreeCounterNode<K, V>>`.
|
|
12500
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
12501
|
+
* an instance of the `AVLTreeCounterNode` class.
|
|
12502
|
+
*/
|
|
12503
|
+
isNode(keyNodeOrEntry) {
|
|
12504
|
+
return keyNodeOrEntry instanceof AVLTreeCounterNode;
|
|
12505
|
+
}
|
|
12506
|
+
/**
|
|
12507
|
+
* Time Complexity: O(log n)
|
|
12508
|
+
* Space Complexity: O(1)
|
|
12509
|
+
*
|
|
12510
|
+
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
12511
|
+
* and update the count.
|
|
12512
|
+
* @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The
|
|
12513
|
+
* `keyNodeOrEntry` parameter can accept a value of type `R`, which can be any type. It
|
|
12514
|
+
* can also accept a value of type `BTNRep<K, V, AVLTreeCounterNode<K, V>>`, which represents a key, node,
|
|
12515
|
+
* entry, or raw element
|
|
12516
|
+
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
12517
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
12518
|
+
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
12519
|
+
* be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
|
|
12520
|
+
* be added once. However, you can specify a different value for `count` if you want to add
|
|
12521
|
+
* @returns a boolean value.
|
|
12522
|
+
*/
|
|
12523
|
+
add(keyNodeOrEntry, value, count = 1) {
|
|
12524
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12525
|
+
if (newNode === void 0) return false;
|
|
12526
|
+
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
12527
|
+
const inserted = super.add(newNode, newValue);
|
|
12528
|
+
if (inserted) {
|
|
12529
|
+
this._count += orgNodeCount;
|
|
12530
|
+
}
|
|
12531
|
+
return true;
|
|
12532
|
+
}
|
|
12533
|
+
/**
|
|
12534
|
+
* Time Complexity: O(log n)
|
|
12535
|
+
* Space Complexity: O(1)
|
|
12536
|
+
*
|
|
12537
|
+
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
12538
|
+
* nodes and maintaining balance in the tree.
|
|
12539
|
+
* @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
|
|
12540
|
+
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
12541
|
+
* binary tree. It can be a key, node, or entry that determines which
|
|
12542
|
+
* node(s) should be deleted.
|
|
12543
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
12544
|
+
* boolean flag that determines whether to ignore the count of the node being deleted. If
|
|
12545
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
12546
|
+
* `ignoreCount` is set to
|
|
12547
|
+
* @returns The `delete` method overrides the default delete behavior in a binary tree data
|
|
12548
|
+
* structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
|
|
12549
|
+
* method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
|
|
12550
|
+
* deleted node and whether balancing is needed in the tree.
|
|
12551
|
+
*/
|
|
12552
|
+
delete(keyNodeOrEntry, ignoreCount = false) {
|
|
12553
|
+
var _a;
|
|
12554
|
+
const deletedResult = [];
|
|
12555
|
+
if (!this.root) return deletedResult;
|
|
12556
|
+
const curr = (_a = this.getNode(keyNodeOrEntry)) != null ? _a : void 0;
|
|
12557
|
+
if (!curr) return deletedResult;
|
|
12558
|
+
const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
|
|
12559
|
+
let needBalanced = void 0, orgCurrent = curr;
|
|
12560
|
+
if (curr.count > 1 && !ignoreCount) {
|
|
12561
|
+
curr.count--;
|
|
12562
|
+
this._count--;
|
|
12563
|
+
} else {
|
|
12564
|
+
if (!curr.left) {
|
|
12565
|
+
if (!parent) {
|
|
12566
|
+
if (curr.right !== void 0 && curr.right !== null) this._setRoot(curr.right);
|
|
12567
|
+
} else {
|
|
12568
|
+
const { familyPosition: fp } = curr;
|
|
12569
|
+
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
12570
|
+
parent.left = curr.right;
|
|
12571
|
+
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
12572
|
+
parent.right = curr.right;
|
|
12573
|
+
}
|
|
12574
|
+
needBalanced = parent;
|
|
12575
|
+
}
|
|
12576
|
+
} else {
|
|
12577
|
+
const leftSubTreeRightMost = curr.left ? this.getRightMost((node) => node, curr.left) : void 0;
|
|
12578
|
+
if (leftSubTreeRightMost) {
|
|
12579
|
+
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
12580
|
+
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
12581
|
+
if (parentOfLeftSubTreeMax) {
|
|
12582
|
+
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
|
|
12583
|
+
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
12584
|
+
} else {
|
|
12585
|
+
parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
12586
|
+
}
|
|
12587
|
+
needBalanced = parentOfLeftSubTreeMax;
|
|
12588
|
+
}
|
|
12589
|
+
}
|
|
12590
|
+
}
|
|
12591
|
+
this._size = this._size - 1;
|
|
12592
|
+
if (orgCurrent) this._count -= orgCurrent.count;
|
|
12593
|
+
}
|
|
12594
|
+
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
12595
|
+
if (needBalanced) {
|
|
12596
|
+
this._balancePath(needBalanced);
|
|
12597
|
+
}
|
|
12598
|
+
return deletedResult;
|
|
12599
|
+
}
|
|
12600
|
+
/**
|
|
12601
|
+
* Time Complexity: O(1)
|
|
12602
|
+
* Space Complexity: O(1)
|
|
12603
|
+
*
|
|
12604
|
+
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
12605
|
+
* zero.
|
|
12606
|
+
*/
|
|
12607
|
+
clear() {
|
|
12608
|
+
super.clear();
|
|
12609
|
+
this._count = 0;
|
|
12610
|
+
}
|
|
12611
|
+
/**
|
|
12612
|
+
* Time Complexity: O(n log n)
|
|
12613
|
+
* Space Complexity: O(log n)
|
|
12614
|
+
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
12615
|
+
* tree using either a recursive or iterative approach.
|
|
12616
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
12617
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
12618
|
+
* default value of `this.iterationType`, which means it will use the iteration type currently set in
|
|
12619
|
+
* the object.
|
|
12620
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
12621
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
12622
|
+
*/
|
|
12623
|
+
perfectlyBalance(iterationType = this.iterationType) {
|
|
12624
|
+
const sorted = this.dfs((node) => node, "IN"), n = sorted.length;
|
|
12625
|
+
if (sorted.length < 1) return false;
|
|
12626
|
+
this.clear();
|
|
12627
|
+
if (iterationType === "RECURSIVE") {
|
|
12628
|
+
const buildBalanceBST = (l, r) => {
|
|
12629
|
+
if (l > r) return;
|
|
12630
|
+
const m = l + Math.floor((r - l) / 2);
|
|
12631
|
+
const midNode = sorted[m];
|
|
12632
|
+
if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
|
|
12633
|
+
else this.add(midNode.key, midNode.value, midNode.count);
|
|
12634
|
+
buildBalanceBST(l, m - 1);
|
|
12635
|
+
buildBalanceBST(m + 1, r);
|
|
12636
|
+
};
|
|
12637
|
+
buildBalanceBST(0, n - 1);
|
|
12638
|
+
return true;
|
|
12639
|
+
} else {
|
|
12640
|
+
const stack = [[0, n - 1]];
|
|
12641
|
+
while (stack.length > 0) {
|
|
12642
|
+
const popped = stack.pop();
|
|
12643
|
+
if (popped) {
|
|
12644
|
+
const [l, r] = popped;
|
|
12645
|
+
if (l <= r) {
|
|
12646
|
+
const m = l + Math.floor((r - l) / 2);
|
|
12647
|
+
const midNode = sorted[m];
|
|
12648
|
+
if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
|
|
12649
|
+
else this.add(midNode.key, midNode.value, midNode.count);
|
|
12650
|
+
stack.push([m + 1, r]);
|
|
12651
|
+
stack.push([l, m - 1]);
|
|
12652
|
+
}
|
|
12653
|
+
}
|
|
12654
|
+
}
|
|
12655
|
+
return true;
|
|
12656
|
+
}
|
|
12657
|
+
}
|
|
12658
|
+
/**
|
|
12659
|
+
* Time complexity: O(n)
|
|
12660
|
+
* Space complexity: O(n)
|
|
12661
|
+
*
|
|
12662
|
+
* The function overrides the clone method to create a deep copy of a tree object.
|
|
12663
|
+
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
12664
|
+
*/
|
|
12665
|
+
clone() {
|
|
12666
|
+
const cloned = this.createTree();
|
|
12667
|
+
if (this._isMapMode) this.bfs((node) => cloned.add(node.key, void 0, node.count));
|
|
12668
|
+
else this.bfs((node) => cloned.add(node.key, node.value, node.count));
|
|
12669
|
+
if (this._isMapMode) cloned._store = this._store;
|
|
12670
|
+
return cloned;
|
|
12671
|
+
}
|
|
12672
|
+
/**
|
|
12673
|
+
* The `map` function in TypeScript overrides the default behavior to create a new AVLTreeCounter
|
|
12674
|
+
* with modified entries based on a provided callback.
|
|
12675
|
+
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
12676
|
+
* AVLTreeCounter. It takes four arguments:
|
|
12677
|
+
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
12678
|
+
* `AVLTreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional
|
|
12679
|
+
* configuration options when creating a new `AVLTreeCounter` instance within the `map` function.
|
|
12680
|
+
* These options
|
|
12681
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
12682
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
12683
|
+
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
12684
|
+
* or
|
|
12685
|
+
* @returns The `map` method is returning a new `AVLTreeCounter` instance with the entries
|
|
12686
|
+
* transformed by the provided `callback` function. Each entry in the original tree is passed to the
|
|
12687
|
+
* `callback` function along with the index and the original tree itself. The transformed entries are
|
|
12688
|
+
* then added to the new `AVLTreeCounter` instance, which is returned at the end.
|
|
12689
|
+
*/
|
|
12690
|
+
map(callback, options, thisArg) {
|
|
12691
|
+
const newTree = new _AVLTreeCounter([], options);
|
|
12692
|
+
let index = 0;
|
|
12693
|
+
for (const [key, value] of this) {
|
|
12694
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
12695
|
+
}
|
|
12696
|
+
return newTree;
|
|
12697
|
+
}
|
|
12698
|
+
/**
|
|
12699
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
12700
|
+
* a node object.
|
|
12701
|
+
* @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The
|
|
12702
|
+
* `keyNodeOrEntry` parameter can be of type `R` or `BTNRep<K, V, AVLTreeCounterNode<K, V>>`.
|
|
12703
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
12704
|
+
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
12705
|
+
* value is provided, it will default to `undefined`.
|
|
12706
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
12707
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
12708
|
+
* @returns either a AVLTreeCounterNode<K, V> object or undefined.
|
|
12709
|
+
*/
|
|
12710
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count = 1) {
|
|
12711
|
+
if (keyNodeOrEntry === void 0 || keyNodeOrEntry === null) return [void 0, void 0];
|
|
12712
|
+
if (this.isNode(keyNodeOrEntry)) return [keyNodeOrEntry, value];
|
|
12713
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
12714
|
+
const [key, entryValue] = keyNodeOrEntry;
|
|
12715
|
+
if (key === void 0 || key === null) return [void 0, void 0];
|
|
12716
|
+
const finalValue = value != null ? value : entryValue;
|
|
12717
|
+
return [this.createNode(key, finalValue, count), finalValue];
|
|
12718
|
+
}
|
|
12719
|
+
return [this.createNode(keyNodeOrEntry, value, count), value];
|
|
12720
|
+
}
|
|
12721
|
+
/**
|
|
12722
|
+
* Time Complexity: O(1)
|
|
12723
|
+
* Space Complexity: O(1)
|
|
12724
|
+
*
|
|
12725
|
+
* The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
|
|
12726
|
+
* in a binary search tree.
|
|
12727
|
+
* @param {BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
|
|
12728
|
+
* that will be swapped with the `destNode`.
|
|
12729
|
+
* @param {BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
|
|
12730
|
+
* node where the properties will be swapped with the source node.
|
|
12731
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
12732
|
+
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
12733
|
+
*/
|
|
12734
|
+
_swapProperties(srcNode, destNode) {
|
|
12735
|
+
srcNode = this.ensureNode(srcNode);
|
|
12736
|
+
destNode = this.ensureNode(destNode);
|
|
12737
|
+
if (srcNode && destNode) {
|
|
12738
|
+
const { key, value, count, height } = destNode;
|
|
12739
|
+
const tempNode = this.createNode(key, value, count);
|
|
12740
|
+
if (tempNode) {
|
|
12741
|
+
tempNode.height = height;
|
|
12742
|
+
destNode.key = srcNode.key;
|
|
12743
|
+
if (!this._isMapMode) destNode.value = srcNode.value;
|
|
12744
|
+
destNode.count = srcNode.count;
|
|
12745
|
+
destNode.height = srcNode.height;
|
|
12746
|
+
srcNode.key = tempNode.key;
|
|
12747
|
+
if (!this._isMapMode) srcNode.value = tempNode.value;
|
|
12748
|
+
srcNode.count = tempNode.count;
|
|
12749
|
+
srcNode.height = tempNode.height;
|
|
12750
|
+
}
|
|
12751
|
+
return destNode;
|
|
12752
|
+
}
|
|
12753
|
+
return void 0;
|
|
12754
|
+
}
|
|
12755
|
+
/**
|
|
12756
|
+
* Time Complexity: O(1)
|
|
12757
|
+
* Space Complexity: O(1)
|
|
12758
|
+
*
|
|
12759
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
12760
|
+
* @param {AVLTreeCounterNode<K, V>} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
12761
|
+
* data structure. It is of type AVLTreeCounterNode<K, V>.
|
|
12762
|
+
* @param {AVLTreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `AVLTreeCounterNode<K, V>` class.
|
|
12269
12763
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
12270
|
-
* superclass, which is of type `
|
|
12764
|
+
* superclass, which is of type `AVLTreeCounterNode<K, V>`.
|
|
12271
12765
|
*/
|
|
12272
12766
|
_replaceNode(oldNode, newNode) {
|
|
12273
12767
|
newNode.count = oldNode.count + newNode.count;
|