binary-tree-typed 2.2.5 → 2.2.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binary-tree-typed",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "description": "Binary Tree. Javascript & Typescript Data Structure.",
5
5
  "browser": "dist/umd/binary-tree-typed.min.js",
6
6
  "umd:main": "dist/umd/binary-tree-typed.min.js",
@@ -178,6 +178,6 @@
178
178
  "typescript": "^4.9.5"
179
179
  },
180
180
  "dependencies": {
181
- "data-structure-typed": "^2.2.5"
181
+ "data-structure-typed": "^2.2.7"
182
182
  }
183
183
  }
@@ -1,5 +1,3 @@
1
- import { isComparable } from '../utils';
2
-
3
1
  export enum DFSOperation {
4
2
  VISIT = 0,
5
3
  PROCESS = 1
@@ -12,8 +10,8 @@ export class Range<K> {
12
10
  public includeLow: boolean = true,
13
11
  public includeHigh: boolean = true
14
12
  ) {
15
- if (!(isComparable(low) && isComparable(high))) throw new RangeError('low or high is not comparable');
16
- if (low > high) throw new RangeError('low must be less than or equal to high');
13
+ // if (!(isComparable(low) && isComparable(high))) throw new RangeError('low or high is not comparable');
14
+ // if (low > high) throw new RangeError('low must be less than or equal to high');
17
15
  }
18
16
 
19
17
  // Determine whether a key is within the range
@@ -178,6 +178,15 @@ export abstract class IterableEntryBase<K = any, V = any> {
178
178
  return accumulator;
179
179
  }
180
180
 
181
+ /**
182
+ * Converts data structure to `[key, value]` pairs.
183
+ * @returns Array of entries.
184
+ * @remarks Time O(n), Space O(n)
185
+ */
186
+ toArray() {
187
+ return [...this];
188
+ }
189
+
181
190
  /**
182
191
  * Visualize the iterable as an array of `[key, value]` pairs (or a custom string).
183
192
  * @returns Array of entries (default) or a string.
@@ -858,6 +858,31 @@ export class BinaryTree<K = any, V = any, R = any>
858
858
  return deletedResult;
859
859
  }
860
860
 
861
+ search(
862
+ keyNodeEntryOrPredicate:
863
+ | K
864
+ | BinaryTreeNode<K, V>
865
+ | [K | null | undefined, V | undefined]
866
+ | null
867
+ | undefined
868
+ | NodePredicate<BinaryTreeNode<K, V> | null>,
869
+ onlyOne?: boolean
870
+ ): (K | undefined)[];
871
+
872
+ search<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
873
+ keyNodeEntryOrPredicate:
874
+ | K
875
+ | BinaryTreeNode<K, V>
876
+ | [K | null | undefined, V | undefined]
877
+ | null
878
+ | undefined
879
+ | NodePredicate<BinaryTreeNode<K, V> | null>,
880
+ onlyOne: boolean,
881
+ callback: C,
882
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
883
+ iterationType?: IterationType
884
+ ): ReturnType<C>[];
885
+
861
886
  /**
862
887
  * Searches the tree for nodes matching a predicate.
863
888
  * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Performs a full DFS (pre-order) scan of the tree. Time O(N), as it may visit every node. Space O(H) for the call stack (recursive) or explicit stack (iterative), where H is the tree height (O(N) worst-case).
@@ -1245,6 +1270,16 @@ export class BinaryTree<K = any, V = any, R = any>
1245
1270
  }
1246
1271
  }
1247
1272
 
1273
+ getPathToRoot(
1274
+ beginNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
1275
+ ): (K | undefined)[];
1276
+
1277
+ getPathToRoot<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(
1278
+ beginNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
1279
+ callback: C,
1280
+ isReverse?: boolean
1281
+ ): ReturnType<C>[];
1282
+
1248
1283
  /**
1249
1284
  * Gets the path from a given node up to the root.
1250
1285
  * @remarks Time O(H), where H is the depth of the `beginNode`. O(N) worst-case. Space O(H) for the result array.
@@ -1273,6 +1308,14 @@ export class BinaryTree<K = any, V = any, R = any>
1273
1308
  return isReverse ? result.reverse() : result;
1274
1309
  }
1275
1310
 
1311
+ getLeftMost(): K | undefined;
1312
+
1313
+ getLeftMost<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(
1314
+ callback: C,
1315
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
1316
+ iterationType?: IterationType
1317
+ ): ReturnType<C>;
1318
+
1276
1319
  /**
1277
1320
  * Finds the leftmost node in a subtree (the node with the smallest key in a BST).
1278
1321
  * @remarks Time O(H), where H is the height of the left spine. O(N) worst-case. Space O(H) for recursive/trampoline stack.
@@ -1312,6 +1355,14 @@ export class BinaryTree<K = any, V = any, R = any>
1312
1355
  }
1313
1356
  }
1314
1357
 
1358
+ getRightMost(): K | undefined;
1359
+
1360
+ getRightMost<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(
1361
+ callback: C,
1362
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
1363
+ iterationType?: IterationType
1364
+ ): ReturnType<C>;
1365
+
1315
1366
  /**
1316
1367
  * Finds the rightmost node in a subtree (the node with the largest key in a BST).
1317
1368
  * @remarks Time O(H), where H is the height of the right spine. O(N) worst-case. Space O(H) for recursive/trampoline stack.
@@ -1394,6 +1445,8 @@ export class BinaryTree<K = any, V = any, R = any>
1394
1445
  return y;
1395
1446
  }
1396
1447
 
1448
+ dfs(): (K | undefined)[];
1449
+
1397
1450
  dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(
1398
1451
  callback?: C,
1399
1452
  pattern?: DFSOrderPattern,
@@ -1437,6 +1490,8 @@ export class BinaryTree<K = any, V = any, R = any>
1437
1490
  return this._dfs(callback, pattern, onlyOne, startNode, iterationType, includeNull);
1438
1491
  }
1439
1492
 
1493
+ bfs(): (K | undefined)[];
1494
+
1440
1495
  bfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(
1441
1496
  callback?: C,
1442
1497
  startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
@@ -1519,6 +1574,14 @@ export class BinaryTree<K = any, V = any, R = any>
1519
1574
  return ans;
1520
1575
  }
1521
1576
 
1577
+ leaves(): (K | undefined)[];
1578
+
1579
+ leaves<C extends NodeCallback<BinaryTreeNode<K, V>>>(
1580
+ callback: C,
1581
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
1582
+ iterationType?: IterationType
1583
+ ): ReturnType<C>[];
1584
+
1522
1585
  /**
1523
1586
  * Finds all leaf nodes in the tree.
1524
1587
  * @remarks Time O(N), visits every node. Space O(H) for recursive stack or O(N) for iterative queue.
@@ -1570,6 +1633,8 @@ export class BinaryTree<K = any, V = any, R = any>
1570
1633
  return leaves;
1571
1634
  }
1572
1635
 
1636
+ listLevels(): (K | undefined)[][];
1637
+
1573
1638
  listLevels<C extends NodeCallback<BinaryTreeNode<K, V>>>(
1574
1639
  callback?: C,
1575
1640
  startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
@@ -1645,6 +1710,8 @@ export class BinaryTree<K = any, V = any, R = any>
1645
1710
  return levelsNodes;
1646
1711
  }
1647
1712
 
1713
+ morris(): (K | undefined)[];
1714
+
1648
1715
  morris<C extends NodeCallback<BinaryTreeNode<K, V>>>(
1649
1716
  callback?: C,
1650
1717
  pattern?: DFSOrderPattern,