directed-graph-typed 2.0.4 → 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.
Files changed (101) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
  2. package/dist/data-structures/base/iterable-element-base.js +149 -107
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
  4. package/dist/data-structures/base/iterable-entry-base.js +59 -116
  5. package/dist/data-structures/base/linear-base.d.ts +250 -192
  6. package/dist/data-structures/base/linear-base.js +137 -274
  7. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  8. package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
  9. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  10. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  11. package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
  12. package/dist/data-structures/binary-tree/avl-tree.js +208 -195
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
  14. package/dist/data-structures/binary-tree/binary-tree.js +612 -879
  15. package/dist/data-structures/binary-tree/bst.d.ts +258 -306
  16. package/dist/data-structures/binary-tree/bst.js +505 -481
  17. package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  18. package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
  19. package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
  20. package/dist/data-structures/binary-tree/tree-counter.js +172 -203
  21. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  22. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
  23. package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
  24. package/dist/data-structures/graph/abstract-graph.js +267 -237
  25. package/dist/data-structures/graph/directed-graph.d.ts +108 -224
  26. package/dist/data-structures/graph/directed-graph.js +146 -233
  27. package/dist/data-structures/graph/map-graph.d.ts +49 -55
  28. package/dist/data-structures/graph/map-graph.js +56 -59
  29. package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
  30. package/dist/data-structures/graph/undirected-graph.js +129 -149
  31. package/dist/data-structures/hash/hash-map.d.ts +164 -338
  32. package/dist/data-structures/hash/hash-map.js +270 -457
  33. package/dist/data-structures/heap/heap.d.ts +214 -289
  34. package/dist/data-structures/heap/heap.js +340 -349
  35. package/dist/data-structures/heap/max-heap.d.ts +11 -47
  36. package/dist/data-structures/heap/max-heap.js +11 -66
  37. package/dist/data-structures/heap/min-heap.d.ts +12 -47
  38. package/dist/data-structures/heap/min-heap.js +11 -66
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  42. package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
  43. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  44. package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
  45. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  46. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
  47. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  48. package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
  49. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
  50. package/dist/data-structures/priority-queue/priority-queue.js +8 -83
  51. package/dist/data-structures/queue/deque.d.ts +227 -254
  52. package/dist/data-structures/queue/deque.js +309 -348
  53. package/dist/data-structures/queue/queue.d.ts +180 -201
  54. package/dist/data-structures/queue/queue.js +265 -248
  55. package/dist/data-structures/stack/stack.d.ts +124 -102
  56. package/dist/data-structures/stack/stack.js +181 -125
  57. package/dist/data-structures/trie/trie.d.ts +164 -165
  58. package/dist/data-structures/trie/trie.js +189 -172
  59. package/dist/interfaces/binary-tree.d.ts +56 -6
  60. package/dist/interfaces/graph.d.ts +16 -0
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
  63. package/dist/types/utils/utils.d.ts +6 -6
  64. package/dist/utils/utils.d.ts +110 -49
  65. package/dist/utils/utils.js +148 -73
  66. package/package.json +2 -2
  67. package/src/data-structures/base/iterable-element-base.ts +238 -115
  68. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  69. package/src/data-structures/base/linear-base.ts +271 -277
  70. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  71. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  72. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  73. package/src/data-structures/binary-tree/binary-tree.ts +681 -905
  74. package/src/data-structures/binary-tree/bst.ts +568 -570
  75. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  76. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  77. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  78. package/src/data-structures/graph/abstract-graph.ts +339 -264
  79. package/src/data-structures/graph/directed-graph.ts +146 -236
  80. package/src/data-structures/graph/map-graph.ts +63 -60
  81. package/src/data-structures/graph/undirected-graph.ts +129 -152
  82. package/src/data-structures/hash/hash-map.ts +274 -496
  83. package/src/data-structures/heap/heap.ts +389 -402
  84. package/src/data-structures/heap/max-heap.ts +12 -76
  85. package/src/data-structures/heap/min-heap.ts +13 -76
  86. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  87. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  88. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  89. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  90. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  91. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  92. package/src/data-structures/queue/deque.ts +381 -357
  93. package/src/data-structures/queue/queue.ts +310 -264
  94. package/src/data-structures/stack/stack.ts +217 -131
  95. package/src/data-structures/trie/trie.ts +240 -175
  96. package/src/interfaces/binary-tree.ts +240 -6
  97. package/src/interfaces/graph.ts +37 -0
  98. package/src/types/data-structures/base/base.ts +5 -5
  99. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  100. package/src/types/utils/utils.ts +9 -5
  101. package/src/utils/utils.ts +152 -86
@@ -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
- * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
15
- * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
16
- * of the binary tree node.
17
- * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
18
- * tree node. If no value is provided, it will be `undefined`.
19
- * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
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
- * The only distinction between a AVLTreeCounter and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
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 = object, MK = any, MV = any, MR = object> extends AVLTree<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
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
- * The constructor initializes a new AVLTreeCounter object with optional initial elements.
37
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
38
- * iterable object that can contain either keys, nodes, entries, or raw elements.
39
- * @param [options] - The `options` parameter is an optional object that can be used to customize the
40
- * behavior of the AVLTreeCounter. It can include properties such as `compareKeys` and
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
- * Time Complexity: O(n)
53
- * Space Complexity: O(1)
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
- * The function creates a new AVLTreeCounterNode with the specified key, value, and count.
62
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
63
- * which is a generic type that can be replaced with any specific type when using the function.
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
- * Time Complexity: O(log n)
90
- * Space Complexity: O(1)
91
- *
92
- * The function overrides the add method of a TypeScript class to add a new node to a data structure
93
- * and update the count.
94
- * @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
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
- * Time Complexity: O(log n)
108
- * Space Complexity: O(1)
109
- *
110
- * The function overrides the delete method in a binary tree data structure, handling deletion of
111
- * nodes and maintaining balance in the tree.
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
- * Time Complexity: O(1)
128
- * Space Complexity: O(1)
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
- * Time Complexity: O(n log n)
136
- * Space Complexity: O(log n)
137
- *
138
- * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
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
- * Time complexity: O(n)
150
- * Space complexity: O(n)
151
- *
152
- * The function overrides the clone method to create a deep copy of a tree object.
153
- * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
154
- */
155
- clone(): AVLTreeCounter<K, V, R, MK, MV, MR>;
156
- /**
157
- * The `map` function in TypeScript overrides the default behavior to create a new AVLTreeCounter
158
- * with modified entries based on a provided callback.
159
- * @param callback - The `callback` parameter is a function that will be called for each entry in the
160
- * AVLTreeCounter. It takes four arguments:
161
- * @param [options] - The `options` parameter in the `override map` function is of type
162
- * `AVLTreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional
163
- * configuration options when creating a new `AVLTreeCounter` instance within the `map` function.
164
- * These options
165
- * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
166
- * the value of `this` when executing the `callback` function. It allows you to set the context
167
- * (value of `this`) for the callback function. This can be useful when you want to access properties
168
- * or
169
- * @returns The `map` method is returning a new `AVLTreeCounter` instance with the entries
170
- * transformed by the provided `callback` function. Each entry in the original tree is passed to the
171
- * `callback` function along with the index and the original tree itself. The transformed entries are
172
- * then added to the new `AVLTreeCounter` instance, which is returned at the end.
173
- */
174
- map<MK, MV, MR>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: AVLTreeCounterOptions<MK, MV, MR>, thisArg?: any): AVLTreeCounter<MK, MV, MR>;
175
- /**
176
- * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
177
- * a node object.
178
- * @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
179
- * `keyNodeOrEntry` parameter can be of type `R` or `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
180
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
181
- * `override` function. It represents the value associated with the key in the data structure. If no
182
- * value is provided, it will default to `undefined`.
183
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
184
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
185
- * @returns either a AVLTreeCounterNode<K, V> object or undefined.
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
- * Time Complexity: O(1)
190
- * Space Complexity: O(1)
191
- *
192
- * The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
193
- * in a binary search tree.
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
- * Time Complexity: O(1)
204
- * Space Complexity: O(1)
205
- *
206
- * The function replaces an old node with a new node and updates the count property of the new node.
207
- * @param {AVLTreeCounterNode<K, V>} oldNode - The oldNode parameter represents the node that needs to be replaced in the
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
  }