linked-list-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/README.md +14 -14
- 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,210 +5,178 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { AVLTreeCounterOptions, BinaryTreeDeleteResult, BSTNOptKeyOrNode, EntryCallback, IterationType } from '../../types';
|
|
8
|
+
import type { AVLTreeCounterOptions, BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
11
|
+
/**
|
|
12
|
+
* AVL node with an extra 'count' field; keeps parent/child links.
|
|
13
|
+
* @remarks Time O(1), Space O(1)
|
|
14
|
+
* @template K
|
|
15
|
+
* @template V
|
|
16
|
+
*/
|
|
11
17
|
export declare class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K, V> {
|
|
12
18
|
parent?: AVLTreeCounterNode<K, V>;
|
|
13
19
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
16
|
-
* of the
|
|
17
|
-
* @param
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
20
|
-
* occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
|
|
21
|
-
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
20
|
+
* Create an AVL counter node.
|
|
21
|
+
* @remarks Time O(1), Space O(1)
|
|
22
|
+
* @param key - Key of the node.
|
|
23
|
+
* @param [value] - Associated value (ignored in map mode).
|
|
24
|
+
* @param [count] - Initial count for this node (default 1).
|
|
25
|
+
* @returns New AVLTreeCounterNode instance.
|
|
22
26
|
*/
|
|
23
27
|
constructor(key: K, value?: V, count?: number);
|
|
24
28
|
_left?: AVLTreeCounterNode<K, V> | null | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Get the left child pointer.
|
|
31
|
+
* @remarks Time O(1), Space O(1)
|
|
32
|
+
* @returns Left child node, or null/undefined.
|
|
33
|
+
*/
|
|
25
34
|
get left(): AVLTreeCounterNode<K, V> | null | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Set the left child and update its parent pointer.
|
|
37
|
+
* @remarks Time O(1), Space O(1)
|
|
38
|
+
* @param v - New left child node, or null/undefined.
|
|
39
|
+
* @returns void
|
|
40
|
+
*/
|
|
26
41
|
set left(v: AVLTreeCounterNode<K, V> | null | undefined);
|
|
27
42
|
_right?: AVLTreeCounterNode<K, V> | null | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Get the right child pointer.
|
|
45
|
+
* @remarks Time O(1), Space O(1)
|
|
46
|
+
* @returns Right child node, or null/undefined.
|
|
47
|
+
*/
|
|
28
48
|
get right(): AVLTreeCounterNode<K, V> | null | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Set the right child and update its parent pointer.
|
|
51
|
+
* @remarks Time O(1), Space O(1)
|
|
52
|
+
* @param v - New right child node, or null/undefined.
|
|
53
|
+
* @returns void
|
|
54
|
+
*/
|
|
29
55
|
set right(v: AVLTreeCounterNode<K, V> | null | undefined);
|
|
30
56
|
}
|
|
31
57
|
/**
|
|
32
|
-
*
|
|
58
|
+
* AVL tree that tracks an aggregate 'count' across nodes; supports balanced insert/delete and map-like mode.
|
|
59
|
+
* @remarks Time O(1), Space O(1)
|
|
60
|
+
* @template K
|
|
61
|
+
* @template V
|
|
62
|
+
* @template R
|
|
33
63
|
*/
|
|
34
|
-
export declare class AVLTreeCounter<K = any, V = any, R
|
|
64
|
+
export declare class AVLTreeCounter<K = any, V = any, R extends object = object> extends AVLTree<K, V, R> implements IBinaryTree<K, V, R> {
|
|
35
65
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
*
|
|
39
|
-
* @param
|
|
40
|
-
*
|
|
41
|
-
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
66
|
+
* Create a AVLTreeCounter instance
|
|
67
|
+
* @remarks Time O(n), Space O(n)
|
|
68
|
+
* @param keysNodesEntriesOrRaws
|
|
69
|
+
* @param options
|
|
70
|
+
* @returns New AVLTreeCounterNode instance.
|
|
42
71
|
*/
|
|
43
72
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: AVLTreeCounterOptions<K, V, R>);
|
|
44
73
|
protected _count: number;
|
|
45
|
-
/**
|
|
46
|
-
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
47
|
-
* search.
|
|
48
|
-
* @returns the sum of the count property of all nodes in the tree.
|
|
49
|
-
*/
|
|
50
74
|
get count(): number;
|
|
51
75
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
56
|
-
* search.
|
|
57
|
-
* @returns the sum of the count property of all nodes in the tree.
|
|
76
|
+
* Compute the total count by traversing the tree (sums node.count).
|
|
77
|
+
* @remarks Time O(N), Space O(H)
|
|
78
|
+
* @returns Total count recomputed from nodes.
|
|
58
79
|
*/
|
|
59
80
|
getComputedCount(): number;
|
|
81
|
+
_createNode(key: K, value?: V, count?: number): AVLTreeCounterNode<K, V>;
|
|
60
82
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
63
|
-
*
|
|
64
|
-
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
65
|
-
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
66
|
-
* @param {number} [count] - The `count` parameter represents the number of occurrences of a
|
|
67
|
-
* key-value pair in the AVLTreeCounterNode. It is an optional parameter, so it can be omitted when
|
|
68
|
-
* calling the `createNode` method. If provided, it specifies the initial count for the node.
|
|
69
|
-
* @returns a new instance of the AVLTreeCounterNode class, casted as AVLTreeCounterNode<K, V>.
|
|
70
|
-
*/
|
|
71
|
-
createNode(key: K, value?: V, count?: number): AVLTreeCounterNode<K, V>;
|
|
72
|
-
/**
|
|
73
|
-
* The function creates a new AVLTreeCounter object with the specified options and returns it.
|
|
74
|
-
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
75
|
-
* configuration options for creating the AVLTreeCounter. It can have the following properties:
|
|
76
|
-
* @returns a new instance of the AVLTreeCounter class, with the specified options, as a TREE
|
|
77
|
-
* object.
|
|
78
|
-
*/
|
|
79
|
-
createTree(options?: AVLTreeCounterOptions<K, V, R>): AVLTreeCounter<K, V, R, MK, MV, MR>;
|
|
80
|
-
/**
|
|
81
|
-
* The function checks if the input is an instance of AVLTreeCounterNode.
|
|
82
|
-
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
83
|
-
* `keyNodeOrEntry` can be of type `R` or `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
84
|
-
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
85
|
-
* an instance of the `AVLTreeCounterNode` class.
|
|
83
|
+
* Type guard: check whether the input is an AVLTreeCounterNode.
|
|
84
|
+
* @remarks Time O(1), Space O(1)
|
|
85
|
+
* @returns True if the value is an AVLTreeCounterNode.
|
|
86
86
|
*/
|
|
87
87
|
isNode(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is AVLTreeCounterNode<K, V>;
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @
|
|
95
|
-
* `keyNodeOrEntry` parameter can accept a value of type `R`, which can be any type. It
|
|
96
|
-
* can also accept a value of type `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`, which represents a key, node,
|
|
97
|
-
* entry, or raw element
|
|
98
|
-
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
99
|
-
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
100
|
-
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
101
|
-
* be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
|
|
102
|
-
* be added once. However, you can specify a different value for `count` if you want to add
|
|
103
|
-
* @returns a boolean value.
|
|
89
|
+
* Insert or increment a node and update aggregate count.
|
|
90
|
+
* @remarks Time O(log N), Space O(1)
|
|
91
|
+
* @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
|
|
92
|
+
* @param [value] - Value when a bare key is provided (ignored in map mode).
|
|
93
|
+
* @param [count] - How much to increase the node's count (default 1).
|
|
94
|
+
* @returns True if inserted/updated; false if ignored.
|
|
104
95
|
*/
|
|
105
96
|
add(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
|
|
106
97
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
|
|
113
|
-
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
114
|
-
* binary tree. It can be a key, node, or entry that determines which
|
|
115
|
-
* node(s) should be deleted.
|
|
116
|
-
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
117
|
-
* boolean flag that determines whether to ignore the count of the node being deleted. If
|
|
118
|
-
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
119
|
-
* `ignoreCount` is set to
|
|
120
|
-
* @returns The `delete` method overrides the default delete behavior in a binary tree data
|
|
121
|
-
* structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
|
|
122
|
-
* method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
|
|
123
|
-
* deleted node and whether balancing is needed in the tree.
|
|
98
|
+
* Delete a node (or decrement its count) and rebalance if needed.
|
|
99
|
+
* @remarks Time O(log N), Space O(1)
|
|
100
|
+
* @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node.
|
|
101
|
+
* @param [ignoreCount] - If true, remove the node regardless of its count.
|
|
102
|
+
* @returns Array of deletion results including deleted node and a rebalance hint when present.
|
|
124
103
|
*/
|
|
125
104
|
delete(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, ignoreCount?: boolean): BinaryTreeDeleteResult<AVLTreeCounterNode<K, V>>[];
|
|
126
105
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
131
|
-
* zero.
|
|
106
|
+
* Remove all nodes and reset aggregate counters.
|
|
107
|
+
* @remarks Time O(N), Space O(1)
|
|
108
|
+
* @returns void
|
|
132
109
|
*/
|
|
133
110
|
clear(): void;
|
|
134
111
|
/**
|
|
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 currently set in
|
|
143
|
-
* the 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.
|
|
112
|
+
* Rebuild the tree into a perfectly balanced form using in-order nodes.
|
|
113
|
+
* @remarks Time O(N), Space O(N)
|
|
114
|
+
* @param [iterationType] - Traversal style to use when constructing the balanced tree.
|
|
115
|
+
* @returns True if rebalancing succeeded (tree not empty).
|
|
146
116
|
*/
|
|
147
117
|
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
148
118
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* @
|
|
160
|
-
*
|
|
161
|
-
* @param [options] -
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* (
|
|
168
|
-
*
|
|
169
|
-
* @
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* a
|
|
178
|
-
* @
|
|
179
|
-
*
|
|
180
|
-
* @
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @param [
|
|
184
|
-
*
|
|
185
|
-
|
|
119
|
+
* Deep copy this tree, preserving map mode and aggregate counts.
|
|
120
|
+
* @remarks Time O(N), Space O(N)
|
|
121
|
+
* @returns A deep copy of this tree.
|
|
122
|
+
*/
|
|
123
|
+
clone(): this;
|
|
124
|
+
/**
|
|
125
|
+
* Create a new AVLTreeCounter by mapping each [key, value] entry.
|
|
126
|
+
* @remarks Time O(N log N), Space O(N)
|
|
127
|
+
* @template MK
|
|
128
|
+
* @template MV
|
|
129
|
+
* @template MR
|
|
130
|
+
* @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
|
|
131
|
+
* @param [options] - Options for the output tree.
|
|
132
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
133
|
+
* @returns A new AVLTreeCounter with mapped entries.
|
|
134
|
+
*/
|
|
135
|
+
map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): AVLTreeCounter<MK, MV, MR>;
|
|
136
|
+
/**
|
|
137
|
+
* (Protected) Create an empty instance of the same concrete class.
|
|
138
|
+
* @remarks Time O(1), Space O(1)
|
|
139
|
+
* @template TK
|
|
140
|
+
* @template TV
|
|
141
|
+
* @template TR
|
|
142
|
+
* @param [options] - Optional constructor options for the like-kind instance.
|
|
143
|
+
* @returns An empty like-kind instance.
|
|
144
|
+
*/
|
|
145
|
+
protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<AVLTreeCounterOptions<TK, TV, TR>>): this;
|
|
146
|
+
/**
|
|
147
|
+
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
148
|
+
* @remarks Time O(N log N), Space O(N)
|
|
149
|
+
* @template TK
|
|
150
|
+
* @template TV
|
|
151
|
+
* @template TR
|
|
152
|
+
* @param iter - Iterable used to seed the new tree.
|
|
153
|
+
* @param [options] - Options merged with the current snapshot.
|
|
154
|
+
* @returns A like-kind AVLTreeCounter built from the iterable.
|
|
155
|
+
*/
|
|
156
|
+
protected _createLike<TK = K, TV = V, TR extends object = R>(iter?: Iterable<TK | AVLTreeCounterNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<AVLTreeCounterOptions<TK, TV, TR>>): AVLTreeCounter<TK, TV, TR>;
|
|
157
|
+
/**
|
|
158
|
+
* (Protected) Normalize input into a node plus its effective value and count.
|
|
159
|
+
* @remarks Time O(1), Space O(1)
|
|
160
|
+
* @param keyNodeOrEntry - Key, node, or [key, value] entry.
|
|
161
|
+
* @param [value] - Value used when a bare key is provided.
|
|
162
|
+
* @param [count] - Count increment to apply (default 1).
|
|
163
|
+
* @returns Tuple [node, value] where node may be undefined.
|
|
186
164
|
*/
|
|
187
165
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): [AVLTreeCounterNode<K, V> | undefined, V | undefined];
|
|
188
166
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* @param {BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
|
|
195
|
-
* that will be swapped with the `destNode`.
|
|
196
|
-
* @param {BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
|
|
197
|
-
* node where the properties will be swapped with the source node.
|
|
198
|
-
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
199
|
-
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
167
|
+
* (Protected) Swap keys/values/counters between the source and destination nodes.
|
|
168
|
+
* @remarks Time O(1), Space O(1)
|
|
169
|
+
* @param srcNode - Source node (or key) whose properties will be moved.
|
|
170
|
+
* @param destNode - Destination node (or key) to receive properties.
|
|
171
|
+
* @returns Destination node after swap, or undefined.
|
|
200
172
|
*/
|
|
201
173
|
protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>, destNode: BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>): AVLTreeCounterNode<K, V> | undefined;
|
|
202
174
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* @
|
|
208
|
-
* data structure. It is of type AVLTreeCounterNode<K, V>.
|
|
209
|
-
* @param {AVLTreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `AVLTreeCounterNode<K, V>` class.
|
|
210
|
-
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
211
|
-
* superclass, which is of type `AVLTreeCounterNode<K, V>`.
|
|
175
|
+
* (Protected) Replace one node by another and adjust counters accordingly.
|
|
176
|
+
* @remarks Time O(1), Space O(1)
|
|
177
|
+
* @param oldNode - Node being replaced.
|
|
178
|
+
* @param newNode - Replacement node.
|
|
179
|
+
* @returns The new node after replacement.
|
|
212
180
|
*/
|
|
213
181
|
protected _replaceNode(oldNode: AVLTreeCounterNode<K, V>, newNode: AVLTreeCounterNode<K, V>): AVLTreeCounterNode<K, V>;
|
|
214
182
|
}
|