data-structure-typed 1.17.4 → 1.18.5
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/README.md +193 -66
- package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
- package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
- package/backup/recursive-type/src/assets/logo.png +0 -0
- package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +288 -0
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +1502 -0
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +503 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/index.ts +11 -0
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +110 -0
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +243 -0
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +55 -0
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/diagrams/README.md +5 -0
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +985 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +478 -0
- package/backup/recursive-type/src/data-structures/graph/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +293 -0
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +67 -0
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +56 -0
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/index.ts +6 -0
- package/backup/recursive-type/src/data-structures/hash/pair.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +3 -0
- package/backup/recursive-type/src/data-structures/heap/heap.ts +176 -0
- package/backup/recursive-type/src/data-structures/heap/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +31 -0
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +34 -0
- package/backup/recursive-type/src/data-structures/index.ts +15 -0
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +42 -0
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +56 -0
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +15 -0
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +13 -0
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +3 -0
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +490 -0
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/backup/recursive-type/src/data-structures/matrix/index.ts +4 -0
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +27 -0
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +208 -0
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +122 -0
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +316 -0
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +354 -0
- package/backup/recursive-type/src/data-structures/queue/deque.ts +251 -0
- package/backup/recursive-type/src/data-structures/queue/index.ts +2 -0
- package/backup/recursive-type/src/data-structures/queue/queue.ts +120 -0
- package/backup/recursive-type/src/data-structures/stack/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/stack/stack.ts +98 -0
- package/backup/recursive-type/src/data-structures/tree/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/tree/tree.ts +80 -0
- package/backup/recursive-type/src/data-structures/trie/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/trie/trie.ts +227 -0
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +5 -0
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +8 -0
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +10 -0
- package/backup/recursive-type/src/data-structures/types/bst.ts +6 -0
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +8 -0
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/heap.ts +5 -0
- package/backup/recursive-type/src/data-structures/types/index.ts +12 -0
- package/backup/recursive-type/src/data-structures/types/navigator.ts +13 -0
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +9 -0
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +1 -0
- package/backup/recursive-type/src/index.ts +1 -0
- package/backup/recursive-type/src/utils/index.ts +2 -0
- package/backup/recursive-type/src/utils/types/index.ts +1 -0
- package/backup/recursive-type/src/utils/types/utils.ts +6 -0
- package/backup/recursive-type/src/utils/utils.ts +78 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/avl-tree.js +12 -20
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +10 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +135 -161
- package/dist/data-structures/binary-tree/binary-tree.js +192 -164
- package/dist/data-structures/binary-tree/bst.d.ts +21 -21
- package/dist/data-structures/binary-tree/bst.js +33 -36
- package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
- package/dist/data-structures/binary-tree/rb-tree.js +68 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -39
- package/dist/data-structures/binary-tree/segment-tree.js +34 -47
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
- package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
- package/dist/data-structures/graph/abstract-graph.d.ts +56 -71
- package/dist/data-structures/graph/abstract-graph.js +87 -92
- package/dist/data-structures/graph/directed-graph.d.ts +128 -105
- package/dist/data-structures/graph/directed-graph.js +161 -121
- package/dist/data-structures/graph/undirected-graph.d.ts +81 -62
- package/dist/data-structures/graph/undirected-graph.js +99 -78
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -5
- package/dist/data-structures/hash/coordinate-map.js +3 -9
- package/dist/data-structures/hash/coordinate-set.d.ts +2 -6
- package/dist/data-structures/hash/coordinate-set.js +3 -9
- package/dist/data-structures/hash/hash-table.d.ts +2 -1
- package/dist/data-structures/hash/hash-table.js +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -1
- package/dist/data-structures/hash/pair.js +7 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -1
- package/dist/data-structures/hash/tree-map.js +7 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -1
- package/dist/data-structures/hash/tree-set.js +7 -0
- package/dist/data-structures/heap/heap.d.ts +0 -14
- package/dist/data-structures/heap/heap.js +3 -27
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
- package/dist/data-structures/interfaces/abstract-graph.js +2 -0
- package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
- package/dist/data-structures/interfaces/avl-tree.js +2 -0
- package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
- package/dist/data-structures/interfaces/binary-tree.js +2 -0
- package/dist/data-structures/interfaces/bst.d.ts +1 -0
- package/dist/data-structures/interfaces/bst.js +2 -0
- package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
- package/dist/data-structures/interfaces/directed-graph.js +2 -0
- package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
- package/dist/data-structures/interfaces/heap.d.ts +1 -0
- package/dist/data-structures/interfaces/heap.js +2 -0
- package/dist/data-structures/interfaces/index.d.ts +13 -0
- package/dist/data-structures/interfaces/index.js +29 -0
- package/dist/data-structures/interfaces/navigator.d.ts +1 -0
- package/dist/data-structures/interfaces/navigator.js +2 -0
- package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
- package/dist/data-structures/interfaces/priority-queue.js +2 -0
- package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
- package/dist/data-structures/interfaces/segment-tree.js +2 -0
- package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
- package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
- package/dist/data-structures/interfaces/tree-multiset.js +2 -0
- package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
- package/dist/data-structures/interfaces/undirected-graph.js +2 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -3
- package/dist/data-structures/linked-list/doubly-linked-list.js +12 -18
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +12 -15
- package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +4 -4
- package/dist/data-structures/queue/deque.d.ts +5 -5
- package/dist/data-structures/queue/deque.js +6 -6
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/tree/tree.d.ts +12 -4
- package/dist/data-structures/tree/tree.js +44 -12
- package/dist/data-structures/trie/trie.d.ts +3 -3
- package/dist/data-structures/trie/trie.js +10 -10
- package/dist/data-structures/types/abstract-graph.d.ts +1 -20
- package/dist/data-structures/types/avl-tree.d.ts +5 -4
- package/dist/data-structures/types/binary-tree.d.ts +6 -5
- package/dist/data-structures/types/bst.d.ts +4 -3
- package/dist/data-structures/types/directed-graph.d.ts +5 -9
- package/dist/data-structures/types/directed-graph.js +7 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -1
- package/dist/data-structures/types/heap.d.ts +2 -2
- package/dist/data-structures/types/index.d.ts +0 -1
- package/dist/data-structures/types/index.js +0 -1
- package/dist/data-structures/types/navigator.d.ts +2 -2
- package/dist/data-structures/types/priority-queue.d.ts +2 -2
- package/dist/data-structures/types/tree-multiset.d.ts +3 -4
- package/docs/assets/search.js +1 -1
- package/docs/classes/AVLTree.html +552 -405
- package/docs/classes/AVLTreeNode.html +107 -242
- package/docs/classes/AaTree.html +18 -13
- package/docs/classes/AbstractEdge.html +77 -68
- package/docs/classes/AbstractGraph.html +223 -115
- package/docs/classes/AbstractVertex.html +71 -45
- package/docs/classes/ArrayDeque.html +31 -26
- package/docs/classes/BST.html +543 -391
- package/docs/classes/BSTNode.html +107 -236
- package/docs/classes/BTree.html +18 -13
- package/docs/classes/BinaryIndexedTree.html +56 -21
- package/docs/classes/BinaryTree.html +564 -355
- package/docs/classes/BinaryTreeNode.html +146 -199
- package/docs/classes/Character.html +21 -16
- package/docs/classes/CoordinateMap.html +49 -52
- package/docs/classes/CoordinateSet.html +50 -53
- package/docs/classes/Deque.html +51 -68
- package/docs/classes/DirectedEdge.html +98 -103
- package/docs/classes/DirectedGraph.html +449 -210
- package/docs/classes/DirectedVertex.html +63 -52
- package/docs/classes/DoublyLinkedList.html +56 -71
- package/docs/classes/DoublyLinkedListNode.html +28 -23
- package/docs/classes/HashTable.html +155 -0
- package/docs/classes/Heap.html +33 -109
- package/docs/classes/HeapItem.html +25 -20
- package/docs/classes/Matrix2D.html +33 -28
- package/docs/classes/MatrixNTI2D.html +21 -16
- package/docs/classes/MaxHeap.html +33 -114
- package/docs/classes/MaxPriorityQueue.html +71 -61
- package/docs/classes/MinHeap.html +33 -114
- package/docs/classes/MinPriorityQueue.html +71 -61
- package/docs/classes/Navigator.html +28 -23
- package/docs/classes/ObjectDeque.html +66 -51
- package/docs/classes/{RBTree.html → Pair.html} +25 -20
- package/docs/classes/PriorityQueue.html +66 -56
- package/docs/classes/Queue.html +33 -28
- package/docs/classes/SegmentTree.html +129 -57
- package/docs/classes/SegmentTreeNode.html +62 -140
- package/docs/classes/SinglyLinkedList.html +53 -58
- package/docs/classes/SinglyLinkedListNode.html +25 -20
- package/docs/classes/SkipLinkedList.html +18 -13
- package/docs/classes/SplayTree.html +18 -13
- package/docs/classes/Stack.html +31 -26
- package/docs/classes/TreeMap.html +155 -0
- package/docs/classes/TreeMultiSet.html +541 -388
- package/docs/classes/TreeNode.html +125 -35
- package/docs/classes/TreeSet.html +155 -0
- package/docs/classes/Trie.html +30 -25
- package/docs/classes/TrieNode.html +33 -28
- package/docs/classes/TwoThreeTree.html +18 -13
- package/docs/classes/UndirectedEdge.html +87 -80
- package/docs/classes/UndirectedGraph.html +356 -178
- package/docs/classes/UndirectedVertex.html +63 -52
- package/docs/classes/Vector2D.html +45 -40
- package/docs/enums/CP.html +21 -16
- package/docs/enums/FamilyPosition.html +21 -16
- package/docs/enums/LoopType.html +20 -15
- package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +47 -44
- package/docs/index.html +203 -69
- package/docs/interfaces/{PriorityQueueOptions.html → IBinaryTree.html} +49 -40
- package/docs/interfaces/IBinaryTreeNode.html +383 -0
- package/docs/interfaces/IDirectedGraph.html +24 -19
- package/docs/interfaces/IGraph.html +122 -89
- package/docs/interfaces/{HeapOptions.html → IUNDirectedGraph.html} +26 -53
- package/docs/modules.html +33 -23
- package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +31 -22
- package/docs/types/BSTComparator.html +18 -13
- package/docs/types/BSTDeletedResult.html +23 -18
- package/docs/types/BinaryTreeDeleted.html +23 -18
- package/docs/types/BinaryTreeNodeId.html +18 -13
- package/docs/types/BinaryTreeNodePropertyName.html +18 -13
- package/docs/types/DFSOrderPattern.html +18 -13
- package/docs/types/DijkstraResult.html +18 -13
- package/docs/types/Direction.html +18 -13
- package/docs/types/{DoublyLinkedListGetBy.html → EdgeId.html} +22 -17
- package/docs/types/{TrlFn.html → HeapOptions.html} +33 -20
- package/docs/types/{TrlAsyncFn.html → NavigatorParams.html} +46 -20
- package/docs/types/NodeOrPropertyName.html +18 -13
- package/docs/types/PriorityQueueComparator.html +18 -13
- package/docs/types/PriorityQueueDFSOrderPattern.html +18 -13
- package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +32 -20
- package/docs/types/RecursiveAVLTreeNode.html +135 -0
- package/docs/types/RecursiveBSTNode.html +135 -0
- package/docs/types/RecursiveBinaryTreeNode.html +135 -0
- package/docs/types/ResultByProperty.html +21 -16
- package/docs/types/ResultsByProperty.html +21 -16
- package/docs/types/SegmentTreeNodeVal.html +18 -13
- package/docs/types/TopologicalStatus.html +18 -13
- package/docs/types/TreeMultiSetDeletedResult.html +23 -18
- package/docs/types/Turning.html +18 -13
- package/docs/types/VertexId.html +18 -13
- package/notes/note.md +12 -1
- package/package.json +11 -3
- package/tsconfig.json +2 -2
- package/docs/interfaces/NavigatorParams.html +0 -197
- package/docs/types/Thunk.html +0 -133
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult } from '../types';
|
|
8
|
+
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult, RecursiveBSTNode } from '../types';
|
|
9
9
|
import { BinaryTree, BinaryTreeNode, LoopType } from './binary-tree';
|
|
10
|
+
import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
|
|
10
11
|
export declare enum CP {
|
|
11
12
|
lt = -1,
|
|
12
13
|
eq = 0,
|
|
13
14
|
gt = 1
|
|
14
15
|
}
|
|
15
|
-
export declare class BSTNode<T> extends BinaryTreeNode<T> {
|
|
16
|
-
clone(): BSTNode<T>;
|
|
16
|
+
export declare class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
|
|
17
17
|
}
|
|
18
|
-
export declare class BST<
|
|
18
|
+
export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBinaryTree<N> {
|
|
19
19
|
/**
|
|
20
20
|
* The constructor function accepts an optional options object and sets the comparator property if provided.
|
|
21
21
|
* @param [options] - An optional object that can contain the following properties:
|
|
@@ -24,30 +24,30 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
24
24
|
comparator?: BSTComparator;
|
|
25
25
|
loopType?: LoopType;
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
_createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
28
28
|
/**
|
|
29
29
|
* The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
|
|
30
30
|
* the ID matches, and returns the inserted node.
|
|
31
31
|
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
|
|
32
32
|
* determine the position of the node in the binary search tree.
|
|
33
|
-
* @param {
|
|
34
|
-
* be of type `
|
|
33
|
+
* @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
|
|
34
|
+
* be of type `N` (the generic type) or `null`.
|
|
35
35
|
* @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
|
|
36
36
|
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
|
|
37
37
|
* inserted once.
|
|
38
|
-
* @returns The method `add` returns a `
|
|
38
|
+
* @returns The method `add` returns a `N` object or `null`.
|
|
39
39
|
*/
|
|
40
|
-
add(id: BinaryTreeNodeId, val:
|
|
40
|
+
add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
41
41
|
/**
|
|
42
42
|
* The `get` function returns the first node in a binary search tree that matches the given property value or name.
|
|
43
|
-
* @param {BinaryTreeNodeId |
|
|
44
|
-
* generic type `
|
|
43
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
44
|
+
* generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
|
|
45
45
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
46
46
|
* specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
|
|
47
47
|
* `'id'`.
|
|
48
|
-
* @returns The method is returning a
|
|
48
|
+
* @returns The method is returning a N object or null.
|
|
49
49
|
*/
|
|
50
|
-
get(nodeProperty: BinaryTreeNodeId |
|
|
50
|
+
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
51
51
|
/**
|
|
52
52
|
* The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
|
|
53
53
|
* leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
|
|
@@ -65,23 +65,23 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
65
65
|
* @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
|
|
66
66
|
* set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
|
|
67
67
|
* set to false or not provided, the count of the node will be taken into account and the
|
|
68
|
-
* @returns an array of `BSTDeletedResult<
|
|
68
|
+
* @returns an array of `BSTDeletedResult<N>` objects.
|
|
69
69
|
*/
|
|
70
|
-
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<
|
|
70
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<N>[];
|
|
71
71
|
/**
|
|
72
72
|
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
|
|
73
73
|
* option to specify the property name and whether to return only one node.
|
|
74
|
-
* @param {BinaryTreeNodeId |
|
|
75
|
-
* generic type `
|
|
74
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
75
|
+
* generic type `N`. It represents the property value that you want to search for in the binary search tree.
|
|
76
76
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
77
77
|
* specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
|
|
78
78
|
* `'id'`.
|
|
79
79
|
* @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
|
|
80
80
|
* nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
|
|
81
81
|
* to false or not provided, the function will return all nodes that match the given nodeProperty.
|
|
82
|
-
* @returns an array of
|
|
82
|
+
* @returns an array of N objects.
|
|
83
83
|
*/
|
|
84
|
-
getNodes(nodeProperty: BinaryTreeNodeId |
|
|
84
|
+
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
85
85
|
/**
|
|
86
86
|
* The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in
|
|
87
87
|
* a binary search tree.
|
|
@@ -96,7 +96,7 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
96
96
|
/**
|
|
97
97
|
* The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
|
|
98
98
|
* that have a greater value than a given node.
|
|
99
|
-
* @param node - The `node` parameter is of type `
|
|
99
|
+
* @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
|
|
100
100
|
* contains properties such as `id` and `count`.
|
|
101
101
|
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
102
102
|
* each node should be increased.
|
|
@@ -105,7 +105,7 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
105
105
|
* defaults to 'id'.
|
|
106
106
|
* @returns a boolean value.
|
|
107
107
|
*/
|
|
108
|
-
allGreaterNodesAdd(node:
|
|
108
|
+
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
109
109
|
/**
|
|
110
110
|
* The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a
|
|
111
111
|
* recursive or iterative approach.
|
|
@@ -38,15 +38,12 @@ var CP;
|
|
|
38
38
|
CP[CP["lt"] = -1] = "lt";
|
|
39
39
|
CP[CP["eq"] = 0] = "eq";
|
|
40
40
|
CP[CP["gt"] = 1] = "gt";
|
|
41
|
-
})(CP
|
|
41
|
+
})(CP || (exports.CP = CP = {}));
|
|
42
42
|
var BSTNode = /** @class */ (function (_super) {
|
|
43
43
|
__extends(BSTNode, _super);
|
|
44
44
|
function BSTNode() {
|
|
45
45
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
46
46
|
}
|
|
47
|
-
BSTNode.prototype.clone = function () {
|
|
48
|
-
return new BSTNode(this.id, this.val, this.count);
|
|
49
|
-
};
|
|
50
47
|
return BSTNode;
|
|
51
48
|
}(binary_tree_1.BinaryTreeNode));
|
|
52
49
|
exports.BSTNode = BSTNode;
|
|
@@ -67,30 +64,30 @@ var BST = /** @class */ (function (_super) {
|
|
|
67
64
|
}
|
|
68
65
|
return _this;
|
|
69
66
|
}
|
|
70
|
-
BST.prototype.
|
|
71
|
-
|
|
67
|
+
BST.prototype._createNode = function (id, val, count) {
|
|
68
|
+
var node = val !== null ? new BSTNode(id, val, count) : null;
|
|
69
|
+
return node;
|
|
72
70
|
};
|
|
73
71
|
/**
|
|
74
72
|
* The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
|
|
75
73
|
* the ID matches, and returns the inserted node.
|
|
76
74
|
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
|
|
77
75
|
* determine the position of the node in the binary search tree.
|
|
78
|
-
* @param {
|
|
79
|
-
* be of type `
|
|
76
|
+
* @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
|
|
77
|
+
* be of type `N` (the generic type) or `null`.
|
|
80
78
|
* @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
|
|
81
79
|
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
|
|
82
80
|
* inserted once.
|
|
83
|
-
* @returns The method `add` returns a `
|
|
81
|
+
* @returns The method `add` returns a `N` object or `null`.
|
|
84
82
|
*/
|
|
85
83
|
BST.prototype.add = function (id, val, count) {
|
|
86
|
-
var _a;
|
|
87
84
|
if (count === void 0) { count = 1; }
|
|
88
85
|
var inserted = null;
|
|
89
|
-
var newNode = this.
|
|
86
|
+
var newNode = this._createNode(id, val, count);
|
|
90
87
|
if (this.root === null) {
|
|
91
|
-
this.
|
|
92
|
-
this.size
|
|
93
|
-
this.count
|
|
88
|
+
this._setRoot(newNode);
|
|
89
|
+
this._setSize(this.size + 1);
|
|
90
|
+
this._setCount(this.count + count);
|
|
94
91
|
inserted = (this.root);
|
|
95
92
|
}
|
|
96
93
|
else {
|
|
@@ -101,7 +98,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
101
98
|
if (this._compare(cur.id, id) === CP.eq) {
|
|
102
99
|
if (newNode) {
|
|
103
100
|
cur.count += newNode.count;
|
|
104
|
-
this.count
|
|
101
|
+
this._setCount(this.count + newNode.count);
|
|
105
102
|
cur.val = newNode.val;
|
|
106
103
|
}
|
|
107
104
|
//Duplicates are not accepted.
|
|
@@ -117,8 +114,8 @@ var BST = /** @class */ (function (_super) {
|
|
|
117
114
|
}
|
|
118
115
|
//Add to the left of the current node
|
|
119
116
|
cur.left = newNode;
|
|
120
|
-
this.size
|
|
121
|
-
this.count
|
|
117
|
+
this._setSize(this.size + 1);
|
|
118
|
+
this._setCount(this.count + newNode.count);
|
|
122
119
|
traversing = false;
|
|
123
120
|
inserted = cur.left;
|
|
124
121
|
}
|
|
@@ -137,8 +134,8 @@ var BST = /** @class */ (function (_super) {
|
|
|
137
134
|
}
|
|
138
135
|
//Add to the right of the current node
|
|
139
136
|
cur.right = newNode;
|
|
140
|
-
this.size
|
|
141
|
-
this.count
|
|
137
|
+
this._setSize(this.size + 1);
|
|
138
|
+
this._setCount(this.count + newNode.count);
|
|
142
139
|
traversing = false;
|
|
143
140
|
inserted = (cur.right);
|
|
144
141
|
}
|
|
@@ -158,12 +155,12 @@ var BST = /** @class */ (function (_super) {
|
|
|
158
155
|
};
|
|
159
156
|
/**
|
|
160
157
|
* The `get` function returns the first node in a binary search tree that matches the given property value or name.
|
|
161
|
-
* @param {BinaryTreeNodeId |
|
|
162
|
-
* generic type `
|
|
158
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
159
|
+
* generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
|
|
163
160
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
164
161
|
* specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
|
|
165
162
|
* `'id'`.
|
|
166
|
-
* @returns The method is returning a
|
|
163
|
+
* @returns The method is returning a N object or null.
|
|
167
164
|
*/
|
|
168
165
|
BST.prototype.get = function (nodeProperty, propertyName) {
|
|
169
166
|
var _a;
|
|
@@ -195,7 +192,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
195
192
|
* @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
|
|
196
193
|
* set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
|
|
197
194
|
* set to false or not provided, the count of the node will be taken into account and the
|
|
198
|
-
* @returns an array of `BSTDeletedResult<
|
|
195
|
+
* @returns an array of `BSTDeletedResult<N>` objects.
|
|
199
196
|
*/
|
|
200
197
|
BST.prototype.remove = function (id, ignoreCount) {
|
|
201
198
|
var bstDeletedResult = [];
|
|
@@ -208,13 +205,13 @@ var BST = /** @class */ (function (_super) {
|
|
|
208
205
|
var needBalanced = null, orgCurrent = curr;
|
|
209
206
|
if (curr.count > 1 && !ignoreCount) {
|
|
210
207
|
curr.count--;
|
|
211
|
-
this.count
|
|
208
|
+
this._setCount(this.count - 1);
|
|
212
209
|
}
|
|
213
210
|
else {
|
|
214
211
|
if (!curr.left) {
|
|
215
212
|
if (!parent) {
|
|
216
213
|
if (curr.right !== undefined)
|
|
217
|
-
this.
|
|
214
|
+
this._setRoot(curr.right);
|
|
218
215
|
}
|
|
219
216
|
else {
|
|
220
217
|
switch (curr.familyPosition) {
|
|
@@ -242,8 +239,8 @@ var BST = /** @class */ (function (_super) {
|
|
|
242
239
|
}
|
|
243
240
|
}
|
|
244
241
|
}
|
|
245
|
-
this.size
|
|
246
|
-
this.count
|
|
242
|
+
this._setSize(this.size - 1);
|
|
243
|
+
this._setCount(this.count - curr.count);
|
|
247
244
|
}
|
|
248
245
|
bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
|
|
249
246
|
return bstDeletedResult;
|
|
@@ -251,15 +248,15 @@ var BST = /** @class */ (function (_super) {
|
|
|
251
248
|
/**
|
|
252
249
|
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
|
|
253
250
|
* option to specify the property name and whether to return only one node.
|
|
254
|
-
* @param {BinaryTreeNodeId |
|
|
255
|
-
* generic type `
|
|
251
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
252
|
+
* generic type `N`. It represents the property value that you want to search for in the binary search tree.
|
|
256
253
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
257
254
|
* specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
|
|
258
255
|
* `'id'`.
|
|
259
256
|
* @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
|
|
260
257
|
* nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
|
|
261
258
|
* to false or not provided, the function will return all nodes that match the given nodeProperty.
|
|
262
|
-
* @returns an array of
|
|
259
|
+
* @returns an array of N objects.
|
|
263
260
|
*/
|
|
264
261
|
BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
|
|
265
262
|
var _this = this;
|
|
@@ -267,7 +264,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
267
264
|
if (!this.root)
|
|
268
265
|
return [];
|
|
269
266
|
var result = [];
|
|
270
|
-
if (this.
|
|
267
|
+
if (this.loopType === binary_tree_1.LoopType.recursive) {
|
|
271
268
|
var _traverse_1 = function (cur) {
|
|
272
269
|
if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
|
|
273
270
|
return;
|
|
@@ -340,7 +337,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
340
337
|
return needSum;
|
|
341
338
|
};
|
|
342
339
|
var sum = 0;
|
|
343
|
-
if (this.
|
|
340
|
+
if (this.loopType === binary_tree_1.LoopType.recursive) {
|
|
344
341
|
var _traverse_2 = function (cur) {
|
|
345
342
|
var compared = _this._compare(cur.id, id);
|
|
346
343
|
if (compared === CP.eq) {
|
|
@@ -400,7 +397,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
400
397
|
/**
|
|
401
398
|
* The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
|
|
402
399
|
* that have a greater value than a given node.
|
|
403
|
-
* @param node - The `node` parameter is of type `
|
|
400
|
+
* @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
|
|
404
401
|
* contains properties such as `id` and `count`.
|
|
405
402
|
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
406
403
|
* each node should be increased.
|
|
@@ -427,7 +424,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
427
424
|
break;
|
|
428
425
|
}
|
|
429
426
|
};
|
|
430
|
-
if (this.
|
|
427
|
+
if (this.loopType === binary_tree_1.LoopType.recursive) {
|
|
431
428
|
var _traverse_3 = function (cur) {
|
|
432
429
|
var compared = _this._compare(cur.id, node.id);
|
|
433
430
|
_sumByPropertyName(cur);
|
|
@@ -468,7 +465,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
468
465
|
this.clear();
|
|
469
466
|
if (sorted.length < 1)
|
|
470
467
|
return false;
|
|
471
|
-
if (this.
|
|
468
|
+
if (this.loopType === binary_tree_1.LoopType.recursive) {
|
|
472
469
|
var buildBalanceBST_1 = function (l, r) {
|
|
473
470
|
if (l > r)
|
|
474
471
|
return;
|
|
@@ -509,7 +506,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
509
506
|
if (!this.root)
|
|
510
507
|
return true;
|
|
511
508
|
var balanced = true;
|
|
512
|
-
if (this.
|
|
509
|
+
if (this.loopType === binary_tree_1.LoopType.recursive) {
|
|
513
510
|
var _height_1 = function (cur) {
|
|
514
511
|
if (!cur)
|
|
515
512
|
return 0;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
18
|
+
var binary_tree_1 = require("./binary-tree");
|
|
19
|
+
var RBColor;
|
|
20
|
+
(function (RBColor) {
|
|
21
|
+
RBColor[RBColor["Red"] = 0] = "Red";
|
|
22
|
+
RBColor[RBColor["Black"] = 1] = "Black";
|
|
23
|
+
})(RBColor || (RBColor = {}));
|
|
24
|
+
var RBNode = /** @class */ (function (_super) {
|
|
25
|
+
__extends(RBNode, _super);
|
|
26
|
+
// override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
|
|
27
|
+
// return val !== null ? new RBNode<T>(id, val, count) : null;
|
|
28
|
+
// }
|
|
29
|
+
function RBNode(id, val, count) {
|
|
30
|
+
var _this = _super.call(this, id, val, count) || this;
|
|
31
|
+
_this._color = RBColor.Red;
|
|
32
|
+
return _this;
|
|
6
33
|
}
|
|
34
|
+
Object.defineProperty(RBNode.prototype, "color", {
|
|
35
|
+
get: function () {
|
|
36
|
+
return this._color;
|
|
37
|
+
},
|
|
38
|
+
set: function (value) {
|
|
39
|
+
this._color = value;
|
|
40
|
+
},
|
|
41
|
+
enumerable: false,
|
|
42
|
+
configurable: true
|
|
43
|
+
});
|
|
44
|
+
return RBNode;
|
|
45
|
+
}(binary_tree_1.BinaryTreeNode));
|
|
46
|
+
var RBTree = /** @class */ (function (_super) {
|
|
47
|
+
__extends(RBTree, _super);
|
|
48
|
+
function RBTree(options) {
|
|
49
|
+
return _super.call(this, options) || this;
|
|
50
|
+
}
|
|
51
|
+
// override _createNode(id: BinaryTreeNodeId, val: N | null, count?: number): RBNode<N> | null {
|
|
52
|
+
// return val !== null ? new RBNode<N>(id, val, count) : null;
|
|
53
|
+
// }
|
|
54
|
+
// private override _root: BinaryTreeNode<N> | null = null;
|
|
55
|
+
//
|
|
56
|
+
// override get root(): BinaryTreeNode<N> | null {
|
|
57
|
+
// return this._root;
|
|
58
|
+
// }
|
|
59
|
+
RBTree.prototype.insert = function (id, val) {
|
|
60
|
+
};
|
|
61
|
+
RBTree.prototype.leftRotate = function (node) {
|
|
62
|
+
};
|
|
63
|
+
RBTree.prototype.rightRotate = function (node) {
|
|
64
|
+
};
|
|
65
|
+
RBTree.prototype.insertFixup = function (node) {
|
|
66
|
+
};
|
|
67
|
+
RBTree.prototype.deleteFixup = function (node) {
|
|
68
|
+
};
|
|
69
|
+
RBTree.prototype.transplant = function (u, v) {
|
|
70
|
+
};
|
|
7
71
|
return RBTree;
|
|
8
|
-
}());
|
|
9
|
-
exports.RBTree = RBTree;
|
|
72
|
+
}(binary_tree_1.BinaryTree));
|
|
@@ -8,53 +8,26 @@
|
|
|
8
8
|
import type { SegmentTreeNodeVal } from '../types';
|
|
9
9
|
export declare class SegmentTreeNode {
|
|
10
10
|
constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null);
|
|
11
|
-
|
|
11
|
+
private _start;
|
|
12
12
|
get start(): number;
|
|
13
13
|
set start(v: number);
|
|
14
|
-
|
|
14
|
+
private _end;
|
|
15
15
|
get end(): number;
|
|
16
16
|
set end(v: number);
|
|
17
|
-
|
|
17
|
+
private _val;
|
|
18
18
|
get val(): SegmentTreeNodeVal | null;
|
|
19
19
|
set val(v: SegmentTreeNodeVal | null);
|
|
20
|
-
|
|
20
|
+
private _sum;
|
|
21
21
|
get sum(): number;
|
|
22
22
|
set sum(v: number);
|
|
23
|
-
|
|
23
|
+
private _left;
|
|
24
24
|
get left(): SegmentTreeNode | null;
|
|
25
25
|
set left(v: SegmentTreeNode | null);
|
|
26
|
-
|
|
26
|
+
private _right;
|
|
27
27
|
get right(): SegmentTreeNode | null;
|
|
28
28
|
set right(v: SegmentTreeNode | null);
|
|
29
|
-
/**
|
|
30
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
31
|
-
*/
|
|
32
|
-
getStart(): number;
|
|
33
|
-
/**
|
|
34
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
35
|
-
*/
|
|
36
|
-
getEnd(): number;
|
|
37
|
-
/**
|
|
38
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
39
|
-
*/
|
|
40
|
-
getVal(): SegmentTreeNodeVal | null;
|
|
41
|
-
/**
|
|
42
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
43
|
-
*/
|
|
44
|
-
getSum(): number;
|
|
45
|
-
/**
|
|
46
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
47
|
-
*/
|
|
48
|
-
getLeft(): SegmentTreeNode | null;
|
|
49
|
-
/**
|
|
50
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
51
|
-
*/
|
|
52
|
-
getRight(): SegmentTreeNode | null;
|
|
53
29
|
}
|
|
54
30
|
export declare class SegmentTree {
|
|
55
|
-
protected _values: number[];
|
|
56
|
-
protected _start: number;
|
|
57
|
-
protected _end: number;
|
|
58
31
|
/**
|
|
59
32
|
* The constructor initializes the values, start, end, and root properties of an object.
|
|
60
33
|
* @param {number[]} values - An array of numbers that will be used to build a binary search tree.
|
|
@@ -65,13 +38,14 @@ export declare class SegmentTree {
|
|
|
65
38
|
* included in the range. If not provided, it defaults to the index of the last element in the "values" array.
|
|
66
39
|
*/
|
|
67
40
|
constructor(values: number[], start?: number, end?: number);
|
|
68
|
-
|
|
41
|
+
private _values;
|
|
42
|
+
get values(): number[];
|
|
43
|
+
private _start;
|
|
44
|
+
get start(): number;
|
|
45
|
+
private _end;
|
|
46
|
+
get end(): number;
|
|
47
|
+
private _root;
|
|
69
48
|
get root(): SegmentTreeNode | null;
|
|
70
|
-
set root(v: SegmentTreeNode | null);
|
|
71
|
-
/**
|
|
72
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
73
|
-
*/
|
|
74
|
-
getRoot(): SegmentTreeNode | null;
|
|
75
49
|
/**
|
|
76
50
|
* The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
|
|
77
51
|
* for each segment.
|
|
@@ -102,4 +76,8 @@ export declare class SegmentTree {
|
|
|
102
76
|
* @returns The function `querySumByRange` returns a number.
|
|
103
77
|
*/
|
|
104
78
|
querySumByRange(indexA: number, indexB: number): number;
|
|
79
|
+
protected _setValues(value: number[]): void;
|
|
80
|
+
protected _setStart(value: number): void;
|
|
81
|
+
protected _setEnd(value: number): void;
|
|
82
|
+
protected _setRoot(v: SegmentTreeNode | null): void;
|
|
105
83
|
}
|
|
@@ -81,42 +81,6 @@ var SegmentTreeNode = /** @class */ (function () {
|
|
|
81
81
|
enumerable: false,
|
|
82
82
|
configurable: true
|
|
83
83
|
});
|
|
84
|
-
/**
|
|
85
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
86
|
-
*/
|
|
87
|
-
SegmentTreeNode.prototype.getStart = function () {
|
|
88
|
-
return this._start;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
92
|
-
*/
|
|
93
|
-
SegmentTreeNode.prototype.getEnd = function () {
|
|
94
|
-
return this._end;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
98
|
-
*/
|
|
99
|
-
SegmentTreeNode.prototype.getVal = function () {
|
|
100
|
-
return this._val;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
104
|
-
*/
|
|
105
|
-
SegmentTreeNode.prototype.getSum = function () {
|
|
106
|
-
return this._sum;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
110
|
-
*/
|
|
111
|
-
SegmentTreeNode.prototype.getLeft = function () {
|
|
112
|
-
return this._left;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
116
|
-
*/
|
|
117
|
-
SegmentTreeNode.prototype.getRight = function () {
|
|
118
|
-
return this._right;
|
|
119
|
-
};
|
|
120
84
|
return SegmentTreeNode;
|
|
121
85
|
}());
|
|
122
86
|
exports.SegmentTreeNode = SegmentTreeNode;
|
|
@@ -140,22 +104,34 @@ var SegmentTree = /** @class */ (function () {
|
|
|
140
104
|
this._end = end;
|
|
141
105
|
this._root = this.build(start, end);
|
|
142
106
|
}
|
|
107
|
+
Object.defineProperty(SegmentTree.prototype, "values", {
|
|
108
|
+
get: function () {
|
|
109
|
+
return this._values;
|
|
110
|
+
},
|
|
111
|
+
enumerable: false,
|
|
112
|
+
configurable: true
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(SegmentTree.prototype, "start", {
|
|
115
|
+
get: function () {
|
|
116
|
+
return this._start;
|
|
117
|
+
},
|
|
118
|
+
enumerable: false,
|
|
119
|
+
configurable: true
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(SegmentTree.prototype, "end", {
|
|
122
|
+
get: function () {
|
|
123
|
+
return this._end;
|
|
124
|
+
},
|
|
125
|
+
enumerable: false,
|
|
126
|
+
configurable: true
|
|
127
|
+
});
|
|
143
128
|
Object.defineProperty(SegmentTree.prototype, "root", {
|
|
144
129
|
get: function () {
|
|
145
130
|
return this._root;
|
|
146
131
|
},
|
|
147
|
-
set: function (v) {
|
|
148
|
-
this._root = v;
|
|
149
|
-
},
|
|
150
132
|
enumerable: false,
|
|
151
133
|
configurable: true
|
|
152
134
|
});
|
|
153
|
-
/**
|
|
154
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
155
|
-
*/
|
|
156
|
-
SegmentTree.prototype.getRoot = function () {
|
|
157
|
-
return this._root;
|
|
158
|
-
};
|
|
159
135
|
/**
|
|
160
136
|
* The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
|
|
161
137
|
* for each segment.
|
|
@@ -166,9 +142,8 @@ var SegmentTree = /** @class */ (function () {
|
|
|
166
142
|
* @returns a SegmentTreeNode object.
|
|
167
143
|
*/
|
|
168
144
|
SegmentTree.prototype.build = function (start, end) {
|
|
169
|
-
if (start === end)
|
|
145
|
+
if (start === end)
|
|
170
146
|
return new SegmentTreeNode(start, end, this._values[start]);
|
|
171
|
-
}
|
|
172
147
|
var mid = start + Math.floor((end - start) / 2);
|
|
173
148
|
var left = this.build(start, mid);
|
|
174
149
|
var right = this.build(mid + 1, end);
|
|
@@ -264,6 +239,18 @@ var SegmentTree = /** @class */ (function () {
|
|
|
264
239
|
};
|
|
265
240
|
return dfs(root, indexA, indexB);
|
|
266
241
|
};
|
|
242
|
+
SegmentTree.prototype._setValues = function (value) {
|
|
243
|
+
this._values = value;
|
|
244
|
+
};
|
|
245
|
+
SegmentTree.prototype._setStart = function (value) {
|
|
246
|
+
this._start = value;
|
|
247
|
+
};
|
|
248
|
+
SegmentTree.prototype._setEnd = function (value) {
|
|
249
|
+
this._end = value;
|
|
250
|
+
};
|
|
251
|
+
SegmentTree.prototype._setRoot = function (v) {
|
|
252
|
+
this._root = v;
|
|
253
|
+
};
|
|
267
254
|
return SegmentTree;
|
|
268
255
|
}());
|
|
269
256
|
exports.SegmentTree = SegmentTree;
|
|
@@ -7,27 +7,28 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
9
|
import type { BinaryTreeNodeId, TreeMultiSetDeletedResult } from '../types';
|
|
10
|
-
|
|
10
|
+
import { IBinaryTree } from '../interfaces';
|
|
11
|
+
export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BST<N> implements IBinaryTree<N> {
|
|
11
12
|
/**
|
|
12
13
|
* The function creates a new BSTNode with the given id, value, and count.
|
|
13
14
|
* @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
|
|
14
15
|
* distinguish one node from another in the tree.
|
|
15
|
-
* @param {
|
|
16
|
+
* @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
|
|
16
17
|
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
|
|
17
18
|
* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
|
|
18
19
|
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
_createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N;
|
|
21
22
|
/**
|
|
22
23
|
* The function overrides the add method of the BinarySearchTree class in TypeScript.
|
|
23
24
|
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
|
|
24
|
-
* @param {
|
|
25
|
-
* can be of type `
|
|
25
|
+
* @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
|
|
26
|
+
* can be of type `N` (the generic type) or `null`.
|
|
26
27
|
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
27
28
|
* of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
|
|
28
|
-
* @returns The `add` method is returning a `BSTNode<
|
|
29
|
+
* @returns The `add` method is returning a `BSTNode<N>` object or `null`.
|
|
29
30
|
*/
|
|
30
|
-
add(id: BinaryTreeNodeId, val:
|
|
31
|
+
add(id: BinaryTreeNodeId, val: N | null, count?: number): N | null;
|
|
31
32
|
/**
|
|
32
33
|
* The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
|
|
33
34
|
* method.
|
|
@@ -38,5 +39,5 @@ export declare class TreeMultiSet<T> extends BST<T> {
|
|
|
38
39
|
* set to `true`, the left sum of all nodes will be recalculated. If it
|
|
39
40
|
* @returns The method is returning an array of TreeMultiSetDeletedResult objects.
|
|
40
41
|
*/
|
|
41
|
-
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<
|
|
42
|
+
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<N>[];
|
|
42
43
|
}
|