heap-typed 2.0.5 → 2.1.1

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 +602 -873
  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 +1 -0
  64. package/dist/utils/utils.d.ts +1 -1
  65. package/dist/utils/utils.js +2 -1
  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 +196 -217
  71. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
  72. package/src/data-structures/binary-tree/avl-tree.ts +237 -206
  73. package/src/data-structures/binary-tree/binary-tree.ts +665 -896
  74. package/src/data-structures/binary-tree/bst.ts +565 -572
  75. package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
  76. package/src/data-structures/binary-tree/tree-counter.ts +195 -219
  77. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
  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 +2 -0
  101. 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
- * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
15
- * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
16
- * used to identify and locate the node within the tree.
17
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
18
- * associated with the key in the Red-Black Tree node. It is not required and can be omitted when
19
- * creating a new node.
20
- * @param [count=1] - The `count` parameter represents the number of occurrences of a particular key
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 = object, MK = any, MV = any, MR = object> extends RedBlackTree<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
67
+ export declare class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R> implements IBinaryTree<K, V, R> {
37
68
  /**
38
- * The constructor function initializes a TreeCounter object with optional initial data.
39
- * @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
40
- * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
41
- * TreeCounter with initial data.
42
- * @param [options] - The `options` parameter is an optional object that can be used to customize the
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
- * The function calculates the sum of the count property of all nodes in a tree structure.
50
- * @returns the sum of the count property of all nodes in the tree.
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
- * Time Complexity: O(n)
55
- * Space Complexity: O(1)
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
- * The function creates a new TreeCounterNode with the specified key, value, color, and count.
64
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
65
- * which is a generic type representing the type of keys in the tree.
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
- * Time Complexity: O(log n)
95
- * Space Complexity: O(1)
96
- *
97
- * The function overrides the add method of a class and adds a new node to a data structure, updating
98
- * the count and returning a boolean indicating success.
99
- * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
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
- * Time Complexity: O(log n)
112
- * Space Complexity: O(1)
113
- *
114
- * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
115
- * structure, handling cases where nodes have children and maintaining balance in the tree.
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
- * 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.
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
- * 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 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
- * 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(): TreeCounter<K, V, R, MK, MV, MR>;
156
- /**
157
- * The `map` function in TypeScript overrides the default behavior to create a new TreeCounter with
158
- * 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
- * map. It takes four arguments:
161
- * @param [options] - The `options` parameter in the `override map` function is of type
162
- * `TreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
163
- * options when creating a new `TreeCounter` instance within the `map` function. These options could
164
- * include things like
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 when it is called within the `map` function. This
168
- * @returns A new TreeCounter instance is being returned, which is populated with entries generated
169
- * by the provided callback function.
170
- */
171
- map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: TreeCounterOptions<MK, MV, MR>, thisArg?: any): TreeCounter<MK, MV, MR>;
172
- /**
173
- * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
174
- * node based on the input.
175
- * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
176
- * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
177
- * @param {V} [value] - The `value` parameter is an optional value that represents the value
178
- * associated with the key in the node. It is used when creating a new node or updating the value of
179
- * an existing node.
180
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
181
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
182
- * @returns either a TreeCounterNode<K, V> object or undefined.
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 = any>(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 = 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 = 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
- * Time Complexity: O(1)
187
- * Space Complexity: O(1)
188
- *
189
- * The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
190
- * in a binary search tree.
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
- * Time Complexity: O(1)
202
- * Space Complexity: O(1)
203
- *
204
- * The function replaces an old node with a new node and updates the count property of the new node.
205
- * @param {TreeCounterNode<K, V>} oldNode - The `oldNode` parameter is the node that you want to replace in the data
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
  }