data-structure-typed 2.0.5 → 2.1.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 +5 -1
- package/COMMANDS.md +27 -0
- package/README.md +5 -34
- package/benchmark/report.html +13 -77
- package/benchmark/report.json +152 -184
- package/dist/cjs/index.cjs +13062 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +12984 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/index.cjs +13091 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +13013 -0
- package/dist/index.js.map +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +219 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +144 -0
- package/dist/types/data-structures/base/linear-base.d.ts +335 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -0
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -0
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -0
- package/dist/{esm → types}/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -0
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -0
- package/dist/types/data-structures/heap/heap.d.ts +503 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -0
- package/dist/types/data-structures/queue/deque.d.ts +431 -0
- package/dist/types/data-structures/queue/queue.d.ts +308 -0
- package/dist/{cjs → types}/data-structures/stack/stack.d.ts +124 -102
- package/dist/types/data-structures/trie/trie.d.ts +350 -0
- package/dist/types/interfaces/binary-tree.d.ts +59 -0
- package/dist/types/interfaces/graph.d.ts +21 -0
- package/dist/{cjs → types}/types/data-structures/base/base.d.ts +1 -1
- package/dist/{esm → types}/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/{cjs → types}/types/utils/utils.d.ts +1 -0
- package/dist/{esm → types}/utils/utils.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +4693 -6484
- package/dist/umd/data-structure-typed.js.map +1 -0
- package/dist/umd/data-structure-typed.min.js +8 -6
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/jest.integration.config.js +3 -0
- package/package.json +13 -12
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
- package/src/data-structures/binary-tree/avl-tree.ts +237 -206
- package/src/data-structures/binary-tree/binary-tree.ts +665 -896
- package/src/data-structures/binary-tree/bst.ts +565 -572
- package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
- package/src/data-structures/binary-tree/tree-counter.ts +195 -219
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/integration/index.html +1 -1
- package/test/performance/benchmark-runner.ts +528 -0
- package/test/performance/data-structures/comparison/comparison.test.ts +27 -57
- package/test/performance/reportor.mjs +43 -43
- package/test/performance/runner-config.json +39 -0
- package/test/performance/single-suite-runner.ts +69 -0
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
- package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +112 -4
- package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +14 -21
- package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
- package/test/unit/data-structures/queue/queue.test.ts +4 -5
- package/test/unit/utils/utils.test.ts +0 -1
- package/tsconfig-base.json +20 -20
- package/tsconfig-types.json +17 -0
- package/tsconfig.test.json +8 -0
- package/tsup.config.js +11 -22
- package/tsup.node.config.ts +37 -0
- package/dist/cjs/common/index.js +0 -29
- package/dist/cjs/common/index.js.map +0 -1
- package/dist/cjs/data-structures/base/index.js +0 -19
- package/dist/cjs/data-structures/base/index.js.map +0 -1
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +0 -116
- package/dist/cjs/data-structures/base/iterable-element-base.js +0 -202
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +0 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +0 -168
- package/dist/cjs/data-structures/base/iterable-entry-base.js +0 -241
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +0 -1
- package/dist/cjs/data-structures/base/linear-base.d.ts +0 -277
- package/dist/cjs/data-structures/base/linear-base.js +0 -553
- package/dist/cjs/data-structures/base/linear-base.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +0 -214
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +0 -409
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -104
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +0 -203
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -302
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -599
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +0 -295
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +0 -910
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +0 -2197
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +0 -461
- package/dist/cjs/data-structures/binary-tree/bst.js +0 -880
- package/dist/cjs/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/index.js +0 -27
- package/dist/cjs/data-structures/binary-tree/index.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +0 -280
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +0 -642
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +0 -298
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +0 -212
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +0 -445
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -267
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +0 -365
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -335
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -867
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +0 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -323
- package/dist/cjs/data-structures/graph/directed-graph.js +0 -613
- package/dist/cjs/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/cjs/data-structures/graph/index.js +0 -21
- package/dist/cjs/data-structures/graph/index.js.map +0 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +0 -84
- package/dist/cjs/data-structures/graph/map-graph.js +0 -111
- package/dist/cjs/data-structures/graph/map-graph.js.map +0 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -231
- package/dist/cjs/data-structures/graph/undirected-graph.js +0 -445
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +0 -519
- package/dist/cjs/data-structures/hash/hash-map.js +0 -880
- package/dist/cjs/data-structures/hash/hash-map.js.map +0 -1
- package/dist/cjs/data-structures/hash/index.js +0 -18
- package/dist/cjs/data-structures/hash/index.js.map +0 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +0 -578
- package/dist/cjs/data-structures/heap/heap.js +0 -911
- package/dist/cjs/data-structures/heap/heap.js.map +0 -1
- package/dist/cjs/data-structures/heap/index.js +0 -20
- package/dist/cjs/data-structures/heap/index.js.map +0 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +0 -68
- package/dist/cjs/data-structures/heap/max-heap.js +0 -96
- package/dist/cjs/data-structures/heap/max-heap.js.map +0 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +0 -68
- package/dist/cjs/data-structures/heap/min-heap.js +0 -87
- package/dist/cjs/data-structures/heap/min-heap.js.map +0 -1
- package/dist/cjs/data-structures/index.js +0 -29
- package/dist/cjs/data-structures/index.js.map +0 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +0 -885
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +0 -1238
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +0 -1
- package/dist/cjs/data-structures/linked-list/index.js +0 -20
- package/dist/cjs/data-structures/linked-list/index.js.map +0 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +0 -500
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +0 -870
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -134
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -245
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/cjs/data-structures/matrix/index.js +0 -19
- package/dist/cjs/data-structures/matrix/index.js.map +0 -1
- package/dist/cjs/data-structures/matrix/matrix.js +0 -449
- package/dist/cjs/data-structures/matrix/matrix.js.map +0 -1
- package/dist/cjs/data-structures/matrix/navigator.js +0 -112
- package/dist/cjs/data-structures/matrix/navigator.js.map +0 -1
- package/dist/cjs/data-structures/priority-queue/index.js +0 -20
- package/dist/cjs/data-structures/priority-queue/index.js.map +0 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +0 -71
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -102
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +0 -72
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -94
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +0 -74
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +0 -96
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +0 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +0 -458
- package/dist/cjs/data-structures/queue/deque.js +0 -919
- package/dist/cjs/data-structures/queue/deque.js.map +0 -1
- package/dist/cjs/data-structures/queue/index.js +0 -19
- package/dist/cjs/data-structures/queue/index.js.map +0 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +0 -329
- package/dist/cjs/data-structures/queue/queue.js +0 -457
- package/dist/cjs/data-structures/queue/queue.js.map +0 -1
- package/dist/cjs/data-structures/stack/index.js +0 -18
- package/dist/cjs/data-structures/stack/index.js.map +0 -1
- package/dist/cjs/data-structures/stack/stack.js +0 -346
- package/dist/cjs/data-structures/stack/stack.js.map +0 -1
- package/dist/cjs/data-structures/tree/index.js +0 -18
- package/dist/cjs/data-structures/tree/index.js.map +0 -1
- package/dist/cjs/data-structures/tree/tree.js +0 -108
- package/dist/cjs/data-structures/tree/tree.js.map +0 -1
- package/dist/cjs/data-structures/trie/index.js +0 -18
- package/dist/cjs/data-structures/trie/index.js.map +0 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -351
- package/dist/cjs/data-structures/trie/trie.js +0 -594
- package/dist/cjs/data-structures/trie/trie.js.map +0 -1
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +0 -9
- package/dist/cjs/interfaces/binary-tree.js +0 -3
- package/dist/cjs/interfaces/binary-tree.js.map +0 -1
- package/dist/cjs/interfaces/doubly-linked-list.js +0 -3
- package/dist/cjs/interfaces/doubly-linked-list.js.map +0 -1
- package/dist/cjs/interfaces/graph.d.ts +0 -5
- package/dist/cjs/interfaces/graph.js +0 -3
- package/dist/cjs/interfaces/graph.js.map +0 -1
- package/dist/cjs/interfaces/heap.js +0 -3
- package/dist/cjs/interfaces/heap.js.map +0 -1
- package/dist/cjs/interfaces/index.js +0 -25
- package/dist/cjs/interfaces/index.js.map +0 -1
- package/dist/cjs/interfaces/navigator.js +0 -3
- package/dist/cjs/interfaces/navigator.js.map +0 -1
- package/dist/cjs/interfaces/priority-queue.js +0 -3
- package/dist/cjs/interfaces/priority-queue.js.map +0 -1
- package/dist/cjs/interfaces/segment-tree.js +0 -3
- package/dist/cjs/interfaces/segment-tree.js.map +0 -1
- package/dist/cjs/interfaces/singly-linked-list.js +0 -3
- package/dist/cjs/interfaces/singly-linked-list.js.map +0 -1
- package/dist/cjs/types/common.js +0 -3
- package/dist/cjs/types/common.js.map +0 -1
- package/dist/cjs/types/data-structures/base/base.js +0 -3
- package/dist/cjs/types/data-structures/base/base.js.map +0 -1
- package/dist/cjs/types/data-structures/base/index.js +0 -18
- package/dist/cjs/types/data-structures/base/index.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js +0 -26
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/segment-tree.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/segment-tree.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js +0 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +0 -10
- package/dist/cjs/types/data-structures/graph/abstract-graph.js +0 -3
- package/dist/cjs/types/data-structures/graph/abstract-graph.js.map +0 -1
- package/dist/cjs/types/data-structures/graph/directed-graph.js +0 -3
- package/dist/cjs/types/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/cjs/types/data-structures/graph/index.js +0 -20
- package/dist/cjs/types/data-structures/graph/index.js.map +0 -1
- package/dist/cjs/types/data-structures/graph/map-graph.js +0 -3
- package/dist/cjs/types/data-structures/graph/map-graph.js.map +0 -1
- package/dist/cjs/types/data-structures/graph/undirected-graph.js +0 -3
- package/dist/cjs/types/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/hash-map.js +0 -3
- package/dist/cjs/types/data-structures/hash/hash-map.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/index.js +0 -18
- package/dist/cjs/types/data-structures/hash/index.js.map +0 -1
- package/dist/cjs/types/data-structures/heap/heap.js +0 -3
- package/dist/cjs/types/data-structures/heap/heap.js.map +0 -1
- package/dist/cjs/types/data-structures/heap/index.js +0 -18
- package/dist/cjs/types/data-structures/heap/index.js.map +0 -1
- package/dist/cjs/types/data-structures/heap/max-heap.js +0 -3
- package/dist/cjs/types/data-structures/heap/max-heap.js.map +0 -1
- package/dist/cjs/types/data-structures/heap/min-heap.js +0 -3
- package/dist/cjs/types/data-structures/heap/min-heap.js.map +0 -1
- package/dist/cjs/types/data-structures/index.js +0 -29
- package/dist/cjs/types/data-structures/index.js.map +0 -1
- package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js +0 -3
- package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
- package/dist/cjs/types/data-structures/linked-list/index.js +0 -20
- package/dist/cjs/types/data-structures/linked-list/index.js.map +0 -1
- package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js +0 -3
- package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js +0 -3
- package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/cjs/types/data-structures/matrix/index.js +0 -19
- package/dist/cjs/types/data-structures/matrix/index.js.map +0 -1
- package/dist/cjs/types/data-structures/matrix/matrix.js +0 -3
- package/dist/cjs/types/data-structures/matrix/matrix.js.map +0 -1
- package/dist/cjs/types/data-structures/matrix/navigator.js +0 -3
- package/dist/cjs/types/data-structures/matrix/navigator.js.map +0 -1
- package/dist/cjs/types/data-structures/priority-queue/index.js +0 -20
- package/dist/cjs/types/data-structures/priority-queue/index.js.map +0 -1
- package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js +0 -3
- package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js +0 -3
- package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.js +0 -3
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.js.map +0 -1
- package/dist/cjs/types/data-structures/queue/deque.js +0 -3
- package/dist/cjs/types/data-structures/queue/deque.js.map +0 -1
- package/dist/cjs/types/data-structures/queue/index.js +0 -19
- package/dist/cjs/types/data-structures/queue/index.js.map +0 -1
- package/dist/cjs/types/data-structures/queue/queue.js +0 -3
- package/dist/cjs/types/data-structures/queue/queue.js.map +0 -1
- package/dist/cjs/types/data-structures/stack/index.js +0 -18
- package/dist/cjs/types/data-structures/stack/index.js.map +0 -1
- package/dist/cjs/types/data-structures/stack/stack.js +0 -3
- package/dist/cjs/types/data-structures/stack/stack.js.map +0 -1
- package/dist/cjs/types/data-structures/tree/index.js +0 -18
- package/dist/cjs/types/data-structures/tree/index.js.map +0 -1
- package/dist/cjs/types/data-structures/tree/tree.js +0 -3
- package/dist/cjs/types/data-structures/tree/tree.js.map +0 -1
- package/dist/cjs/types/data-structures/trie/index.js +0 -18
- package/dist/cjs/types/data-structures/trie/index.js.map +0 -1
- package/dist/cjs/types/data-structures/trie/trie.js +0 -3
- package/dist/cjs/types/data-structures/trie/trie.js.map +0 -1
- package/dist/cjs/types/index.js +0 -20
- package/dist/cjs/types/index.js.map +0 -1
- package/dist/cjs/types/utils/index.js +0 -19
- package/dist/cjs/types/utils/index.js.map +0 -1
- package/dist/cjs/types/utils/utils.js +0 -3
- package/dist/cjs/types/utils/utils.js.map +0 -1
- package/dist/cjs/types/utils/validate-type.js +0 -3
- package/dist/cjs/types/utils/validate-type.js.map +0 -1
- package/dist/cjs/utils/index.js +0 -19
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/number.js +0 -24
- package/dist/cjs/utils/number.js.map +0 -1
- package/dist/cjs/utils/utils.d.ts +0 -209
- package/dist/cjs/utils/utils.js +0 -353
- package/dist/cjs/utils/utils.js.map +0 -1
- package/dist/esm/common/index.d.ts +0 -12
- package/dist/esm/common/index.js +0 -29
- package/dist/esm/common/index.js.map +0 -1
- package/dist/esm/data-structures/base/index.d.ts +0 -2
- package/dist/esm/data-structures/base/index.js +0 -3
- package/dist/esm/data-structures/base/index.js.map +0 -1
- package/dist/esm/data-structures/base/iterable-element-base.d.ts +0 -116
- package/dist/esm/data-structures/base/iterable-element-base.js +0 -199
- package/dist/esm/data-structures/base/iterable-element-base.js.map +0 -1
- package/dist/esm/data-structures/base/iterable-entry-base.d.ts +0 -168
- package/dist/esm/data-structures/base/iterable-entry-base.js +0 -237
- package/dist/esm/data-structures/base/iterable-entry-base.js.map +0 -1
- package/dist/esm/data-structures/base/linear-base.d.ts +0 -277
- package/dist/esm/data-structures/base/linear-base.js +0 -549
- package/dist/esm/data-structures/base/linear-base.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +0 -214
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +0 -410
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -104
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +0 -205
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +0 -302
- package/dist/esm/data-structures/binary-tree/avl-tree.js +0 -601
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js +0 -296
- package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +0 -910
- package/dist/esm/data-structures/binary-tree/binary-tree.js +0 -2198
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/bst.d.ts +0 -461
- package/dist/esm/data-structures/binary-tree/bst.js +0 -881
- package/dist/esm/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/index.d.ts +0 -10
- package/dist/esm/data-structures/binary-tree/index.js +0 -11
- package/dist/esm/data-structures/binary-tree/index.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +0 -280
- package/dist/esm/data-structures/binary-tree/red-black-tree.js +0 -641
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/esm/data-structures/binary-tree/segment-tree.js +0 -295
- package/dist/esm/data-structures/binary-tree/segment-tree.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +0 -212
- package/dist/esm/data-structures/binary-tree/tree-counter.js +0 -446
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +0 -1
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +0 -367
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/esm/data-structures/graph/abstract-graph.d.ts +0 -335
- package/dist/esm/data-structures/graph/abstract-graph.js +0 -862
- package/dist/esm/data-structures/graph/abstract-graph.js.map +0 -1
- package/dist/esm/data-structures/graph/directed-graph.d.ts +0 -323
- package/dist/esm/data-structures/graph/directed-graph.js +0 -609
- package/dist/esm/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/esm/data-structures/graph/index.d.ts +0 -4
- package/dist/esm/data-structures/graph/index.js +0 -5
- package/dist/esm/data-structures/graph/index.js.map +0 -1
- package/dist/esm/data-structures/graph/map-graph.d.ts +0 -84
- package/dist/esm/data-structures/graph/map-graph.js +0 -108
- package/dist/esm/data-structures/graph/map-graph.js.map +0 -1
- package/dist/esm/data-structures/graph/undirected-graph.d.ts +0 -231
- package/dist/esm/data-structures/graph/undirected-graph.js +0 -439
- package/dist/esm/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/esm/data-structures/hash/hash-map.d.ts +0 -519
- package/dist/esm/data-structures/hash/hash-map.js +0 -878
- package/dist/esm/data-structures/hash/hash-map.js.map +0 -1
- package/dist/esm/data-structures/hash/index.d.ts +0 -1
- package/dist/esm/data-structures/hash/index.js +0 -2
- package/dist/esm/data-structures/hash/index.js.map +0 -1
- package/dist/esm/data-structures/heap/heap.d.ts +0 -578
- package/dist/esm/data-structures/heap/heap.js +0 -914
- package/dist/esm/data-structures/heap/heap.js.map +0 -1
- package/dist/esm/data-structures/heap/index.d.ts +0 -3
- package/dist/esm/data-structures/heap/index.js +0 -4
- package/dist/esm/data-structures/heap/index.js.map +0 -1
- package/dist/esm/data-structures/heap/max-heap.d.ts +0 -68
- package/dist/esm/data-structures/heap/max-heap.js +0 -95
- package/dist/esm/data-structures/heap/max-heap.js.map +0 -1
- package/dist/esm/data-structures/heap/min-heap.d.ts +0 -68
- package/dist/esm/data-structures/heap/min-heap.js +0 -83
- package/dist/esm/data-structures/heap/min-heap.js.map +0 -1
- package/dist/esm/data-structures/index.d.ts +0 -12
- package/dist/esm/data-structures/index.js +0 -13
- package/dist/esm/data-structures/index.js.map +0 -1
- package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +0 -885
- package/dist/esm/data-structures/linked-list/doubly-linked-list.js +0 -1236
- package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +0 -1
- package/dist/esm/data-structures/linked-list/index.d.ts +0 -3
- package/dist/esm/data-structures/linked-list/index.js +0 -4
- package/dist/esm/data-structures/linked-list/index.js.map +0 -1
- package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +0 -500
- package/dist/esm/data-structures/linked-list/singly-linked-list.js +0 -866
- package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -134
- package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -243
- package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/esm/data-structures/matrix/index.d.ts +0 -2
- package/dist/esm/data-structures/matrix/index.js +0 -3
- package/dist/esm/data-structures/matrix/index.js.map +0 -1
- package/dist/esm/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/esm/data-structures/matrix/matrix.js +0 -444
- package/dist/esm/data-structures/matrix/matrix.js.map +0 -1
- package/dist/esm/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/esm/data-structures/matrix/navigator.js +0 -114
- package/dist/esm/data-structures/matrix/navigator.js.map +0 -1
- package/dist/esm/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/esm/data-structures/priority-queue/index.js +0 -4
- package/dist/esm/data-structures/priority-queue/index.js.map +0 -1
- package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +0 -71
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js +0 -101
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +0 -72
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js +0 -90
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +0 -74
- package/dist/esm/data-structures/priority-queue/priority-queue.js +0 -92
- package/dist/esm/data-structures/priority-queue/priority-queue.js.map +0 -1
- package/dist/esm/data-structures/queue/deque.d.ts +0 -458
- package/dist/esm/data-structures/queue/deque.js +0 -915
- package/dist/esm/data-structures/queue/deque.js.map +0 -1
- package/dist/esm/data-structures/queue/index.d.ts +0 -2
- package/dist/esm/data-structures/queue/index.js +0 -3
- package/dist/esm/data-structures/queue/index.js.map +0 -1
- package/dist/esm/data-structures/queue/queue.d.ts +0 -329
- package/dist/esm/data-structures/queue/queue.js +0 -452
- package/dist/esm/data-structures/queue/queue.js.map +0 -1
- package/dist/esm/data-structures/stack/index.d.ts +0 -1
- package/dist/esm/data-structures/stack/index.js +0 -2
- package/dist/esm/data-structures/stack/index.js.map +0 -1
- package/dist/esm/data-structures/stack/stack.d.ts +0 -284
- package/dist/esm/data-structures/stack/stack.js +0 -342
- package/dist/esm/data-structures/stack/stack.js.map +0 -1
- package/dist/esm/data-structures/tree/index.d.ts +0 -1
- package/dist/esm/data-structures/tree/index.js +0 -2
- package/dist/esm/data-structures/tree/index.js.map +0 -1
- package/dist/esm/data-structures/tree/tree.d.ts +0 -62
- package/dist/esm/data-structures/tree/tree.js +0 -107
- package/dist/esm/data-structures/tree/tree.js.map +0 -1
- package/dist/esm/data-structures/trie/index.d.ts +0 -1
- package/dist/esm/data-structures/trie/index.js +0 -2
- package/dist/esm/data-structures/trie/index.js.map +0 -1
- package/dist/esm/data-structures/trie/trie.d.ts +0 -351
- package/dist/esm/data-structures/trie/trie.js +0 -592
- package/dist/esm/data-structures/trie/trie.js.map +0 -1
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/interfaces/binary-tree.d.ts +0 -9
- package/dist/esm/interfaces/binary-tree.js +0 -2
- package/dist/esm/interfaces/binary-tree.js.map +0 -1
- package/dist/esm/interfaces/doubly-linked-list.d.ts +0 -1
- package/dist/esm/interfaces/doubly-linked-list.js +0 -2
- package/dist/esm/interfaces/doubly-linked-list.js.map +0 -1
- package/dist/esm/interfaces/graph.d.ts +0 -5
- package/dist/esm/interfaces/graph.js +0 -2
- package/dist/esm/interfaces/graph.js.map +0 -1
- package/dist/esm/interfaces/heap.d.ts +0 -1
- package/dist/esm/interfaces/heap.js +0 -2
- package/dist/esm/interfaces/heap.js.map +0 -1
- package/dist/esm/interfaces/index.d.ts +0 -8
- package/dist/esm/interfaces/index.js +0 -9
- package/dist/esm/interfaces/index.js.map +0 -1
- package/dist/esm/interfaces/navigator.d.ts +0 -1
- package/dist/esm/interfaces/navigator.js +0 -2
- package/dist/esm/interfaces/navigator.js.map +0 -1
- package/dist/esm/interfaces/priority-queue.d.ts +0 -1
- package/dist/esm/interfaces/priority-queue.js +0 -2
- package/dist/esm/interfaces/priority-queue.js.map +0 -1
- package/dist/esm/interfaces/segment-tree.d.ts +0 -1
- package/dist/esm/interfaces/segment-tree.js +0 -2
- package/dist/esm/interfaces/segment-tree.js.map +0 -1
- package/dist/esm/interfaces/singly-linked-list.d.ts +0 -1
- package/dist/esm/interfaces/singly-linked-list.js +0 -2
- package/dist/esm/interfaces/singly-linked-list.js.map +0 -1
- package/dist/esm/types/common.d.ts +0 -15
- package/dist/esm/types/common.js +0 -2
- package/dist/esm/types/common.js.map +0 -1
- package/dist/esm/types/data-structures/base/base.d.ts +0 -13
- package/dist/esm/types/data-structures/base/base.js +0 -2
- package/dist/esm/types/data-structures/base/base.js.map +0 -1
- package/dist/esm/types/data-structures/base/index.d.ts +0 -1
- package/dist/esm/types/data-structures/base/index.js +0 -2
- package/dist/esm/types/data-structures/base/index.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -2
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -2
- package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
- package/dist/esm/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/avl-tree.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -1
- package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/binary-tree.d.ts +0 -29
- package/dist/esm/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/binary-tree.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/bst.d.ts +0 -12
- package/dist/esm/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/bst.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/index.d.ts +0 -9
- package/dist/esm/types/data-structures/binary-tree/index.js +0 -10
- package/dist/esm/types/data-structures/binary-tree/index.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/red-black-tree.d.ts +0 -3
- package/dist/esm/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/segment-tree.d.ts +0 -1
- package/dist/esm/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/segment-tree.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +0 -2
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +0 -1
- package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -2
- package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
- package/dist/esm/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/esm/types/data-structures/graph/abstract-graph.js.map +0 -1
- package/dist/esm/types/data-structures/graph/directed-graph.d.ts +0 -1
- package/dist/esm/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/esm/types/data-structures/graph/directed-graph.js.map +0 -1
- package/dist/esm/types/data-structures/graph/index.d.ts +0 -3
- package/dist/esm/types/data-structures/graph/index.js +0 -4
- package/dist/esm/types/data-structures/graph/index.js.map +0 -1
- package/dist/esm/types/data-structures/graph/map-graph.d.ts +0 -1
- package/dist/esm/types/data-structures/graph/map-graph.js +0 -2
- package/dist/esm/types/data-structures/graph/map-graph.js.map +0 -1
- package/dist/esm/types/data-structures/graph/undirected-graph.d.ts +0 -1
- package/dist/esm/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/esm/types/data-structures/graph/undirected-graph.js.map +0 -1
- package/dist/esm/types/data-structures/hash/hash-map.d.ts +0 -19
- package/dist/esm/types/data-structures/hash/hash-map.js +0 -2
- package/dist/esm/types/data-structures/hash/hash-map.js.map +0 -1
- package/dist/esm/types/data-structures/hash/index.d.ts +0 -2
- package/dist/esm/types/data-structures/hash/index.js +0 -2
- package/dist/esm/types/data-structures/hash/index.js.map +0 -1
- package/dist/esm/types/data-structures/heap/heap.d.ts +0 -5
- package/dist/esm/types/data-structures/heap/heap.js +0 -2
- package/dist/esm/types/data-structures/heap/heap.js.map +0 -1
- package/dist/esm/types/data-structures/heap/index.d.ts +0 -1
- package/dist/esm/types/data-structures/heap/index.js +0 -2
- package/dist/esm/types/data-structures/heap/index.js.map +0 -1
- package/dist/esm/types/data-structures/heap/max-heap.d.ts +0 -1
- package/dist/esm/types/data-structures/heap/max-heap.js +0 -2
- package/dist/esm/types/data-structures/heap/max-heap.js.map +0 -1
- package/dist/esm/types/data-structures/heap/min-heap.d.ts +0 -1
- package/dist/esm/types/data-structures/heap/min-heap.js +0 -2
- package/dist/esm/types/data-structures/heap/min-heap.js.map +0 -1
- package/dist/esm/types/data-structures/index.d.ts +0 -12
- package/dist/esm/types/data-structures/index.js +0 -13
- package/dist/esm/types/data-structures/index.js.map +0 -1
- package/dist/esm/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -2
- package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
- package/dist/esm/types/data-structures/linked-list/index.d.ts +0 -3
- package/dist/esm/types/data-structures/linked-list/index.js +0 -4
- package/dist/esm/types/data-structures/linked-list/index.js.map +0 -1
- package/dist/esm/types/data-structures/linked-list/singly-linked-list.d.ts +0 -2
- package/dist/esm/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/esm/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
- package/dist/esm/types/data-structures/linked-list/skip-linked-list.d.ts +0 -4
- package/dist/esm/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/esm/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
- package/dist/esm/types/data-structures/matrix/index.d.ts +0 -2
- package/dist/esm/types/data-structures/matrix/index.js +0 -3
- package/dist/esm/types/data-structures/matrix/index.js.map +0 -1
- package/dist/esm/types/data-structures/matrix/matrix.d.ts +0 -7
- package/dist/esm/types/data-structures/matrix/matrix.js +0 -2
- package/dist/esm/types/data-structures/matrix/matrix.js.map +0 -1
- package/dist/esm/types/data-structures/matrix/navigator.d.ts +0 -14
- package/dist/esm/types/data-structures/matrix/navigator.js +0 -2
- package/dist/esm/types/data-structures/matrix/navigator.js.map +0 -1
- package/dist/esm/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/esm/types/data-structures/priority-queue/index.js +0 -4
- package/dist/esm/types/data-structures/priority-queue/index.js.map +0 -1
- package/dist/esm/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -1
- package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
- package/dist/esm/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -1
- package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
- package/dist/esm/types/data-structures/priority-queue/priority-queue.d.ts +0 -2
- package/dist/esm/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/esm/types/data-structures/priority-queue/priority-queue.js.map +0 -1
- package/dist/esm/types/data-structures/queue/deque.d.ts +0 -4
- package/dist/esm/types/data-structures/queue/deque.js +0 -2
- package/dist/esm/types/data-structures/queue/deque.js.map +0 -1
- package/dist/esm/types/data-structures/queue/index.d.ts +0 -2
- package/dist/esm/types/data-structures/queue/index.js +0 -3
- package/dist/esm/types/data-structures/queue/index.js.map +0 -1
- package/dist/esm/types/data-structures/queue/queue.d.ts +0 -4
- package/dist/esm/types/data-structures/queue/queue.js +0 -2
- package/dist/esm/types/data-structures/queue/queue.js.map +0 -1
- package/dist/esm/types/data-structures/stack/index.d.ts +0 -1
- package/dist/esm/types/data-structures/stack/index.js +0 -2
- package/dist/esm/types/data-structures/stack/index.js.map +0 -1
- package/dist/esm/types/data-structures/stack/stack.d.ts +0 -2
- package/dist/esm/types/data-structures/stack/stack.js +0 -2
- package/dist/esm/types/data-structures/stack/stack.js.map +0 -1
- package/dist/esm/types/data-structures/tree/index.d.ts +0 -1
- package/dist/esm/types/data-structures/tree/index.js +0 -2
- package/dist/esm/types/data-structures/tree/index.js.map +0 -1
- package/dist/esm/types/data-structures/tree/tree.d.ts +0 -1
- package/dist/esm/types/data-structures/tree/tree.js +0 -2
- package/dist/esm/types/data-structures/tree/tree.js.map +0 -1
- package/dist/esm/types/data-structures/trie/index.d.ts +0 -1
- package/dist/esm/types/data-structures/trie/index.js +0 -2
- package/dist/esm/types/data-structures/trie/index.js.map +0 -1
- package/dist/esm/types/data-structures/trie/trie.d.ts +0 -4
- package/dist/esm/types/data-structures/trie/trie.js +0 -2
- package/dist/esm/types/data-structures/trie/trie.js.map +0 -1
- package/dist/esm/types/index.d.ts +0 -3
- package/dist/esm/types/index.js +0 -4
- package/dist/esm/types/index.js.map +0 -1
- package/dist/esm/types/utils/index.d.ts +0 -2
- package/dist/esm/types/utils/index.js +0 -3
- package/dist/esm/types/utils/index.js.map +0 -1
- package/dist/esm/types/utils/utils.d.ts +0 -21
- package/dist/esm/types/utils/utils.js +0 -2
- package/dist/esm/types/utils/utils.js.map +0 -1
- package/dist/esm/types/utils/validate-type.d.ts +0 -19
- package/dist/esm/types/utils/validate-type.js +0 -2
- package/dist/esm/types/utils/validate-type.js.map +0 -1
- package/dist/esm/utils/index.d.ts +0 -2
- package/dist/esm/utils/index.js +0 -3
- package/dist/esm/utils/index.js.map +0 -1
- package/dist/esm/utils/number.d.ts +0 -14
- package/dist/esm/utils/number.js +0 -21
- package/dist/esm/utils/number.js.map +0 -1
- package/dist/esm/utils/utils.js +0 -324
- package/dist/esm/utils/utils.js.map +0 -1
- package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
- package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
- package/tsconfig-cjs.json +0 -14
- package/tsconfig-esm.json +0 -14
- /package/dist/{cjs → types}/common/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/base/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/binary-tree/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/graph/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/hash/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/heap/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/matrix/matrix.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/matrix/navigator.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/queue/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/stack/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/tree/index.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{cjs → types}/data-structures/trie/index.d.ts +0 -0
- /package/dist/{cjs → types}/index.d.ts +0 -0
- /package/dist/{cjs → types}/interfaces/doubly-linked-list.d.ts +0 -0
- /package/dist/{cjs → types}/interfaces/heap.d.ts +0 -0
- /package/dist/{cjs → types}/interfaces/index.d.ts +0 -0
- /package/dist/{cjs → types}/interfaces/navigator.d.ts +0 -0
- /package/dist/{cjs → types}/interfaces/priority-queue.d.ts +0 -0
- /package/dist/{cjs → types}/interfaces/segment-tree.d.ts +0 -0
- /package/dist/{cjs → types}/interfaces/singly-linked-list.d.ts +0 -0
- /package/dist/{cjs → types}/types/common.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/base/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-tree.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/bst.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/red-black-tree.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-counter.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/graph/directed-graph.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/graph/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/graph/map-graph.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/graph/undirected-graph.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/hash/hash-map.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/hash/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/heap/heap.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/heap/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/heap/max-heap.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/heap/min-heap.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/linked-list/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/matrix/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/matrix/matrix.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/matrix/navigator.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/priority-queue/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/queue/deque.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/queue/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/queue/queue.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/stack/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/stack/stack.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/tree/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/tree/tree.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/trie/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/data-structures/trie/trie.d.ts +0 -0
- /package/dist/{cjs → types}/types/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/utils/index.d.ts +0 -0
- /package/dist/{cjs → types}/types/utils/validate-type.d.ts +0 -0
- /package/dist/{cjs → types}/utils/index.d.ts +0 -0
- /package/dist/{cjs → types}/utils/number.d.ts +0 -0
|
@@ -1,880 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BST = exports.BSTNode = void 0;
|
|
4
|
-
const binary_tree_1 = require("./binary-tree");
|
|
5
|
-
const queue_1 = require("../queue");
|
|
6
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
const common_1 = require("../../common");
|
|
8
|
-
class BSTNode extends binary_tree_1.BinaryTreeNode {
|
|
9
|
-
/**
|
|
10
|
-
* This TypeScript constructor function initializes an instance with a key and an optional value.
|
|
11
|
-
* @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
|
|
12
|
-
* within a data structure. It serves as a reference or identifier for accessing or manipulating the
|
|
13
|
-
* associated value.
|
|
14
|
-
* @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
|
|
15
|
-
* have to be provided when creating an instance of the class. If a value is not provided, it will
|
|
16
|
-
* default to `undefined`.
|
|
17
|
-
*/
|
|
18
|
-
constructor(key, value) {
|
|
19
|
-
super(key, value);
|
|
20
|
-
this.parent = undefined;
|
|
21
|
-
this._left = undefined;
|
|
22
|
-
this._right = undefined;
|
|
23
|
-
}
|
|
24
|
-
get left() {
|
|
25
|
-
return this._left;
|
|
26
|
-
}
|
|
27
|
-
set left(v) {
|
|
28
|
-
if (v) {
|
|
29
|
-
v.parent = this;
|
|
30
|
-
}
|
|
31
|
-
this._left = v;
|
|
32
|
-
}
|
|
33
|
-
get right() {
|
|
34
|
-
return this._right;
|
|
35
|
-
}
|
|
36
|
-
set right(v) {
|
|
37
|
-
if (v) {
|
|
38
|
-
v.parent = this;
|
|
39
|
-
}
|
|
40
|
-
this._right = v;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.BSTNode = BSTNode;
|
|
44
|
-
/**
|
|
45
|
-
* 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
|
|
46
|
-
* 2. Unique Keys: No duplicate keys in a standard BST.
|
|
47
|
-
* 3. Efficient Search: Enables quick search, minimum, and maximum operations.
|
|
48
|
-
* 4. Inorder Traversal: Yields nodes in ascending order.
|
|
49
|
-
* 5. Logarithmic Operations: Ideal operations like insertion, deletion, and searching are O(log n) time-efficient.
|
|
50
|
-
* 6. Balance Variability: Can become unbalanced; special types maintain balance.
|
|
51
|
-
* 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
|
|
52
|
-
* @example
|
|
53
|
-
* // Merge 3 sorted datasets
|
|
54
|
-
* const dataset1 = new BST<number, string>([
|
|
55
|
-
* [1, 'A'],
|
|
56
|
-
* [7, 'G']
|
|
57
|
-
* ]);
|
|
58
|
-
* const dataset2 = [
|
|
59
|
-
* [2, 'B'],
|
|
60
|
-
* [6, 'F']
|
|
61
|
-
* ];
|
|
62
|
-
* const dataset3 = new BST<number, string>([
|
|
63
|
-
* [3, 'C'],
|
|
64
|
-
* [5, 'E'],
|
|
65
|
-
* [4, 'D']
|
|
66
|
-
* ]);
|
|
67
|
-
*
|
|
68
|
-
* // Merge datasets into a single BinarySearchTree
|
|
69
|
-
* const merged = new BST<number, string>(dataset1);
|
|
70
|
-
* merged.addMany(dataset2);
|
|
71
|
-
* merged.merge(dataset3);
|
|
72
|
-
*
|
|
73
|
-
* // Verify merged dataset is in sorted order
|
|
74
|
-
* console.log([...merged.values()]); // ['A', 'B', 'C', 'D', 'E', 'F', 'G']
|
|
75
|
-
* @example
|
|
76
|
-
* // Find elements in a range
|
|
77
|
-
* const bst = new BST<number>([10, 5, 15, 3, 7, 12, 18]);
|
|
78
|
-
* console.log(bst.search(new Range(5, 10))); // [5, 7, 10]
|
|
79
|
-
* console.log(bst.rangeSearch([4, 12], node => node.key.toString())); // ['5', '7', '10', '12']
|
|
80
|
-
* console.log(bst.search(new Range(4, 12, true, false))); // [5, 7, 10]
|
|
81
|
-
* console.log(bst.rangeSearch([15, 20])); // [15, 18]
|
|
82
|
-
* console.log(bst.search(new Range(15, 20, false))); // [18]
|
|
83
|
-
* @example
|
|
84
|
-
* // Find lowest common ancestor
|
|
85
|
-
* const bst = new BST<number>([20, 10, 30, 5, 15, 25, 35, 3, 7, 12, 18]);
|
|
86
|
-
*
|
|
87
|
-
* // LCA helper function
|
|
88
|
-
* const findLCA = (num1: number, num2: number): number | undefined => {
|
|
89
|
-
* const path1 = bst.getPathToRoot(num1);
|
|
90
|
-
* const path2 = bst.getPathToRoot(num2);
|
|
91
|
-
* // Find the first common ancestor
|
|
92
|
-
* return findFirstCommon(path1, path2);
|
|
93
|
-
* };
|
|
94
|
-
*
|
|
95
|
-
* function findFirstCommon(arr1: number[], arr2: number[]): number | undefined {
|
|
96
|
-
* for (const num of arr1) {
|
|
97
|
-
* if (arr2.indexOf(num) !== -1) {
|
|
98
|
-
* return num;
|
|
99
|
-
* }
|
|
100
|
-
* }
|
|
101
|
-
* return undefined;
|
|
102
|
-
* }
|
|
103
|
-
*
|
|
104
|
-
* // Assertions
|
|
105
|
-
* console.log(findLCA(3, 10)); // 7
|
|
106
|
-
* console.log(findLCA(5, 35)); // 15
|
|
107
|
-
* console.log(findLCA(20, 30)); // 25
|
|
108
|
-
*/
|
|
109
|
-
class BST extends binary_tree_1.BinaryTree {
|
|
110
|
-
/**
|
|
111
|
-
* This TypeScript constructor initializes a binary search tree with optional options and adds
|
|
112
|
-
* elements if provided.
|
|
113
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
114
|
-
* iterable that can contain elements of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It is used to
|
|
115
|
-
* initialize the binary search tree with keys, nodes, entries, or raw data.
|
|
116
|
-
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
117
|
-
* properties:
|
|
118
|
-
*/
|
|
119
|
-
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
120
|
-
super([], options);
|
|
121
|
-
this._root = undefined;
|
|
122
|
-
this._isReverse = false;
|
|
123
|
-
this._comparator = (a, b) => {
|
|
124
|
-
if ((0, utils_1.isComparable)(a) && (0, utils_1.isComparable)(b)) {
|
|
125
|
-
if (a > b)
|
|
126
|
-
return 1;
|
|
127
|
-
if (a < b)
|
|
128
|
-
return -1;
|
|
129
|
-
return 0;
|
|
130
|
-
}
|
|
131
|
-
if (this._specifyComparable) {
|
|
132
|
-
if (this._specifyComparable(a) > this._specifyComparable(b))
|
|
133
|
-
return 1;
|
|
134
|
-
if (this._specifyComparable(a) < this._specifyComparable(b))
|
|
135
|
-
return -1;
|
|
136
|
-
return 0;
|
|
137
|
-
}
|
|
138
|
-
if (typeof a === 'object' || typeof b === 'object') {
|
|
139
|
-
throw TypeError(`When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.`);
|
|
140
|
-
}
|
|
141
|
-
return 0;
|
|
142
|
-
};
|
|
143
|
-
if (options) {
|
|
144
|
-
const { specifyComparable, isReverse } = options;
|
|
145
|
-
if (typeof specifyComparable === 'function')
|
|
146
|
-
this._specifyComparable = specifyComparable;
|
|
147
|
-
if (isReverse !== undefined)
|
|
148
|
-
this._isReverse = isReverse;
|
|
149
|
-
}
|
|
150
|
-
if (keysNodesEntriesOrRaws)
|
|
151
|
-
this.addMany(keysNodesEntriesOrRaws);
|
|
152
|
-
}
|
|
153
|
-
get root() {
|
|
154
|
-
return this._root;
|
|
155
|
-
}
|
|
156
|
-
get isReverse() {
|
|
157
|
-
return this._isReverse;
|
|
158
|
-
}
|
|
159
|
-
get comparator() {
|
|
160
|
-
return this._comparator;
|
|
161
|
-
}
|
|
162
|
-
get specifyComparable() {
|
|
163
|
-
return this._specifyComparable;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Time Complexity: O(1)
|
|
167
|
-
* Space Complexity: O(1)
|
|
168
|
-
*
|
|
169
|
-
* The function creates a new BSTNode with the given key and value and returns it.
|
|
170
|
-
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
171
|
-
* being created.
|
|
172
|
-
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
173
|
-
* value associated with the key in the node being created.
|
|
174
|
-
* @returns The method is returning a new instance of the BSTNode class, casted as the BSTNode<K, V> type.
|
|
175
|
-
*/
|
|
176
|
-
createNode(key, value) {
|
|
177
|
-
return new BSTNode(key, this._isMapMode ? undefined : value);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Time Complexity: O(1)
|
|
181
|
-
* Space Complexity: O(1)
|
|
182
|
-
*
|
|
183
|
-
* The function creates a new binary search tree with the specified options.
|
|
184
|
-
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
185
|
-
* behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
|
|
186
|
-
* following properties:
|
|
187
|
-
* @returns a new instance of the BST class with the provided options.
|
|
188
|
-
*/
|
|
189
|
-
createTree(options) {
|
|
190
|
-
return new BST([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, specifyComparable: this._specifyComparable, toEntryFn: this._toEntryFn, isReverse: this._isReverse }, options));
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Time Complexity: O(log n)
|
|
194
|
-
* Space Complexity: O(log n)
|
|
195
|
-
*
|
|
196
|
-
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
197
|
-
* it doesn't exist.
|
|
198
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
199
|
-
* `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
|
|
200
|
-
* entry, or raw element that needs to be ensured in the tree.
|
|
201
|
-
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
202
|
-
* parameter that specifies the type of iteration to be used when ensuring a node. It has a default
|
|
203
|
-
* value of `'ITERATIVE'`.
|
|
204
|
-
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
205
|
-
* not be ensured.
|
|
206
|
-
*/
|
|
207
|
-
ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
|
|
208
|
-
var _a;
|
|
209
|
-
return (_a = super.ensureNode(keyNodeOrEntry, iterationType)) !== null && _a !== void 0 ? _a : undefined;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Time Complexity: O(1)
|
|
213
|
-
* Space Complexity: O(1)
|
|
214
|
-
*
|
|
215
|
-
* The function checks if the input is an instance of the BSTNode class.
|
|
216
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
217
|
-
* `keyNodeOrEntry` can be of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
|
|
218
|
-
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
219
|
-
* an instance of the `BSTNode` class.
|
|
220
|
-
*/
|
|
221
|
-
isNode(keyNodeOrEntry) {
|
|
222
|
-
return keyNodeOrEntry instanceof BSTNode;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Time Complexity: O(1)
|
|
226
|
-
* Space Complexity: O(1)
|
|
227
|
-
*
|
|
228
|
-
* The function "override isValidKey" checks if a key is comparable based on a given comparator.
|
|
229
|
-
* @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
|
|
230
|
-
* type `K`.
|
|
231
|
-
* @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
|
|
232
|
-
* the result of the `isComparable` function with the condition `this._compare !==
|
|
233
|
-
* this._DEFAULT_COMPARATOR`.
|
|
234
|
-
*/
|
|
235
|
-
isValidKey(key) {
|
|
236
|
-
return (0, utils_1.isComparable)(key, this._specifyComparable !== undefined);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Time Complexity: O(log n)
|
|
240
|
-
* Space Complexity: O(log n)
|
|
241
|
-
*
|
|
242
|
-
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
243
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
244
|
-
* `keyNodeOrEntry` can accept a value of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
|
|
245
|
-
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
246
|
-
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
247
|
-
* @returns a boolean value.
|
|
248
|
-
*/
|
|
249
|
-
add(keyNodeOrEntry, value) {
|
|
250
|
-
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
251
|
-
if (newNode === undefined)
|
|
252
|
-
return false;
|
|
253
|
-
if (this._root === undefined) {
|
|
254
|
-
this._setRoot(newNode);
|
|
255
|
-
if (this._isMapMode)
|
|
256
|
-
this._setValue(newNode === null || newNode === void 0 ? void 0 : newNode.key, newValue);
|
|
257
|
-
this._size++;
|
|
258
|
-
return true;
|
|
259
|
-
}
|
|
260
|
-
let current = this._root;
|
|
261
|
-
while (current !== undefined) {
|
|
262
|
-
if (this._compare(current.key, newNode.key) === 0) {
|
|
263
|
-
this._replaceNode(current, newNode);
|
|
264
|
-
if (this._isMapMode)
|
|
265
|
-
this._setValue(current.key, newValue);
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
else if (this._compare(current.key, newNode.key) > 0) {
|
|
269
|
-
if (current.left === undefined) {
|
|
270
|
-
current.left = newNode;
|
|
271
|
-
if (this._isMapMode)
|
|
272
|
-
this._setValue(newNode === null || newNode === void 0 ? void 0 : newNode.key, newValue);
|
|
273
|
-
this._size++;
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
if (current.left !== null)
|
|
277
|
-
current = current.left;
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
if (current.right === undefined) {
|
|
281
|
-
current.right = newNode;
|
|
282
|
-
if (this._isMapMode)
|
|
283
|
-
this._setValue(newNode === null || newNode === void 0 ? void 0 : newNode.key, newValue);
|
|
284
|
-
this._size++;
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
if (current.right !== null)
|
|
288
|
-
current = current.right;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Time Complexity: O(k log n)
|
|
295
|
-
* Space Complexity: O(k + log n)
|
|
296
|
-
*
|
|
297
|
-
* The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
|
|
298
|
-
* an array indicating whether each key or node was successfully inserted.
|
|
299
|
-
* @param keysNodesEntriesOrRaws - An iterable containing keys, nodes, entries, or raw
|
|
300
|
-
* elements to be added to the data structure.
|
|
301
|
-
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
302
|
-
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
303
|
-
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
304
|
-
* @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
|
|
305
|
-
* adding the elements. If set to true, the tree will be balanced using a binary search tree
|
|
306
|
-
* algorithm. If set to false, the elements will be added without balancing the tree. The default
|
|
307
|
-
* value is true.
|
|
308
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
309
|
-
* specifies the type of iteration to use when adding multiple keys or nodes to the binary search
|
|
310
|
-
* tree. It can have two possible values:
|
|
311
|
-
* @returns The function `addMany` returns an array of booleans indicating whether each element was
|
|
312
|
-
* successfully inserted into the data structure.
|
|
313
|
-
*/
|
|
314
|
-
addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
315
|
-
const inserted = [];
|
|
316
|
-
let valuesIterator;
|
|
317
|
-
if (values) {
|
|
318
|
-
valuesIterator = values[Symbol.iterator]();
|
|
319
|
-
}
|
|
320
|
-
if (!isBalanceAdd) {
|
|
321
|
-
for (let kve of keysNodesEntriesOrRaws) {
|
|
322
|
-
const value = valuesIterator === null || valuesIterator === void 0 ? void 0 : valuesIterator.next().value;
|
|
323
|
-
if (this.isRaw(kve))
|
|
324
|
-
kve = this._toEntryFn(kve);
|
|
325
|
-
inserted.push(this.add(kve, value));
|
|
326
|
-
}
|
|
327
|
-
return inserted;
|
|
328
|
-
}
|
|
329
|
-
const realBTNExemplars = [];
|
|
330
|
-
let i = 0;
|
|
331
|
-
for (const kve of keysNodesEntriesOrRaws) {
|
|
332
|
-
realBTNExemplars.push({ key: kve, value: valuesIterator === null || valuesIterator === void 0 ? void 0 : valuesIterator.next().value, orgIndex: i });
|
|
333
|
-
i++;
|
|
334
|
-
}
|
|
335
|
-
let sorted = [];
|
|
336
|
-
sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
|
|
337
|
-
let keyA, keyB;
|
|
338
|
-
if (this.isRaw(a))
|
|
339
|
-
keyA = this._toEntryFn(a)[0];
|
|
340
|
-
else if (this.isEntry(a))
|
|
341
|
-
keyA = a[0];
|
|
342
|
-
else if (this.isRealNode(a))
|
|
343
|
-
keyA = a.key;
|
|
344
|
-
else {
|
|
345
|
-
keyA = a;
|
|
346
|
-
}
|
|
347
|
-
if (this.isRaw(b))
|
|
348
|
-
keyB = this._toEntryFn(b)[0];
|
|
349
|
-
else if (this.isEntry(b))
|
|
350
|
-
keyB = b[0];
|
|
351
|
-
else if (this.isRealNode(b))
|
|
352
|
-
keyB = b.key;
|
|
353
|
-
else {
|
|
354
|
-
keyB = b;
|
|
355
|
-
}
|
|
356
|
-
if (keyA !== undefined && keyA !== null && keyB !== undefined && keyB !== null) {
|
|
357
|
-
return this._compare(keyA, keyB);
|
|
358
|
-
}
|
|
359
|
-
return 0;
|
|
360
|
-
});
|
|
361
|
-
const _dfs = (arr) => {
|
|
362
|
-
if (arr.length === 0)
|
|
363
|
-
return;
|
|
364
|
-
const mid = Math.floor((arr.length - 1) / 2);
|
|
365
|
-
const { key, value } = arr[mid];
|
|
366
|
-
const { orgIndex } = arr[mid];
|
|
367
|
-
if (this.isRaw(key)) {
|
|
368
|
-
const entry = this._toEntryFn(key);
|
|
369
|
-
inserted[orgIndex] = this.add(entry);
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
inserted[orgIndex] = this.add(key, value);
|
|
373
|
-
}
|
|
374
|
-
_dfs(arr.slice(0, mid));
|
|
375
|
-
_dfs(arr.slice(mid + 1));
|
|
376
|
-
};
|
|
377
|
-
const _iterate = () => {
|
|
378
|
-
const n = sorted.length;
|
|
379
|
-
const stack = [[0, n - 1]];
|
|
380
|
-
while (stack.length > 0) {
|
|
381
|
-
const popped = stack.pop();
|
|
382
|
-
if (popped) {
|
|
383
|
-
const [l, r] = popped;
|
|
384
|
-
if (l <= r) {
|
|
385
|
-
const m = l + Math.floor((r - l) / 2);
|
|
386
|
-
const { key, value } = sorted[m];
|
|
387
|
-
const { orgIndex } = sorted[m];
|
|
388
|
-
if (this.isRaw(key)) {
|
|
389
|
-
const entry = this._toEntryFn(key);
|
|
390
|
-
inserted[orgIndex] = this.add(entry);
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
inserted[orgIndex] = this.add(key, value);
|
|
394
|
-
}
|
|
395
|
-
stack.push([m + 1, r]);
|
|
396
|
-
stack.push([l, m - 1]);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
if (iterationType === 'RECURSIVE') {
|
|
402
|
-
_dfs(sorted);
|
|
403
|
-
}
|
|
404
|
-
else {
|
|
405
|
-
_iterate();
|
|
406
|
-
}
|
|
407
|
-
return inserted;
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Time Complexity: O(log n)
|
|
411
|
-
* Space Complexity: O(k + log n)
|
|
412
|
-
*
|
|
413
|
-
* The function `search` in TypeScript overrides the search behavior in a binary tree structure based
|
|
414
|
-
* on specified criteria.
|
|
415
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
416
|
-
* `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
|
|
417
|
-
* following types:
|
|
418
|
-
* @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
|
|
419
|
-
* search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
|
|
420
|
-
* search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
|
|
421
|
-
* @param {C} callback - The `callback` parameter in the `override search` function is a function
|
|
422
|
-
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
423
|
-
* extends `NodeCallback<BSTNode<K, V> | null>`. The callback function should accept a node of type `BSTNode<K, V>` as its
|
|
424
|
-
* argument and
|
|
425
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `override search`
|
|
426
|
-
* method represents the node from which the search operation will begin. It is the starting point
|
|
427
|
-
* for searching within the tree data structure. The method ensures that the `startNode` is a valid
|
|
428
|
-
* node before proceeding with the search operation. If the `
|
|
429
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `override search`
|
|
430
|
-
* function determines the type of iteration to be used during the search operation. It can have two
|
|
431
|
-
* possible values:
|
|
432
|
-
* @returns The `override search` method returns an array of values that match the search criteria
|
|
433
|
-
* specified by the input parameters. The method performs a search operation on a binary tree
|
|
434
|
-
* structure based on the provided key, predicate, and other options. The search results are
|
|
435
|
-
* collected in an array and returned as the output of the method.
|
|
436
|
-
*/
|
|
437
|
-
search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
438
|
-
if (keyNodeEntryOrPredicate === undefined)
|
|
439
|
-
return [];
|
|
440
|
-
if (keyNodeEntryOrPredicate === null)
|
|
441
|
-
return [];
|
|
442
|
-
startNode = this.ensureNode(startNode);
|
|
443
|
-
if (!startNode)
|
|
444
|
-
return [];
|
|
445
|
-
let predicate;
|
|
446
|
-
const isRange = this.isRange(keyNodeEntryOrPredicate);
|
|
447
|
-
// Set predicate based on parameter type
|
|
448
|
-
if (isRange) {
|
|
449
|
-
predicate = node => {
|
|
450
|
-
if (!node)
|
|
451
|
-
return false;
|
|
452
|
-
return keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
else {
|
|
456
|
-
predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
457
|
-
}
|
|
458
|
-
const shouldVisitLeft = (cur) => {
|
|
459
|
-
if (!cur)
|
|
460
|
-
return false;
|
|
461
|
-
if (!this.isRealNode(cur.left))
|
|
462
|
-
return false;
|
|
463
|
-
if (isRange) {
|
|
464
|
-
const range = keyNodeEntryOrPredicate;
|
|
465
|
-
const leftS = this.isReverse ? range.high : range.low;
|
|
466
|
-
const leftI = this.isReverse ? range.includeHigh : range.includeLow;
|
|
467
|
-
return (leftI && this._compare(cur.key, leftS) >= 0) || (!leftI && this._compare(cur.key, leftS) > 0);
|
|
468
|
-
}
|
|
469
|
-
if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
470
|
-
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
471
|
-
return benchmarkKey !== null && benchmarkKey !== undefined && this._compare(cur.key, benchmarkKey) > 0;
|
|
472
|
-
}
|
|
473
|
-
return true;
|
|
474
|
-
};
|
|
475
|
-
const shouldVisitRight = (cur) => {
|
|
476
|
-
if (!cur)
|
|
477
|
-
return false;
|
|
478
|
-
if (!this.isRealNode(cur.right))
|
|
479
|
-
return false;
|
|
480
|
-
if (isRange) {
|
|
481
|
-
const range = keyNodeEntryOrPredicate;
|
|
482
|
-
const rightS = this.isReverse ? range.low : range.high;
|
|
483
|
-
const rightI = this.isReverse ? range.includeLow : range.includeLow;
|
|
484
|
-
return (rightI && this._compare(cur.key, rightS) <= 0) || (!rightI && this._compare(cur.key, rightS) < 0);
|
|
485
|
-
}
|
|
486
|
-
if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
487
|
-
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
488
|
-
return benchmarkKey !== null && benchmarkKey !== undefined && this._compare(cur.key, benchmarkKey) < 0;
|
|
489
|
-
}
|
|
490
|
-
return true;
|
|
491
|
-
};
|
|
492
|
-
return super._dfs(callback, 'IN', onlyOne, startNode, iterationType, false, shouldVisitLeft, shouldVisitRight, () => true, cur => {
|
|
493
|
-
if (cur)
|
|
494
|
-
return predicate(cur);
|
|
495
|
-
return false;
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Time Complexity: O(log n)
|
|
500
|
-
* Space Complexity: O(k + log n)
|
|
501
|
-
*
|
|
502
|
-
* The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
|
|
503
|
-
* @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
|
|
504
|
-
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
505
|
-
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
506
|
-
* function that is used to process each node that is found within the specified range during the
|
|
507
|
-
* search operation. It is of type `NodeCallback<BSTNode<K, V> | null>`, where `BSTNode<K, V>` is the type of nodes in the
|
|
508
|
-
* data structure.
|
|
509
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `rangeSearch`
|
|
510
|
-
* function represents the node from which the search for nodes within the specified range will
|
|
511
|
-
* begin. It is the starting point for the range search operation.
|
|
512
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
513
|
-
* is used to specify the type of iteration to be performed during the search operation. It has a
|
|
514
|
-
* default value of `this.iterationType`, which suggests that it is likely a property of the class or
|
|
515
|
-
* object that the `rangeSearch`
|
|
516
|
-
* @returns The `rangeSearch` function is returning the result of calling the `search` method with
|
|
517
|
-
* the specified parameters.
|
|
518
|
-
*/
|
|
519
|
-
rangeSearch(range, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
520
|
-
const searchRange = range instanceof common_1.Range ? range : new common_1.Range(range[0], range[1]);
|
|
521
|
-
return this.search(searchRange, false, callback, startNode, iterationType);
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Time Complexity: O(log n)
|
|
525
|
-
* Space Complexity: O(log n)
|
|
526
|
-
*
|
|
527
|
-
* This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
|
|
528
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
|
|
529
|
-
* parameter can be of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `R`, or `NodePredicate<BSTNode<K, V>>`.
|
|
530
|
-
* @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
|
|
531
|
-
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
532
|
-
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
533
|
-
* node of the binary search tree.
|
|
534
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `getNode` method is a
|
|
535
|
-
* parameter that specifies the type of iteration to be used. It has a default value of
|
|
536
|
-
* `this.iterationType`, which means it will use the iteration type defined in the class instance if
|
|
537
|
-
* no value is provided when calling the method.
|
|
538
|
-
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<BSTNode<K, V>>`).
|
|
539
|
-
* It is using the `getNodes` method to find the node based on the provided keyNodeEntryOrPredicate, beginning at
|
|
540
|
-
* the specified root node (`startNode`) and using the specified iteration type. The method then
|
|
541
|
-
* returns the first node found or `undefined` if no node is found.
|
|
542
|
-
*/
|
|
543
|
-
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
544
|
-
var _a;
|
|
545
|
-
return (_a = this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0]) !== null && _a !== void 0 ? _a : undefined;
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Time complexity: O(n)
|
|
549
|
-
* Space complexity: O(n)
|
|
550
|
-
*
|
|
551
|
-
* The function `dfs` in TypeScript overrides the base class method with default parameters and
|
|
552
|
-
* returns the result of the super class `dfs` method.
|
|
553
|
-
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
554
|
-
* visited during the Depth-First Search traversal. It is a generic type `C` that extends the
|
|
555
|
-
* `NodeCallback` interface for `BSTNode<K, V>`. The default value for `callback` is `this._
|
|
556
|
-
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `override dfs` method
|
|
557
|
-
* specifies the order in which the Depth-First Search (DFS) traversal should be performed on the
|
|
558
|
-
* Binary Search Tree (BST). The possible values for the `pattern` parameter are:
|
|
559
|
-
* @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `override dfs` method is a
|
|
560
|
-
* boolean flag that indicates whether you want to stop the depth-first search traversal after
|
|
561
|
-
* finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set
|
|
562
|
-
* to `true`, the traversal will stop after finding
|
|
563
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} startNode -
|
|
564
|
-
* The `startNode` parameter in the `override dfs` method can be one of the following types:
|
|
565
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `override dfs` method
|
|
566
|
-
* specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
|
|
567
|
-
* Binary Search Tree (BST). It is used to determine the order in which nodes are visited during the
|
|
568
|
-
* traversal. The possible values for `
|
|
569
|
-
* @returns The `override` function is returning the result of calling the `dfs` method from the
|
|
570
|
-
* superclass, with the provided arguments `callback`, `pattern`, `onlyOne`, `startNode`, and
|
|
571
|
-
* `iterationType`. The return type is an array of the return type of the callback function `C`.
|
|
572
|
-
*/
|
|
573
|
-
dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = 'IN', onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
|
|
574
|
-
return super.dfs(callback, pattern, onlyOne, startNode, iterationType);
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Time complexity: O(n)
|
|
578
|
-
* Space complexity: O(n)
|
|
579
|
-
*
|
|
580
|
-
* The function overrides the breadth-first search method and returns an array of the return types of
|
|
581
|
-
* the callback function.
|
|
582
|
-
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
583
|
-
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
584
|
-
* node being visited, and it can return a value of any type.
|
|
585
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
586
|
-
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
587
|
-
* object. If no value is provided, the default value is the root of the tree.
|
|
588
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
589
|
-
* of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of
|
|
590
|
-
* the following values:
|
|
591
|
-
* @returns an array of the return type of the callback function.
|
|
592
|
-
*/
|
|
593
|
-
bfs(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
594
|
-
return super.bfs(callback, startNode, iterationType, false);
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Time complexity: O(n)
|
|
598
|
-
* Space complexity: O(n)
|
|
599
|
-
*
|
|
600
|
-
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
601
|
-
* containing the results of the callback function applied to each level of the tree.
|
|
602
|
-
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
603
|
-
* `NodeCallback<BSTNode<K, V> | null>`. It represents a callback function that will be called for each node in the
|
|
604
|
-
* tree during the iteration process.
|
|
605
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
606
|
-
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
607
|
-
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
608
|
-
* value is provided, the root of
|
|
609
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
610
|
-
* of iteration to be performed on the tree. It can have one of the following values:
|
|
611
|
-
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
612
|
-
* function.
|
|
613
|
-
*/
|
|
614
|
-
listLevels(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
615
|
-
return super.listLevels(callback, startNode, iterationType, false);
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Time complexity: O(n)
|
|
619
|
-
* Space complexity: O(n)
|
|
620
|
-
*
|
|
621
|
-
* The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
|
|
622
|
-
* each node that meets a certain condition based on a target node and a comparison value.
|
|
623
|
-
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
624
|
-
* that meets the condition specified by the `lesserOrGreater` parameter. It takes a single argument,
|
|
625
|
-
* which is the current node being traversed, and returns a value of any type.
|
|
626
|
-
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
627
|
-
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
628
|
-
* 0, or 1, where:
|
|
629
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } targetNode - The `targetNode` parameter is the node in
|
|
630
|
-
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
631
|
-
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
632
|
-
* `targetNode` is provided,
|
|
633
|
-
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
634
|
-
* traversal to be performed on the binary tree. It can have two possible values:
|
|
635
|
-
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
636
|
-
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
637
|
-
*/
|
|
638
|
-
lesserOrGreaterTraverse(callback = this._DEFAULT_NODE_CALLBACK, lesserOrGreater = -1, targetNode = this._root, iterationType = this.iterationType) {
|
|
639
|
-
const targetNodeEnsured = this.ensureNode(targetNode);
|
|
640
|
-
const ans = [];
|
|
641
|
-
if (!this._root)
|
|
642
|
-
return ans;
|
|
643
|
-
if (!targetNodeEnsured)
|
|
644
|
-
return ans;
|
|
645
|
-
const targetKey = targetNodeEnsured.key;
|
|
646
|
-
if (iterationType === 'RECURSIVE') {
|
|
647
|
-
const dfs = (cur) => {
|
|
648
|
-
const compared = this._compare(cur.key, targetKey);
|
|
649
|
-
if (Math.sign(compared) === lesserOrGreater)
|
|
650
|
-
ans.push(callback(cur));
|
|
651
|
-
// TODO here can be optimized to O(log n)
|
|
652
|
-
if (this.isRealNode(cur.left))
|
|
653
|
-
dfs(cur.left);
|
|
654
|
-
if (this.isRealNode(cur.right))
|
|
655
|
-
dfs(cur.right);
|
|
656
|
-
};
|
|
657
|
-
dfs(this._root);
|
|
658
|
-
return ans;
|
|
659
|
-
}
|
|
660
|
-
else {
|
|
661
|
-
const queue = new queue_1.Queue([this._root]);
|
|
662
|
-
while (queue.length > 0) {
|
|
663
|
-
const cur = queue.shift();
|
|
664
|
-
if (this.isRealNode(cur)) {
|
|
665
|
-
const compared = this._compare(cur.key, targetKey);
|
|
666
|
-
if (Math.sign(compared) === lesserOrGreater)
|
|
667
|
-
ans.push(callback(cur));
|
|
668
|
-
if (this.isRealNode(cur.left))
|
|
669
|
-
queue.push(cur.left);
|
|
670
|
-
if (this.isRealNode(cur.right))
|
|
671
|
-
queue.push(cur.right);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
return ans;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Time complexity: O(n)
|
|
679
|
-
* Space complexity: O(n)
|
|
680
|
-
*
|
|
681
|
-
* The `perfectlyBalance` function takes an optional `iterationType` parameter and returns `true` if
|
|
682
|
-
* the binary search tree is perfectly balanced, otherwise it returns `false`.
|
|
683
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
684
|
-
* specifies the type of iteration to use when building a balanced binary search tree. It has a
|
|
685
|
-
* default value of `this.iterationType`, which means it will use the iteration type specified in the
|
|
686
|
-
* current instance of the class.
|
|
687
|
-
* @returns The function `perfectlyBalance` returns a boolean value.
|
|
688
|
-
*/
|
|
689
|
-
perfectlyBalance(iterationType = this.iterationType) {
|
|
690
|
-
const sorted = this.dfs(node => node, 'IN'), n = sorted.length;
|
|
691
|
-
this._clearNodes();
|
|
692
|
-
if (sorted.length < 1)
|
|
693
|
-
return false;
|
|
694
|
-
if (iterationType === 'RECURSIVE') {
|
|
695
|
-
const buildBalanceBST = (l, r) => {
|
|
696
|
-
if (l > r)
|
|
697
|
-
return;
|
|
698
|
-
const m = l + Math.floor((r - l) / 2);
|
|
699
|
-
const midNode = sorted[m];
|
|
700
|
-
if (this._isMapMode && midNode !== null)
|
|
701
|
-
this.add(midNode.key);
|
|
702
|
-
else if (midNode !== null)
|
|
703
|
-
this.add([midNode.key, midNode.value]);
|
|
704
|
-
buildBalanceBST(l, m - 1);
|
|
705
|
-
buildBalanceBST(m + 1, r);
|
|
706
|
-
};
|
|
707
|
-
buildBalanceBST(0, n - 1);
|
|
708
|
-
return true;
|
|
709
|
-
}
|
|
710
|
-
else {
|
|
711
|
-
const stack = [[0, n - 1]];
|
|
712
|
-
while (stack.length > 0) {
|
|
713
|
-
const popped = stack.pop();
|
|
714
|
-
if (popped) {
|
|
715
|
-
const [l, r] = popped;
|
|
716
|
-
if (l <= r) {
|
|
717
|
-
const m = l + Math.floor((r - l) / 2);
|
|
718
|
-
const midNode = sorted[m];
|
|
719
|
-
if (this._isMapMode && midNode !== null)
|
|
720
|
-
this.add(midNode.key);
|
|
721
|
-
else if (midNode !== null)
|
|
722
|
-
this.add([midNode.key, midNode.value]);
|
|
723
|
-
stack.push([m + 1, r]);
|
|
724
|
-
stack.push([l, m - 1]);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
return true;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
/**
|
|
732
|
-
* Time Complexity: O(n)
|
|
733
|
-
* Space Complexity: O(log n)
|
|
734
|
-
*
|
|
735
|
-
* The function `isAVLBalanced` checks if a binary tree is AVL balanced using either a recursive or
|
|
736
|
-
* iterative approach.
|
|
737
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
738
|
-
* specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default
|
|
739
|
-
* value of `this.iterationType`, which means it will use the iteration type specified in the current
|
|
740
|
-
* instance of the AVL tree.
|
|
741
|
-
* @returns a boolean value.
|
|
742
|
-
*/
|
|
743
|
-
isAVLBalanced(iterationType = this.iterationType) {
|
|
744
|
-
if (!this._root)
|
|
745
|
-
return true;
|
|
746
|
-
let balanced = true;
|
|
747
|
-
if (iterationType === 'RECURSIVE') {
|
|
748
|
-
const _height = (cur) => {
|
|
749
|
-
if (!cur)
|
|
750
|
-
return 0;
|
|
751
|
-
const leftHeight = _height(cur.left), rightHeight = _height(cur.right);
|
|
752
|
-
if (Math.abs(leftHeight - rightHeight) > 1)
|
|
753
|
-
balanced = false;
|
|
754
|
-
return Math.max(leftHeight, rightHeight) + 1;
|
|
755
|
-
};
|
|
756
|
-
_height(this._root);
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
const stack = [];
|
|
760
|
-
let node = this._root, last = undefined;
|
|
761
|
-
const depths = new Map();
|
|
762
|
-
while (stack.length > 0 || node) {
|
|
763
|
-
if (node) {
|
|
764
|
-
stack.push(node);
|
|
765
|
-
if (node.left !== null)
|
|
766
|
-
node = node.left;
|
|
767
|
-
}
|
|
768
|
-
else {
|
|
769
|
-
node = stack[stack.length - 1];
|
|
770
|
-
if (!node.right || last === node.right) {
|
|
771
|
-
node = stack.pop();
|
|
772
|
-
if (node) {
|
|
773
|
-
const left = node.left ? depths.get(node.left) : -1;
|
|
774
|
-
const right = node.right ? depths.get(node.right) : -1;
|
|
775
|
-
if (Math.abs(left - right) > 1)
|
|
776
|
-
return false;
|
|
777
|
-
depths.set(node, 1 + Math.max(left, right));
|
|
778
|
-
last = node;
|
|
779
|
-
node = undefined;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
else
|
|
783
|
-
node = node.right;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
return balanced;
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* Time complexity: O(n)
|
|
791
|
-
* Space complexity: O(n)
|
|
792
|
-
*
|
|
793
|
-
* The `map` function in TypeScript overrides the default map behavior for a binary search tree by
|
|
794
|
-
* applying a callback function to each entry and creating a new tree with the results.
|
|
795
|
-
* @param callback - A function that will be called for each entry in the BST. It takes four
|
|
796
|
-
* arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
|
|
797
|
-
* the BST itself.
|
|
798
|
-
* @param [options] - The `options` parameter in the `override map` method is of type `BSTOptions<MK,
|
|
799
|
-
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the Binary
|
|
800
|
-
* Search Tree (BST) being created in the `map` method. These options could include configuration
|
|
801
|
-
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` method is used to specify
|
|
802
|
-
* the value of `this` that should be used when executing the `callback` function. It allows you to
|
|
803
|
-
* set the context or scope in which the callback function will be called. This can be useful when
|
|
804
|
-
* you want
|
|
805
|
-
* @returns The `map` method is returning a new Binary Search Tree (`BST`) instance with the entries
|
|
806
|
-
* transformed by the provided callback function.
|
|
807
|
-
*/
|
|
808
|
-
map(callback, options, thisArg) {
|
|
809
|
-
const newTree = new BST([], options);
|
|
810
|
-
let index = 0;
|
|
811
|
-
for (const [key, value] of this) {
|
|
812
|
-
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
813
|
-
}
|
|
814
|
-
return newTree;
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Time complexity: O(n)
|
|
818
|
-
* Space complexity: O(n)
|
|
819
|
-
*
|
|
820
|
-
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
821
|
-
* structure.
|
|
822
|
-
* @returns The `cloned` object is being returned.
|
|
823
|
-
*/
|
|
824
|
-
clone() {
|
|
825
|
-
const cloned = this.createTree();
|
|
826
|
-
this._clone(cloned);
|
|
827
|
-
return cloned;
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* Time Complexity: O(1)
|
|
831
|
-
* Space Complexity: O(1)
|
|
832
|
-
*
|
|
833
|
-
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
834
|
-
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - A variable that can be of
|
|
835
|
-
* type R or K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined . It represents either a key, a node, an entry, or a raw
|
|
836
|
-
* element.
|
|
837
|
-
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
838
|
-
* value associated with a key in a key-value pair.
|
|
839
|
-
* @returns either a BSTNode<K, V> object or undefined.
|
|
840
|
-
*/
|
|
841
|
-
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
|
|
842
|
-
const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
843
|
-
if (node === null)
|
|
844
|
-
return [undefined, undefined];
|
|
845
|
-
return [node, value !== null && value !== void 0 ? value : entryValue];
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* Time Complexity: O(1)
|
|
849
|
-
* Space Complexity: O(1)
|
|
850
|
-
*
|
|
851
|
-
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
852
|
-
* root.
|
|
853
|
-
* @param {OptNode<BSTNode<K, V>>} v - v is a parameter of type BSTNode<K, V> or undefined.
|
|
854
|
-
*/
|
|
855
|
-
_setRoot(v) {
|
|
856
|
-
if (v) {
|
|
857
|
-
v.parent = undefined;
|
|
858
|
-
}
|
|
859
|
-
this._root = v;
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* Time Complexity: O(1)
|
|
863
|
-
* Space Complexity: O(1)
|
|
864
|
-
*
|
|
865
|
-
* The _compare function compares two values using a specified comparator function and optionally
|
|
866
|
-
* reverses the result.
|
|
867
|
-
* @param {K} a - The parameter `a` is of type `K`, which is used as an input for comparison in the
|
|
868
|
-
* `_compare` method.
|
|
869
|
-
* @param {K} b - The parameter `b` in the `_compare` function is of type `K`.
|
|
870
|
-
* @returns The `_compare` method is returning the result of the ternary expression. If `_isReverse`
|
|
871
|
-
* is true, it returns the negation of the result of calling the `_comparator` function with
|
|
872
|
-
* arguments `a` and `b`. If `_isReverse` is false, it returns the result of calling the
|
|
873
|
-
* `_comparator` function with arguments `a` and `b`.
|
|
874
|
-
*/
|
|
875
|
-
_compare(a, b) {
|
|
876
|
-
return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
exports.BST = BST;
|
|
880
|
-
//# sourceMappingURL=bst.js.map
|