min-heap-typed 1.39.4 → 1.39.6

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 (47) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +6 -6
  2. package/dist/data-structures/binary-tree/avl-tree.js +13 -13
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +7 -7
  4. package/dist/data-structures/binary-tree/binary-tree.js +17 -17
  5. package/dist/data-structures/binary-tree/bst.d.ts +6 -6
  6. package/dist/data-structures/binary-tree/bst.js +13 -13
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +2 -2
  8. package/dist/data-structures/binary-tree/rb-tree.js +4 -4
  9. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -7
  10. package/dist/data-structures/binary-tree/segment-tree.js +16 -16
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  12. package/dist/data-structures/binary-tree/tree-multiset.js +18 -18
  13. package/dist/data-structures/graph/abstract-graph.d.ts +96 -96
  14. package/dist/data-structures/graph/abstract-graph.js +64 -64
  15. package/dist/data-structures/graph/directed-graph.d.ts +68 -68
  16. package/dist/data-structures/graph/directed-graph.js +48 -48
  17. package/dist/data-structures/graph/map-graph.d.ts +13 -13
  18. package/dist/data-structures/graph/map-graph.js +15 -15
  19. package/dist/data-structures/graph/undirected-graph.d.ts +42 -42
  20. package/dist/data-structures/graph/undirected-graph.js +32 -32
  21. package/dist/data-structures/hash/hash-table.d.ts +4 -4
  22. package/dist/data-structures/hash/hash-table.js +8 -8
  23. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
  24. package/dist/data-structures/linked-list/doubly-linked-list.js +54 -54
  25. package/dist/data-structures/linked-list/singly-linked-list.d.ts +24 -24
  26. package/dist/data-structures/linked-list/singly-linked-list.js +52 -52
  27. package/dist/data-structures/queue/queue.d.ts +1 -1
  28. package/dist/data-structures/queue/queue.js +4 -4
  29. package/dist/interfaces/binary-tree.d.ts +2 -2
  30. package/dist/interfaces/graph.d.ts +3 -3
  31. package/package.json +2 -2
  32. package/src/data-structures/binary-tree/avl-tree.ts +13 -13
  33. package/src/data-structures/binary-tree/binary-tree.ts +18 -18
  34. package/src/data-structures/binary-tree/bst.ts +16 -16
  35. package/src/data-structures/binary-tree/rb-tree.ts +6 -6
  36. package/src/data-structures/binary-tree/segment-tree.ts +15 -15
  37. package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
  38. package/src/data-structures/graph/abstract-graph.ts +156 -154
  39. package/src/data-structures/graph/directed-graph.ts +99 -94
  40. package/src/data-structures/graph/map-graph.ts +22 -25
  41. package/src/data-structures/graph/undirected-graph.ts +62 -60
  42. package/src/data-structures/hash/hash-table.ts +9 -9
  43. package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
  44. package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
  45. package/src/data-structures/queue/queue.ts +2 -2
  46. package/src/interfaces/binary-tree.ts +2 -2
  47. package/src/interfaces/graph.ts +3 -3
@@ -12,8 +12,8 @@ import {IBinaryTree} from '../../interfaces';
12
12
  import {Queue} from '../queue';
13
13
 
14
14
  export class BSTNode<V = any, N extends BSTNode<V, N> = BSTNodeNested<V>> extends BinaryTreeNode<V, N> {
15
- constructor(key: BTNKey, val?: V) {
16
- super(key, val);
15
+ constructor(key: BTNKey, value?: V) {
16
+ super(key, value);
17
17
  }
18
18
  }
19
19
 
@@ -41,12 +41,12 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
41
41
  * The function creates a new binary search tree node with the given key and value.
42
42
  * @param {BTNKey} key - The key parameter is the key value that will be associated with
43
43
  * the new node. It is used to determine the position of the node in the binary search tree.
44
- * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It
44
+ * @param [value] - The parameter `value` is an optional value that can be assigned to the node. It
45
45
  * represents the value associated with the node in a binary search tree.
46
46
  * @returns a new instance of the BSTNode class with the specified key and value.
47
47
  */
48
- override createNode(key: BTNKey, val?: V): N {
49
- return new BSTNode<V, N>(key, val) as N;
48
+ override createNode(key: BTNKey, value?: V): N {
49
+ return new BSTNode<V, N>(key, value) as N;
50
50
  }
51
51
 
52
52
  /**
@@ -54,19 +54,19 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
54
54
  * into the tree.
55
55
  * @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
56
56
  * `BTNKey` (which can be a number or a string), a `BSTNode` object, or `null`.
57
- * @param [val] - The `val` parameter is the value to be assigned to the new node being added to the
57
+ * @param [value] - The `value` parameter is the value to be assigned to the new node being added to the
58
58
  * binary search tree.
59
59
  * @returns the inserted node (N) if it was successfully added to the binary search tree. If the node
60
60
  * was not added or if the parameters were invalid, it returns null or undefined.
61
61
  */
62
- override add(keyOrNode: BTNKey | N | null, val?: V): N | null | undefined {
62
+ override add(keyOrNode: BTNKey | N | null, value?: V): N | null | undefined {
63
63
  // TODO support node as a parameter
64
64
  let inserted: N | null = null;
65
65
  let newNode: N | null = null;
66
66
  if (keyOrNode instanceof BSTNode) {
67
67
  newNode = keyOrNode;
68
68
  } else if (typeof keyOrNode === 'number') {
69
- newNode = this.createNode(keyOrNode, val);
69
+ newNode = this.createNode(keyOrNode, value);
70
70
  } else if (keyOrNode === null) {
71
71
  newNode = null;
72
72
  }
@@ -81,7 +81,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
81
81
  if (cur !== null && newNode !== null) {
82
82
  if (this._compare(cur.key, newNode.key) === CP.eq) {
83
83
  if (newNode) {
84
- cur.val = newNode.val;
84
+ cur.value = newNode.value;
85
85
  }
86
86
  //Duplicates are not accepted.
87
87
  traversing = false;
@@ -128,7 +128,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
128
128
  /**
129
129
  * The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
130
130
  * maintaining balance.
131
- * @param {[BTNKey | N, N['val']][]} keysOrNodes - The `arr` parameter in the `addMany` function
131
+ * @param {[BTNKey | N, N['value']][]} keysOrNodes - The `arr` parameter in the `addMany` function
132
132
  * represents an array of keys or nodes that need to be added to the binary search tree. It can be an
133
133
  * array of `BTNKey` or `N` (which represents the node type in the binary search tree) or
134
134
  * `null
@@ -154,15 +154,15 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
154
154
  return super.addMany(keysOrNodes, data);
155
155
  }
156
156
  const inserted: (N | null | undefined)[] = [];
157
- const combinedArr: [BTNKey | N, N['val']][] = keysOrNodes.map((value, index) => [value, data?.[index]]);
157
+ const combinedArr: [BTNKey | N, N['value']][] = keysOrNodes.map((value, index) => [value, data?.[index]]);
158
158
  let sorted = [];
159
159
 
160
- function isNodeOrNullTuple(arr: [BTNKey | N, N['val']][]): arr is [N, N['val']][] {
160
+ function isNodeOrNullTuple(arr: [BTNKey | N, N['value']][]): arr is [N, N['value']][] {
161
161
  for (const [keyOrNode] of arr) if (keyOrNode instanceof BSTNode) return true;
162
162
  return false;
163
163
  }
164
164
 
165
- function isBinaryTreeKeyOrNullTuple(arr: [BTNKey | N, N['val']][]): arr is [BTNKey, N['val']][] {
165
+ function isBinaryTreeKeyOrNullTuple(arr: [BTNKey | N, N['value']][]): arr is [BTNKey, N['value']][] {
166
166
  for (const [keyOrNode] of arr) if (typeof keyOrNode === 'number') return true;
167
167
  return false;
168
168
  }
@@ -178,7 +178,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
178
178
  throw new Error('Invalid input keysOrNodes');
179
179
  }
180
180
  sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode);
181
- sortedData = sorted.map(([, val]) => val);
181
+ sortedData = sorted.map(([, value]) => value);
182
182
  const recursive = (arr: (BTNKey | null | N)[], data?: (V | undefined)[]) => {
183
183
  if (arr.length === 0) return;
184
184
 
@@ -426,7 +426,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
426
426
  if (l > r) return;
427
427
  const m = l + Math.floor((r - l) / 2);
428
428
  const midNode = sorted[m];
429
- this.add(midNode.key, midNode.val);
429
+ this.add(midNode.key, midNode.value);
430
430
  buildBalanceBST(l, m - 1);
431
431
  buildBalanceBST(m + 1, r);
432
432
  };
@@ -442,7 +442,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
442
442
  if (l <= r) {
443
443
  const m = l + Math.floor((r - l) / 2);
444
444
  const midNode = sorted[m];
445
- this.add(midNode.key, midNode.val);
445
+ this.add(midNode.key, midNode.value);
446
446
  stack.push([m + 1, r]);
447
447
  stack.push([l, m - 1]);
448
448
  }
@@ -3,8 +3,8 @@ import {IBinaryTree} from '../../interfaces';
3
3
  import {BST, BSTNode} from './bst';
4
4
 
5
5
  export class RBTreeNode<V = any, N extends RBTreeNode<V, N> = RBTreeNodeNested<V>> extends BSTNode<V, N> {
6
- constructor(key: BTNKey, val?: V) {
7
- super(key, val);
6
+ constructor(key: BTNKey, value?: V) {
7
+ super(key, value);
8
8
  this._color = RBColor.RED;
9
9
  }
10
10
 
@@ -27,12 +27,12 @@ export class RBTree<V, N extends RBTreeNode<V, N> = RBTreeNode<V, RBTreeNodeNest
27
27
  super(options);
28
28
  }
29
29
 
30
- override createNode(key: BTNKey, val?: V): N {
31
- return new RBTreeNode(key, val) as N;
30
+ override createNode(key: BTNKey, value?: V): N {
31
+ return new RBTreeNode(key, value) as N;
32
32
  }
33
33
 
34
- // override add(keyOrNode: BTNKey | N | null, val?: V): N | null | undefined {
35
- // const inserted = super.add(keyOrNode, val);
34
+ // override add(keyOrNode: BTNKey | N | null, value?: V): N | null | undefined {
35
+ // const inserted = super.add(keyOrNode, value);
36
36
  // if (inserted) this._fixInsertViolation(inserted);
37
37
  // return inserted;
38
38
  // }
@@ -9,11 +9,11 @@
9
9
  import type {SegmentTreeNodeVal} from '../../types';
10
10
 
11
11
  export class SegmentTreeNode {
12
- constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null) {
12
+ constructor(start: number, end: number, sum: number, value?: SegmentTreeNodeVal | null) {
13
13
  this._start = start;
14
14
  this._end = end;
15
15
  this._sum = sum;
16
- this._val = val || null;
16
+ this._value = value || null;
17
17
  }
18
18
 
19
19
  private _start = 0;
@@ -35,14 +35,14 @@ export class SegmentTreeNode {
35
35
  this._end = v;
36
36
  }
37
37
 
38
- private _val: SegmentTreeNodeVal | null = null;
38
+ private _value: SegmentTreeNodeVal | null = null;
39
39
 
40
- get val(): SegmentTreeNodeVal | null {
41
- return this._val;
40
+ get value(): SegmentTreeNodeVal | null {
41
+ return this._value;
42
42
  }
43
43
 
44
- set val(v: SegmentTreeNodeVal | null) {
45
- this._val = v;
44
+ set value(v: SegmentTreeNodeVal | null) {
45
+ this._value = v;
46
46
  }
47
47
 
48
48
  private _sum = 0;
@@ -154,30 +154,30 @@ export class SegmentTree {
154
154
  * updated.
155
155
  * @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
156
156
  * the `SegmentTreeNode` at the specified `index`.
157
- * @param {SegmentTreeNodeVal} [val] - The `val` parameter is an optional value that can be assigned to the `val`
157
+ * @param {SegmentTreeNodeVal} [value] - The `value` parameter is an optional value that can be assigned to the `value`
158
158
  * property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
159
- * cur.val = val;` and pass a value for `val` in the
159
+ * cur.value = value;` and pass a value for `value` in the
160
160
  * @returns The function does not return anything.
161
161
  */
162
- updateNode(index: number, sum: number, val?: SegmentTreeNodeVal) {
162
+ updateNode(index: number, sum: number, value?: SegmentTreeNodeVal) {
163
163
  const root = this.root || null;
164
164
  if (!root) {
165
165
  return;
166
166
  }
167
- const dfs = (cur: SegmentTreeNode, index: number, sum: number, val?: SegmentTreeNodeVal) => {
167
+ const dfs = (cur: SegmentTreeNode, index: number, sum: number, value?: SegmentTreeNodeVal) => {
168
168
  if (cur.start === cur.end && cur.start === index) {
169
169
  cur.sum = sum;
170
- if (val !== undefined) cur.val = val;
170
+ if (value !== undefined) cur.value = value;
171
171
  return;
172
172
  }
173
173
  const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
174
174
  if (index <= mid) {
175
175
  if (cur.left) {
176
- dfs(cur.left, index, sum, val);
176
+ dfs(cur.left, index, sum, value);
177
177
  }
178
178
  } else {
179
179
  if (cur.right) {
180
- dfs(cur.right, index, sum, val);
180
+ dfs(cur.right, index, sum, value);
181
181
  }
182
182
  }
183
183
  if (cur.left && cur.right) {
@@ -185,7 +185,7 @@ export class SegmentTree {
185
185
  }
186
186
  };
187
187
 
188
- dfs(root, index, sum, val);
188
+ dfs(root, index, sum, value);
189
189
  }
190
190
 
191
191
  /**
@@ -20,14 +20,14 @@ export class TreeMultisetNode<
20
20
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
21
21
  * @param {BTNKey} key - The `key` parameter is of type `BTNKey` and represents the unique identifier
22
22
  * of the binary tree node.
23
- * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary
23
+ * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
24
24
  * tree node. If no value is provided, it will be `undefined`.
25
25
  * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
26
26
  * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
27
27
  * parameter when creating a new instance of the `BinaryTreeNode` class.
28
28
  */
29
- constructor(key: BTNKey, val?: V, count = 1) {
30
- super(key, val);
29
+ constructor(key: BTNKey, value?: V, count = 1) {
30
+ super(key, value);
31
31
  this.count = count;
32
32
  }
33
33
  }
@@ -59,13 +59,13 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
59
59
  * The function creates a new BSTNode with the given key, value, and count.
60
60
  * @param {BTNKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
61
61
  * distinguish one node from another in the tree.
62
- * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
62
+ * @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
63
63
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
64
64
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
65
65
  * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
66
66
  */
67
- override createNode(key: BTNKey, val?: V, count?: number): N {
68
- return new TreeMultisetNode(key, val, count) as N;
67
+ override createNode(key: BTNKey, value?: V, count?: number): N {
68
+ return new TreeMultisetNode(key, value, count) as N;
69
69
  }
70
70
 
71
71
  /**
@@ -74,22 +74,22 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
74
74
  * @param {BTNKey | N | null} 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
76
  * node to be added), or `null` (which represents a null node).
77
- * @param [val] - The `val` parameter represents the value associated with the key that is being
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
82
  * @returns The function `add` returns a value of type `N | null | undefined`.
83
83
  */
84
- override add(keyOrNode: BTNKey | N | null, val?: V, count = 1): N | null | undefined {
84
+ override add(keyOrNode: BTNKey | N | null, value?: V, count = 1): N | null | undefined {
85
85
  let inserted: N | null | undefined = undefined,
86
86
  newNode: N | null;
87
87
  if (keyOrNode instanceof TreeMultisetNode) {
88
- newNode = this.createNode(keyOrNode.key, keyOrNode.val, keyOrNode.count);
88
+ newNode = this.createNode(keyOrNode.key, keyOrNode.value, keyOrNode.count);
89
89
  } else if (keyOrNode === null) {
90
90
  newNode = null;
91
91
  } else {
92
- newNode = this.createNode(keyOrNode, val, count);
92
+ newNode = this.createNode(keyOrNode, value, count);
93
93
  }
94
94
  if (!this.root) {
95
95
  this._setRoot(newNode);
@@ -103,7 +103,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
103
103
  if (cur) {
104
104
  if (newNode) {
105
105
  if (this._compare(cur.key, newNode.key) === CP.eq) {
106
- cur.val = newNode.val;
106
+ cur.value = newNode.value;
107
107
  cur.count += newNode.count;
108
108
  this._setCount(this.count + newNode.count);
109
109
  traversing = false;
@@ -199,7 +199,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
199
199
  const keyOrNode = keysOrNodes[i];
200
200
 
201
201
  if (keyOrNode instanceof TreeMultisetNode) {
202
- inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count));
202
+ inserted.push(this.add(keyOrNode.key, keyOrNode.value, keyOrNode.count));
203
203
  continue;
204
204
  }
205
205
 
@@ -233,7 +233,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
233
233
  if (l > r) return;
234
234
  const m = l + Math.floor((r - l) / 2);
235
235
  const midNode = sorted[m];
236
- this.add(midNode.key, midNode.val, midNode.count);
236
+ this.add(midNode.key, midNode.value, midNode.count);
237
237
  buildBalanceBST(l, m - 1);
238
238
  buildBalanceBST(m + 1, r);
239
239
  };
@@ -249,7 +249,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
249
249
  if (l <= r) {
250
250
  const m = l + Math.floor((r - l) / 2);
251
251
  const midNode = sorted[m];
252
- this.add(midNode.key, midNode.val, midNode.count);
252
+ this.add(midNode.key, midNode.value, midNode.count);
253
253
  stack.push([m + 1, r]);
254
254
  stack.push([l, m - 1]);
255
255
  }
@@ -351,18 +351,18 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
351
351
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
352
352
  */
353
353
  protected override _swap(srcNode: N, destNode: N): N {
354
- const {key, val, count, height} = destNode;
355
- const tempNode = this.createNode(key, val, count);
354
+ const {key, value, count, height} = destNode;
355
+ const tempNode = this.createNode(key, value, count);
356
356
  if (tempNode) {
357
357
  tempNode.height = height;
358
358
 
359
359
  destNode.key = srcNode.key;
360
- destNode.val = srcNode.val;
360
+ destNode.value = srcNode.value;
361
361
  destNode.count = srcNode.count;
362
362
  destNode.height = srcNode.height;
363
363
 
364
364
  srcNode.key = tempNode.key;
365
- srcNode.val = tempNode.val;
365
+ srcNode.value = tempNode.value;
366
366
  srcNode.count = tempNode.count;
367
367
  srcNode.height = tempNode.height;
368
368
  }