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,34 +1,39 @@
|
|
|
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
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
get color() {
|
|
24
|
-
return this._color;
|
|
17
|
+
parent = undefined;
|
|
18
|
+
_left = undefined;
|
|
19
|
+
get left() {
|
|
20
|
+
return this._left;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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;
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
@@ -86,14 +91,15 @@ export class RedBlackTreeNode extends BSTNode {
|
|
|
86
91
|
*/
|
|
87
92
|
export class RedBlackTree extends BST {
|
|
88
93
|
/**
|
|
89
|
-
* This
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* constructor
|
|
95
|
-
*
|
|
96
|
-
*
|
|
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
|
|
97
103
|
*/
|
|
98
104
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
99
105
|
super([], options);
|
|
@@ -103,14 +109,13 @@ export class RedBlackTree extends BST {
|
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
111
|
_root;
|
|
106
|
-
/**
|
|
107
|
-
* The function returns the root node of a tree or undefined if there is no root.
|
|
108
|
-
* @returns The root node of the tree structure, or undefined if there is no root node.
|
|
109
|
-
*/
|
|
110
112
|
get root() {
|
|
111
113
|
return this._root;
|
|
112
114
|
}
|
|
113
115
|
/**
|
|
116
|
+
* Time Complexity: O(1)
|
|
117
|
+
* Space Complexity: O(1)
|
|
118
|
+
*
|
|
114
119
|
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
115
120
|
* @param {K} key - The key parameter represents the key value of the node being created. It is of
|
|
116
121
|
* type K, which is a generic type that can be replaced with any specific type when using the
|
|
@@ -128,15 +133,14 @@ export class RedBlackTree extends BST {
|
|
|
128
133
|
return new RedBlackTreeNode(key, this._isMapMode ? undefined : value, color);
|
|
129
134
|
}
|
|
130
135
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
136
|
+
* Time Complexity: O(1)
|
|
137
|
+
* Space Complexity: O(1)
|
|
138
|
+
*
|
|
139
|
+
* The function creates a new Red-Black Tree with the specified options.
|
|
140
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
141
|
+
* configuration options for creating the Red-Black Tree. It has the following properties:
|
|
142
|
+
* @returns a new instance of a RedBlackTree object.
|
|
138
143
|
*/
|
|
139
|
-
// @ts-ignore
|
|
140
144
|
createTree(options) {
|
|
141
145
|
return new RedBlackTree([], {
|
|
142
146
|
iterationType: this.iterationType,
|
|
@@ -151,13 +155,13 @@ export class RedBlackTree extends BST {
|
|
|
151
155
|
* Space Complexity: O(1)
|
|
152
156
|
*
|
|
153
157
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
154
|
-
* @param {BTNRep<K, V,
|
|
155
|
-
* `
|
|
156
|
-
* @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
|
|
157
161
|
* an instance of the `RedBlackTreeNode` class.
|
|
158
162
|
*/
|
|
159
|
-
isNode(
|
|
160
|
-
return
|
|
163
|
+
isNode(keyNodeOrEntry) {
|
|
164
|
+
return keyNodeOrEntry instanceof RedBlackTreeNode;
|
|
161
165
|
}
|
|
162
166
|
/**
|
|
163
167
|
* Time Complexity: O(1)
|
|
@@ -172,12 +176,12 @@ export class RedBlackTree extends BST {
|
|
|
172
176
|
}
|
|
173
177
|
/**
|
|
174
178
|
* Time Complexity: O(log n)
|
|
175
|
-
* Space Complexity: O(
|
|
179
|
+
* Space Complexity: O(log n)
|
|
176
180
|
*
|
|
177
181
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
178
182
|
* added.
|
|
179
|
-
* @param {BTNRep<K, V,
|
|
180
|
-
* `
|
|
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>>`.
|
|
181
185
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
182
186
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
183
187
|
* structure.
|
|
@@ -185,8 +189,8 @@ export class RedBlackTree extends BST {
|
|
|
185
189
|
* the method returns true. If the node already exists and its value is updated, the method also
|
|
186
190
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
187
191
|
*/
|
|
188
|
-
add(
|
|
189
|
-
const [newNode, newValue] = this.
|
|
192
|
+
add(keyNodeOrEntry, value) {
|
|
193
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
190
194
|
if (!this.isRealNode(newNode))
|
|
191
195
|
return false;
|
|
192
196
|
const insertStatus = this._insert(newNode);
|
|
@@ -212,35 +216,37 @@ export class RedBlackTree extends BST {
|
|
|
212
216
|
}
|
|
213
217
|
/**
|
|
214
218
|
* Time Complexity: O(log n)
|
|
215
|
-
* Space Complexity: O(
|
|
219
|
+
* Space Complexity: O(log n)
|
|
216
220
|
*
|
|
217
221
|
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
218
222
|
* a given predicate and maintain the binary search tree properties.
|
|
219
|
-
* @param {BTNRep<K, V,
|
|
223
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
220
224
|
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
221
225
|
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
222
226
|
* function that determines which node(s) should be deleted.
|
|
223
|
-
* @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>>`
|
|
224
228
|
* objects. Each object in the array contains information about the deleted node and whether
|
|
225
229
|
* balancing is needed.
|
|
226
230
|
*/
|
|
227
|
-
delete(
|
|
228
|
-
if (
|
|
231
|
+
delete(keyNodeOrEntry) {
|
|
232
|
+
if (keyNodeOrEntry === null)
|
|
229
233
|
return [];
|
|
230
234
|
const results = [];
|
|
231
235
|
let nodeToDelete;
|
|
232
|
-
if (this._isPredicate(
|
|
233
|
-
nodeToDelete = this.getNode(
|
|
236
|
+
if (this._isPredicate(keyNodeOrEntry))
|
|
237
|
+
nodeToDelete = this.getNode(keyNodeOrEntry);
|
|
234
238
|
else
|
|
235
|
-
nodeToDelete = this.isRealNode(
|
|
239
|
+
nodeToDelete = this.isRealNode(keyNodeOrEntry) ? keyNodeOrEntry : this.getNode(keyNodeOrEntry);
|
|
236
240
|
if (!nodeToDelete) {
|
|
237
241
|
return results;
|
|
238
242
|
}
|
|
239
243
|
let originalColor = nodeToDelete.color;
|
|
240
244
|
let replacementNode;
|
|
241
245
|
if (!this.isRealNode(nodeToDelete.left)) {
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
if (nodeToDelete.right !== null) {
|
|
247
|
+
replacementNode = nodeToDelete.right;
|
|
248
|
+
this._transplant(nodeToDelete, nodeToDelete.right);
|
|
249
|
+
}
|
|
244
250
|
}
|
|
245
251
|
else if (!this.isRealNode(nodeToDelete.right)) {
|
|
246
252
|
replacementNode = nodeToDelete.left;
|
|
@@ -250,15 +256,18 @@ export class RedBlackTree extends BST {
|
|
|
250
256
|
const successor = this.getLeftMost(node => node, nodeToDelete.right);
|
|
251
257
|
if (successor) {
|
|
252
258
|
originalColor = successor.color;
|
|
253
|
-
|
|
259
|
+
if (successor.right !== null)
|
|
260
|
+
replacementNode = successor.right;
|
|
254
261
|
if (successor.parent === nodeToDelete) {
|
|
255
262
|
if (this.isRealNode(replacementNode)) {
|
|
256
263
|
replacementNode.parent = successor;
|
|
257
264
|
}
|
|
258
265
|
}
|
|
259
266
|
else {
|
|
260
|
-
|
|
261
|
-
|
|
267
|
+
if (successor.right !== null) {
|
|
268
|
+
this._transplant(successor, successor.right);
|
|
269
|
+
successor.right = nodeToDelete.right;
|
|
270
|
+
}
|
|
262
271
|
if (this.isRealNode(successor.right)) {
|
|
263
272
|
successor.right.parent = successor;
|
|
264
273
|
}
|
|
@@ -301,7 +310,6 @@ export class RedBlackTree extends BST {
|
|
|
301
310
|
* @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
|
|
302
311
|
* provided callback function.
|
|
303
312
|
*/
|
|
304
|
-
// @ts-ignore
|
|
305
313
|
map(callback, options, thisArg) {
|
|
306
314
|
const newTree = new RedBlackTree([], options);
|
|
307
315
|
let index = 0;
|
|
@@ -310,13 +318,26 @@ export class RedBlackTree extends BST {
|
|
|
310
318
|
}
|
|
311
319
|
return newTree;
|
|
312
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
|
+
}
|
|
313
334
|
/**
|
|
314
335
|
* Time Complexity: O(1)
|
|
315
336
|
* Space Complexity: O(1)
|
|
316
337
|
*
|
|
317
338
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
318
339
|
* root.
|
|
319
|
-
* @param {
|
|
340
|
+
* @param {RedBlackTreeNode<K, V> | undefined} v - v is a parameter of type RedBlackTreeNode<K, V> or undefined.
|
|
320
341
|
*/
|
|
321
342
|
_setRoot(v) {
|
|
322
343
|
if (v) {
|
|
@@ -329,9 +350,9 @@ export class RedBlackTree extends BST {
|
|
|
329
350
|
* Space Complexity: O(1)
|
|
330
351
|
*
|
|
331
352
|
* The function replaces an old node with a new node while preserving the color of the old node.
|
|
332
|
-
* @param {
|
|
353
|
+
* @param {RedBlackTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
333
354
|
* the data structure.
|
|
334
|
-
* @param {
|
|
355
|
+
* @param {RedBlackTreeNode<K, V>} newNode - The `newNode` parameter is of type `RedBlackTreeNode<K, V>`, which represents a node in a
|
|
335
356
|
* data structure.
|
|
336
357
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
337
358
|
* superclass, with the `oldNode` and `newNode` parameters.
|
|
@@ -342,11 +363,11 @@ export class RedBlackTree extends BST {
|
|
|
342
363
|
}
|
|
343
364
|
/**
|
|
344
365
|
* Time Complexity: O(log n)
|
|
345
|
-
* Space Complexity: O(
|
|
366
|
+
* Space Complexity: O(log n)
|
|
346
367
|
*
|
|
347
368
|
* The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
|
|
348
369
|
* maintain the red-black tree properties.
|
|
349
|
-
* @param {
|
|
370
|
+
* @param {RedBlackTreeNode<K, V>} node - The `node` parameter represents the node that needs to be inserted into the
|
|
350
371
|
* binary search tree.
|
|
351
372
|
* @returns a string value indicating the result of the insertion operation. It can return either
|
|
352
373
|
* 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
|
|
@@ -390,9 +411,9 @@ export class RedBlackTree extends BST {
|
|
|
390
411
|
* Space Complexity: O(1)
|
|
391
412
|
*
|
|
392
413
|
* The function `_transplant` is used to replace a node `u` with another node `v` in a binary tree.
|
|
393
|
-
* @param {
|
|
394
|
-
* @param {
|
|
395
|
-
* 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`.
|
|
396
417
|
*/
|
|
397
418
|
_transplant(u, v) {
|
|
398
419
|
if (!u.parent) {
|
|
@@ -413,7 +434,7 @@ export class RedBlackTree extends BST {
|
|
|
413
434
|
* Space Complexity: O(1)
|
|
414
435
|
*
|
|
415
436
|
* The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
|
|
416
|
-
* @param {
|
|
437
|
+
* @param {RedBlackTreeNode<K, V> | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
|
|
417
438
|
* structure. It can either be a valid node or `undefined`.
|
|
418
439
|
*/
|
|
419
440
|
_insertFixup(z) {
|
|
@@ -450,7 +471,7 @@ export class RedBlackTree extends BST {
|
|
|
450
471
|
else {
|
|
451
472
|
// Symmetric case for the right child (left and right exchanged)
|
|
452
473
|
// Follow the same logic as above with left and right exchanged
|
|
453
|
-
const y = z?.parent?.parent?.left;
|
|
474
|
+
const y = z?.parent?.parent?.left ?? undefined;
|
|
454
475
|
if (y?.color === 'RED') {
|
|
455
476
|
z.parent.color = 'BLACK';
|
|
456
477
|
y.color = 'BLACK';
|
|
@@ -480,7 +501,7 @@ export class RedBlackTree extends BST {
|
|
|
480
501
|
*
|
|
481
502
|
* The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
|
|
482
503
|
* the colors and performing rotations.
|
|
483
|
-
* @param {
|
|
504
|
+
* @param {RedBlackTreeNode<K, V> | undefined} node - The `node` parameter represents a node in a binary tree. It can
|
|
484
505
|
* be either a valid node object or `undefined`.
|
|
485
506
|
* @returns The function does not return any value. It has a return type of `void`, which means it
|
|
486
507
|
* does not return anything.
|
|
@@ -565,7 +586,7 @@ export class RedBlackTree extends BST {
|
|
|
565
586
|
* Space Complexity: O(1)
|
|
566
587
|
*
|
|
567
588
|
* The `_leftRotate` function performs a left rotation on a given node in a binary tree.
|
|
568
|
-
* @param {
|
|
589
|
+
* @param {RedBlackTreeNode<K, V> | undefined} x - The parameter `x` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
569
590
|
* node in a binary tree or `undefined` if there is no node.
|
|
570
591
|
* @returns void, which means it does not return any value.
|
|
571
592
|
*/
|
|
@@ -596,7 +617,7 @@ export class RedBlackTree extends BST {
|
|
|
596
617
|
* Space Complexity: O(1)
|
|
597
618
|
*
|
|
598
619
|
* The `_rightRotate` function performs a right rotation on a given node in a binary tree.
|
|
599
|
-
* @param {
|
|
620
|
+
* @param {RedBlackTreeNode<K, V> | undefined} y - The parameter `y` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
600
621
|
* node in a binary tree or `undefined` if there is no node.
|
|
601
622
|
* @returns void, which means it does not return any value.
|
|
602
623
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"red-black-t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,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
|
+
}
|