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,911 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* data-structure-typed
|
|
4
|
-
* @author Kirk Qi
|
|
5
|
-
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.FibonacciHeap = exports.FibonacciHeapNode = exports.Heap = void 0;
|
|
10
|
-
const base_1 = require("../base");
|
|
11
|
-
/**
|
|
12
|
-
* 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
|
|
13
|
-
* 2. Heap Properties: Each node in a heap follows a specific order property, which varies depending on the type of heap:
|
|
14
|
-
* Max Heap: The value of each parent node is greater than or equal to the value of its children.
|
|
15
|
-
* Min Heap: The value of each parent node is less than or equal to the value of its children.
|
|
16
|
-
* 3. Root Node Access: In a heap, the largest element (in a max heap) or the smallest element (in a min heap) is always at the root of the tree.
|
|
17
|
-
* 4. Efficient Insertion and Deletion: Due to its structure, a heap allows for insertion and deletion operations in logarithmic time (O(log n)).
|
|
18
|
-
* 5. Managing Dynamic Data Sets: Heaps effectively manage dynamic data sets, especially when frequent access to the largest or smallest elements is required.
|
|
19
|
-
* 6. Non-linear Search: While a heap allows rapid access to its largest or smallest element, it is less efficient for other operations, such as searching for a specific element, as it is not designed for these tasks.
|
|
20
|
-
* 7. Efficient Sorting Algorithms: For example, heap sort. Heap sort uses the properties of a heap to sort elements.
|
|
21
|
-
* 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prime's minimum-spanning tree algorithm, which use heaps to improve performance.
|
|
22
|
-
* @example
|
|
23
|
-
* // Use Heap to sort an array
|
|
24
|
-
* function heapSort(arr: number[]): number[] {
|
|
25
|
-
* const heap = new Heap<number>(arr, { comparator: (a, b) => a - b });
|
|
26
|
-
* const sorted: number[] = [];
|
|
27
|
-
* while (!heap.isEmpty()) {
|
|
28
|
-
* sorted.push(heap.poll()!); // Poll minimum element
|
|
29
|
-
* }
|
|
30
|
-
* return sorted;
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* const array = [5, 3, 8, 4, 1, 2];
|
|
34
|
-
* console.log(heapSort(array)); // [1, 2, 3, 4, 5, 8]
|
|
35
|
-
* @example
|
|
36
|
-
* // Use Heap to solve top k problems
|
|
37
|
-
* function topKElements(arr: number[], k: number): number[] {
|
|
38
|
-
* const heap = new Heap<number>([], { comparator: (a, b) => b - a }); // Max heap
|
|
39
|
-
* arr.forEach(num => {
|
|
40
|
-
* heap.add(num);
|
|
41
|
-
* if (heap.size > k) heap.poll(); // Keep the heap size at K
|
|
42
|
-
* });
|
|
43
|
-
* return heap.toArray();
|
|
44
|
-
* }
|
|
45
|
-
*
|
|
46
|
-
* const numbers = [10, 30, 20, 5, 15, 25];
|
|
47
|
-
* console.log(topKElements(numbers, 3)); // [15, 10, 5]
|
|
48
|
-
* @example
|
|
49
|
-
* // Use Heap to merge sorted sequences
|
|
50
|
-
* function mergeSortedSequences(sequences: number[][]): number[] {
|
|
51
|
-
* const heap = new Heap<{ value: number; seqIndex: number; itemIndex: number }>([], {
|
|
52
|
-
* comparator: (a, b) => a.value - b.value // Min heap
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* // Initialize heap
|
|
56
|
-
* sequences.forEach((seq, seqIndex) => {
|
|
57
|
-
* if (seq.length) {
|
|
58
|
-
* heap.add({ value: seq[0], seqIndex, itemIndex: 0 });
|
|
59
|
-
* }
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* const merged: number[] = [];
|
|
63
|
-
* while (!heap.isEmpty()) {
|
|
64
|
-
* const { value, seqIndex, itemIndex } = heap.poll()!;
|
|
65
|
-
* merged.push(value);
|
|
66
|
-
*
|
|
67
|
-
* if (itemIndex + 1 < sequences[seqIndex].length) {
|
|
68
|
-
* heap.add({
|
|
69
|
-
* value: sequences[seqIndex][itemIndex + 1],
|
|
70
|
-
* seqIndex,
|
|
71
|
-
* itemIndex: itemIndex + 1
|
|
72
|
-
* });
|
|
73
|
-
* }
|
|
74
|
-
* }
|
|
75
|
-
*
|
|
76
|
-
* return merged;
|
|
77
|
-
* }
|
|
78
|
-
*
|
|
79
|
-
* const sequences = [
|
|
80
|
-
* [1, 4, 7],
|
|
81
|
-
* [2, 5, 8],
|
|
82
|
-
* [3, 6, 9]
|
|
83
|
-
* ];
|
|
84
|
-
* console.log(mergeSortedSequences(sequences)); // [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
85
|
-
* @example
|
|
86
|
-
* // Use Heap to dynamically maintain the median
|
|
87
|
-
* class MedianFinder {
|
|
88
|
-
* private low: MaxHeap<number>; // Max heap, stores the smaller half
|
|
89
|
-
* private high: MinHeap<number>; // Min heap, stores the larger half
|
|
90
|
-
*
|
|
91
|
-
* constructor() {
|
|
92
|
-
* this.low = new MaxHeap<number>([]);
|
|
93
|
-
* this.high = new MinHeap<number>([]);
|
|
94
|
-
* }
|
|
95
|
-
*
|
|
96
|
-
* addNum(num: number): void {
|
|
97
|
-
* if (this.low.isEmpty() || num <= this.low.peek()!) this.low.add(num);
|
|
98
|
-
* else this.high.add(num);
|
|
99
|
-
*
|
|
100
|
-
* // Balance heaps
|
|
101
|
-
* if (this.low.size > this.high.size + 1) this.high.add(this.low.poll()!);
|
|
102
|
-
* else if (this.high.size > this.low.size) this.low.add(this.high.poll()!);
|
|
103
|
-
* }
|
|
104
|
-
*
|
|
105
|
-
* findMedian(): number {
|
|
106
|
-
* if (this.low.size === this.high.size) return (this.low.peek()! + this.high.peek()!) / 2;
|
|
107
|
-
* return this.low.peek()!;
|
|
108
|
-
* }
|
|
109
|
-
* }
|
|
110
|
-
*
|
|
111
|
-
* const medianFinder = new MedianFinder();
|
|
112
|
-
* medianFinder.addNum(10);
|
|
113
|
-
* console.log(medianFinder.findMedian()); // 10
|
|
114
|
-
* medianFinder.addNum(20);
|
|
115
|
-
* console.log(medianFinder.findMedian()); // 15
|
|
116
|
-
* medianFinder.addNum(30);
|
|
117
|
-
* console.log(medianFinder.findMedian()); // 20
|
|
118
|
-
* medianFinder.addNum(40);
|
|
119
|
-
* console.log(medianFinder.findMedian()); // 25
|
|
120
|
-
* medianFinder.addNum(50);
|
|
121
|
-
* console.log(medianFinder.findMedian()); // 30
|
|
122
|
-
* @example
|
|
123
|
-
* // Use Heap for load balancing
|
|
124
|
-
* function loadBalance(requests: number[], servers: number): number[] {
|
|
125
|
-
* const serverHeap = new Heap<{ id: number; load: number }>([], { comparator: (a, b) => a.load - b.load }); // min heap
|
|
126
|
-
* const serverLoads = new Array(servers).fill(0);
|
|
127
|
-
*
|
|
128
|
-
* for (let i = 0; i < servers; i++) {
|
|
129
|
-
* serverHeap.add({ id: i, load: 0 });
|
|
130
|
-
* }
|
|
131
|
-
*
|
|
132
|
-
* requests.forEach(req => {
|
|
133
|
-
* const server = serverHeap.poll()!;
|
|
134
|
-
* serverLoads[server.id] += req;
|
|
135
|
-
* server.load += req;
|
|
136
|
-
* serverHeap.add(server); // The server after updating the load is re-entered into the heap
|
|
137
|
-
* });
|
|
138
|
-
*
|
|
139
|
-
* return serverLoads;
|
|
140
|
-
* }
|
|
141
|
-
*
|
|
142
|
-
* const requests = [5, 2, 8, 3, 7];
|
|
143
|
-
* console.log(loadBalance(requests, 3)); // [12, 8, 5]
|
|
144
|
-
* @example
|
|
145
|
-
* // Use Heap to schedule tasks
|
|
146
|
-
* type Task = [string, number];
|
|
147
|
-
*
|
|
148
|
-
* function scheduleTasks(tasks: Task[], machines: number): Map<number, Task[]> {
|
|
149
|
-
* const machineHeap = new Heap<{ id: number; load: number }>([], { comparator: (a, b) => a.load - b.load }); // Min heap
|
|
150
|
-
* const allocation = new Map<number, Task[]>();
|
|
151
|
-
*
|
|
152
|
-
* // Initialize the load on each machine
|
|
153
|
-
* for (let i = 0; i < machines; i++) {
|
|
154
|
-
* machineHeap.add({ id: i, load: 0 });
|
|
155
|
-
* allocation.set(i, []);
|
|
156
|
-
* }
|
|
157
|
-
*
|
|
158
|
-
* // Assign tasks
|
|
159
|
-
* tasks.forEach(([task, load]) => {
|
|
160
|
-
* const machine = machineHeap.poll()!;
|
|
161
|
-
* allocation.get(machine.id)!.push([task, load]);
|
|
162
|
-
* machine.load += load;
|
|
163
|
-
* machineHeap.add(machine); // The machine after updating the load is re-entered into the heap
|
|
164
|
-
* });
|
|
165
|
-
*
|
|
166
|
-
* return allocation;
|
|
167
|
-
* }
|
|
168
|
-
*
|
|
169
|
-
* const tasks: Task[] = [
|
|
170
|
-
* ['Task1', 3],
|
|
171
|
-
* ['Task2', 1],
|
|
172
|
-
* ['Task3', 2],
|
|
173
|
-
* ['Task4', 5],
|
|
174
|
-
* ['Task5', 4]
|
|
175
|
-
* ];
|
|
176
|
-
* const expectedMap = new Map<number, Task[]>();
|
|
177
|
-
* expectedMap.set(0, [
|
|
178
|
-
* ['Task1', 3],
|
|
179
|
-
* ['Task4', 5]
|
|
180
|
-
* ]);
|
|
181
|
-
* expectedMap.set(1, [
|
|
182
|
-
* ['Task2', 1],
|
|
183
|
-
* ['Task3', 2],
|
|
184
|
-
* ['Task5', 4]
|
|
185
|
-
* ]);
|
|
186
|
-
* console.log(scheduleTasks(tasks, 2)); // expectedMap
|
|
187
|
-
*/
|
|
188
|
-
class Heap extends base_1.IterableElementBase {
|
|
189
|
-
/**
|
|
190
|
-
* The constructor initializes a heap data structure with optional elements and options.
|
|
191
|
-
* @param elements - The `elements` parameter is an iterable object that contains the initial
|
|
192
|
-
* elements to be added to the heap.
|
|
193
|
-
* It is an optional parameter, and if not provided, the heap will
|
|
194
|
-
* be initialized as empty.
|
|
195
|
-
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
196
|
-
* configuration options for the heap.
|
|
197
|
-
* In this case, it is used to specify a custom comparator
|
|
198
|
-
* function for comparing elements in the heap.
|
|
199
|
-
* The comparator function is used to determine the
|
|
200
|
-
* order of elements in the heap.
|
|
201
|
-
*/
|
|
202
|
-
constructor(elements = [], options) {
|
|
203
|
-
super(options);
|
|
204
|
-
this._elements = [];
|
|
205
|
-
this._DEFAULT_COMPARATOR = (a, b) => {
|
|
206
|
-
if (typeof a === 'object' || typeof b === 'object') {
|
|
207
|
-
throw TypeError(`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`);
|
|
208
|
-
}
|
|
209
|
-
if (a > b)
|
|
210
|
-
return 1;
|
|
211
|
-
if (a < b)
|
|
212
|
-
return -1;
|
|
213
|
-
return 0;
|
|
214
|
-
};
|
|
215
|
-
this._comparator = this._DEFAULT_COMPARATOR;
|
|
216
|
-
if (options) {
|
|
217
|
-
const { comparator } = options;
|
|
218
|
-
if (comparator)
|
|
219
|
-
this._comparator = comparator;
|
|
220
|
-
}
|
|
221
|
-
this.addMany(elements);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* The function returns an array of elements.
|
|
225
|
-
* @returns The element array is being returned.
|
|
226
|
-
*/
|
|
227
|
-
get elements() {
|
|
228
|
-
return this._elements;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Get the size (number of elements) of the heap.
|
|
232
|
-
*/
|
|
233
|
-
get size() {
|
|
234
|
-
return this.elements.length;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Get the last element in the heap, which is not necessarily a leaf node.
|
|
238
|
-
* @returns The last element or undefined if the heap is empty.
|
|
239
|
-
*/
|
|
240
|
-
get leaf() {
|
|
241
|
-
var _a;
|
|
242
|
-
return (_a = this.elements[this.size - 1]) !== null && _a !== void 0 ? _a : undefined;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Static method that creates a binary heap from an array of elements and a comparison function.
|
|
246
|
-
* @returns A new Heap instance.
|
|
247
|
-
* @param elements
|
|
248
|
-
* @param options
|
|
249
|
-
*/
|
|
250
|
-
static heapify(elements, options) {
|
|
251
|
-
return new Heap(elements, options);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Time Complexity: O(log n)
|
|
255
|
-
* Space Complexity: O(1)
|
|
256
|
-
*
|
|
257
|
-
* The add function pushes an element into an array and then triggers a bubble-up operation.
|
|
258
|
-
* @param {E} element - The `element` parameter represents the element that you want to add to the
|
|
259
|
-
* data structure.
|
|
260
|
-
* @returns The `add` method is returning a boolean value, which is the result of calling the
|
|
261
|
-
* `_bubbleUp` method with the index `this.elements.length - 1` as an argument.
|
|
262
|
-
*/
|
|
263
|
-
add(element) {
|
|
264
|
-
this._elements.push(element);
|
|
265
|
-
return this._bubbleUp(this.elements.length - 1);
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Time Complexity: O(k log n)
|
|
269
|
-
* Space Complexity: O(1)
|
|
270
|
-
*
|
|
271
|
-
* The `addMany` function iterates over elements and adds them to a collection, returning an array of
|
|
272
|
-
* boolean values indicating success or failure.
|
|
273
|
-
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `addMany` method is
|
|
274
|
-
* an iterable containing elements of type `E` or `R`. The method iterates over each element in the
|
|
275
|
-
* iterable and adds them to the data structure. If a transformation function `_toElementFn` is
|
|
276
|
-
* provided, it transforms the element
|
|
277
|
-
* @returns The `addMany` method returns an array of boolean values indicating whether each element
|
|
278
|
-
* in the input iterable was successfully added to the data structure.
|
|
279
|
-
*/
|
|
280
|
-
addMany(elements) {
|
|
281
|
-
const ans = [];
|
|
282
|
-
for (const el of elements) {
|
|
283
|
-
if (this._toElementFn) {
|
|
284
|
-
ans.push(this.add(this._toElementFn(el)));
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
ans.push(this.add(el));
|
|
288
|
-
}
|
|
289
|
-
return ans;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Time Complexity: O(log n)
|
|
293
|
-
* Space Complexity: O(1)
|
|
294
|
-
*
|
|
295
|
-
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
296
|
-
* @returns The top element or undefined if the heap is empty.
|
|
297
|
-
*/
|
|
298
|
-
poll() {
|
|
299
|
-
if (this.elements.length === 0)
|
|
300
|
-
return;
|
|
301
|
-
const value = this.elements[0];
|
|
302
|
-
const last = this.elements.pop();
|
|
303
|
-
if (this.elements.length) {
|
|
304
|
-
this.elements[0] = last;
|
|
305
|
-
this._sinkDown(0, this.elements.length >> 1);
|
|
306
|
-
}
|
|
307
|
-
return value;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Time Complexity: O(1)
|
|
311
|
-
* Space Complexity: O(1)
|
|
312
|
-
*
|
|
313
|
-
* Peek at the top element of the heap without removing it.
|
|
314
|
-
* @returns The top element or undefined if the heap is empty.
|
|
315
|
-
*/
|
|
316
|
-
peek() {
|
|
317
|
-
return this.elements[0];
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Check if the heap is empty.
|
|
321
|
-
* @returns True if the heap is empty, otherwise false.
|
|
322
|
-
*/
|
|
323
|
-
isEmpty() {
|
|
324
|
-
return this.size === 0;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Reset the elements of the heap. Make the elements empty.
|
|
328
|
-
*/
|
|
329
|
-
clear() {
|
|
330
|
-
this._elements = [];
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Time Complexity: O(n)
|
|
334
|
-
* Space Complexity: O(n)
|
|
335
|
-
*
|
|
336
|
-
* Clear and add elements of the heap
|
|
337
|
-
* @param elements
|
|
338
|
-
*/
|
|
339
|
-
refill(elements) {
|
|
340
|
-
this._elements = elements;
|
|
341
|
-
return this.fix();
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Time Complexity: O(n)
|
|
345
|
-
* Space Complexity: O(1)
|
|
346
|
-
*
|
|
347
|
-
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
348
|
-
* @param element - the element to check.
|
|
349
|
-
* @returns Returns true if the specified element is contained; otherwise, returns false.
|
|
350
|
-
*/
|
|
351
|
-
has(element) {
|
|
352
|
-
return this.elements.includes(element);
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Time Complexity: O(n)
|
|
356
|
-
* Space Complexity: O(1)
|
|
357
|
-
*
|
|
358
|
-
* The `delete` function removes an element from an array-like data structure, maintaining the order
|
|
359
|
-
* and structure of the remaining elements.
|
|
360
|
-
* @param {E} element - The `element` parameter represents the element that you want to delete from
|
|
361
|
-
* the array `this.elements`.
|
|
362
|
-
* @returns The `delete` function is returning a boolean value. It returns `true` if the element was
|
|
363
|
-
* successfully deleted from the array, and `false` if the element was not found in the array.
|
|
364
|
-
*/
|
|
365
|
-
delete(element) {
|
|
366
|
-
const index = this.elements.indexOf(element);
|
|
367
|
-
if (index < 0)
|
|
368
|
-
return false;
|
|
369
|
-
if (index === 0) {
|
|
370
|
-
this.poll();
|
|
371
|
-
}
|
|
372
|
-
else if (index === this.elements.length - 1) {
|
|
373
|
-
this.elements.pop();
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
this.elements.splice(index, 1, this.elements.pop());
|
|
377
|
-
this._bubbleUp(index);
|
|
378
|
-
this._sinkDown(index, this.elements.length >> 1);
|
|
379
|
-
}
|
|
380
|
-
return true;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Time Complexity: O(n)
|
|
384
|
-
* Space Complexity: O(log n)
|
|
385
|
-
*
|
|
386
|
-
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
387
|
-
* @param order - Traverse order parameter: 'IN' (in-order), 'PRE' (pre-order) or 'POST' (post-order).
|
|
388
|
-
* @returns An array containing elements traversed in the specified order.
|
|
389
|
-
*/
|
|
390
|
-
dfs(order = 'PRE') {
|
|
391
|
-
const result = [];
|
|
392
|
-
// Auxiliary recursive function, traverses the binary heap according to the traversal order
|
|
393
|
-
const _dfs = (index) => {
|
|
394
|
-
const left = 2 * index + 1, right = left + 1;
|
|
395
|
-
if (index < this.size) {
|
|
396
|
-
if (order === 'IN') {
|
|
397
|
-
_dfs(left);
|
|
398
|
-
result.push(this.elements[index]);
|
|
399
|
-
_dfs(right);
|
|
400
|
-
}
|
|
401
|
-
else if (order === 'PRE') {
|
|
402
|
-
result.push(this.elements[index]);
|
|
403
|
-
_dfs(left);
|
|
404
|
-
_dfs(right);
|
|
405
|
-
}
|
|
406
|
-
else if (order === 'POST') {
|
|
407
|
-
_dfs(left);
|
|
408
|
-
_dfs(right);
|
|
409
|
-
result.push(this.elements[index]);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
_dfs(0); // Traverse starting from the root node
|
|
414
|
-
return result;
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Time Complexity: O(n)
|
|
418
|
-
* Space Complexity: O(n)
|
|
419
|
-
*
|
|
420
|
-
* Clone the heap, creating a new heap with the same elements.
|
|
421
|
-
* @returns A new Heap instance containing the same elements.
|
|
422
|
-
*/
|
|
423
|
-
clone() {
|
|
424
|
-
return new Heap(this, { comparator: this.comparator, toElementFn: this.toElementFn });
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Time Complexity: O(n log n)
|
|
428
|
-
* Space Complexity: O(n)
|
|
429
|
-
*
|
|
430
|
-
* Sort the elements in the heap and return them as an array.
|
|
431
|
-
* @returns An array containing the elements sorted in ascending order.
|
|
432
|
-
*/
|
|
433
|
-
sort() {
|
|
434
|
-
const visitedNode = [];
|
|
435
|
-
const cloned = new Heap(this, { comparator: this.comparator });
|
|
436
|
-
while (cloned.size !== 0) {
|
|
437
|
-
const top = cloned.poll();
|
|
438
|
-
if (top !== undefined)
|
|
439
|
-
visitedNode.push(top);
|
|
440
|
-
}
|
|
441
|
-
return visitedNode;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Time Complexity: O(n log n)
|
|
445
|
-
* Space Complexity: O(n)
|
|
446
|
-
*
|
|
447
|
-
* Fix the entire heap to maintain heap properties.
|
|
448
|
-
*/
|
|
449
|
-
fix() {
|
|
450
|
-
const results = [];
|
|
451
|
-
for (let i = Math.floor(this.size / 2); i >= 0; i--)
|
|
452
|
-
results.push(this._sinkDown(i, this.elements.length >> 1));
|
|
453
|
-
return results;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Time Complexity: O(n)
|
|
457
|
-
* Space Complexity: O(n)
|
|
458
|
-
*
|
|
459
|
-
* The `filter` function creates a new Heap object containing elements that pass a given callback
|
|
460
|
-
* function.
|
|
461
|
-
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
462
|
-
* the heap. It takes three arguments: the current element, the index of the current element, and the
|
|
463
|
-
* heap itself. The callback function should return a boolean value indicating whether the current
|
|
464
|
-
* element should be included in the filtered list
|
|
465
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
466
|
-
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
467
|
-
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
468
|
-
* @returns The `filter` method is returning a new `Heap` object that contains the elements that pass
|
|
469
|
-
* the filter condition specified by the `callback` function.
|
|
470
|
-
*/
|
|
471
|
-
filter(callback, thisArg) {
|
|
472
|
-
const filteredList = new Heap([], { toElementFn: this.toElementFn, comparator: this.comparator });
|
|
473
|
-
let index = 0;
|
|
474
|
-
for (const current of this) {
|
|
475
|
-
if (callback.call(thisArg, current, index, this)) {
|
|
476
|
-
filteredList.add(current);
|
|
477
|
-
}
|
|
478
|
-
index++;
|
|
479
|
-
}
|
|
480
|
-
return filteredList;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Time Complexity: O(n)
|
|
484
|
-
* Space Complexity: O(n)
|
|
485
|
-
*
|
|
486
|
-
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
487
|
-
* original heap.
|
|
488
|
-
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
489
|
-
* the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
|
|
490
|
-
* element), and `this` (the heap itself). The callback function should return a value of
|
|
491
|
-
* @param comparator - The `comparator` parameter is a function that defines the order of the
|
|
492
|
-
* elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
|
|
493
|
-
* if `a` should be placed before `b`, a positive number if `a` should be placed after
|
|
494
|
-
* @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
|
|
495
|
-
* element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
|
|
496
|
-
* returns a value of type `T`. This function is used to transform the elements of the original
|
|
497
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
498
|
-
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
499
|
-
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
500
|
-
* value of
|
|
501
|
-
* @returns a new instance of the `Heap` class with the mapped elements.
|
|
502
|
-
*/
|
|
503
|
-
map(callback, comparator, toElementFn, thisArg) {
|
|
504
|
-
const mappedHeap = new Heap([], { comparator, toElementFn });
|
|
505
|
-
let index = 0;
|
|
506
|
-
for (const el of this) {
|
|
507
|
-
mappedHeap.add(callback.call(thisArg, el, index, this));
|
|
508
|
-
index++;
|
|
509
|
-
}
|
|
510
|
-
return mappedHeap;
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* The function returns the value of the _comparator property.
|
|
514
|
-
* @returns The `_comparator` property is being returned.
|
|
515
|
-
*/
|
|
516
|
-
get comparator() {
|
|
517
|
-
return this._comparator;
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* The function `_getIterator` returns an iterable iterator for the elements in the class.
|
|
521
|
-
*/
|
|
522
|
-
*_getIterator() {
|
|
523
|
-
for (const element of this.elements) {
|
|
524
|
-
yield element;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Time Complexity: O(log n)
|
|
529
|
-
* Space Complexity: O(1)
|
|
530
|
-
*
|
|
531
|
-
* Float operation to maintain heap properties after adding an element.
|
|
532
|
-
* @param index - The index of the newly added element.
|
|
533
|
-
*/
|
|
534
|
-
_bubbleUp(index) {
|
|
535
|
-
const element = this.elements[index];
|
|
536
|
-
while (index > 0) {
|
|
537
|
-
const parent = (index - 1) >> 1;
|
|
538
|
-
const parentItem = this.elements[parent];
|
|
539
|
-
if (this.comparator(parentItem, element) <= 0)
|
|
540
|
-
break;
|
|
541
|
-
this.elements[index] = parentItem;
|
|
542
|
-
index = parent;
|
|
543
|
-
}
|
|
544
|
-
this.elements[index] = element;
|
|
545
|
-
return true;
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Time Complexity: O(log n)
|
|
549
|
-
* Space Complexity: O(1)
|
|
550
|
-
*
|
|
551
|
-
* Sinking operation to maintain heap properties after removing the top element.
|
|
552
|
-
* @param index - The index from which to start sinking.
|
|
553
|
-
* @param halfLength
|
|
554
|
-
*/
|
|
555
|
-
_sinkDown(index, halfLength) {
|
|
556
|
-
const element = this.elements[index];
|
|
557
|
-
while (index < halfLength) {
|
|
558
|
-
let left = (index << 1) | 1;
|
|
559
|
-
const right = left + 1;
|
|
560
|
-
let minItem = this.elements[left];
|
|
561
|
-
if (right < this.elements.length && this.comparator(minItem, this.elements[right]) > 0) {
|
|
562
|
-
left = right;
|
|
563
|
-
minItem = this.elements[right];
|
|
564
|
-
}
|
|
565
|
-
if (this.comparator(minItem, element) >= 0)
|
|
566
|
-
break;
|
|
567
|
-
this.elements[index] = minItem;
|
|
568
|
-
index = left;
|
|
569
|
-
}
|
|
570
|
-
this.elements[index] = element;
|
|
571
|
-
return true;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
exports.Heap = Heap;
|
|
575
|
-
class FibonacciHeapNode {
|
|
576
|
-
/**
|
|
577
|
-
* The constructor function initializes an object with an element and a degree, and sets the marked
|
|
578
|
-
* property to false.
|
|
579
|
-
* @param {E} element - The "element" parameter represents the value or data that will be stored in
|
|
580
|
-
* the node of a data structure. It can be any type of data, such as a number, string, object, or
|
|
581
|
-
* even another data structure.
|
|
582
|
-
* @param [degree=0] - The degree parameter represents the degree of the element in a data structure
|
|
583
|
-
* called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
|
|
584
|
-
* degree is set to 0 when a new node is created.
|
|
585
|
-
*/
|
|
586
|
-
constructor(element, degree = 0) {
|
|
587
|
-
this.element = element;
|
|
588
|
-
this.degree = degree;
|
|
589
|
-
this.marked = false;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
exports.FibonacciHeapNode = FibonacciHeapNode;
|
|
593
|
-
class FibonacciHeap {
|
|
594
|
-
/**
|
|
595
|
-
* The constructor function initializes a FibonacciHeap object with an optional comparator function.
|
|
596
|
-
* @param [comparator] - The `comparator` parameter is an optional argument that represents a
|
|
597
|
-
* function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
|
|
598
|
-
* will be used to determine the order of elements in the heap. If no comparator function is
|
|
599
|
-
* provided, a default comparator function will be used.
|
|
600
|
-
*/
|
|
601
|
-
constructor(comparator) {
|
|
602
|
-
this._size = 0;
|
|
603
|
-
this.clear();
|
|
604
|
-
this._comparator = comparator || this._defaultComparator;
|
|
605
|
-
if (typeof this.comparator !== 'function') {
|
|
606
|
-
throw new Error('FibonacciHeap constructor: given comparator should be a function.');
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* The function returns the root node of a Fibonacci heap.
|
|
611
|
-
* @returns The method is returning either a FibonacciHeapNode object or undefined.
|
|
612
|
-
*/
|
|
613
|
-
get root() {
|
|
614
|
-
return this._root;
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* The function returns the size of an object.
|
|
618
|
-
* @returns The size of the object, which is a number.
|
|
619
|
-
*/
|
|
620
|
-
get size() {
|
|
621
|
-
return this._size;
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* The function returns the minimum node in a Fibonacci heap.
|
|
625
|
-
* @returns The method is returning the minimum node of the Fibonacci heap, which is of type
|
|
626
|
-
* `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
|
|
627
|
-
*/
|
|
628
|
-
get min() {
|
|
629
|
-
return this._min;
|
|
630
|
-
}
|
|
631
|
-
/**
|
|
632
|
-
* The function returns the comparator used for comparing elements.
|
|
633
|
-
* @returns The `_comparator` property of the object.
|
|
634
|
-
*/
|
|
635
|
-
get comparator() {
|
|
636
|
-
return this._comparator;
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Get the size (number of elements) of the heap.
|
|
640
|
-
* @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
|
|
641
|
-
*/
|
|
642
|
-
clear() {
|
|
643
|
-
this._root = undefined;
|
|
644
|
-
this._min = undefined;
|
|
645
|
-
this._size = 0;
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Time Complexity: O(1)
|
|
649
|
-
* Space Complexity: O(1)
|
|
650
|
-
*
|
|
651
|
-
* Insert an element into the heap and maintain the heap properties.
|
|
652
|
-
* @param element
|
|
653
|
-
* @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
|
|
654
|
-
*/
|
|
655
|
-
add(element) {
|
|
656
|
-
return this.push(element);
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* Time Complexity: O(1)
|
|
660
|
-
* Space Complexity: O(1)
|
|
661
|
-
*
|
|
662
|
-
* Insert an element into the heap and maintain the heap properties.
|
|
663
|
-
* @param element
|
|
664
|
-
* @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
|
|
665
|
-
*/
|
|
666
|
-
push(element) {
|
|
667
|
-
const node = this.createNode(element);
|
|
668
|
-
node.left = node;
|
|
669
|
-
node.right = node;
|
|
670
|
-
this.mergeWithRoot(node);
|
|
671
|
-
if (!this.min || this.comparator(node.element, this.min.element) <= 0) {
|
|
672
|
-
this._min = node;
|
|
673
|
-
}
|
|
674
|
-
this._size++;
|
|
675
|
-
return this;
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Time Complexity: O(1)
|
|
679
|
-
* Space Complexity: O(1)
|
|
680
|
-
*
|
|
681
|
-
* Peek at the top element of the heap without removing it.
|
|
682
|
-
* @returns The top element or undefined if the heap is empty.
|
|
683
|
-
* @protected
|
|
684
|
-
*/
|
|
685
|
-
peek() {
|
|
686
|
-
return this.min ? this.min.element : undefined;
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
690
|
-
* Space Complexity: O(1)
|
|
691
|
-
*
|
|
692
|
-
* Get the size (number of elements) of the heap.
|
|
693
|
-
* @param {FibonacciHeapNode<E>} head - The head of the linked list.
|
|
694
|
-
* @protected
|
|
695
|
-
* @returns FibonacciHeapNode<E>[] - An array containing the elements of the linked list.
|
|
696
|
-
*/
|
|
697
|
-
consumeLinkedList(head) {
|
|
698
|
-
const elements = [];
|
|
699
|
-
if (!head)
|
|
700
|
-
return elements;
|
|
701
|
-
let node = head;
|
|
702
|
-
let flag = false;
|
|
703
|
-
while (true) {
|
|
704
|
-
if (node === head && flag)
|
|
705
|
-
break;
|
|
706
|
-
else if (node === head)
|
|
707
|
-
flag = true;
|
|
708
|
-
if (node) {
|
|
709
|
-
elements.push(node);
|
|
710
|
-
node = node.right;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
return elements;
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Time Complexity: O(1)
|
|
717
|
-
* Space Complexity: O(1)
|
|
718
|
-
*
|
|
719
|
-
* @param parent
|
|
720
|
-
* @param node
|
|
721
|
-
*/
|
|
722
|
-
mergeWithChild(parent, node) {
|
|
723
|
-
if (!parent.child) {
|
|
724
|
-
parent.child = node;
|
|
725
|
-
}
|
|
726
|
-
else {
|
|
727
|
-
node.right = parent.child.right;
|
|
728
|
-
node.left = parent.child;
|
|
729
|
-
parent.child.right.left = node;
|
|
730
|
-
parent.child.right = node;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
/**
|
|
734
|
-
* Time Complexity: O(log n)
|
|
735
|
-
* Space Complexity: O(1)
|
|
736
|
-
*
|
|
737
|
-
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
738
|
-
* @returns The top element or undefined if the heap is empty.
|
|
739
|
-
*/
|
|
740
|
-
poll() {
|
|
741
|
-
return this.pop();
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Time Complexity: O(log n)
|
|
745
|
-
* Space Complexity: O(1)
|
|
746
|
-
*
|
|
747
|
-
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
748
|
-
* @returns The top element or undefined if the heap is empty.
|
|
749
|
-
*/
|
|
750
|
-
pop() {
|
|
751
|
-
if (this._size === 0)
|
|
752
|
-
return undefined;
|
|
753
|
-
const z = this.min;
|
|
754
|
-
if (z.child) {
|
|
755
|
-
const elements = this.consumeLinkedList(z.child);
|
|
756
|
-
for (const node of elements) {
|
|
757
|
-
this.mergeWithRoot(node);
|
|
758
|
-
node.parent = undefined;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
this.removeFromRoot(z);
|
|
762
|
-
if (z === z.right) {
|
|
763
|
-
this._min = undefined;
|
|
764
|
-
this._root = undefined;
|
|
765
|
-
}
|
|
766
|
-
else {
|
|
767
|
-
this._min = z.right;
|
|
768
|
-
this._consolidate();
|
|
769
|
-
}
|
|
770
|
-
this._size--;
|
|
771
|
-
return z.element;
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Time Complexity: O(1)
|
|
775
|
-
* Space Complexity: O(1)
|
|
776
|
-
*
|
|
777
|
-
* merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
|
|
778
|
-
* @param heapToMerge
|
|
779
|
-
*/
|
|
780
|
-
merge(heapToMerge) {
|
|
781
|
-
if (heapToMerge.size === 0) {
|
|
782
|
-
return; // Nothing to merge
|
|
783
|
-
}
|
|
784
|
-
// Merge the root lists of the two heaps
|
|
785
|
-
if (this.root && heapToMerge.root) {
|
|
786
|
-
const thisRoot = this.root;
|
|
787
|
-
const otherRoot = heapToMerge.root;
|
|
788
|
-
const thisRootRight = thisRoot.right;
|
|
789
|
-
const otherRootLeft = otherRoot.left;
|
|
790
|
-
thisRoot.right = otherRoot;
|
|
791
|
-
otherRoot.left = thisRoot;
|
|
792
|
-
thisRootRight.left = otherRootLeft;
|
|
793
|
-
otherRootLeft.right = thisRootRight;
|
|
794
|
-
}
|
|
795
|
-
// Update the minimum node
|
|
796
|
-
if (!this.min || (heapToMerge.min && this.comparator(heapToMerge.min.element, this.min.element) < 0)) {
|
|
797
|
-
this._min = heapToMerge.min;
|
|
798
|
-
}
|
|
799
|
-
// Update the size
|
|
800
|
-
this._size += heapToMerge.size;
|
|
801
|
-
// Clear the heap that was merged
|
|
802
|
-
heapToMerge.clear();
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* Create a new node.
|
|
806
|
-
* @param element
|
|
807
|
-
* @protected
|
|
808
|
-
*/
|
|
809
|
-
createNode(element) {
|
|
810
|
-
return new FibonacciHeapNode(element);
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Default comparator function used by the heap.
|
|
814
|
-
* @param {E} a
|
|
815
|
-
* @param {E} b
|
|
816
|
-
* @protected
|
|
817
|
-
*/
|
|
818
|
-
_defaultComparator(a, b) {
|
|
819
|
-
if (a < b)
|
|
820
|
-
return -1;
|
|
821
|
-
if (a > b)
|
|
822
|
-
return 1;
|
|
823
|
-
return 0;
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* Time Complexity: O(1)
|
|
827
|
-
* Space Complexity: O(1)
|
|
828
|
-
*
|
|
829
|
-
* Merge the given node with the root list.
|
|
830
|
-
* @param node - The node to be merged.
|
|
831
|
-
*/
|
|
832
|
-
mergeWithRoot(node) {
|
|
833
|
-
if (!this.root) {
|
|
834
|
-
this._root = node;
|
|
835
|
-
}
|
|
836
|
-
else {
|
|
837
|
-
node.right = this.root.right;
|
|
838
|
-
node.left = this.root;
|
|
839
|
-
this.root.right.left = node;
|
|
840
|
-
this.root.right = node;
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Time Complexity: O(1)
|
|
845
|
-
* Space Complexity: O(1)
|
|
846
|
-
*
|
|
847
|
-
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
848
|
-
* @param node - The node to be removed.
|
|
849
|
-
* @protected
|
|
850
|
-
*/
|
|
851
|
-
removeFromRoot(node) {
|
|
852
|
-
if (this.root === node)
|
|
853
|
-
this._root = node.right;
|
|
854
|
-
if (node.left)
|
|
855
|
-
node.left.right = node.right;
|
|
856
|
-
if (node.right)
|
|
857
|
-
node.right.left = node.left;
|
|
858
|
-
}
|
|
859
|
-
/**
|
|
860
|
-
* Time Complexity: O(1)
|
|
861
|
-
* Space Complexity: O(1)
|
|
862
|
-
*
|
|
863
|
-
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
864
|
-
* @param y
|
|
865
|
-
* @param x
|
|
866
|
-
* @protected
|
|
867
|
-
*/
|
|
868
|
-
_link(y, x) {
|
|
869
|
-
this.removeFromRoot(y);
|
|
870
|
-
y.left = y;
|
|
871
|
-
y.right = y;
|
|
872
|
-
this.mergeWithChild(x, y);
|
|
873
|
-
x.degree++;
|
|
874
|
-
y.parent = x;
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Time Complexity: O(n log n)
|
|
878
|
-
* Space Complexity: O(n)
|
|
879
|
-
*
|
|
880
|
-
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
881
|
-
* @protected
|
|
882
|
-
*/
|
|
883
|
-
_consolidate() {
|
|
884
|
-
const A = new Array(this._size);
|
|
885
|
-
const elements = this.consumeLinkedList(this.root);
|
|
886
|
-
let x, y, d, t;
|
|
887
|
-
for (const node of elements) {
|
|
888
|
-
x = node;
|
|
889
|
-
d = x.degree;
|
|
890
|
-
while (A[d]) {
|
|
891
|
-
y = A[d];
|
|
892
|
-
if (this.comparator(x.element, y.element) > 0) {
|
|
893
|
-
t = x;
|
|
894
|
-
x = y;
|
|
895
|
-
y = t;
|
|
896
|
-
}
|
|
897
|
-
this._link(y, x);
|
|
898
|
-
A[d] = undefined;
|
|
899
|
-
d++;
|
|
900
|
-
}
|
|
901
|
-
A[d] = x;
|
|
902
|
-
}
|
|
903
|
-
for (let i = 0; i < this._size; i++) {
|
|
904
|
-
if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
|
|
905
|
-
this._min = A[i];
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
exports.FibonacciHeap = FibonacciHeap;
|
|
911
|
-
//# sourceMappingURL=heap.js.map
|