directed-graph-typed 2.0.5 → 2.1.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/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/data-structures/base/iterable-element-base.js +149 -107
- package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/data-structures/base/linear-base.d.ts +250 -192
- package/dist/data-structures/base/linear-base.js +137 -274
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/data-structures/binary-tree/binary-tree.js +598 -869
- package/dist/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/data-structures/binary-tree/bst.js +505 -481
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/data-structures/graph/abstract-graph.js +267 -237
- package/dist/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/data-structures/graph/directed-graph.js +146 -233
- package/dist/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/data-structures/graph/map-graph.js +56 -59
- package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/data-structures/graph/undirected-graph.js +129 -149
- package/dist/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/data-structures/hash/hash-map.js +270 -457
- package/dist/data-structures/heap/heap.d.ts +214 -289
- package/dist/data-structures/heap/heap.js +340 -349
- package/dist/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/data-structures/heap/max-heap.js +11 -66
- package/dist/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/data-structures/heap/min-heap.js +11 -66
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/data-structures/queue/deque.d.ts +227 -254
- package/dist/data-structures/queue/deque.js +309 -348
- package/dist/data-structures/queue/queue.d.ts +180 -201
- package/dist/data-structures/queue/queue.js +265 -248
- package/dist/data-structures/stack/stack.d.ts +124 -102
- package/dist/data-structures/stack/stack.js +181 -125
- package/dist/data-structures/trie/trie.d.ts +164 -165
- package/dist/data-structures/trie/trie.js +189 -172
- package/dist/interfaces/binary-tree.d.ts +56 -6
- package/dist/interfaces/graph.d.ts +16 -0
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +2 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
- package/src/data-structures/binary-tree/avl-tree.ts +239 -206
- package/src/data-structures/binary-tree/binary-tree.ts +664 -893
- package/src/data-structures/binary-tree/bst.ts +568 -570
- package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
- package/src/data-structures/binary-tree/tree-counter.ts +199 -218
- package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
|
@@ -5,208 +5,186 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, EntryCallback, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
|
|
9
|
+
import { BSTOptions } from '../../types';
|
|
10
|
+
import { BSTNode } from './bst';
|
|
9
11
|
import { IBinaryTree } from '../../interfaces';
|
|
10
12
|
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
13
|
+
/**
|
|
14
|
+
* RB-tree node with an extra 'count' field; keeps parent/child links.
|
|
15
|
+
* @remarks Time O(1), Space O(1)
|
|
16
|
+
* @template K
|
|
17
|
+
* @template V
|
|
18
|
+
*/
|
|
11
19
|
export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<K, V> {
|
|
12
20
|
parent?: TreeCounterNode<K, V>;
|
|
13
21
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
16
|
-
*
|
|
17
|
-
* @param
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* in the Red-Black Tree. It is an optional parameter with a default value of 1.
|
|
22
|
-
* @param {RBTNColor} [color=BLACK] - The `color` parameter is used to specify the color of the node
|
|
23
|
-
* in a Red-Black Tree. It is optional and has a default value of `'BLACK'`.
|
|
22
|
+
* Create a tree counter node.
|
|
23
|
+
* @remarks Time O(1), Space O(1)
|
|
24
|
+
* @param key - Key of the node.
|
|
25
|
+
* @param [value] - Value associated with the key (ignored in map mode).
|
|
26
|
+
* @param [count] - Initial count for this node (default 1).
|
|
27
|
+
* @param color - Initial color ('RED' or 'BLACK').
|
|
28
|
+
* @returns New TreeCounterNode instance.
|
|
24
29
|
*/
|
|
25
30
|
constructor(key: K, value?: V, count?: number, color?: RBTNColor);
|
|
26
31
|
_left?: TreeCounterNode<K, V> | null | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Get the left child pointer.
|
|
34
|
+
* @remarks Time O(1), Space O(1)
|
|
35
|
+
* @returns Left child node, or null/undefined.
|
|
36
|
+
*/
|
|
27
37
|
get left(): TreeCounterNode<K, V> | null | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Set the left child and update its parent pointer.
|
|
40
|
+
* @remarks Time O(1), Space O(1)
|
|
41
|
+
* @param v - New left child node, or null/undefined.
|
|
42
|
+
* @returns void
|
|
43
|
+
*/
|
|
28
44
|
set left(v: TreeCounterNode<K, V> | null | undefined);
|
|
29
45
|
_right?: TreeCounterNode<K, V> | null | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Get the right child pointer.
|
|
48
|
+
* @remarks Time O(1), Space O(1)
|
|
49
|
+
* @returns Right child node, or null/undefined.
|
|
50
|
+
*/
|
|
30
51
|
get right(): TreeCounterNode<K, V> | null | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Set the right child and update its parent pointer.
|
|
54
|
+
* @remarks Time O(1), Space O(1)
|
|
55
|
+
* @param v - New right child node, or null/undefined.
|
|
56
|
+
* @returns void
|
|
57
|
+
*/
|
|
31
58
|
set right(v: TreeCounterNode<K, V> | null | undefined);
|
|
32
59
|
}
|
|
33
60
|
/**
|
|
34
|
-
*
|
|
61
|
+
* Red-Black Tree–based counter map (key → value with per-node count). Supports O(log N) updates and map-like mode.
|
|
62
|
+
* @remarks Time O(1), Space O(1)
|
|
63
|
+
* @template K
|
|
64
|
+
* @template V
|
|
65
|
+
* @template R
|
|
35
66
|
*/
|
|
36
|
-
export declare class TreeCounter<K = any, V = any, R
|
|
67
|
+
export declare class TreeCounter<K = any, V = any, R extends object = object> extends RedBlackTree<K, V, R> implements IBinaryTree<K, V, R> {
|
|
37
68
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
41
|
-
* TreeCounter
|
|
42
|
-
* @
|
|
43
|
-
* behavior of the `TreeCounter` constructor. It can include properties such as `compareKeys` and
|
|
44
|
-
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
69
|
+
* Create a TreeCounter and optionally bulk-insert items.
|
|
70
|
+
* @remarks Time O(N log N), Space O(N)
|
|
71
|
+
* @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
|
|
72
|
+
* @param [options] - Options for TreeCounter (comparator, reverse, map mode).
|
|
73
|
+
* @returns New TreeCounter instance.
|
|
45
74
|
*/
|
|
46
75
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: TreeCounterOptions<K, V, R>);
|
|
47
76
|
protected _count: number;
|
|
48
77
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @
|
|
78
|
+
* Get the total aggregate count across all nodes.
|
|
79
|
+
* @remarks Time O(1), Space O(1)
|
|
80
|
+
* @returns Total count.
|
|
51
81
|
*/
|
|
52
82
|
get count(): number;
|
|
53
83
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
58
|
-
* search.
|
|
59
|
-
* @returns the sum of the count property of all nodes in the tree.
|
|
84
|
+
* Compute the total count by traversing the tree (sums node.count).
|
|
85
|
+
* @remarks Time O(N), Space O(H)
|
|
86
|
+
* @returns Total count recomputed from nodes.
|
|
60
87
|
*/
|
|
61
88
|
getComputedCount(): number;
|
|
89
|
+
_createNode(key: K, value?: V, color?: RBTNColor, count?: number): TreeCounterNode<K, V>;
|
|
62
90
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
66
|
-
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
67
|
-
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
68
|
-
* @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
|
|
69
|
-
* a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
|
|
70
|
-
* @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
|
|
71
|
-
* the tree. It is an optional parameter and is used to keep track of the number of values associated
|
|
72
|
-
* with a key in the tree.
|
|
73
|
-
* @returns A new instance of the TreeCounterNode class, casted as TreeCounterNode<K, V>.
|
|
74
|
-
*/
|
|
75
|
-
createNode(key: K, value?: V, color?: RBTNColor, count?: number): TreeCounterNode<K, V>;
|
|
76
|
-
/**
|
|
77
|
-
* The function creates a new instance of a TreeCounter with the specified options and returns it.
|
|
78
|
-
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
79
|
-
* configuration options for creating the `TreeCounter`. It is of type `TreeCounterOptions<K, V,
|
|
80
|
-
* R>`.
|
|
81
|
-
* @returns a new instance of the `TreeCounter` class, with the provided options merged with the
|
|
82
|
-
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
83
|
-
*/
|
|
84
|
-
createTree(options?: TreeCounterOptions<K, V, R>): TreeCounter<K, V, R, MK, MV, MR>;
|
|
85
|
-
/**
|
|
86
|
-
* The function checks if the input is an instance of the TreeCounterNode class.
|
|
87
|
-
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
88
|
-
* `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
89
|
-
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
90
|
-
* an instance of the `TreeCounterNode` class.
|
|
91
|
+
* Type guard: check whether the input is a TreeCounterNode.
|
|
92
|
+
* @remarks Time O(1), Space O(1)
|
|
93
|
+
* @returns True if the value is a TreeCounterNode.
|
|
91
94
|
*/
|
|
92
95
|
isNode(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is TreeCounterNode<K, V>;
|
|
93
96
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @
|
|
100
|
-
* `keyNodeOrEntry` parameter can accept one of the following types:
|
|
101
|
-
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
102
|
-
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
103
|
-
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
104
|
-
* be added to the data structure. By default, it is set to 1, meaning that if no value is provided
|
|
105
|
-
* for `count`, the key-value pair will be added once.
|
|
106
|
-
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
107
|
-
* was successful, and false otherwise.
|
|
97
|
+
* Insert or increment a node and update aggregate count.
|
|
98
|
+
* @remarks Time O(log N), Space O(1)
|
|
99
|
+
* @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
|
|
100
|
+
* @param [value] - Value when a bare key is provided (ignored in map mode).
|
|
101
|
+
* @param [count] - How much to increase the node's count (default 1).
|
|
102
|
+
* @returns True if inserted/updated; false if ignored.
|
|
108
103
|
*/
|
|
109
104
|
add(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
|
|
110
105
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
|
|
117
|
-
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
118
|
-
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
119
|
-
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
120
|
-
* boolean flag that determines whether to ignore the count of nodes when performing deletion. If
|
|
121
|
-
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
122
|
-
* `ignoreCount` is `false
|
|
123
|
-
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
|
|
106
|
+
* Delete a node (or decrement its count) and rebalance if needed.
|
|
107
|
+
* @remarks Time O(log N), Space O(1)
|
|
108
|
+
* @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node.
|
|
109
|
+
* @param [ignoreCount] - If true, remove the node regardless of its count.
|
|
110
|
+
* @returns Array of deletion results including deleted node and a rebalance hint when present.
|
|
124
111
|
*/
|
|
125
112
|
delete(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, ignoreCount?: boolean): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[];
|
|
126
113
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
131
|
-
* zero.
|
|
114
|
+
* Remove all nodes and reset aggregate counters.
|
|
115
|
+
* @remarks Time O(N), Space O(1)
|
|
116
|
+
* @returns void
|
|
132
117
|
*/
|
|
133
118
|
clear(): void;
|
|
134
119
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* tree using either a recursive or iterative approach.
|
|
140
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
141
|
-
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
142
|
-
* default value of `this.iterationType`, which means it will use the iteration type specified by the
|
|
143
|
-
* `iterationType` property of the current object.
|
|
144
|
-
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
145
|
-
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
120
|
+
* Rebuild the tree into a perfectly balanced form using in-order nodes.
|
|
121
|
+
* @remarks Time O(N), Space O(N)
|
|
122
|
+
* @param [iterationType] - Traversal style to use when constructing the balanced tree.
|
|
123
|
+
* @returns True if rebalancing succeeded (tree not empty).
|
|
146
124
|
*/
|
|
147
125
|
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
148
126
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* (
|
|
168
|
-
* @
|
|
169
|
-
*
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* @
|
|
181
|
-
*
|
|
182
|
-
* @
|
|
127
|
+
* Create a new TreeCounter by mapping each [key, value] entry.
|
|
128
|
+
* @remarks Time O(N log N), Space O(N)
|
|
129
|
+
* @template MK
|
|
130
|
+
* @template MV
|
|
131
|
+
* @template MR
|
|
132
|
+
* @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
|
|
133
|
+
* @param [options] - Options for the output tree.
|
|
134
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
135
|
+
* @returns A new TreeCounter with mapped entries.
|
|
136
|
+
*/
|
|
137
|
+
map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): TreeCounter<MK, MV, MR>;
|
|
138
|
+
/**
|
|
139
|
+
* Deep copy this tree, preserving map mode and aggregate counts.
|
|
140
|
+
* @remarks Time O(N), Space O(N)
|
|
141
|
+
* @returns A deep copy of this tree.
|
|
142
|
+
*/
|
|
143
|
+
clone(): this;
|
|
144
|
+
/**
|
|
145
|
+
* (Protected) Create an empty instance of the same concrete class.
|
|
146
|
+
* @remarks Time O(1), Space O(1)
|
|
147
|
+
* @template TK
|
|
148
|
+
* @template TV
|
|
149
|
+
* @template TR
|
|
150
|
+
* @param [options] - Optional constructor options for the like-kind instance.
|
|
151
|
+
* @returns An empty like-kind instance.
|
|
152
|
+
*/
|
|
153
|
+
protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this;
|
|
154
|
+
/**
|
|
155
|
+
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
156
|
+
* @remarks Time O(N log N), Space O(N)
|
|
157
|
+
* @template TK
|
|
158
|
+
* @template TV
|
|
159
|
+
* @template TR
|
|
160
|
+
* @param iter - Iterable used to seed the new tree.
|
|
161
|
+
* @param [options] - Options merged with the current snapshot.
|
|
162
|
+
* @returns A like-kind TreeCounter built from the iterable.
|
|
163
|
+
*/
|
|
164
|
+
protected _createLike<TK = K, TV = V, TR extends object = R>(iter?: Iterable<TK | BSTNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BSTOptions<TK, TV, TR>>): TreeCounter<TK, TV, TR>;
|
|
165
|
+
/**
|
|
166
|
+
* (Protected) Normalize input into a node plus its effective value and count.
|
|
167
|
+
* @remarks Time O(1), Space O(1)
|
|
168
|
+
* @param keyNodeOrEntry - Key, node, or [key, value] entry.
|
|
169
|
+
* @param [value] - Value used when a bare key is provided.
|
|
170
|
+
* @param [count] - Count increment to apply (default 1).
|
|
171
|
+
* @returns Tuple [node, value] where node may be undefined.
|
|
183
172
|
*/
|
|
184
173
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): [TreeCounterNode<K, V> | undefined, V | undefined];
|
|
185
174
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
|
|
192
|
-
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
193
|
-
* instance of the `BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>` class.
|
|
194
|
-
* @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
|
|
195
|
-
* node where the properties will be swapped with the source node.
|
|
196
|
-
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
197
|
-
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
175
|
+
* (Protected) Swap keys/values/counters between the source and destination nodes.
|
|
176
|
+
* @remarks Time O(1), Space O(1)
|
|
177
|
+
* @param srcNode - Source node (or key) whose properties will be moved.
|
|
178
|
+
* @param destNode - Destination node (or key) to receive properties.
|
|
179
|
+
* @returns Destination node after swap, or undefined.
|
|
198
180
|
*/
|
|
199
181
|
protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>, destNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>): TreeCounterNode<K, V> | undefined;
|
|
200
182
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @
|
|
206
|
-
* structure.
|
|
207
|
-
* @param {TreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `TreeCounterNode<K, V>` class.
|
|
208
|
-
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
209
|
-
* superclass, which is of type `TreeCounterNode<K, V>`.
|
|
183
|
+
* (Protected) Replace one node by another and adjust counters accordingly.
|
|
184
|
+
* @remarks Time O(1), Space O(1)
|
|
185
|
+
* @param oldNode - Node being replaced.
|
|
186
|
+
* @param newNode - Replacement node.
|
|
187
|
+
* @returns The new node after replacement.
|
|
210
188
|
*/
|
|
211
189
|
protected _replaceNode(oldNode: TreeCounterNode<K, V>, newNode: TreeCounterNode<K, V>): TreeCounterNode<K, V>;
|
|
212
190
|
}
|