min-heap-typed 1.42.3 → 1.42.4

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.
@@ -71,23 +71,24 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
71
71
  /**
72
72
  * The `add` function adds a new node to a binary search tree, updating the count if the key already
73
73
  * exists, and balancing the tree if necessary.
74
- * @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
74
+ * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can be either a
75
75
  * `BTNKey` (which represents the key of the node to be added), a `N` (which represents a
76
- * node to be added), or `null` (which represents a null node).
76
+ * node to be added), or `undefined` (which represents a undefined node).
77
77
  * @param [value] - The `value` parameter represents the value associated with the key that is being
78
78
  * added to the binary tree.
79
79
  * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
80
80
  * pair that will be added to the binary tree. It has a default value of 1, which means that if no
81
81
  * count is specified, the default count will be 1.
82
- * @returns The function `add` returns a value of type `N | null | undefined`.
82
+ * @returns The function `add` returns a value of type `N | undefined | undefined`.
83
83
  */
84
- override add(keyOrNode: BTNKey | N | null, value?: V, count = 1): N | null | undefined {
85
- let inserted: N | null | undefined = undefined,
86
- newNode: N | null;
84
+ override add(keyOrNode: BTNKey | N | null | undefined, value?: V, count = 1): N | undefined {
85
+ if(keyOrNode === null) return undefined;
86
+ let inserted: N | undefined = undefined,
87
+ newNode: N | undefined;
87
88
  if (keyOrNode instanceof TreeMultisetNode) {
88
89
  newNode = this.createNode(keyOrNode.key, keyOrNode.value, keyOrNode.count);
89
- } else if (keyOrNode === null) {
90
- newNode = null;
90
+ } else if (keyOrNode === undefined) {
91
+ newNode = undefined;
91
92
  } else {
92
93
  newNode = this.createNode(keyOrNode, value, count);
93
94
  }
@@ -138,7 +139,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
138
139
  }
139
140
  }
140
141
  } else {
141
- // TODO may need to support null inserted
142
+ // TODO may need to support undefined inserted
142
143
  }
143
144
  } else {
144
145
  traversing = false;
@@ -151,17 +152,17 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
151
152
 
152
153
  /**
153
154
  * The function adds a new node to a binary tree if there is an available slot in the parent node.
154
- * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to
155
- * the tree. It can be either a node object (`N`) or `null`.
155
+ * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be added to
156
+ * the tree. It can be either a node object (`N`) or `undefined`.
156
157
  * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
157
158
  * be added as a child.
158
159
  * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
159
160
  */
160
- override _addTo(newNode: N | null, parent: N): N | null | undefined {
161
+ override _addTo(newNode: N | undefined, parent: N): N | undefined {
161
162
  if (parent) {
162
163
  if (parent.left === undefined) {
163
164
  parent.left = newNode;
164
- if (newNode !== null) {
165
+ if (newNode !== undefined) {
165
166
  this._size = this.size + 1;
166
167
  this._setCount(this.count + newNode.count);
167
168
  }
@@ -169,7 +170,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
169
170
  return parent.left;
170
171
  } else if (parent.right === undefined) {
171
172
  parent.right = newNode;
172
- if (newNode !== null) {
173
+ if (newNode !== undefined) {
173
174
  this._size = this.size + 1;
174
175
  this._setCount(this.count + newNode.count);
175
176
  }
@@ -185,15 +186,15 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
185
186
  /**
186
187
  * The `addMany` function adds multiple keys or nodes to a TreeMultiset and returns an array of the
187
188
  * inserted nodes.
188
- * @param {(BTNKey | null)[] | (N | null)[]} keysOrNodes - An array of keys or nodes to be
189
+ * @param {(BTNKey | undefined)[] | (N | undefined)[]} keysOrNodes - An array of keys or nodes to be
189
190
  * added to the multiset. Each element can be either a BTNKey or a TreeMultisetNode.
190
191
  * @param {V[]} [data] - The `data` parameter is an optional array of values that correspond
191
192
  * to the keys or nodes being added to the multiset. It is used to associate additional data with
192
193
  * each key or node.
193
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
194
+ * @returns The function `addMany` returns an array of `N`, `undefined`, or `undefined` values.
194
195
  */
195
- override addMany(keysOrNodes: (BTNKey | null)[] | (N | null)[], data?: V[]): (N | null | undefined)[] {
196
- const inserted: (N | null | undefined)[] = [];
196
+ override addMany(keysOrNodes: (BTNKey | undefined)[] | (N | undefined)[], data?: V[]): (N | undefined)[] {
197
+ const inserted: (N | undefined | undefined)[] = [];
197
198
 
198
199
  for (let i = 0; i < keysOrNodes.length; i++) {
199
200
  const keyOrNode = keysOrNodes[i];
@@ -203,7 +204,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
203
204
  continue;
204
205
  }
205
206
 
206
- if (keyOrNode === null) {
207
+ if (keyOrNode === undefined) {
207
208
  inserted.push(this.add(NaN, undefined, 0));
208
209
  continue;
209
210
  }
@@ -283,11 +284,11 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
283
284
  const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
284
285
  if (!this.root) return bstDeletedResult;
285
286
 
286
- const curr: N | null = this.getNode(identifier, callback);
287
+ const curr: N | undefined = this.getNode(identifier, callback) ?? undefined;
287
288
  if (!curr) return bstDeletedResult;
288
289
 
289
- const parent: N | null = curr?.parent ? curr.parent : null;
290
- let needBalanced: N | null = null,
290
+ const parent: N | undefined = curr?.parent ? curr.parent : undefined;
291
+ let needBalanced: N | undefined = undefined,
291
292
  orgCurrent = curr;
292
293
 
293
294
  if (curr.count > 1 && !ignoreCount) {
@@ -307,7 +308,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
307
308
  needBalanced = parent;
308
309
  }
309
310
  } else {
310
- const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
311
+ const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : undefined;
311
312
  if (leftSubTreeRightMost) {
312
313
  const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
313
314
  orgCurrent = this._swap(curr, leftSubTreeRightMost);
@@ -24,7 +24,7 @@ export enum FamilyPosition {
24
24
 
25
25
  export type BTNKey = number;
26
26
 
27
- export type BinaryTreeDeletedResult<N> = { deleted: N | null | undefined; needBalanced: N | null };
27
+ export type BinaryTreeDeletedResult<N> = { deleted: N | null | undefined; needBalanced: N | null | undefined };
28
28
 
29
29
  export type BinaryTreeNodeNested<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
30
30
 
@@ -1,8 +1,8 @@
1
- // import {BinaryTreeOptions} from './binary-tree';
2
- // import {RBTreeNode} from '../../../data-structures';
1
+ import {RBTreeNode} from '../../../data-structures';
2
+ import {BSTOptions} from "./bst";
3
3
 
4
4
  export enum RBTNColor { RED = 1, BLACK = 0}
5
5
 
6
- // export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
- //
8
- // export type RBTreeOptions = BinaryTreeOptions & {}
6
+ export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
+
8
+ export type RBTreeOptions = BSTOptions & {};