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,5 +1,5 @@
|
|
|
1
1
|
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
2
|
-
export class
|
|
2
|
+
export class TreeCounterNode extends RedBlackTreeNode {
|
|
3
3
|
/**
|
|
4
4
|
* The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
|
|
5
5
|
* @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
|
|
@@ -16,15 +16,39 @@ export class TreeMultiMapNode extends RedBlackTreeNode {
|
|
|
16
16
|
super(key, value, color);
|
|
17
17
|
this.count = count;
|
|
18
18
|
}
|
|
19
|
+
parent = undefined;
|
|
20
|
+
_left = undefined;
|
|
21
|
+
get left() {
|
|
22
|
+
return this._left;
|
|
23
|
+
}
|
|
24
|
+
set left(v) {
|
|
25
|
+
if (v) {
|
|
26
|
+
v.parent = this;
|
|
27
|
+
}
|
|
28
|
+
this._left = v;
|
|
29
|
+
}
|
|
30
|
+
_right = undefined;
|
|
31
|
+
get right() {
|
|
32
|
+
return this._right;
|
|
33
|
+
}
|
|
34
|
+
set right(v) {
|
|
35
|
+
if (v) {
|
|
36
|
+
v.parent = this;
|
|
37
|
+
}
|
|
38
|
+
this._right = v;
|
|
39
|
+
}
|
|
19
40
|
}
|
|
20
|
-
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
export class TreeCounter extends RedBlackTree {
|
|
21
45
|
/**
|
|
22
|
-
* The constructor function initializes a
|
|
46
|
+
* The constructor function initializes a TreeCounter object with optional initial data.
|
|
23
47
|
* @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
|
|
24
48
|
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
25
|
-
*
|
|
49
|
+
* TreeCounter with initial data.
|
|
26
50
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
27
|
-
* behavior of the `
|
|
51
|
+
* behavior of the `TreeCounter` constructor. It can include properties such as `compareKeys` and
|
|
28
52
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
29
53
|
*/
|
|
30
54
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -55,7 +79,7 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
55
79
|
return sum;
|
|
56
80
|
}
|
|
57
81
|
/**
|
|
58
|
-
* The function creates a new
|
|
82
|
+
* The function creates a new TreeCounterNode with the specified key, value, color, and count.
|
|
59
83
|
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
60
84
|
* which is a generic type representing the type of keys in the tree.
|
|
61
85
|
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
@@ -65,72 +89,37 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
65
89
|
* @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
|
|
66
90
|
* the tree. It is an optional parameter and is used to keep track of the number of values associated
|
|
67
91
|
* with a key in the tree.
|
|
68
|
-
* @returns A new instance of the
|
|
92
|
+
* @returns A new instance of the TreeCounterNode class, casted as TreeCounterNode<K, V>.
|
|
69
93
|
*/
|
|
70
94
|
createNode(key, value, color = 'BLACK', count) {
|
|
71
|
-
return new
|
|
95
|
+
return new TreeCounterNode(key, this._isMapMode ? undefined : value, count, color);
|
|
72
96
|
}
|
|
73
97
|
/**
|
|
74
|
-
* The function creates a new instance of a
|
|
98
|
+
* The function creates a new instance of a TreeCounter with the specified options and returns it.
|
|
75
99
|
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
76
|
-
* configuration options for creating the `
|
|
100
|
+
* configuration options for creating the `TreeCounter`. It is of type `TreeCounterOptions<K, V,
|
|
77
101
|
* R>`.
|
|
78
|
-
* @returns a new instance of the `
|
|
102
|
+
* @returns a new instance of the `TreeCounter` class, with the provided options merged with the
|
|
79
103
|
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
80
104
|
*/
|
|
81
105
|
createTree(options) {
|
|
82
|
-
return new
|
|
106
|
+
return new TreeCounter([], {
|
|
83
107
|
iterationType: this.iterationType,
|
|
84
|
-
isMapMode: this._isMapMode,
|
|
85
108
|
specifyComparable: this._specifyComparable,
|
|
109
|
+
isMapMode: this._isMapMode,
|
|
86
110
|
toEntryFn: this._toEntryFn,
|
|
87
111
|
...options
|
|
88
112
|
});
|
|
89
113
|
}
|
|
90
114
|
/**
|
|
91
|
-
* The function
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
97
|
-
* an existing node.
|
|
98
|
-
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
99
|
-
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
100
|
-
* @returns either a NODE object or undefined.
|
|
101
|
-
*/
|
|
102
|
-
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
103
|
-
if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null)
|
|
104
|
-
return [undefined, undefined];
|
|
105
|
-
if (this.isNode(keyNodeEntryOrRaw))
|
|
106
|
-
return [keyNodeEntryOrRaw, value];
|
|
107
|
-
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
108
|
-
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
109
|
-
if (key === undefined || key === null)
|
|
110
|
-
return [undefined, undefined];
|
|
111
|
-
const finalValue = value ?? entryValue;
|
|
112
|
-
if (this.isKey(key))
|
|
113
|
-
return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
|
|
114
|
-
}
|
|
115
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
116
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
117
|
-
const finalValue = value ?? entryValue;
|
|
118
|
-
if (this.isKey(key))
|
|
119
|
-
return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
|
|
120
|
-
}
|
|
121
|
-
if (this.isKey(keyNodeEntryOrRaw))
|
|
122
|
-
return [this.createNode(keyNodeEntryOrRaw, value, 'BLACK', count), value];
|
|
123
|
-
return [undefined, undefined];
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
127
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
128
|
-
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
129
|
-
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
130
|
-
* an instance of the `TreeMultiMapNode` class.
|
|
115
|
+
* The function checks if the input is an instance of the TreeCounterNode class.
|
|
116
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
|
|
117
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
|
|
118
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
119
|
+
* an instance of the `TreeCounterNode` class.
|
|
131
120
|
*/
|
|
132
|
-
isNode(
|
|
133
|
-
return
|
|
121
|
+
isNode(keyNodeOrEntry) {
|
|
122
|
+
return keyNodeOrEntry instanceof TreeCounterNode;
|
|
134
123
|
}
|
|
135
124
|
/**
|
|
136
125
|
* Time Complexity: O(log n)
|
|
@@ -138,8 +127,8 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
138
127
|
*
|
|
139
128
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
140
129
|
* the count and returning a boolean indicating success.
|
|
141
|
-
* @param {BTNRep<K, V,
|
|
142
|
-
* `
|
|
130
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The
|
|
131
|
+
* `keyNodeOrEntry` parameter can accept one of the following types:
|
|
143
132
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
144
133
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
145
134
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
@@ -148,8 +137,8 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
148
137
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
149
138
|
* was successful, and false otherwise.
|
|
150
139
|
*/
|
|
151
|
-
add(
|
|
152
|
-
const [newNode, newValue] = this.
|
|
140
|
+
add(keyNodeOrEntry, value, count = 1) {
|
|
141
|
+
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
153
142
|
const orgCount = newNode?.count || 0;
|
|
154
143
|
const isSuccessAdded = super.add(newNode, newValue);
|
|
155
144
|
if (isSuccessAdded) {
|
|
@@ -166,24 +155,24 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
166
155
|
*
|
|
167
156
|
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
168
157
|
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
169
|
-
* @param {BTNRep<K, V,
|
|
158
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
|
|
170
159
|
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
171
160
|
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
172
161
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
173
162
|
* boolean flag that determines whether to ignore the count of nodes when performing deletion. If
|
|
174
163
|
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
175
164
|
* `ignoreCount` is `false
|
|
176
|
-
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<
|
|
165
|
+
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
|
|
177
166
|
*/
|
|
178
|
-
delete(
|
|
179
|
-
if (
|
|
167
|
+
delete(keyNodeOrEntry, ignoreCount = false) {
|
|
168
|
+
if (keyNodeOrEntry === null)
|
|
180
169
|
return [];
|
|
181
170
|
const results = [];
|
|
182
171
|
let nodeToDelete;
|
|
183
|
-
if (this._isPredicate(
|
|
184
|
-
nodeToDelete = this.getNode(
|
|
172
|
+
if (this._isPredicate(keyNodeOrEntry))
|
|
173
|
+
nodeToDelete = this.getNode(keyNodeOrEntry);
|
|
185
174
|
else
|
|
186
|
-
nodeToDelete = this.isRealNode(
|
|
175
|
+
nodeToDelete = this.isRealNode(keyNodeOrEntry) ? keyNodeOrEntry : this.getNode(keyNodeOrEntry);
|
|
187
176
|
if (!nodeToDelete) {
|
|
188
177
|
return results;
|
|
189
178
|
}
|
|
@@ -352,16 +341,65 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
352
341
|
cloned._store = this._store;
|
|
353
342
|
return cloned;
|
|
354
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* The `map` function in TypeScript overrides the default behavior to create a new TreeCounter with
|
|
346
|
+
* modified entries based on a provided callback.
|
|
347
|
+
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
348
|
+
* map. It takes four arguments:
|
|
349
|
+
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
350
|
+
* `TreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
|
|
351
|
+
* options when creating a new `TreeCounter` instance within the `map` function. These options could
|
|
352
|
+
* include things like
|
|
353
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
354
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
355
|
+
* (value of `this`) for the callback function when it is called within the `map` function. This
|
|
356
|
+
* @returns A new TreeCounter instance is being returned, which is populated with entries generated
|
|
357
|
+
* by the provided callback function.
|
|
358
|
+
*/
|
|
359
|
+
map(callback, options, thisArg) {
|
|
360
|
+
const newTree = new TreeCounter([], options);
|
|
361
|
+
let index = 0;
|
|
362
|
+
for (const [key, value] of this) {
|
|
363
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
364
|
+
}
|
|
365
|
+
return newTree;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
369
|
+
* node based on the input.
|
|
370
|
+
* @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
|
|
371
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
|
|
372
|
+
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
373
|
+
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
374
|
+
* an existing node.
|
|
375
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
376
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
377
|
+
* @returns either a TreeCounterNode<K, V> object or undefined.
|
|
378
|
+
*/
|
|
379
|
+
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count = 1) {
|
|
380
|
+
if (keyNodeOrEntry === undefined || keyNodeOrEntry === null)
|
|
381
|
+
return [undefined, undefined];
|
|
382
|
+
if (this.isNode(keyNodeOrEntry))
|
|
383
|
+
return [keyNodeOrEntry, value];
|
|
384
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
385
|
+
const [key, entryValue] = keyNodeOrEntry;
|
|
386
|
+
if (key === undefined || key === null)
|
|
387
|
+
return [undefined, undefined];
|
|
388
|
+
const finalValue = value ?? entryValue;
|
|
389
|
+
return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
|
|
390
|
+
}
|
|
391
|
+
return [this.createNode(keyNodeOrEntry, value, 'BLACK', count), value];
|
|
392
|
+
}
|
|
355
393
|
/**
|
|
356
394
|
* Time Complexity: O(1)
|
|
357
395
|
* Space Complexity: O(1)
|
|
358
396
|
*
|
|
359
397
|
* The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
|
|
360
398
|
* in a binary search tree.
|
|
361
|
-
* @param {R | BSTNOptKeyOrNode<K,
|
|
399
|
+
* @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
|
|
362
400
|
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
363
|
-
* instance of the `BSTNOptKeyOrNode<K,
|
|
364
|
-
* @param {R | BSTNOptKeyOrNode<K,
|
|
401
|
+
* instance of the `BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>` class.
|
|
402
|
+
* @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
|
|
365
403
|
* node where the properties will be swapped with the source node.
|
|
366
404
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
367
405
|
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
@@ -394,38 +432,15 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
394
432
|
* Space Complexity: O(1)
|
|
395
433
|
*
|
|
396
434
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
397
|
-
* @param {
|
|
435
|
+
* @param {TreeCounterNode<K, V>} oldNode - The `oldNode` parameter is the node that you want to replace in the data
|
|
398
436
|
* structure.
|
|
399
|
-
* @param {
|
|
437
|
+
* @param {TreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `TreeCounterNode<K, V>` class.
|
|
400
438
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
401
|
-
* superclass, which is of type `
|
|
439
|
+
* superclass, which is of type `TreeCounterNode<K, V>`.
|
|
402
440
|
*/
|
|
403
441
|
_replaceNode(oldNode, newNode) {
|
|
404
442
|
newNode.count = oldNode.count + newNode.count;
|
|
405
443
|
return super._replaceNode(oldNode, newNode);
|
|
406
444
|
}
|
|
407
|
-
/**
|
|
408
|
-
* The `map` function in TypeScript overrides the default behavior to create a new TreeMultiMap with
|
|
409
|
-
* modified entries based on a provided callback.
|
|
410
|
-
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
411
|
-
* map. It takes four arguments:
|
|
412
|
-
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
413
|
-
* `TreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
|
|
414
|
-
* options when creating a new `TreeMultiMap` instance within the `map` function. These options could
|
|
415
|
-
* include things like
|
|
416
|
-
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
417
|
-
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
418
|
-
* (value of `this`) for the callback function when it is called within the `map` function. This
|
|
419
|
-
* @returns A new TreeMultiMap instance is being returned, which is populated with entries generated
|
|
420
|
-
* by the provided callback function.
|
|
421
|
-
*/
|
|
422
|
-
map(callback, options, thisArg) {
|
|
423
|
-
const newTree = new TreeMultiMap([], options);
|
|
424
|
-
let index = 0;
|
|
425
|
-
for (const [key, value] of this) {
|
|
426
|
-
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
427
|
-
}
|
|
428
|
-
return newTree;
|
|
429
|
-
}
|
|
430
445
|
}
|
|
431
|
-
//# sourceMappingURL=tree-
|
|
446
|
+
//# sourceMappingURL=tree-counter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-counter.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-counter.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,OAAO,eAAkC,SAAQ,gBAAsB;IAC3E;;;;;;;;;;;OAWG;IACH,YAAY,GAAM,EAAE,KAAS,EAAE,KAAK,GAAG,CAAC,EAAE,QAAmB,OAAO;QAClE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAEQ,MAAM,GAA2B,SAAS,CAAC;IAE3C,KAAK,GAA0C,SAAS,CAAC;IAElE,IAAa,IAAI;QACf,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAa,IAAI,CAAC,CAAuC;QACvD,IAAI,CAAC,EAAE,CAAC;YACN,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;IAEQ,MAAM,GAA0C,SAAS,CAAC;IAEnE,IAAa,KAAK;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAa,KAAK,CAAC,CAAuC;QACxD,IAAI,CAAC,EAAE,CAAC;YACN,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC;QAClB,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@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { BTNRep, OptNodeOrNull, TreeMultiMapOptions } from '../../types';
|
|
9
|
+
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
10
|
+
import { IBinaryTree } from '../../interfaces';
|
|
11
|
+
export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]> {
|
|
12
|
+
/**
|
|
13
|
+
* This TypeScript constructor initializes an object with a key of type K and an array of values of
|
|
14
|
+
* type V.
|
|
15
|
+
* @param {K} key - The `key` parameter is typically used to store a unique identifier or key for the
|
|
16
|
+
* data being stored in the data structure. It helps in quickly accessing or retrieving the
|
|
17
|
+
* associated value in the data structure.
|
|
18
|
+
* @param {V[]} value - The `value` parameter in the constructor represents an array of values of
|
|
19
|
+
* type `V`.
|
|
20
|
+
*/
|
|
21
|
+
constructor(key: K, value: V[]);
|
|
22
|
+
parent?: TreeMultiMapNode<K, V>;
|
|
23
|
+
_left?: OptNodeOrNull<TreeMultiMapNode<K, V>>;
|
|
24
|
+
get left(): OptNodeOrNull<TreeMultiMapNode<K, V>>;
|
|
25
|
+
set left(v: OptNodeOrNull<TreeMultiMapNode<K, V>>);
|
|
26
|
+
_right?: OptNodeOrNull<TreeMultiMapNode<K, V>>;
|
|
27
|
+
get right(): OptNodeOrNull<TreeMultiMapNode<K, V>>;
|
|
28
|
+
set right(v: OptNodeOrNull<TreeMultiMapNode<K, V>>);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Find elements in a range
|
|
34
|
+
* const tmm = new TreeMultiMap<number>([10, 5, 15, 3, 7, 12, 18]);
|
|
35
|
+
* console.log(tmm.search(new Range(5, 10))); // [5, 10, 7]
|
|
36
|
+
* console.log(tmm.search(new Range(4, 12))); // [5, 10, 12, 7]
|
|
37
|
+
* console.log(tmm.search(new Range(15, 20))); // [15, 18]
|
|
38
|
+
*/
|
|
39
|
+
export declare class TreeMultiMap<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> {
|
|
40
|
+
/**
|
|
41
|
+
* The constructor initializes an TreeMultiMap with the provided keys, nodes, entries, or raw data
|
|
42
|
+
* and options.
|
|
43
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
44
|
+
* iterable that can contain either key-value pairs represented as `BTNRep<K, V[],
|
|
45
|
+
* TreeMultiMapNode<K, V>>` or raw data represented as `R`. This parameter is used to initialize
|
|
46
|
+
* the RedBlackTreeMulti
|
|
47
|
+
* @param [options] - The `options` parameter in the constructor is of type
|
|
48
|
+
* `TreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
|
|
49
|
+
* additional options for configuring the TreeMultiMap instance.
|
|
50
|
+
*/
|
|
51
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V[], TreeMultiMapNode<K, V>> | R>, options?: TreeMultiMapOptions<K, V[], R>);
|
|
52
|
+
/**
|
|
53
|
+
* Time Complexity: O(1)
|
|
54
|
+
* Space Complexity: O(1)
|
|
55
|
+
*
|
|
56
|
+
* The `createTree` function in TypeScript overrides the default implementation to create a new
|
|
57
|
+
* TreeMultiMap with specified options.
|
|
58
|
+
* @param [options] - The `options` parameter in the `createTree` method is of type
|
|
59
|
+
* `TreeMultiMapOptions<K, V[], R>`. This parameter allows you to pass additional configuration
|
|
60
|
+
* options when creating a new `TreeMultiMap` instance. It includes properties such as
|
|
61
|
+
* `iterationType`, `specifyComparable
|
|
62
|
+
* @returns A new instance of `TreeMultiMap` is being returned, with an empty array as the initial
|
|
63
|
+
* data and the provided options merged with the existing properties of the current object.
|
|
64
|
+
*/
|
|
65
|
+
createTree(options?: TreeMultiMapOptions<K, V[], R>): TreeMultiMap<K, V, R, MK, MV, MR>;
|
|
66
|
+
/**
|
|
67
|
+
* Time Complexity: O(1)
|
|
68
|
+
* Space Complexity: O(1)
|
|
69
|
+
*
|
|
70
|
+
* The function `createNode` overrides the method to create a new `TreeMultiMapNode` with a specified
|
|
71
|
+
* key and an empty array of values.
|
|
72
|
+
* @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
|
|
73
|
+
* that will be created in the TreeMultiMap data structure.
|
|
74
|
+
* @returns A new instance of `TreeMultiMapNode<K, V>` is being returned, with the specified key and
|
|
75
|
+
* an empty array as its value.
|
|
76
|
+
*/
|
|
77
|
+
createNode(key: K): TreeMultiMapNode<K, V>;
|
|
78
|
+
add(node: BTNRep<K, V[], TreeMultiMapNode<K, V>>): boolean;
|
|
79
|
+
add(key: K, value: V): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Time Complexity: O(log n)
|
|
82
|
+
* Space Complexity: O(log n)
|
|
83
|
+
*
|
|
84
|
+
* The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
|
|
85
|
+
* and deletes the entire node if no values are left for that key.
|
|
86
|
+
* @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
87
|
+
* parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
|
|
88
|
+
* array of values, or just a key itself.
|
|
89
|
+
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
90
|
+
* value that you want to remove from the multi-map data structure associated with a particular key.
|
|
91
|
+
* The function checks if the value exists in the array of values associated with the key, and if
|
|
92
|
+
* found, removes it from the array.
|
|
93
|
+
* @returns The `deleteValue` function returns a boolean value - `true` if the specified `value` was
|
|
94
|
+
* successfully deleted from the values associated with the `keyNodeOrEntry`, and `false` otherwise.
|
|
95
|
+
*/
|
|
96
|
+
deleteValue(keyNodeOrEntry: BTNRep<K, V[], TreeMultiMapNode<K, V>> | K, value: V): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Time Complexity: O(n)
|
|
99
|
+
* Space Complexity: O(n)
|
|
100
|
+
*
|
|
101
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
102
|
+
* structure.
|
|
103
|
+
* @returns The `cloned` object is being returned.
|
|
104
|
+
*/
|
|
105
|
+
clone(): TreeMultiMap<K, V, R, MK, MV, MR>;
|
|
106
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
2
|
+
export class TreeMultiMapNode extends RedBlackTreeNode {
|
|
3
|
+
/**
|
|
4
|
+
* This TypeScript constructor initializes an object with a key of type K and an array of values of
|
|
5
|
+
* type V.
|
|
6
|
+
* @param {K} key - The `key` parameter is typically used to store a unique identifier or key for the
|
|
7
|
+
* data being stored in the data structure. It helps in quickly accessing or retrieving the
|
|
8
|
+
* associated value in the data structure.
|
|
9
|
+
* @param {V[]} value - The `value` parameter in the constructor represents an array of values of
|
|
10
|
+
* type `V`.
|
|
11
|
+
*/
|
|
12
|
+
constructor(key, value) {
|
|
13
|
+
super(key, value);
|
|
14
|
+
}
|
|
15
|
+
parent = undefined;
|
|
16
|
+
_left = undefined;
|
|
17
|
+
get left() {
|
|
18
|
+
return this._left;
|
|
19
|
+
}
|
|
20
|
+
set left(v) {
|
|
21
|
+
if (v) {
|
|
22
|
+
v.parent = this;
|
|
23
|
+
}
|
|
24
|
+
this._left = v;
|
|
25
|
+
}
|
|
26
|
+
_right = undefined;
|
|
27
|
+
get right() {
|
|
28
|
+
return this._right;
|
|
29
|
+
}
|
|
30
|
+
set right(v) {
|
|
31
|
+
if (v) {
|
|
32
|
+
v.parent = this;
|
|
33
|
+
}
|
|
34
|
+
this._right = v;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Find elements in a range
|
|
41
|
+
* const tmm = new TreeMultiMap<number>([10, 5, 15, 3, 7, 12, 18]);
|
|
42
|
+
* console.log(tmm.search(new Range(5, 10))); // [5, 10, 7]
|
|
43
|
+
* console.log(tmm.search(new Range(4, 12))); // [5, 10, 12, 7]
|
|
44
|
+
* console.log(tmm.search(new Range(15, 20))); // [15, 18]
|
|
45
|
+
*/
|
|
46
|
+
export class TreeMultiMap extends RedBlackTree {
|
|
47
|
+
/**
|
|
48
|
+
* The constructor initializes an TreeMultiMap with the provided keys, nodes, entries, or raw data
|
|
49
|
+
* and options.
|
|
50
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
51
|
+
* iterable that can contain either key-value pairs represented as `BTNRep<K, V[],
|
|
52
|
+
* TreeMultiMapNode<K, V>>` or raw data represented as `R`. This parameter is used to initialize
|
|
53
|
+
* the RedBlackTreeMulti
|
|
54
|
+
* @param [options] - The `options` parameter in the constructor is of type
|
|
55
|
+
* `TreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
|
|
56
|
+
* additional options for configuring the TreeMultiMap instance.
|
|
57
|
+
*/
|
|
58
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
59
|
+
super([], { ...options, isMapMode: true });
|
|
60
|
+
if (keysNodesEntriesOrRaws) {
|
|
61
|
+
this.addMany(keysNodesEntriesOrRaws);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Time Complexity: O(1)
|
|
66
|
+
* Space Complexity: O(1)
|
|
67
|
+
*
|
|
68
|
+
* The `createTree` function in TypeScript overrides the default implementation to create a new
|
|
69
|
+
* TreeMultiMap with specified options.
|
|
70
|
+
* @param [options] - The `options` parameter in the `createTree` method is of type
|
|
71
|
+
* `TreeMultiMapOptions<K, V[], R>`. This parameter allows you to pass additional configuration
|
|
72
|
+
* options when creating a new `TreeMultiMap` instance. It includes properties such as
|
|
73
|
+
* `iterationType`, `specifyComparable
|
|
74
|
+
* @returns A new instance of `TreeMultiMap` is being returned, with an empty array as the initial
|
|
75
|
+
* data and the provided options merged with the existing properties of the current object.
|
|
76
|
+
*/
|
|
77
|
+
createTree(options) {
|
|
78
|
+
return new TreeMultiMap([], {
|
|
79
|
+
iterationType: this.iterationType,
|
|
80
|
+
specifyComparable: this._specifyComparable,
|
|
81
|
+
toEntryFn: this._toEntryFn,
|
|
82
|
+
isReverse: this._isReverse,
|
|
83
|
+
...options
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Time Complexity: O(1)
|
|
88
|
+
* Space Complexity: O(1)
|
|
89
|
+
*
|
|
90
|
+
* The function `createNode` overrides the method to create a new `TreeMultiMapNode` with a specified
|
|
91
|
+
* key and an empty array of values.
|
|
92
|
+
* @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
|
|
93
|
+
* that will be created in the TreeMultiMap data structure.
|
|
94
|
+
* @returns A new instance of `TreeMultiMapNode<K, V>` is being returned, with the specified key and
|
|
95
|
+
* an empty array as its value.
|
|
96
|
+
*/
|
|
97
|
+
createNode(key) {
|
|
98
|
+
return new TreeMultiMapNode(key, []);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Time Complexity: O(log n)
|
|
102
|
+
* Space Complexity: O(log n)
|
|
103
|
+
*
|
|
104
|
+
* The function `add` in TypeScript overrides the superclass method to add key-value pairs to a
|
|
105
|
+
* TreeMultiMapNode, handling different input types and scenarios.
|
|
106
|
+
* @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
107
|
+
* parameter in the `override add` method can be either a `BTNRep` object containing a key, an array
|
|
108
|
+
* of values, and a `TreeMultiMapNode`, or just a key.
|
|
109
|
+
* @param {V} [value] - The `value` parameter in the `override add` method represents the value that
|
|
110
|
+
* you want to add to the TreeMultiMap. If the key is already present in the map, the new value will
|
|
111
|
+
* be added to the existing list of values associated with that key. If the key is not present,
|
|
112
|
+
* @returns The `add` method is returning a boolean value, which indicates whether the operation was
|
|
113
|
+
* successful or not.
|
|
114
|
+
*/
|
|
115
|
+
add(keyNodeOrEntry, value) {
|
|
116
|
+
if (this.isRealNode(keyNodeOrEntry))
|
|
117
|
+
return super.add(keyNodeOrEntry);
|
|
118
|
+
const _commonAdd = (key, values) => {
|
|
119
|
+
if (key === undefined || key === null)
|
|
120
|
+
return false;
|
|
121
|
+
const existingValues = this.get(key);
|
|
122
|
+
if (existingValues !== undefined && values !== undefined) {
|
|
123
|
+
for (const value of values)
|
|
124
|
+
existingValues.push(value);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
const existingNode = this.getNode(key);
|
|
128
|
+
if (this.isRealNode(existingNode)) {
|
|
129
|
+
if (existingValues === undefined) {
|
|
130
|
+
super.add(key, values);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
if (values !== undefined) {
|
|
134
|
+
for (const value of values)
|
|
135
|
+
existingValues.push(value);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
return super.add(key, values);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
if (this.isEntry(keyNodeOrEntry)) {
|
|
147
|
+
const [key, values] = keyNodeOrEntry;
|
|
148
|
+
return _commonAdd(key, value !== undefined ? [value] : values);
|
|
149
|
+
}
|
|
150
|
+
return _commonAdd(keyNodeOrEntry, value !== undefined ? [value] : undefined);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Time Complexity: O(log n)
|
|
154
|
+
* Space Complexity: O(log n)
|
|
155
|
+
*
|
|
156
|
+
* The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
|
|
157
|
+
* and deletes the entire node if no values are left for that key.
|
|
158
|
+
* @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
159
|
+
* parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
|
|
160
|
+
* array of values, or just a key itself.
|
|
161
|
+
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
162
|
+
* value that you want to remove from the multi-map data structure associated with a particular key.
|
|
163
|
+
* The function checks if the value exists in the array of values associated with the key, and if
|
|
164
|
+
* found, removes it from the array.
|
|
165
|
+
* @returns The `deleteValue` function returns a boolean value - `true` if the specified `value` was
|
|
166
|
+
* successfully deleted from the values associated with the `keyNodeOrEntry`, and `false` otherwise.
|
|
167
|
+
*/
|
|
168
|
+
deleteValue(keyNodeOrEntry, value) {
|
|
169
|
+
const values = this.get(keyNodeOrEntry);
|
|
170
|
+
if (Array.isArray(values)) {
|
|
171
|
+
const index = values.indexOf(value);
|
|
172
|
+
if (index === -1)
|
|
173
|
+
return false;
|
|
174
|
+
values.splice(index, 1);
|
|
175
|
+
// If no values left, remove the entire node
|
|
176
|
+
if (values.length === 0)
|
|
177
|
+
this.delete(keyNodeOrEntry);
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Time Complexity: O(n)
|
|
184
|
+
* Space Complexity: O(n)
|
|
185
|
+
*
|
|
186
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
187
|
+
* structure.
|
|
188
|
+
* @returns The `cloned` object is being returned.
|
|
189
|
+
*/
|
|
190
|
+
clone() {
|
|
191
|
+
const cloned = this.createTree();
|
|
192
|
+
this._clone(cloned);
|
|
193
|
+
return cloned;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=tree-multi-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multi-map.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGlE,MAAM,OAAO,gBAAmC,SAAQ,gBAAwB;IAC9E;;;;;;;;OAQG;IACH,YAAY,GAAM,EAAE,KAAU;QAC5B,KAAK,C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> {
|
|
|
34
34
|
*/
|
|
35
35
|
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
37
40
|
export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V> = DirectedVertex<V>, EO extends DirectedEdge<E> = DirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
|
|
38
41
|
/**
|
|
39
42
|
* The constructor function initializes an instance of a class.
|