data-structure-typed 1.54.0 → 1.54.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -0
- package/benchmark/report.html +1 -28
- package/benchmark/report.json +17 -326
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts → cjs/data-structures/binary-tree/avl-tree-counter.d.ts} +54 -47
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +408 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -177
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -340
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +102 -57
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +110 -47
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +240 -190
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +269 -240
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +145 -112
- package/dist/cjs/data-structures/binary-tree/bst.js +180 -129
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js +2 -0
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +100 -82
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +115 -79
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.d.ts → cjs/data-structures/binary-tree/tree-counter.d.ts} +74 -64
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +445 -0
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +78 -174
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +142 -377
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +3 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js +3 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js +3 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js +3 -0
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js +3 -0
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -4
- package/dist/cjs/data-structures/trie/trie.js +0 -4
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +8 -8
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +3 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js +3 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/cjs/types/data-structures/binary-tree/{rb-tree.js → tree-counter.js} +1 -1
- 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 +2 -5
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.js → esm/data-structures/binary-tree/avl-tree-counter.js} +73 -60
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +191 -0
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +234 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/avl-tree.js +110 -47
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.d.ts +240 -190
- package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.js +272 -245
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.d.ts +145 -112
- package/dist/{mjs → esm}/data-structures/binary-tree/bst.js +201 -155
- package/dist/esm/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/{mjs/types/data-structures/binary-tree/index.d.ts → esm/data-structures/binary-tree/index.js} +6 -2
- package/dist/{mjs → esm}/data-structures/binary-tree/index.js.map +1 -1
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.d.ts +100 -82
- package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.js +115 -79
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/{mjs/data-structures/binary-tree/tree-multi-map.js → esm/data-structures/binary-tree/tree-counter.js} +111 -96
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +106 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +196 -0
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/directed-graph.js +3 -0
- package/dist/esm/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/map-graph.js +3 -0
- package/dist/esm/data-structures/graph/map-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/graph/undirected-graph.js +3 -0
- package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/matrix.js +3 -0
- package/dist/esm/data-structures/matrix/matrix.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/matrix/navigator.js +3 -0
- package/dist/esm/data-structures/matrix/navigator.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/{mjs → esm}/data-structures/trie/trie.d.ts +0 -4
- package/dist/{mjs → esm}/data-structures/trie/trie.js +0 -4
- package/dist/esm/data-structures/trie/trie.js.map +1 -0
- package/dist/esm/interfaces/binary-tree.d.ts +9 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
- package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/dist/{mjs/data-structures/binary-tree/index.js → esm/types/data-structures/binary-tree/index.d.ts} +4 -4
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js +3 -1
- package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/esm/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/esm/types/data-structures/binary-tree/red-black-tree.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +1 -0
- package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/umd/data-structure-typed.js +1464 -895
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +14 -19
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +155 -393
- package/src/data-structures/binary-tree/avl-tree.ts +144 -93
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +433 -405
- package/src/data-structures/binary-tree/bst.ts +261 -239
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +163 -134
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +161 -429
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- package/src/data-structures/trie/trie.ts +0 -4
- package/src/interfaces/binary-tree.ts +10 -24
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -5
- package/src/types/data-structures/binary-tree/index.ts +3 -1
- package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
- 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.mjs +135 -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.js +45 -0
- 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.js +249 -0
- 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/cjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -6
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -189
- package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/mjs/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/map-graph.js.map +0 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix.js.map +0 -1
- package/dist/mjs/data-structures/matrix/navigator.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/mjs/data-structures/trie/trie.js.map +0 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +0 -9
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -5
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -6
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.js +0 -2
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.js.map +0 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
- /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/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,20 +1,40 @@
|
|
|
1
1
|
import { BST, BSTNode } from './bst';
|
|
2
2
|
export class RedBlackTreeNode extends BSTNode {
|
|
3
3
|
/**
|
|
4
|
-
* The constructor
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Tree Node. It is an optional parameter with a default value of `'BLACK'`.
|
|
4
|
+
* The constructor initializes a node with a key, value, and color for a Red-Black Tree.
|
|
5
|
+
* @param {K} key - The `key` parameter is a key of type `K` that is used to identify the node in a
|
|
6
|
+
* Red-Black Tree data structure.
|
|
7
|
+
* @param {V} [value] - The `value` parameter in the constructor is an optional parameter of type
|
|
8
|
+
* `V`. It represents the value associated with the key in the data structure being constructed.
|
|
9
|
+
* @param {RBTNColor} [color=BLACK] - The `color` parameter in the constructor is used to specify the
|
|
10
|
+
* color of the node in a Red-Black Tree. It has a default value of 'BLACK' if not provided
|
|
11
|
+
* explicitly.
|
|
13
12
|
*/
|
|
14
13
|
constructor(key, value, color = 'BLACK') {
|
|
15
14
|
super(key, value);
|
|
16
15
|
this._color = color;
|
|
17
16
|
}
|
|
17
|
+
parent = undefined;
|
|
18
|
+
_left = undefined;
|
|
19
|
+
get left() {
|
|
20
|
+
return this._left;
|
|
21
|
+
}
|
|
22
|
+
set left(v) {
|
|
23
|
+
if (v) {
|
|
24
|
+
v.parent = this;
|
|
25
|
+
}
|
|
26
|
+
this._left = v;
|
|
27
|
+
}
|
|
28
|
+
_right = undefined;
|
|
29
|
+
get right() {
|
|
30
|
+
return this._right;
|
|
31
|
+
}
|
|
32
|
+
set right(v) {
|
|
33
|
+
if (v) {
|
|
34
|
+
v.parent = this;
|
|
35
|
+
}
|
|
36
|
+
this._right = v;
|
|
37
|
+
}
|
|
18
38
|
}
|
|
19
39
|
/**
|
|
20
40
|
* 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high but the query efficiency is slightly lower.
|
|
@@ -71,14 +91,15 @@ export class RedBlackTreeNode extends BSTNode {
|
|
|
71
91
|
*/
|
|
72
92
|
export class RedBlackTree extends BST {
|
|
73
93
|
/**
|
|
74
|
-
* This
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* constructor
|
|
80
|
-
*
|
|
81
|
-
*
|
|
94
|
+
* This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
|
|
95
|
+
* raw data.
|
|
96
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
97
|
+
* iterable that can contain either `BTNRep<K, V, RedBlackTreeNode<K, V>>` objects or `R` objects. It
|
|
98
|
+
* is used to initialize the Red-Black Tree with keys, nodes, entries, or
|
|
99
|
+
* @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
|
|
100
|
+
* V, R>`. It is an optional parameter that allows you to specify additional options for the
|
|
101
|
+
* RedBlackTree class. These options could include configuration settings, behavior customization, or
|
|
102
|
+
* any other parameters that are specific to
|
|
82
103
|
*/
|
|
83
104
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
84
105
|
super([], options);
|
|
@@ -88,14 +109,13 @@ export class RedBlackTree extends BST {
|
|
|
88
109
|
}
|
|
89
110
|
}
|
|
90
111
|
_root;
|
|
91
|
-
/**
|
|
92
|
-
* The function returns the root node of a tree or undefined if there is no root.
|
|
93
|
-
* @returns The root node of the tree structure, or undefined if there is no root node.
|
|
94
|
-
*/
|
|
95
112
|
get root() {
|
|
96
113
|
return this._root;
|
|
97
114
|
}
|
|
98
115
|
/**
|
|
116
|
+
* Time Complexity: O(1)
|
|
117
|
+
* Space Complexity: O(1)
|
|
118
|
+
*
|
|
99
119
|
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
100
120
|
* @param {K} key - The key parameter represents the key value of the node being created. It is of
|
|
101
121
|
* type K, which is a generic type that can be replaced with any specific type when using the
|
|
@@ -113,6 +133,9 @@ export class RedBlackTree extends BST {
|
|
|
113
133
|
return new RedBlackTreeNode(key, this._isMapMode ? undefined : value, color);
|
|
114
134
|
}
|
|
115
135
|
/**
|
|
136
|
+
* Time Complexity: O(1)
|
|
137
|
+
* Space Complexity: O(1)
|
|
138
|
+
*
|
|
116
139
|
* The function creates a new Red-Black Tree with the specified options.
|
|
117
140
|
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
118
141
|
* configuration options for creating the Red-Black Tree. It has the following properties:
|
|
@@ -132,13 +155,13 @@ export class RedBlackTree extends BST {
|
|
|
132
155
|
* Space Complexity: O(1)
|
|
133
156
|
*
|
|
134
157
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
135
|
-
* @param {BTNRep<K, V,
|
|
136
|
-
* `
|
|
137
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
158
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
159
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
|
|
160
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
138
161
|
* an instance of the `RedBlackTreeNode` class.
|
|
139
162
|
*/
|
|
140
|
-
isNode(
|
|
141
|
-
return
|
|
163
|
+
isNode(keyNodeOrEntry) {
|
|
164
|
+
return keyNodeOrEntry instanceof RedBlackTreeNode;
|
|
142
165
|
}
|
|
143
166
|
/**
|
|
144
167
|
* Time Complexity: O(1)
|
|
@@ -153,12 +176,12 @@ export class RedBlackTree extends BST {
|
|
|
153
176
|
}
|
|
154
177
|
/**
|
|
155
178
|
* Time Complexity: O(log n)
|
|
156
|
-
* Space Complexity: O(
|
|
179
|
+
* Space Complexity: O(log n)
|
|
157
180
|
*
|
|
158
181
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
159
182
|
* added.
|
|
160
|
-
* @param {BTNRep<K, V,
|
|
161
|
-
* `
|
|
183
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
184
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
|
|
162
185
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
163
186
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
164
187
|
* structure.
|
|
@@ -166,8 +189,8 @@ export class RedBlackTree extends BST {
|
|
|
166
189
|
* the method returns true. If the node already exists and its value is updated, the method also
|
|
167
190
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
168
191
|
*/
|
|
169
|
-
add(
|
|
170
|
-
const [newNode, newValue] = this.
|
|
192
|
+
add(keyNodeOrEntry, value) {
|
|
193
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
171
194
|
if (!this.isRealNode(newNode))
|
|
172
195
|
return false;
|
|
173
196
|
const insertStatus = this._insert(newNode);
|
|
@@ -193,27 +216,27 @@ export class RedBlackTree extends BST {
|
|
|
193
216
|
}
|
|
194
217
|
/**
|
|
195
218
|
* Time Complexity: O(log n)
|
|
196
|
-
* Space Complexity: O(
|
|
219
|
+
* Space Complexity: O(log n)
|
|
197
220
|
*
|
|
198
221
|
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
199
222
|
* a given predicate and maintain the binary search tree properties.
|
|
200
|
-
* @param {BTNRep<K, V,
|
|
223
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
201
224
|
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
202
225
|
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
203
226
|
* function that determines which node(s) should be deleted.
|
|
204
|
-
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<
|
|
227
|
+
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>`
|
|
205
228
|
* objects. Each object in the array contains information about the deleted node and whether
|
|
206
229
|
* balancing is needed.
|
|
207
230
|
*/
|
|
208
|
-
delete(
|
|
209
|
-
if (
|
|
231
|
+
delete(keyNodeOrEntry) {
|
|
232
|
+
if (keyNodeOrEntry === null)
|
|
210
233
|
return [];
|
|
211
234
|
const results = [];
|
|
212
235
|
let nodeToDelete;
|
|
213
|
-
if (this._isPredicate(
|
|
214
|
-
nodeToDelete = this.getNode(
|
|
236
|
+
if (this._isPredicate(keyNodeOrEntry))
|
|
237
|
+
nodeToDelete = this.getNode(keyNodeOrEntry);
|
|
215
238
|
else
|
|
216
|
-
nodeToDelete = this.isRealNode(
|
|
239
|
+
nodeToDelete = this.isRealNode(keyNodeOrEntry) ? keyNodeOrEntry : this.getNode(keyNodeOrEntry);
|
|
217
240
|
if (!nodeToDelete) {
|
|
218
241
|
return results;
|
|
219
242
|
}
|
|
@@ -267,13 +290,54 @@ export class RedBlackTree extends BST {
|
|
|
267
290
|
results.push({ deleted: nodeToDelete, needBalanced: undefined });
|
|
268
291
|
return results;
|
|
269
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Time Complexity: O(n)
|
|
295
|
+
* Space Complexity: O(n)
|
|
296
|
+
*
|
|
297
|
+
* The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
|
|
298
|
+
* applying a callback to each entry in the original tree.
|
|
299
|
+
* @param callback - A function that will be called for each entry in the tree, with parameters
|
|
300
|
+
* representing the key, value, index, and the tree itself. It should return an entry for the new
|
|
301
|
+
* tree.
|
|
302
|
+
* @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
|
|
303
|
+
* MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
|
|
304
|
+
* Tree that will be created during the mapping process. These options could include things like
|
|
305
|
+
* custom comparators
|
|
306
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
307
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
308
|
+
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
309
|
+
* or
|
|
310
|
+
* @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
|
|
311
|
+
* provided callback function.
|
|
312
|
+
*/
|
|
313
|
+
map(callback, options, thisArg) {
|
|
314
|
+
const newTree = new RedBlackTree([], options);
|
|
315
|
+
let index = 0;
|
|
316
|
+
for (const [key, value] of this) {
|
|
317
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
318
|
+
}
|
|
319
|
+
return newTree;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Time Complexity: O(n)
|
|
323
|
+
* Space Complexity: O(n)
|
|
324
|
+
*
|
|
325
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
326
|
+
* structure.
|
|
327
|
+
* @returns The `cloned` object is being returned.
|
|
328
|
+
*/
|
|
329
|
+
clone() {
|
|
330
|
+
const cloned = this.createTree();
|
|
331
|
+
this._clone(cloned);
|
|
332
|
+
return cloned;
|
|
333
|
+
}
|
|
270
334
|
/**
|
|
271
335
|
* Time Complexity: O(1)
|
|
272
336
|
* Space Complexity: O(1)
|
|
273
337
|
*
|
|
274
338
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
275
339
|
* root.
|
|
276
|
-
* @param {
|
|
340
|
+
* @param {RedBlackTreeNode<K, V> | undefined} v - v is a parameter of type RedBlackTreeNode<K, V> or undefined.
|
|
277
341
|
*/
|
|
278
342
|
_setRoot(v) {
|
|
279
343
|
if (v) {
|
|
@@ -286,9 +350,9 @@ export class RedBlackTree extends BST {
|
|
|
286
350
|
* Space Complexity: O(1)
|
|
287
351
|
*
|
|
288
352
|
* The function replaces an old node with a new node while preserving the color of the old node.
|
|
289
|
-
* @param {
|
|
353
|
+
* @param {RedBlackTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
290
354
|
* the data structure.
|
|
291
|
-
* @param {
|
|
355
|
+
* @param {RedBlackTreeNode<K, V>} newNode - The `newNode` parameter is of type `RedBlackTreeNode<K, V>`, which represents a node in a
|
|
292
356
|
* data structure.
|
|
293
357
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
294
358
|
* superclass, with the `oldNode` and `newNode` parameters.
|
|
@@ -299,11 +363,11 @@ export class RedBlackTree extends BST {
|
|
|
299
363
|
}
|
|
300
364
|
/**
|
|
301
365
|
* Time Complexity: O(log n)
|
|
302
|
-
* Space Complexity: O(
|
|
366
|
+
* Space Complexity: O(log n)
|
|
303
367
|
*
|
|
304
368
|
* The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
|
|
305
369
|
* maintain the red-black tree properties.
|
|
306
|
-
* @param {
|
|
370
|
+
* @param {RedBlackTreeNode<K, V>} node - The `node` parameter represents the node that needs to be inserted into the
|
|
307
371
|
* binary search tree.
|
|
308
372
|
* @returns a string value indicating the result of the insertion operation. It can return either
|
|
309
373
|
* 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
|
|
@@ -347,9 +411,9 @@ export class RedBlackTree extends BST {
|
|
|
347
411
|
* Space Complexity: O(1)
|
|
348
412
|
*
|
|
349
413
|
* The function `_transplant` is used to replace a node `u` with another node `v` in a binary tree.
|
|
350
|
-
* @param {
|
|
351
|
-
* @param {
|
|
352
|
-
* either be a `
|
|
414
|
+
* @param {RedBlackTreeNode<K, V>} u - The parameter "u" represents a node in a binary tree.
|
|
415
|
+
* @param {RedBlackTreeNode<K, V> | undefined} v - The parameter `v` is of type `RedBlackTreeNode<K, V> | undefined`, which means it can
|
|
416
|
+
* either be a `RedBlackTreeNode<K, V>` object or `undefined`.
|
|
353
417
|
*/
|
|
354
418
|
_transplant(u, v) {
|
|
355
419
|
if (!u.parent) {
|
|
@@ -370,7 +434,7 @@ export class RedBlackTree extends BST {
|
|
|
370
434
|
* Space Complexity: O(1)
|
|
371
435
|
*
|
|
372
436
|
* The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
|
|
373
|
-
* @param {
|
|
437
|
+
* @param {RedBlackTreeNode<K, V> | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
|
|
374
438
|
* structure. It can either be a valid node or `undefined`.
|
|
375
439
|
*/
|
|
376
440
|
_insertFixup(z) {
|
|
@@ -437,7 +501,7 @@ export class RedBlackTree extends BST {
|
|
|
437
501
|
*
|
|
438
502
|
* The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
|
|
439
503
|
* the colors and performing rotations.
|
|
440
|
-
* @param {
|
|
504
|
+
* @param {RedBlackTreeNode<K, V> | undefined} node - The `node` parameter represents a node in a binary tree. It can
|
|
441
505
|
* be either a valid node object or `undefined`.
|
|
442
506
|
* @returns The function does not return any value. It has a return type of `void`, which means it
|
|
443
507
|
* does not return anything.
|
|
@@ -522,7 +586,7 @@ export class RedBlackTree extends BST {
|
|
|
522
586
|
* Space Complexity: O(1)
|
|
523
587
|
*
|
|
524
588
|
* The `_leftRotate` function performs a left rotation on a given node in a binary tree.
|
|
525
|
-
* @param {
|
|
589
|
+
* @param {RedBlackTreeNode<K, V> | undefined} x - The parameter `x` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
526
590
|
* node in a binary tree or `undefined` if there is no node.
|
|
527
591
|
* @returns void, which means it does not return any value.
|
|
528
592
|
*/
|
|
@@ -553,7 +617,7 @@ export class RedBlackTree extends BST {
|
|
|
553
617
|
* Space Complexity: O(1)
|
|
554
618
|
*
|
|
555
619
|
* The `_rightRotate` function performs a right rotation on a given node in a binary tree.
|
|
556
|
-
* @param {
|
|
620
|
+
* @param {RedBlackTreeNode<K, V> | undefined} y - The parameter `y` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
557
621
|
* node in a binary tree or `undefined` if there is no node.
|
|
558
622
|
* @returns void, which means it does not return any value.
|
|
559
623
|
*/
|
|
@@ -579,33 +643,5 @@ export class RedBlackTree extends BST {
|
|
|
579
643
|
x.right = y;
|
|
580
644
|
y.parent = x;
|
|
581
645
|
}
|
|
582
|
-
/**
|
|
583
|
-
* Time Complexity: O(n)
|
|
584
|
-
* Space Complexity: O(n)
|
|
585
|
-
*
|
|
586
|
-
* The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
|
|
587
|
-
* applying a callback to each entry in the original tree.
|
|
588
|
-
* @param callback - A function that will be called for each entry in the tree, with parameters
|
|
589
|
-
* representing the key, value, index, and the tree itself. It should return an entry for the new
|
|
590
|
-
* tree.
|
|
591
|
-
* @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
|
|
592
|
-
* MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
|
|
593
|
-
* Tree that will be created during the mapping process. These options could include things like
|
|
594
|
-
* custom comparators
|
|
595
|
-
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
596
|
-
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
597
|
-
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
598
|
-
* or
|
|
599
|
-
* @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
|
|
600
|
-
* provided callback function.
|
|
601
|
-
*/
|
|
602
|
-
map(callback, options, thisArg) {
|
|
603
|
-
const newTree = new RedBlackTree([], options);
|
|
604
|
-
let index = 0;
|
|
605
|
-
for (const [key, value] of this) {
|
|
606
|
-
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
607
|
-
}
|
|
608
|
-
return newTree;
|
|
609
|
-
}
|
|
610
646
|
}
|
|
611
647
|
//# sourceMappingURL=red-black-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"red-black-tree.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/red-black-tree.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGrC,MAAM,OAAO,gBAAmC,SAAQ,OAAa;IACnE;;;;;;;;;OASG;IACH,YAAY,GAAM,EAAE,KAAS,EAAE,QAAmB,OAAO;QACvD,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAEQ,MAAM,GAA4B,SAAS,CAAC;IAE5C,KAAK,GAA2C,SAAS,CAAC;IAEnE,IAAa,IAAI;QACf,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAa,IAAI,CAAC,CAAwC;QACxD,IAAI,CAAC,EAAE,CAAC;YACN,CAAC,CAAC,MAAM,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,CAAC,KAAK,GAAG,CAAC,CAAC;QACrB,CAAC;QAED,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QACX,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACf,CAAC;IAED;;;;;;;;OAQG;IACO,YAAY,CAAC,CAAqC;QAC1D,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACjB,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC;QAEjB,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACrB,CAAC;QAED,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;QAEpB,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YACd,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnB,CAAC;aAAM,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC/B,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;QACrB,CAAC;QAED,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;QACZ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, EntryCallback, IterationType, OptNodeOrNull, RBTNColor, TreeCounterOptions } from '../../types';
|
|
9
|
+
import { IBinaryTree } from '../../interfaces';
|
|
10
|
+
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
11
|
+
export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<K, V> {
|
|
12
|
+
/**
|
|
13
|
+
* The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
|
|
14
|
+
* @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
|
|
15
|
+
* used to identify and locate the node within the tree.
|
|
16
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
17
|
+
* associated with the key in the Red-Black Tree node. It is not required and can be omitted when
|
|
18
|
+
* creating a new node.
|
|
19
|
+
* @param [count=1] - The `count` parameter represents the number of occurrences of a particular key
|
|
20
|
+
* in the Red-Black Tree. It is an optional parameter with a default value of 1.
|
|
21
|
+
* @param {RBTNColor} [color=BLACK] - The `color` parameter is used to specify the color of the node
|
|
22
|
+
* in a Red-Black Tree. It is optional and has a default value of `'BLACK'`.
|
|
23
|
+
*/
|
|
24
|
+
constructor(key: K, value?: V, count?: number, color?: RBTNColor);
|
|
25
|
+
parent?: TreeCounterNode<K, V>;
|
|
26
|
+
_left?: OptNodeOrNull<TreeCounterNode<K, V>>;
|
|
27
|
+
get left(): OptNodeOrNull<TreeCounterNode<K, V>>;
|
|
28
|
+
set left(v: OptNodeOrNull<TreeCounterNode<K, V>>);
|
|
29
|
+
_right?: OptNodeOrNull<TreeCounterNode<K, V>>;
|
|
30
|
+
get right(): OptNodeOrNull<TreeCounterNode<K, V>>;
|
|
31
|
+
set right(v: OptNodeOrNull<TreeCounterNode<K, V>>);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends RedBlackTree<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
|
|
37
|
+
/**
|
|
38
|
+
* The constructor function initializes a TreeCounter object with optional initial data.
|
|
39
|
+
* @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
|
|
40
|
+
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
41
|
+
* TreeCounter with initial data.
|
|
42
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
43
|
+
* behavior of the `TreeCounter` constructor. It can include properties such as `compareKeys` and
|
|
44
|
+
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
45
|
+
*/
|
|
46
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, TreeCounterNode<K, V>> | R>, options?: TreeCounterOptions<K, V, R>);
|
|
47
|
+
protected _count: number;
|
|
48
|
+
/**
|
|
49
|
+
* The function calculates the sum of the count property of all nodes in a tree structure.
|
|
50
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
51
|
+
*/
|
|
52
|
+
get count(): number;
|
|
53
|
+
/**
|
|
54
|
+
* Time Complexity: O(n)
|
|
55
|
+
* Space Complexity: O(1)
|
|
56
|
+
*
|
|
57
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
58
|
+
* search.
|
|
59
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
60
|
+
*/
|
|
61
|
+
getComputedCount(): number;
|
|
62
|
+
/**
|
|
63
|
+
* The function creates a new TreeCounterNode with the specified key, value, color, and count.
|
|
64
|
+
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
65
|
+
* which is a generic type representing the type of keys in the tree.
|
|
66
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
67
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
68
|
+
* @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
|
|
69
|
+
* a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
|
|
70
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
|
|
71
|
+
* the tree. It is an optional parameter and is used to keep track of the number of values associated
|
|
72
|
+
* with a key in the tree.
|
|
73
|
+
* @returns A new instance of the TreeCounterNode class, casted as TreeCounterNode<K, V>.
|
|
74
|
+
*/
|
|
75
|
+
createNode(key: K, value?: V, color?: RBTNColor, count?: number): TreeCounterNode<K, V>;
|
|
76
|
+
/**
|
|
77
|
+
* The function creates a new instance of a TreeCounter with the specified options and returns it.
|
|
78
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
79
|
+
* configuration options for creating the `TreeCounter`. It is of type `TreeCounterOptions<K, V,
|
|
80
|
+
* R>`.
|
|
81
|
+
* @returns a new instance of the `TreeCounter` class, with the provided options merged with the
|
|
82
|
+
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
83
|
+
*/
|
|
84
|
+
createTree(options?: TreeCounterOptions<K, V, R>): TreeCounter<K, V, R, MK, MV, MR>;
|
|
85
|
+
/**
|
|
86
|
+
* The function checks if the input is an instance of the TreeCounterNode class.
|
|
87
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
|
|
88
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
|
|
89
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
90
|
+
* an instance of the `TreeCounterNode` class.
|
|
91
|
+
*/
|
|
92
|
+
isNode(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>): keyNodeOrEntry is TreeCounterNode<K, V>;
|
|
93
|
+
/**
|
|
94
|
+
* Time Complexity: O(log n)
|
|
95
|
+
* Space Complexity: O(1)
|
|
96
|
+
*
|
|
97
|
+
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
98
|
+
* the count and returning a boolean indicating success.
|
|
99
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The
|
|
100
|
+
* `keyNodeOrEntry` parameter can accept one of the following types:
|
|
101
|
+
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
102
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
103
|
+
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
104
|
+
* be added to the data structure. By default, it is set to 1, meaning that if no value is provided
|
|
105
|
+
* for `count`, the key-value pair will be added once.
|
|
106
|
+
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
107
|
+
* was successful, and false otherwise.
|
|
108
|
+
*/
|
|
109
|
+
add(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>, value?: V, count?: number): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Time Complexity: O(log n)
|
|
112
|
+
* Space Complexity: O(1)
|
|
113
|
+
*
|
|
114
|
+
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
115
|
+
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
116
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
|
|
117
|
+
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
118
|
+
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
119
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
120
|
+
* boolean flag that determines whether to ignore the count of nodes when performing deletion. If
|
|
121
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
122
|
+
* `ignoreCount` is `false
|
|
123
|
+
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
|
|
124
|
+
*/
|
|
125
|
+
delete(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>, ignoreCount?: boolean): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[];
|
|
126
|
+
/**
|
|
127
|
+
* Time Complexity: O(1)
|
|
128
|
+
* Space Complexity: O(1)
|
|
129
|
+
*
|
|
130
|
+
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
131
|
+
* zero.
|
|
132
|
+
*/
|
|
133
|
+
clear(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Time Complexity: O(n log n)
|
|
136
|
+
* Space Complexity: O(log n)
|
|
137
|
+
*
|
|
138
|
+
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
139
|
+
* tree using either a recursive or iterative approach.
|
|
140
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
141
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
142
|
+
* default value of `this.iterationType`, which means it will use the iteration type specified by the
|
|
143
|
+
* `iterationType` property of the current object.
|
|
144
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
145
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
146
|
+
*/
|
|
147
|
+
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Time complexity: O(n)
|
|
150
|
+
* Space complexity: O(n)
|
|
151
|
+
*
|
|
152
|
+
* The function overrides the clone method to create a deep copy of a tree object.
|
|
153
|
+
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
154
|
+
*/
|
|
155
|
+
clone(): TreeCounter<K, V, R, MK, MV, MR>;
|
|
156
|
+
/**
|
|
157
|
+
* The `map` function in TypeScript overrides the default behavior to create a new TreeCounter with
|
|
158
|
+
* modified entries based on a provided callback.
|
|
159
|
+
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
160
|
+
* map. It takes four arguments:
|
|
161
|
+
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
162
|
+
* `TreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
|
|
163
|
+
* options when creating a new `TreeCounter` instance within the `map` function. These options could
|
|
164
|
+
* include things like
|
|
165
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
166
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
167
|
+
* (value of `this`) for the callback function when it is called within the `map` function. This
|
|
168
|
+
* @returns A new TreeCounter instance is being returned, which is populated with entries generated
|
|
169
|
+
* by the provided callback function.
|
|
170
|
+
*/
|
|
171
|
+
map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: TreeCounterOptions<MK, MV, MR>, thisArg?: any): TreeCounter<MK, MV, MR>;
|
|
172
|
+
/**
|
|
173
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
174
|
+
* node based on the input.
|
|
175
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
|
|
176
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
|
|
177
|
+
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
178
|
+
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
179
|
+
* an existing node.
|
|
180
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
181
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
182
|
+
* @returns either a TreeCounterNode<K, V> object or undefined.
|
|
183
|
+
*/
|
|
184
|
+
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>, value?: V, count?: number): [TreeCounterNode<K, V> | undefined, V | undefined];
|
|
185
|
+
/**
|
|
186
|
+
* Time Complexity: O(1)
|
|
187
|
+
* Space Complexity: O(1)
|
|
188
|
+
*
|
|
189
|
+
* The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
|
|
190
|
+
* in a binary search tree.
|
|
191
|
+
* @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
|
|
192
|
+
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
193
|
+
* instance of the `BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>` class.
|
|
194
|
+
* @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
|
|
195
|
+
* node where the properties will be swapped with the source node.
|
|
196
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
197
|
+
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
198
|
+
*/
|
|
199
|
+
protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>, destNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>): TreeCounterNode<K, V> | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Time Complexity: O(1)
|
|
202
|
+
* Space Complexity: O(1)
|
|
203
|
+
*
|
|
204
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
205
|
+
* @param {TreeCounterNode<K, V>} oldNode - The `oldNode` parameter is the node that you want to replace in the data
|
|
206
|
+
* structure.
|
|
207
|
+
* @param {TreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `TreeCounterNode<K, V>` class.
|
|
208
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
209
|
+
* superclass, which is of type `TreeCounterNode<K, V>`.
|
|
210
|
+
*/
|
|
211
|
+
protected _replaceNode(oldNode: TreeCounterNode<K, V>, newNode: TreeCounterNode<K, V>): TreeCounterNode<K, V>;
|
|
212
|
+
}
|