tree-multimap-typed 2.1.2 → 2.2.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/dist/cjs/index.cjs +424 -184
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +4300 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +424 -184
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +4289 -0
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +65 -3
- package/dist/umd/tree-multimap-typed.js +259 -17
- package/dist/umd/tree-multimap-typed.js.map +1 -1
- package/dist/umd/tree-multimap-typed.min.js +3 -3
- package/dist/umd/tree-multimap-typed.min.js.map +1 -1
- package/package.json +20 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +102 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +115 -11
- package/src/data-structures/binary-tree/avl-tree.ts +105 -14
- package/src/data-structures/binary-tree/bst.ts +102 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +108 -18
- package/src/data-structures/binary-tree/tree-counter.ts +101 -10
- package/src/data-structures/binary-tree/tree-multi-map.ts +122 -11
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/tsup.node.config.js +40 -6
|
@@ -5,16 +5,18 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { AVLTreeCounterOptions, BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType } from '../../types';
|
|
8
|
+
import type { AVLTreeCounterOptions, BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, FamilyPosition, IterationType, RBTNColor } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
|
-
import { AVLTree
|
|
10
|
+
import { AVLTree } from './avl-tree';
|
|
11
11
|
/**
|
|
12
12
|
* AVL node with an extra 'count' field; keeps parent/child links.
|
|
13
13
|
* @remarks Time O(1), Space O(1)
|
|
14
14
|
* @template K
|
|
15
15
|
* @template V
|
|
16
16
|
*/
|
|
17
|
-
export declare class AVLTreeCounterNode<K = any, V = any>
|
|
17
|
+
export declare class AVLTreeCounterNode<K = any, V = any> {
|
|
18
|
+
key: K;
|
|
19
|
+
value?: V;
|
|
18
20
|
parent?: AVLTreeCounterNode<K, V>;
|
|
19
21
|
/**
|
|
20
22
|
* Create an AVL counter node.
|
|
@@ -53,6 +55,58 @@ export declare class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K,
|
|
|
53
55
|
* @returns void
|
|
54
56
|
*/
|
|
55
57
|
set right(v: AVLTreeCounterNode<K, V> | null | undefined);
|
|
58
|
+
_height: number;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
61
|
+
* @remarks Time O(1), Space O(1)
|
|
62
|
+
*
|
|
63
|
+
* @returns The height.
|
|
64
|
+
*/
|
|
65
|
+
get height(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Sets the height of the node.
|
|
68
|
+
* @remarks Time O(1), Space O(1)
|
|
69
|
+
*
|
|
70
|
+
* @param value - The new height.
|
|
71
|
+
*/
|
|
72
|
+
set height(value: number);
|
|
73
|
+
_color: RBTNColor;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
76
|
+
* @remarks Time O(1), Space O(1)
|
|
77
|
+
*
|
|
78
|
+
* @returns The node's color.
|
|
79
|
+
*/
|
|
80
|
+
get color(): RBTNColor;
|
|
81
|
+
/**
|
|
82
|
+
* Sets the color of the node.
|
|
83
|
+
* @remarks Time O(1), Space O(1)
|
|
84
|
+
*
|
|
85
|
+
* @param value - The new color.
|
|
86
|
+
*/
|
|
87
|
+
set color(value: RBTNColor);
|
|
88
|
+
_count: number;
|
|
89
|
+
/**
|
|
90
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
91
|
+
* @remarks Time O(1), Space O(1)
|
|
92
|
+
*
|
|
93
|
+
* @returns The subtree node count.
|
|
94
|
+
*/
|
|
95
|
+
get count(): number;
|
|
96
|
+
/**
|
|
97
|
+
* Sets the count of nodes in the subtree.
|
|
98
|
+
* @remarks Time O(1), Space O(1)
|
|
99
|
+
*
|
|
100
|
+
* @param value - The new count.
|
|
101
|
+
*/
|
|
102
|
+
set count(value: number);
|
|
103
|
+
/**
|
|
104
|
+
* Gets the position of the node relative to its parent.
|
|
105
|
+
* @remarks Time O(1), Space O(1)
|
|
106
|
+
*
|
|
107
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
108
|
+
*/
|
|
109
|
+
get familyPosition(): FamilyPosition;
|
|
56
110
|
}
|
|
57
111
|
/**
|
|
58
112
|
* AVL tree that tracks an aggregate 'count' across nodes; supports balanced insert/delete and map-like mode.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { AVLTreeMultiMapOptions, AVLTreeOptions, ElemOf, EntryCallback, IterationType } from '../../types';
|
|
8
|
+
import type { AVLTreeMultiMapOptions, AVLTreeOptions, ElemOf, EntryCallback, FamilyPosition, IterationType, RBTNColor } from '../../types';
|
|
9
9
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
/**
|
|
@@ -14,7 +14,9 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
14
14
|
* @template K
|
|
15
15
|
* @template V
|
|
16
16
|
*/
|
|
17
|
-
export declare class AVLTreeMultiMapNode<K = any, V = any>
|
|
17
|
+
export declare class AVLTreeMultiMapNode<K = any, V = any> {
|
|
18
|
+
key: K;
|
|
19
|
+
value?: V[];
|
|
18
20
|
parent?: AVLTreeMultiMapNode<K, V>;
|
|
19
21
|
/**
|
|
20
22
|
* Create an AVLTreeMultiMap node with a value bucket.
|
|
@@ -23,7 +25,7 @@ export declare class AVLTreeMultiMapNode<K = any, V = any> extends AVLTreeNode<K
|
|
|
23
25
|
* @param value - Initial array of values.
|
|
24
26
|
* @returns New AVLTreeMultiMapNode instance.
|
|
25
27
|
*/
|
|
26
|
-
constructor(key: K, value
|
|
28
|
+
constructor(key: K, value?: V[]);
|
|
27
29
|
_left?: AVLTreeMultiMapNode<K, V> | null | undefined;
|
|
28
30
|
/**
|
|
29
31
|
* Get the left child pointer.
|
|
@@ -52,6 +54,58 @@ export declare class AVLTreeMultiMapNode<K = any, V = any> extends AVLTreeNode<K
|
|
|
52
54
|
* @returns void
|
|
53
55
|
*/
|
|
54
56
|
set right(v: AVLTreeMultiMapNode<K, V> | null | undefined);
|
|
57
|
+
_height: number;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
60
|
+
* @remarks Time O(1), Space O(1)
|
|
61
|
+
*
|
|
62
|
+
* @returns The height.
|
|
63
|
+
*/
|
|
64
|
+
get height(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the height of the node.
|
|
67
|
+
* @remarks Time O(1), Space O(1)
|
|
68
|
+
*
|
|
69
|
+
* @param value - The new height.
|
|
70
|
+
*/
|
|
71
|
+
set height(value: number);
|
|
72
|
+
_color: RBTNColor;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
75
|
+
* @remarks Time O(1), Space O(1)
|
|
76
|
+
*
|
|
77
|
+
* @returns The node's color.
|
|
78
|
+
*/
|
|
79
|
+
get color(): RBTNColor;
|
|
80
|
+
/**
|
|
81
|
+
* Sets the color of the node.
|
|
82
|
+
* @remarks Time O(1), Space O(1)
|
|
83
|
+
*
|
|
84
|
+
* @param value - The new color.
|
|
85
|
+
*/
|
|
86
|
+
set color(value: RBTNColor);
|
|
87
|
+
_count: number;
|
|
88
|
+
/**
|
|
89
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
90
|
+
* @remarks Time O(1), Space O(1)
|
|
91
|
+
*
|
|
92
|
+
* @returns The subtree node count.
|
|
93
|
+
*/
|
|
94
|
+
get count(): number;
|
|
95
|
+
/**
|
|
96
|
+
* Sets the count of nodes in the subtree.
|
|
97
|
+
* @remarks Time O(1), Space O(1)
|
|
98
|
+
*
|
|
99
|
+
* @param value - The new count.
|
|
100
|
+
*/
|
|
101
|
+
set count(value: number);
|
|
102
|
+
/**
|
|
103
|
+
* Gets the position of the node relative to its parent.
|
|
104
|
+
* @remarks Time O(1), Space O(1)
|
|
105
|
+
*
|
|
106
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
107
|
+
*/
|
|
108
|
+
get familyPosition(): FamilyPosition;
|
|
55
109
|
}
|
|
56
110
|
/**
|
|
57
111
|
* AVL-tree–based multimap (key → array of values). Preserves O(log N) updates and supports map-like mode.
|
|
@@ -70,6 +124,14 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<
|
|
|
70
124
|
*/
|
|
71
125
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | R>, options?: AVLTreeMultiMapOptions<K, V[], R>);
|
|
72
126
|
createNode(key: K, value?: V[]): AVLTreeMultiMapNode<K, V>;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the given item is a `AVLTreeMultiMapNode` instance.
|
|
129
|
+
* @remarks Time O(1), Space O(1)
|
|
130
|
+
*
|
|
131
|
+
* @param keyNodeOrEntry - The item to check.
|
|
132
|
+
* @returns True if it's a AVLTreeMultiMapNode, false otherwise.
|
|
133
|
+
*/
|
|
134
|
+
isNode(keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): keyNodeOrEntry is AVLTreeMultiMapNode<K, V>;
|
|
73
135
|
add(keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
|
|
74
136
|
add(key: K, value: V): boolean;
|
|
75
137
|
/**
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import { BST
|
|
9
|
-
import type { AVLTreeOptions, BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType } from '../../types';
|
|
8
|
+
import { BST } from './bst';
|
|
9
|
+
import type { AVLTreeOptions, BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, FamilyPosition, IterationType, RBTNColor } from '../../types';
|
|
10
10
|
import { BSTOptions } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
/**
|
|
@@ -16,7 +16,9 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
16
16
|
* @template K - The type of the key.
|
|
17
17
|
* @template V - The type of the value.
|
|
18
18
|
*/
|
|
19
|
-
export declare class AVLTreeNode<K = any, V = any>
|
|
19
|
+
export declare class AVLTreeNode<K = any, V = any> {
|
|
20
|
+
key: K;
|
|
21
|
+
value?: V;
|
|
20
22
|
parent?: AVLTreeNode<K, V>;
|
|
21
23
|
/**
|
|
22
24
|
* Creates an instance of AVLTreeNode.
|
|
@@ -56,6 +58,58 @@ export declare class AVLTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
56
58
|
* @param v - The node to set as the right child.
|
|
57
59
|
*/
|
|
58
60
|
set right(v: AVLTreeNode<K, V> | null | undefined);
|
|
61
|
+
_height: number;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
64
|
+
* @remarks Time O(1), Space O(1)
|
|
65
|
+
*
|
|
66
|
+
* @returns The height.
|
|
67
|
+
*/
|
|
68
|
+
get height(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the height of the node.
|
|
71
|
+
* @remarks Time O(1), Space O(1)
|
|
72
|
+
*
|
|
73
|
+
* @param value - The new height.
|
|
74
|
+
*/
|
|
75
|
+
set height(value: number);
|
|
76
|
+
_color: RBTNColor;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
79
|
+
* @remarks Time O(1), Space O(1)
|
|
80
|
+
*
|
|
81
|
+
* @returns The node's color.
|
|
82
|
+
*/
|
|
83
|
+
get color(): RBTNColor;
|
|
84
|
+
/**
|
|
85
|
+
* Sets the color of the node.
|
|
86
|
+
* @remarks Time O(1), Space O(1)
|
|
87
|
+
*
|
|
88
|
+
* @param value - The new color.
|
|
89
|
+
*/
|
|
90
|
+
set color(value: RBTNColor);
|
|
91
|
+
_count: number;
|
|
92
|
+
/**
|
|
93
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
94
|
+
* @remarks Time O(1), Space O(1)
|
|
95
|
+
*
|
|
96
|
+
* @returns The subtree node count.
|
|
97
|
+
*/
|
|
98
|
+
get count(): number;
|
|
99
|
+
/**
|
|
100
|
+
* Sets the count of nodes in the subtree.
|
|
101
|
+
* @remarks Time O(1), Space O(1)
|
|
102
|
+
*
|
|
103
|
+
* @param value - The new count.
|
|
104
|
+
*/
|
|
105
|
+
set count(value: number);
|
|
106
|
+
/**
|
|
107
|
+
* Gets the position of the node relative to its parent.
|
|
108
|
+
* @remarks Time O(1), Space O(1)
|
|
109
|
+
*
|
|
110
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
111
|
+
*/
|
|
112
|
+
get familyPosition(): FamilyPosition;
|
|
59
113
|
}
|
|
60
114
|
/**
|
|
61
115
|
* Represents a self-balancing AVL (Adelson-Velsky and Landis) Tree.
|
|
@@ -219,7 +273,7 @@ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> imp
|
|
|
219
273
|
* @param [options] - Options for the new tree.
|
|
220
274
|
* @returns A new AVLTree.
|
|
221
275
|
*/
|
|
222
|
-
protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK |
|
|
276
|
+
protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | AVLTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BSTOptions<TK, TV, TR>>): AVLTree<TK, TV, TR>;
|
|
223
277
|
/**
|
|
224
278
|
* (Protected) Swaps properties of two nodes, including height.
|
|
225
279
|
* @remarks Time O(H) (due to `ensureNode`), but O(1) if nodes are passed directly.
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeOptions, BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNode } from '../../types';
|
|
9
|
-
import { BinaryTree
|
|
8
|
+
import type { BinaryTreeOptions, BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodePredicate, OptNode, RBTNColor } from '../../types';
|
|
9
|
+
import { BinaryTree } from './binary-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { Range } from '../../common';
|
|
12
12
|
/**
|
|
@@ -15,7 +15,9 @@ import { Range } from '../../common';
|
|
|
15
15
|
* @template K - The type of the key.
|
|
16
16
|
* @template V - The type of the value.
|
|
17
17
|
*/
|
|
18
|
-
export declare class BSTNode<K = any, V = any>
|
|
18
|
+
export declare class BSTNode<K = any, V = any> {
|
|
19
|
+
key: K;
|
|
20
|
+
value?: V;
|
|
19
21
|
parent?: BSTNode<K, V>;
|
|
20
22
|
/**
|
|
21
23
|
* Creates an instance of BSTNode.
|
|
@@ -55,6 +57,58 @@ export declare class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
|
55
57
|
* @param v - The node to set as the right child.
|
|
56
58
|
*/
|
|
57
59
|
set right(v: BSTNode<K, V> | null | undefined);
|
|
60
|
+
_height: number;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
63
|
+
* @remarks Time O(1), Space O(1)
|
|
64
|
+
*
|
|
65
|
+
* @returns The height.
|
|
66
|
+
*/
|
|
67
|
+
get height(): number;
|
|
68
|
+
/**
|
|
69
|
+
* Sets the height of the node.
|
|
70
|
+
* @remarks Time O(1), Space O(1)
|
|
71
|
+
*
|
|
72
|
+
* @param value - The new height.
|
|
73
|
+
*/
|
|
74
|
+
set height(value: number);
|
|
75
|
+
_color: RBTNColor;
|
|
76
|
+
/**
|
|
77
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
78
|
+
* @remarks Time O(1), Space O(1)
|
|
79
|
+
*
|
|
80
|
+
* @returns The node's color.
|
|
81
|
+
*/
|
|
82
|
+
get color(): RBTNColor;
|
|
83
|
+
/**
|
|
84
|
+
* Sets the color of the node.
|
|
85
|
+
* @remarks Time O(1), Space O(1)
|
|
86
|
+
*
|
|
87
|
+
* @param value - The new color.
|
|
88
|
+
*/
|
|
89
|
+
set color(value: RBTNColor);
|
|
90
|
+
_count: number;
|
|
91
|
+
/**
|
|
92
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
93
|
+
* @remarks Time O(1), Space O(1)
|
|
94
|
+
*
|
|
95
|
+
* @returns The subtree node count.
|
|
96
|
+
*/
|
|
97
|
+
get count(): number;
|
|
98
|
+
/**
|
|
99
|
+
* Sets the count of nodes in the subtree.
|
|
100
|
+
* @remarks Time O(1), Space O(1)
|
|
101
|
+
*
|
|
102
|
+
* @param value - The new count.
|
|
103
|
+
*/
|
|
104
|
+
set count(value: number);
|
|
105
|
+
/**
|
|
106
|
+
* Gets the position of the node relative to its parent.
|
|
107
|
+
* @remarks Time O(1), Space O(1)
|
|
108
|
+
*
|
|
109
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
110
|
+
*/
|
|
111
|
+
get familyPosition(): FamilyPosition;
|
|
58
112
|
}
|
|
59
113
|
/**
|
|
60
114
|
* Represents a Binary Search Tree (BST).
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BinaryTreeOptions, CRUD, EntryCallback, RBTNColor, RedBlackTreeOptions } from '../../types';
|
|
9
|
-
import { BST
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeOptions, CRUD, EntryCallback, FamilyPosition, RBTNColor, RedBlackTreeOptions } from '../../types';
|
|
9
|
+
import { BST } from './bst';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
|
-
export declare class RedBlackTreeNode<K = any, V = any>
|
|
11
|
+
export declare class RedBlackTreeNode<K = any, V = any> {
|
|
12
|
+
key: K;
|
|
13
|
+
value?: V;
|
|
12
14
|
parent?: RedBlackTreeNode<K, V>;
|
|
13
15
|
/**
|
|
14
16
|
* Create a Red-Black Tree and optionally bulk-insert items.
|
|
@@ -47,6 +49,58 @@ export declare class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
47
49
|
* @returns void
|
|
48
50
|
*/
|
|
49
51
|
set right(v: RedBlackTreeNode<K, V> | null | undefined);
|
|
52
|
+
_height: number;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
55
|
+
* @remarks Time O(1), Space O(1)
|
|
56
|
+
*
|
|
57
|
+
* @returns The height.
|
|
58
|
+
*/
|
|
59
|
+
get height(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Sets the height of the node.
|
|
62
|
+
* @remarks Time O(1), Space O(1)
|
|
63
|
+
*
|
|
64
|
+
* @param value - The new height.
|
|
65
|
+
*/
|
|
66
|
+
set height(value: number);
|
|
67
|
+
_color: RBTNColor;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
70
|
+
* @remarks Time O(1), Space O(1)
|
|
71
|
+
*
|
|
72
|
+
* @returns The node's color.
|
|
73
|
+
*/
|
|
74
|
+
get color(): RBTNColor;
|
|
75
|
+
/**
|
|
76
|
+
* Sets the color of the node.
|
|
77
|
+
* @remarks Time O(1), Space O(1)
|
|
78
|
+
*
|
|
79
|
+
* @param value - The new color.
|
|
80
|
+
*/
|
|
81
|
+
set color(value: RBTNColor);
|
|
82
|
+
_count: number;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
85
|
+
* @remarks Time O(1), Space O(1)
|
|
86
|
+
*
|
|
87
|
+
* @returns The subtree node count.
|
|
88
|
+
*/
|
|
89
|
+
get count(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Sets the count of nodes in the subtree.
|
|
92
|
+
* @remarks Time O(1), Space O(1)
|
|
93
|
+
*
|
|
94
|
+
* @param value - The new count.
|
|
95
|
+
*/
|
|
96
|
+
set count(value: number);
|
|
97
|
+
/**
|
|
98
|
+
* Gets the position of the node relative to its parent.
|
|
99
|
+
* @remarks Time O(1), Space O(1)
|
|
100
|
+
*
|
|
101
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
102
|
+
*/
|
|
103
|
+
get familyPosition(): FamilyPosition;
|
|
50
104
|
}
|
|
51
105
|
/**
|
|
52
106
|
* Represents a Red-Black Tree (self-balancing BST) supporting map-like mode and stable O(log n) updates.
|
|
@@ -54,7 +108,7 @@ export declare class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
54
108
|
* @template K
|
|
55
109
|
* @template V
|
|
56
110
|
* @template R
|
|
57
|
-
* 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high but the query efficiency is slightly lower.
|
|
111
|
+
* 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high, but the query efficiency is slightly lower.
|
|
58
112
|
* 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
|
|
59
113
|
* @example
|
|
60
114
|
* // using Red-Black Tree as a price-based index for stock data
|
|
@@ -5,18 +5,20 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, FamilyPosition, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
|
|
9
9
|
import { BSTOptions } from '../../types';
|
|
10
10
|
import { BSTNode } from './bst';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
|
-
import { RedBlackTree
|
|
12
|
+
import { RedBlackTree } from './red-black-tree';
|
|
13
13
|
/**
|
|
14
14
|
* RB-tree node with an extra 'count' field; keeps parent/child links.
|
|
15
15
|
* @remarks Time O(1), Space O(1)
|
|
16
16
|
* @template K
|
|
17
17
|
* @template V
|
|
18
18
|
*/
|
|
19
|
-
export declare class TreeCounterNode<K = any, V = any>
|
|
19
|
+
export declare class TreeCounterNode<K = any, V = any> {
|
|
20
|
+
key: K;
|
|
21
|
+
value?: V;
|
|
20
22
|
parent?: TreeCounterNode<K, V>;
|
|
21
23
|
/**
|
|
22
24
|
* Create a tree counter node.
|
|
@@ -56,6 +58,58 @@ export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<
|
|
|
56
58
|
* @returns void
|
|
57
59
|
*/
|
|
58
60
|
set right(v: TreeCounterNode<K, V> | null | undefined);
|
|
61
|
+
_height: number;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
64
|
+
* @remarks Time O(1), Space O(1)
|
|
65
|
+
*
|
|
66
|
+
* @returns The height.
|
|
67
|
+
*/
|
|
68
|
+
get height(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the height of the node.
|
|
71
|
+
* @remarks Time O(1), Space O(1)
|
|
72
|
+
*
|
|
73
|
+
* @param value - The new height.
|
|
74
|
+
*/
|
|
75
|
+
set height(value: number);
|
|
76
|
+
_color: RBTNColor;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
79
|
+
* @remarks Time O(1), Space O(1)
|
|
80
|
+
*
|
|
81
|
+
* @returns The node's color.
|
|
82
|
+
*/
|
|
83
|
+
get color(): RBTNColor;
|
|
84
|
+
/**
|
|
85
|
+
* Sets the color of the node.
|
|
86
|
+
* @remarks Time O(1), Space O(1)
|
|
87
|
+
*
|
|
88
|
+
* @param value - The new color.
|
|
89
|
+
*/
|
|
90
|
+
set color(value: RBTNColor);
|
|
91
|
+
_count: number;
|
|
92
|
+
/**
|
|
93
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
94
|
+
* @remarks Time O(1), Space O(1)
|
|
95
|
+
*
|
|
96
|
+
* @returns The subtree node count.
|
|
97
|
+
*/
|
|
98
|
+
get count(): number;
|
|
99
|
+
/**
|
|
100
|
+
* Sets the count of nodes in the subtree.
|
|
101
|
+
* @remarks Time O(1), Space O(1)
|
|
102
|
+
*
|
|
103
|
+
* @param value - The new count.
|
|
104
|
+
*/
|
|
105
|
+
set count(value: number);
|
|
106
|
+
/**
|
|
107
|
+
* Gets the position of the node relative to its parent.
|
|
108
|
+
* @remarks Time O(1), Space O(1)
|
|
109
|
+
*
|
|
110
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
111
|
+
*/
|
|
112
|
+
get familyPosition(): FamilyPosition;
|
|
59
113
|
}
|
|
60
114
|
/**
|
|
61
115
|
* Red-Black Tree–based counter map (key → value with per-node count). Supports O(log N) updates and map-like mode.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { ElemOf, EntryCallback, RedBlackTreeOptions, TreeMultiMapOptions } from '../../types';
|
|
8
|
+
import type { ElemOf, EntryCallback, FamilyPosition, RBTNColor, RedBlackTreeOptions, TreeMultiMapOptions } from '../../types';
|
|
9
9
|
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
/**
|
|
@@ -14,7 +14,9 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
14
14
|
* @template K
|
|
15
15
|
* @template V
|
|
16
16
|
*/
|
|
17
|
-
export declare class TreeMultiMapNode<K = any, V = any>
|
|
17
|
+
export declare class TreeMultiMapNode<K = any, V = any> {
|
|
18
|
+
key: K;
|
|
19
|
+
value?: V[];
|
|
18
20
|
parent?: TreeMultiMapNode<K, V>;
|
|
19
21
|
/**
|
|
20
22
|
* Create a TreeMultiMap node with an optional value bucket.
|
|
@@ -23,7 +25,7 @@ export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode
|
|
|
23
25
|
* @param [value] - Initial array of values.
|
|
24
26
|
* @returns New TreeMultiMapNode instance.
|
|
25
27
|
*/
|
|
26
|
-
constructor(key: K, value?: V[]);
|
|
28
|
+
constructor(key: K, value?: V[], color?: RBTNColor);
|
|
27
29
|
_left?: TreeMultiMapNode<K, V> | null | undefined;
|
|
28
30
|
/**
|
|
29
31
|
* Get the left child pointer.
|
|
@@ -52,6 +54,58 @@ export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode
|
|
|
52
54
|
* @returns void
|
|
53
55
|
*/
|
|
54
56
|
set right(v: TreeMultiMapNode<K, V> | null | undefined);
|
|
57
|
+
_height: number;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
60
|
+
* @remarks Time O(1), Space O(1)
|
|
61
|
+
*
|
|
62
|
+
* @returns The height.
|
|
63
|
+
*/
|
|
64
|
+
get height(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the height of the node.
|
|
67
|
+
* @remarks Time O(1), Space O(1)
|
|
68
|
+
*
|
|
69
|
+
* @param value - The new height.
|
|
70
|
+
*/
|
|
71
|
+
set height(value: number);
|
|
72
|
+
_color: RBTNColor;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
75
|
+
* @remarks Time O(1), Space O(1)
|
|
76
|
+
*
|
|
77
|
+
* @returns The node's color.
|
|
78
|
+
*/
|
|
79
|
+
get color(): RBTNColor;
|
|
80
|
+
/**
|
|
81
|
+
* Sets the color of the node.
|
|
82
|
+
* @remarks Time O(1), Space O(1)
|
|
83
|
+
*
|
|
84
|
+
* @param value - The new color.
|
|
85
|
+
*/
|
|
86
|
+
set color(value: RBTNColor);
|
|
87
|
+
_count: number;
|
|
88
|
+
/**
|
|
89
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
90
|
+
* @remarks Time O(1), Space O(1)
|
|
91
|
+
*
|
|
92
|
+
* @returns The subtree node count.
|
|
93
|
+
*/
|
|
94
|
+
get count(): number;
|
|
95
|
+
/**
|
|
96
|
+
* Sets the count of nodes in the subtree.
|
|
97
|
+
* @remarks Time O(1), Space O(1)
|
|
98
|
+
*
|
|
99
|
+
* @param value - The new count.
|
|
100
|
+
*/
|
|
101
|
+
set count(value: number);
|
|
102
|
+
/**
|
|
103
|
+
* Gets the position of the node relative to its parent.
|
|
104
|
+
* @remarks Time O(1), Space O(1)
|
|
105
|
+
*
|
|
106
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
107
|
+
*/
|
|
108
|
+
get familyPosition(): FamilyPosition;
|
|
55
109
|
}
|
|
56
110
|
/**
|
|
57
111
|
* Red-Black Tree–based multimap (key → array of values). Preserves O(log N) updates and supports map-like mode.
|
|
@@ -234,6 +288,14 @@ export declare class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTre
|
|
|
234
288
|
*/
|
|
235
289
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | R>, options?: TreeMultiMapOptions<K, V[], R>);
|
|
236
290
|
createNode(key: K, value?: V[]): TreeMultiMapNode<K, V>;
|
|
291
|
+
/**
|
|
292
|
+
* Checks if the given item is a `TreeMultiMapNode` instance.
|
|
293
|
+
* @remarks Time O(1), Space O(1)
|
|
294
|
+
*
|
|
295
|
+
* @param keyNodeOrEntry - The item to check.
|
|
296
|
+
* @returns True if it's a TreeMultiMapNode, false otherwise.
|
|
297
|
+
*/
|
|
298
|
+
isNode(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): keyNodeOrEntry is TreeMultiMapNode<K, V>;
|
|
237
299
|
add(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
|
|
238
300
|
add(key: K, value: V): boolean;
|
|
239
301
|
/**
|