min-heap-typed 1.40.0-rc → 1.41.0
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/.dependency-cruiser.js +422 -422
- package/.eslintrc.js +59 -59
- package/.prettierrc.js +14 -14
- package/README.md +20 -3
- package/coverage/clover.xml +11 -7
- package/coverage/coverage-final.json +95 -1
- package/coverage/coverage-summary.json +59 -2
- package/coverage/lcov-report/base.css +278 -99
- package/coverage/lcov-report/index.html +69 -65
- package/coverage/lcov-report/index.ts.html +36 -35
- package/coverage/lcov-report/sorter.js +15 -5
- package/dist/data-structures/binary-tree/avl-tree.d.ts +106 -0
- package/dist/data-structures/binary-tree/avl-tree.js +347 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +269 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +363 -0
- package/dist/data-structures/binary-tree/binary-tree.js +1135 -0
- package/dist/data-structures/binary-tree/bst.d.ts +167 -0
- package/dist/data-structures/binary-tree/bst.js +512 -0
- package/dist/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/data-structures/binary-tree/index.js +23 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +97 -0
- package/dist/data-structures/binary-tree/rb-tree.js +388 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +67 -0
- package/dist/data-structures/binary-tree/segment-tree.js +180 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +126 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +355 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +313 -0
- package/dist/data-structures/graph/abstract-graph.js +884 -0
- package/dist/data-structures/graph/directed-graph.d.ts +194 -0
- package/dist/data-structures/graph/directed-graph.js +404 -0
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/index.js +20 -0
- package/dist/data-structures/graph/map-graph.d.ts +73 -0
- package/dist/data-structures/graph/map-graph.js +93 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +120 -0
- package/dist/data-structures/graph/undirected-graph.js +239 -0
- package/dist/data-structures/hash/coordinate-map.d.ts +44 -0
- package/dist/data-structures/hash/coordinate-map.js +62 -0
- package/dist/data-structures/hash/coordinate-set.d.ts +36 -0
- package/dist/data-structures/hash/coordinate-set.js +52 -0
- package/dist/data-structures/hash/hash-map.d.ts +50 -0
- package/dist/data-structures/hash/hash-map.js +153 -0
- package/dist/data-structures/hash/hash-table.d.ts +103 -0
- package/dist/data-structures/hash/hash-table.js +236 -0
- package/dist/data-structures/hash/index.d.ts +6 -0
- package/dist/data-structures/hash/index.js +22 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.js +6 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.js +6 -0
- package/dist/data-structures/heap/heap.d.ts +235 -0
- package/dist/data-structures/heap/heap.js +515 -0
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/index.js +19 -0
- package/dist/data-structures/heap/max-heap.d.ts +15 -0
- package/dist/data-structures/heap/max-heap.js +26 -0
- package/dist/data-structures/heap/min-heap.d.ts +15 -0
- package/dist/data-structures/heap/min-heap.js +26 -0
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/index.js +27 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +569 -0
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/index.js +19 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +232 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +533 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +80 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +187 -0
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/index.js +20 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +28 -0
- package/dist/data-structures/matrix/matrix2d.d.ts +107 -0
- package/dist/data-structures/matrix/matrix2d.js +199 -0
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +106 -0
- package/dist/data-structures/matrix/vector2d.d.ts +200 -0
- package/dist/data-structures/matrix/vector2d.js +290 -0
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/index.js +19 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +26 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +26 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/priority-queue.js +17 -0
- package/dist/data-structures/queue/deque.d.ts +161 -0
- package/dist/data-structures/queue/deque.js +264 -0
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/index.js +18 -0
- package/dist/data-structures/queue/queue.d.ts +122 -0
- package/dist/data-structures/queue/queue.js +187 -0
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/index.js +17 -0
- package/dist/data-structures/stack/stack.d.ts +64 -0
- package/dist/data-structures/stack/stack.js +94 -0
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/index.js +17 -0
- package/dist/data-structures/tree/tree.d.ts +8 -0
- package/dist/data-structures/tree/tree.js +40 -0
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/index.js +17 -0
- package/dist/data-structures/trie/trie.d.ts +79 -0
- package/dist/data-structures/trie/trie.js +251 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +18 -4
- package/dist/interfaces/binary-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.js +2 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/doubly-linked-list.js +2 -0
- package/dist/interfaces/graph.d.ts +5 -0
- package/dist/interfaces/graph.js +2 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/heap.js +2 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/interfaces/index.js +24 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/navigator.js +2 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/priority-queue.js +2 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/segment-tree.js +2 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.js +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
- package/dist/types/data-structures/binary-tree/bst.js +2 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/index.js +22 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/rb-tree.js +13 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
- package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
- package/dist/types/data-structures/graph/abstract-graph.js +2 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/graph/directed-graph.js +9 -0
- package/dist/types/data-structures/graph/index.d.ts +3 -0
- package/dist/types/data-structures/graph/index.js +19 -0
- package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/map-graph.js +2 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/undirected-graph.js +2 -0
- package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-map.js +2 -0
- package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-set.js +2 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-map.js +2 -0
- package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-table.js +2 -0
- package/dist/types/data-structures/hash/index.d.ts +1 -0
- package/dist/types/data-structures/hash/index.js +2 -0
- package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-map.js +2 -0
- package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-set.js +2 -0
- package/dist/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/data-structures/heap/heap.js +2 -0
- package/dist/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/data-structures/heap/index.js +17 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/max-heap.js +2 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/min-heap.js +2 -0
- package/dist/types/data-structures/index.d.ts +11 -0
- package/dist/types/data-structures/index.js +27 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/index.d.ts +2 -0
- package/dist/types/data-structures/linked-list/index.js +18 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
- package/dist/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.js +17 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix.js +2 -0
- package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix2d.js +2 -0
- package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/data-structures/matrix/navigator.js +2 -0
- package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/vector2d.js +2 -0
- package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/types/data-structures/priority-queue/index.js +19 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
- package/dist/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/types/data-structures/queue/deque.js +2 -0
- package/dist/types/data-structures/queue/index.d.ts +2 -0
- package/dist/types/data-structures/queue/index.js +18 -0
- package/dist/types/data-structures/queue/queue.d.ts +1 -0
- package/dist/types/data-structures/queue/queue.js +2 -0
- package/dist/types/data-structures/stack/index.d.ts +1 -0
- package/dist/types/data-structures/stack/index.js +17 -0
- package/dist/types/data-structures/stack/stack.d.ts +1 -0
- package/dist/types/data-structures/stack/stack.js +2 -0
- package/dist/types/data-structures/tree/index.d.ts +1 -0
- package/dist/types/data-structures/tree/index.js +17 -0
- package/dist/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/data-structures/tree/tree.js +2 -0
- package/dist/types/data-structures/trie/index.d.ts +1 -0
- package/dist/types/data-structures/trie/index.js +17 -0
- package/dist/types/data-structures/trie/trie.d.ts +1 -0
- package/dist/types/data-structures/trie/trie.js +2 -0
- package/dist/types/helpers.d.ts +8 -0
- package/dist/types/helpers.js +9 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.js +18 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/utils.js +2 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/types/utils/validate-type.js +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +20 -0
- package/dist/utils/utils.js +73 -0
- package/jest.config.js +6 -6
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +350 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1284 -0
- package/src/data-structures/binary-tree/bst.ts +522 -0
- package/src/data-structures/binary-tree/index.ts +7 -0
- package/src/data-structures/binary-tree/rb-tree.ts +426 -0
- package/src/data-structures/binary-tree/segment-tree.ts +190 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +379 -0
- package/src/data-structures/graph/abstract-graph.ts +1000 -0
- package/src/data-structures/graph/directed-graph.ts +449 -0
- package/src/data-structures/graph/index.ts +4 -0
- package/src/data-structures/graph/map-graph.ts +106 -0
- package/src/data-structures/graph/undirected-graph.ts +259 -0
- package/src/data-structures/hash/coordinate-map.ts +63 -0
- package/src/data-structures/hash/coordinate-set.ts +52 -0
- package/src/data-structures/hash/hash-map.ts +185 -0
- package/src/data-structures/hash/hash-table.ts +268 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/tree-map.ts +2 -0
- package/src/data-structures/hash/tree-set.ts +2 -0
- package/src/data-structures/heap/heap.ts +589 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +26 -0
- package/src/data-structures/heap/min-heap.ts +26 -0
- package/src/data-structures/index.ts +11 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +605 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +576 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +221 -0
- package/src/data-structures/matrix/index.ts +4 -0
- package/src/data-structures/matrix/matrix.ts +27 -0
- package/src/data-structures/matrix/matrix2d.ts +211 -0
- package/src/data-structures/matrix/navigator.ts +121 -0
- package/src/data-structures/matrix/vector2d.ts +315 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +25 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +25 -0
- package/src/data-structures/priority-queue/priority-queue.ts +16 -0
- package/src/data-structures/queue/deque.ts +282 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +209 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +102 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +41 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +262 -0
- package/src/index.ts +4 -1
- package/src/interfaces/binary-tree.ts +10 -0
- package/src/interfaces/doubly-linked-list.ts +1 -0
- package/src/interfaces/graph.ts +7 -0
- package/src/interfaces/heap.ts +1 -0
- package/src/interfaces/index.ts +8 -0
- package/src/interfaces/navigator.ts +1 -0
- package/src/interfaces/priority-queue.ts +1 -0
- package/src/interfaces/segment-tree.ts +1 -0
- package/src/interfaces/singly-linked-list.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
- package/src/types/data-structures/binary-tree/bst.ts +11 -0
- package/src/types/data-structures/binary-tree/index.ts +6 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
- package/src/types/data-structures/graph/abstract-graph.ts +11 -0
- package/src/types/data-structures/graph/directed-graph.ts +8 -0
- package/src/types/data-structures/graph/index.ts +3 -0
- package/src/types/data-structures/graph/map-graph.ts +1 -0
- package/src/types/data-structures/graph/undirected-graph.ts +1 -0
- package/src/types/data-structures/hash/coordinate-map.ts +1 -0
- package/src/types/data-structures/hash/coordinate-set.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +1 -0
- package/src/types/data-structures/hash/hash-table.ts +1 -0
- package/src/types/data-structures/hash/index.ts +1 -0
- package/src/types/data-structures/hash/tree-map.ts +1 -0
- package/src/types/data-structures/hash/tree-set.ts +1 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/heap/index.ts +1 -0
- package/src/types/data-structures/heap/max-heap.ts +1 -0
- package/src/types/data-structures/heap/min-heap.ts +1 -0
- package/src/types/data-structures/index.ts +11 -0
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/index.ts +2 -0
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +1 -0
- package/src/types/data-structures/matrix/matrix2d.ts +1 -0
- package/src/types/data-structures/matrix/navigator.ts +14 -0
- package/src/types/data-structures/matrix/vector2d.ts +1 -0
- package/src/types/data-structures/priority-queue/index.ts +3 -0
- package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/data-structures/queue/deque.ts +1 -0
- package/src/types/data-structures/queue/index.ts +2 -0
- package/src/types/data-structures/queue/queue.ts +1 -0
- package/src/types/data-structures/stack/index.ts +1 -0
- package/src/types/data-structures/stack/stack.ts +1 -0
- package/src/types/data-structures/tree/index.ts +1 -0
- package/src/types/data-structures/tree/tree.ts +1 -0
- package/src/types/data-structures/trie/index.ts +1 -0
- package/src/types/data-structures/trie/trie.ts +1 -0
- package/src/types/helpers.ts +11 -0
- package/src/types/index.ts +3 -0
- package/src/types/utils/index.ts +2 -0
- package/src/types/utils/utils.ts +6 -0
- package/src/types/utils/validate-type.ts +35 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +86 -0
- package/tsconfig.json +1 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { BTNKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
|
|
9
|
+
import { BinaryTreeDeletedResult, BTNCallback, IterationType } from '../../types';
|
|
10
|
+
import { IBinaryTree } from '../../interfaces';
|
|
11
|
+
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
12
|
+
export declare class TreeMultisetNode<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, N> {
|
|
13
|
+
count: number;
|
|
14
|
+
/**
|
|
15
|
+
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
16
|
+
* @param {BTNKey} key - The `key` parameter is of type `BTNKey` and represents the unique identifier
|
|
17
|
+
* of the binary tree node.
|
|
18
|
+
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
|
|
19
|
+
* tree node. If no value is provided, it will be `undefined`.
|
|
20
|
+
* @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
|
|
21
|
+
* occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
|
|
22
|
+
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
23
|
+
*/
|
|
24
|
+
constructor(key: BTNKey, value?: V, count?: number);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The only distinction between a TreeMultiset and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
28
|
+
*/
|
|
29
|
+
export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNode<V, TreeMultisetNodeNested<V>>> extends AVLTree<V, N> implements IBinaryTree<V, N> {
|
|
30
|
+
/**
|
|
31
|
+
* The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to
|
|
32
|
+
* merge duplicated values.
|
|
33
|
+
* @param {TreeMultisetOptions} [options] - An optional object that contains additional configuration options for the
|
|
34
|
+
* TreeMultiset.
|
|
35
|
+
*/
|
|
36
|
+
constructor(options?: TreeMultisetOptions);
|
|
37
|
+
private _count;
|
|
38
|
+
get count(): number;
|
|
39
|
+
/**
|
|
40
|
+
* The function creates a new BSTNode with the given key, value, and count.
|
|
41
|
+
* @param {BTNKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
|
|
42
|
+
* distinguish one node from another in the tree.
|
|
43
|
+
* @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
|
|
44
|
+
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
|
|
45
|
+
* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
|
|
46
|
+
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
|
|
47
|
+
*/
|
|
48
|
+
createNode(key: BTNKey, value?: V, count?: number): N;
|
|
49
|
+
/**
|
|
50
|
+
* The `add` function adds a new node to a binary search tree, updating the count if the key already
|
|
51
|
+
* exists, and balancing the tree if necessary.
|
|
52
|
+
* @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
|
|
53
|
+
* `BTNKey` (which represents the key of the node to be added), a `N` (which represents a
|
|
54
|
+
* node to be added), or `null` (which represents a null node).
|
|
55
|
+
* @param [value] - The `value` parameter represents the value associated with the key that is being
|
|
56
|
+
* added to the binary tree.
|
|
57
|
+
* @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
|
|
58
|
+
* pair that will be added to the binary tree. It has a default value of 1, which means that if no
|
|
59
|
+
* count is specified, the default count will be 1.
|
|
60
|
+
* @returns The function `add` returns a value of type `N | null | undefined`.
|
|
61
|
+
*/
|
|
62
|
+
add(keyOrNode: BTNKey | N | null, value?: V, count?: number): N | null | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* The function adds a new node to a binary tree if there is an available slot in the parent node.
|
|
65
|
+
* @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to
|
|
66
|
+
* the tree. It can be either a node object (`N`) or `null`.
|
|
67
|
+
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will
|
|
68
|
+
* be added as a child.
|
|
69
|
+
* @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
|
|
70
|
+
*/
|
|
71
|
+
_addTo(newNode: N | null, parent: N): N | null | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* The `addMany` function adds multiple keys or nodes to a TreeMultiset and returns an array of the
|
|
74
|
+
* inserted nodes.
|
|
75
|
+
* @param {(BTNKey | null)[] | (N | null)[]} keysOrNodes - An array of keys or nodes to be
|
|
76
|
+
* added to the multiset. Each element can be either a BTNKey or a TreeMultisetNode.
|
|
77
|
+
* @param {V[]} [data] - The `data` parameter is an optional array of values that correspond
|
|
78
|
+
* to the keys or nodes being added to the multiset. It is used to associate additional data with
|
|
79
|
+
* each key or node.
|
|
80
|
+
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
81
|
+
*/
|
|
82
|
+
addMany(keysOrNodes: (BTNKey | null)[] | (N | null)[], data?: V[]): (N | null | undefined)[];
|
|
83
|
+
/**
|
|
84
|
+
* The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
|
|
85
|
+
* binary search tree using either a recursive or iterative approach.
|
|
86
|
+
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
87
|
+
* type of iteration to use when building a balanced binary search tree. It can have two possible
|
|
88
|
+
* values:
|
|
89
|
+
* @returns a boolean value.
|
|
90
|
+
*/
|
|
91
|
+
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
|
|
94
|
+
* node along with the parent node that needs to be balanced.
|
|
95
|
+
* @param {ReturnType<C>} identifier - The `identifier` parameter is either a
|
|
96
|
+
* `BTNKey` or a generic type `N`. It represents the property of the node that we are
|
|
97
|
+
* searching for. It can be a specific key value or any other property of the node.
|
|
98
|
+
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
99
|
+
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
100
|
+
* included in the result. The `callback` parameter has a default value of
|
|
101
|
+
* `((node: N) => node.key)`
|
|
102
|
+
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
103
|
+
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
104
|
+
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
105
|
+
* decremented by 1 and
|
|
106
|
+
* @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
107
|
+
*/
|
|
108
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
109
|
+
/**
|
|
110
|
+
* The clear() function clears the contents of a data structure and sets the count to zero.
|
|
111
|
+
*/
|
|
112
|
+
clear(): void;
|
|
113
|
+
/**
|
|
114
|
+
* The function swaps the values of two nodes in a binary tree.
|
|
115
|
+
* @param {N} srcNode - The source node that needs to be swapped with the destination node.
|
|
116
|
+
* @param {N} destNode - The `destNode` parameter represents the destination node where the values
|
|
117
|
+
* from `srcNode` will be swapped into.
|
|
118
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
119
|
+
*/
|
|
120
|
+
protected _swap(srcNode: N, destNode: N): N;
|
|
121
|
+
/**
|
|
122
|
+
* The function sets the value of the "_count" property.
|
|
123
|
+
* @param {number} v - number
|
|
124
|
+
*/
|
|
125
|
+
protected _setCount(v: number): void;
|
|
126
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TreeMultiset = exports.TreeMultisetNode = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const avl_tree_1 = require("./avl-tree");
|
|
6
|
+
class TreeMultisetNode extends avl_tree_1.AVLTreeNode {
|
|
7
|
+
/**
|
|
8
|
+
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
9
|
+
* @param {BTNKey} key - The `key` parameter is of type `BTNKey` and represents the unique identifier
|
|
10
|
+
* of the binary tree node.
|
|
11
|
+
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
|
|
12
|
+
* tree node. If no value is provided, it will be `undefined`.
|
|
13
|
+
* @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
|
|
14
|
+
* occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
|
|
15
|
+
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
16
|
+
*/
|
|
17
|
+
constructor(key, value, count = 1) {
|
|
18
|
+
super(key, value);
|
|
19
|
+
this.count = count;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.TreeMultisetNode = TreeMultisetNode;
|
|
23
|
+
/**
|
|
24
|
+
* The only distinction between a TreeMultiset and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
25
|
+
*/
|
|
26
|
+
class TreeMultiset extends avl_tree_1.AVLTree {
|
|
27
|
+
/**
|
|
28
|
+
* The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to
|
|
29
|
+
* merge duplicated values.
|
|
30
|
+
* @param {TreeMultisetOptions} [options] - An optional object that contains additional configuration options for the
|
|
31
|
+
* TreeMultiset.
|
|
32
|
+
*/
|
|
33
|
+
constructor(options) {
|
|
34
|
+
super(options);
|
|
35
|
+
this._count = 0;
|
|
36
|
+
}
|
|
37
|
+
get count() {
|
|
38
|
+
return this._count;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The function creates a new BSTNode with the given key, value, and count.
|
|
42
|
+
* @param {BTNKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
|
|
43
|
+
* distinguish one node from another in the tree.
|
|
44
|
+
* @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
|
|
45
|
+
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
|
|
46
|
+
* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
|
|
47
|
+
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
|
|
48
|
+
*/
|
|
49
|
+
createNode(key, value, count) {
|
|
50
|
+
return new TreeMultisetNode(key, value, count);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The `add` function adds a new node to a binary search tree, updating the count if the key already
|
|
54
|
+
* exists, and balancing the tree if necessary.
|
|
55
|
+
* @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
|
|
56
|
+
* `BTNKey` (which represents the key of the node to be added), a `N` (which represents a
|
|
57
|
+
* node to be added), or `null` (which represents a null node).
|
|
58
|
+
* @param [value] - The `value` parameter represents the value associated with the key that is being
|
|
59
|
+
* added to the binary tree.
|
|
60
|
+
* @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
|
|
61
|
+
* pair that will be added to the binary tree. It has a default value of 1, which means that if no
|
|
62
|
+
* count is specified, the default count will be 1.
|
|
63
|
+
* @returns The function `add` returns a value of type `N | null | undefined`.
|
|
64
|
+
*/
|
|
65
|
+
add(keyOrNode, value, count = 1) {
|
|
66
|
+
let inserted = undefined, newNode;
|
|
67
|
+
if (keyOrNode instanceof TreeMultisetNode) {
|
|
68
|
+
newNode = this.createNode(keyOrNode.key, keyOrNode.value, keyOrNode.count);
|
|
69
|
+
}
|
|
70
|
+
else if (keyOrNode === null) {
|
|
71
|
+
newNode = null;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
newNode = this.createNode(keyOrNode, value, count);
|
|
75
|
+
}
|
|
76
|
+
if (!this.root) {
|
|
77
|
+
this._setRoot(newNode);
|
|
78
|
+
this._size = this.size + 1;
|
|
79
|
+
newNode && this._setCount(this.count + newNode.count);
|
|
80
|
+
inserted = this.root;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
let cur = this.root;
|
|
84
|
+
let traversing = true;
|
|
85
|
+
while (traversing) {
|
|
86
|
+
if (cur) {
|
|
87
|
+
if (newNode) {
|
|
88
|
+
if (this._compare(cur.key, newNode.key) === types_1.CP.eq) {
|
|
89
|
+
cur.value = newNode.value;
|
|
90
|
+
cur.count += newNode.count;
|
|
91
|
+
this._setCount(this.count + newNode.count);
|
|
92
|
+
traversing = false;
|
|
93
|
+
inserted = cur;
|
|
94
|
+
}
|
|
95
|
+
else if (this._compare(cur.key, newNode.key) === types_1.CP.gt) {
|
|
96
|
+
// Traverse left of the node
|
|
97
|
+
if (cur.left === undefined) {
|
|
98
|
+
//Add to the left of the current node
|
|
99
|
+
cur.left = newNode;
|
|
100
|
+
this._size = this.size + 1;
|
|
101
|
+
this._setCount(this.count + newNode.count);
|
|
102
|
+
traversing = false;
|
|
103
|
+
inserted = cur.left;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
//Traverse the left of the current node
|
|
107
|
+
if (cur.left)
|
|
108
|
+
cur = cur.left;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else if (this._compare(cur.key, newNode.key) === types_1.CP.lt) {
|
|
112
|
+
// Traverse right of the node
|
|
113
|
+
if (cur.right === undefined) {
|
|
114
|
+
//Add to the right of the current node
|
|
115
|
+
cur.right = newNode;
|
|
116
|
+
this._size = this.size + 1;
|
|
117
|
+
this._setCount(this.count + newNode.count);
|
|
118
|
+
traversing = false;
|
|
119
|
+
inserted = cur.right;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
//Traverse the left of the current node
|
|
123
|
+
if (cur.right)
|
|
124
|
+
cur = cur.right;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// TODO may need to support null inserted
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
traversing = false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (inserted)
|
|
138
|
+
this._balancePath(inserted);
|
|
139
|
+
return inserted;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The function adds a new node to a binary tree if there is an available slot in the parent node.
|
|
143
|
+
* @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to
|
|
144
|
+
* the tree. It can be either a node object (`N`) or `null`.
|
|
145
|
+
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will
|
|
146
|
+
* be added as a child.
|
|
147
|
+
* @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
|
|
148
|
+
*/
|
|
149
|
+
_addTo(newNode, parent) {
|
|
150
|
+
if (parent) {
|
|
151
|
+
if (parent.left === undefined) {
|
|
152
|
+
parent.left = newNode;
|
|
153
|
+
if (newNode !== null) {
|
|
154
|
+
this._size = this.size + 1;
|
|
155
|
+
this._setCount(this.count + newNode.count);
|
|
156
|
+
}
|
|
157
|
+
return parent.left;
|
|
158
|
+
}
|
|
159
|
+
else if (parent.right === undefined) {
|
|
160
|
+
parent.right = newNode;
|
|
161
|
+
if (newNode !== null) {
|
|
162
|
+
this._size = (this.size + 1);
|
|
163
|
+
this._setCount(this.count + newNode.count);
|
|
164
|
+
}
|
|
165
|
+
return parent.right;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The `addMany` function adds multiple keys or nodes to a TreeMultiset and returns an array of the
|
|
177
|
+
* inserted nodes.
|
|
178
|
+
* @param {(BTNKey | null)[] | (N | null)[]} keysOrNodes - An array of keys or nodes to be
|
|
179
|
+
* added to the multiset. Each element can be either a BTNKey or a TreeMultisetNode.
|
|
180
|
+
* @param {V[]} [data] - The `data` parameter is an optional array of values that correspond
|
|
181
|
+
* to the keys or nodes being added to the multiset. It is used to associate additional data with
|
|
182
|
+
* each key or node.
|
|
183
|
+
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
184
|
+
*/
|
|
185
|
+
addMany(keysOrNodes, data) {
|
|
186
|
+
const inserted = [];
|
|
187
|
+
for (let i = 0; i < keysOrNodes.length; i++) {
|
|
188
|
+
const keyOrNode = keysOrNodes[i];
|
|
189
|
+
if (keyOrNode instanceof TreeMultisetNode) {
|
|
190
|
+
inserted.push(this.add(keyOrNode.key, keyOrNode.value, keyOrNode.count));
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (keyOrNode === null) {
|
|
194
|
+
inserted.push(this.add(NaN, undefined, 0));
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
inserted.push(this.add(keyOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
|
|
198
|
+
}
|
|
199
|
+
return inserted;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
|
|
203
|
+
* binary search tree using either a recursive or iterative approach.
|
|
204
|
+
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
205
|
+
* type of iteration to use when building a balanced binary search tree. It can have two possible
|
|
206
|
+
* values:
|
|
207
|
+
* @returns a boolean value.
|
|
208
|
+
*/
|
|
209
|
+
perfectlyBalance(iterationType = this.iterationType) {
|
|
210
|
+
const sorted = this.dfs(node => node, 'in'), n = sorted.length;
|
|
211
|
+
if (sorted.length < 1)
|
|
212
|
+
return false;
|
|
213
|
+
this.clear();
|
|
214
|
+
if (iterationType === types_1.IterationType.RECURSIVE) {
|
|
215
|
+
const buildBalanceBST = (l, r) => {
|
|
216
|
+
if (l > r)
|
|
217
|
+
return;
|
|
218
|
+
const m = l + Math.floor((r - l) / 2);
|
|
219
|
+
const midNode = sorted[m];
|
|
220
|
+
this.add(midNode.key, midNode.value, midNode.count);
|
|
221
|
+
buildBalanceBST(l, m - 1);
|
|
222
|
+
buildBalanceBST(m + 1, r);
|
|
223
|
+
};
|
|
224
|
+
buildBalanceBST(0, n - 1);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
const stack = [[0, n - 1]];
|
|
229
|
+
while (stack.length > 0) {
|
|
230
|
+
const popped = stack.pop();
|
|
231
|
+
if (popped) {
|
|
232
|
+
const [l, r] = popped;
|
|
233
|
+
if (l <= r) {
|
|
234
|
+
const m = l + Math.floor((r - l) / 2);
|
|
235
|
+
const midNode = sorted[m];
|
|
236
|
+
this.add(midNode.key, midNode.value, midNode.count);
|
|
237
|
+
stack.push([m + 1, r]);
|
|
238
|
+
stack.push([l, m - 1]);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
|
|
247
|
+
* node along with the parent node that needs to be balanced.
|
|
248
|
+
* @param {ReturnType<C>} identifier - The `identifier` parameter is either a
|
|
249
|
+
* `BTNKey` or a generic type `N`. It represents the property of the node that we are
|
|
250
|
+
* searching for. It can be a specific key value or any other property of the node.
|
|
251
|
+
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
252
|
+
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
253
|
+
* included in the result. The `callback` parameter has a default value of
|
|
254
|
+
* `((node: N) => node.key)`
|
|
255
|
+
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
256
|
+
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
257
|
+
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
258
|
+
* decremented by 1 and
|
|
259
|
+
* @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
260
|
+
*/
|
|
261
|
+
delete(identifier, callback = ((node) => node.key), ignoreCount = false) {
|
|
262
|
+
const bstDeletedResult = [];
|
|
263
|
+
if (!this.root)
|
|
264
|
+
return bstDeletedResult;
|
|
265
|
+
const curr = this.get(identifier, callback);
|
|
266
|
+
if (!curr)
|
|
267
|
+
return bstDeletedResult;
|
|
268
|
+
const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
|
|
269
|
+
let needBalanced = null, orgCurrent = curr;
|
|
270
|
+
if (curr.count > 1 && !ignoreCount) {
|
|
271
|
+
curr.count--;
|
|
272
|
+
this._setCount(this.count - 1);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
if (!curr.left) {
|
|
276
|
+
if (!parent) {
|
|
277
|
+
if (curr.right !== undefined)
|
|
278
|
+
this._setRoot(curr.right);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
const { familyPosition: fp } = curr;
|
|
282
|
+
if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
|
|
283
|
+
parent.left = curr.right;
|
|
284
|
+
}
|
|
285
|
+
else if (fp === types_1.FamilyPosition.RIGHT || fp === types_1.FamilyPosition.ROOT_RIGHT) {
|
|
286
|
+
parent.right = curr.right;
|
|
287
|
+
}
|
|
288
|
+
needBalanced = parent;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
|
|
293
|
+
if (leftSubTreeRightMost) {
|
|
294
|
+
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
295
|
+
orgCurrent = this._swap(curr, leftSubTreeRightMost);
|
|
296
|
+
if (parentOfLeftSubTreeMax) {
|
|
297
|
+
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
|
|
298
|
+
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
302
|
+
}
|
|
303
|
+
needBalanced = parentOfLeftSubTreeMax;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
this._size = this.size - 1;
|
|
308
|
+
// TODO How to handle when the count of target node is lesser than current node's count
|
|
309
|
+
this._setCount(this.count - orgCurrent.count);
|
|
310
|
+
}
|
|
311
|
+
bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
312
|
+
if (needBalanced) {
|
|
313
|
+
this._balancePath(needBalanced);
|
|
314
|
+
}
|
|
315
|
+
return bstDeletedResult;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* The clear() function clears the contents of a data structure and sets the count to zero.
|
|
319
|
+
*/
|
|
320
|
+
clear() {
|
|
321
|
+
super.clear();
|
|
322
|
+
this._setCount(0);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The function swaps the values of two nodes in a binary tree.
|
|
326
|
+
* @param {N} srcNode - The source node that needs to be swapped with the destination node.
|
|
327
|
+
* @param {N} destNode - The `destNode` parameter represents the destination node where the values
|
|
328
|
+
* from `srcNode` will be swapped into.
|
|
329
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
330
|
+
*/
|
|
331
|
+
_swap(srcNode, destNode) {
|
|
332
|
+
const { key, value, count, height } = destNode;
|
|
333
|
+
const tempNode = this.createNode(key, value, count);
|
|
334
|
+
if (tempNode) {
|
|
335
|
+
tempNode.height = height;
|
|
336
|
+
destNode.key = srcNode.key;
|
|
337
|
+
destNode.value = srcNode.value;
|
|
338
|
+
destNode.count = srcNode.count;
|
|
339
|
+
destNode.height = srcNode.height;
|
|
340
|
+
srcNode.key = tempNode.key;
|
|
341
|
+
srcNode.value = tempNode.value;
|
|
342
|
+
srcNode.count = tempNode.count;
|
|
343
|
+
srcNode.height = tempNode.height;
|
|
344
|
+
}
|
|
345
|
+
return destNode;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* The function sets the value of the "_count" property.
|
|
349
|
+
* @param {number} v - number
|
|
350
|
+
*/
|
|
351
|
+
_setCount(v) {
|
|
352
|
+
this._count = v;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
exports.TreeMultiset = TreeMultiset;
|