deque-typed 1.53.7 → 1.53.9

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 (68) hide show
  1. package/dist/common/index.js +5 -0
  2. package/dist/data-structures/base/iterable-entry-base.js +4 -4
  3. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +36 -17
  4. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +65 -36
  5. package/dist/data-structures/binary-tree/avl-tree.d.ts +12 -8
  6. package/dist/data-structures/binary-tree/avl-tree.js +19 -6
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +53 -40
  8. package/dist/data-structures/binary-tree/binary-tree.js +76 -72
  9. package/dist/data-structures/binary-tree/bst.d.ts +87 -52
  10. package/dist/data-structures/binary-tree/bst.js +111 -63
  11. package/dist/data-structures/binary-tree/index.d.ts +1 -1
  12. package/dist/data-structures/binary-tree/index.js +1 -1
  13. package/dist/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +83 -10
  14. package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +91 -44
  15. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +34 -18
  16. package/dist/data-structures/binary-tree/tree-multi-map.js +66 -40
  17. package/dist/data-structures/graph/abstract-graph.js +2 -2
  18. package/dist/data-structures/hash/hash-map.d.ts +31 -1
  19. package/dist/data-structures/hash/hash-map.js +35 -5
  20. package/dist/data-structures/heap/heap.d.ts +20 -3
  21. package/dist/data-structures/heap/heap.js +31 -11
  22. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
  23. package/dist/data-structures/linked-list/doubly-linked-list.js +68 -21
  24. package/dist/data-structures/linked-list/singly-linked-list.d.ts +44 -11
  25. package/dist/data-structures/linked-list/singly-linked-list.js +70 -26
  26. package/dist/data-structures/queue/deque.d.ts +37 -8
  27. package/dist/data-structures/queue/deque.js +73 -29
  28. package/dist/data-structures/queue/queue.d.ts +41 -1
  29. package/dist/data-structures/queue/queue.js +51 -9
  30. package/dist/data-structures/stack/stack.d.ts +27 -10
  31. package/dist/data-structures/stack/stack.js +39 -20
  32. package/dist/data-structures/trie/trie.d.ts +8 -3
  33. package/dist/data-structures/trie/trie.js +8 -3
  34. package/dist/interfaces/binary-tree.d.ts +3 -4
  35. package/dist/types/data-structures/base/base.d.ts +1 -1
  36. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  37. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  38. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
  39. package/dist/types/data-structures/binary-tree/bst.d.ts +3 -4
  40. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
  41. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
  42. package/package.json +2 -2
  43. package/src/common/index.ts +7 -1
  44. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  45. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +82 -55
  46. package/src/data-structures/binary-tree/avl-tree.ts +32 -15
  47. package/src/data-structures/binary-tree/binary-tree.ts +89 -84
  48. package/src/data-structures/binary-tree/bst.ts +149 -97
  49. package/src/data-structures/binary-tree/index.ts +1 -1
  50. package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +105 -55
  51. package/src/data-structures/binary-tree/tree-multi-map.ts +81 -51
  52. package/src/data-structures/graph/abstract-graph.ts +2 -2
  53. package/src/data-structures/hash/hash-map.ts +37 -7
  54. package/src/data-structures/heap/heap.ts +33 -10
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +75 -21
  56. package/src/data-structures/linked-list/singly-linked-list.ts +77 -27
  57. package/src/data-structures/queue/deque.ts +72 -28
  58. package/src/data-structures/queue/queue.ts +50 -7
  59. package/src/data-structures/stack/stack.ts +39 -20
  60. package/src/data-structures/trie/trie.ts +8 -3
  61. package/src/interfaces/binary-tree.ts +3 -13
  62. package/src/types/data-structures/base/base.ts +1 -1
  63. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -4
  64. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -4
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -3
  66. package/src/types/data-structures/binary-tree/bst.ts +3 -5
  67. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -6
  68. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -6
@@ -113,6 +113,9 @@ class BinaryTree extends base_1.IterableEntryBase {
113
113
  return this._toEntryFn;
114
114
  }
115
115
  /**
116
+ * Time Complexity: O(1)
117
+ * Space Complexity: O(1)
118
+ *
116
119
  * The function creates a new binary tree node with a specified key and optional value.
117
120
  * @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
118
121
  * @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
@@ -125,57 +128,22 @@ class BinaryTree extends base_1.IterableEntryBase {
125
128
  return new BinaryTreeNode(key, this._isMapMode ? undefined : value);
126
129
  }
127
130
  /**
128
- * The function creates a binary tree with the specified options.
129
- * @param [options] - The `options` parameter in the `createTree` function is an optional parameter
130
- * that allows you to provide partial configuration options for creating a binary tree. It is of type
131
- * `Partial<BinaryTreeOptions<K, V, R>>`, which means you can pass in an object containing a subset
132
- * of properties
133
- * @returns A new instance of a binary tree with the specified options is being returned.
131
+ * Time Complexity: O(1)
132
+ * Space Complexity: O(1)
133
+ *
134
+ * The `createTree` function creates a new binary tree based on the provided options.
135
+ * @param [options] - The `options` parameter in the `createTree` method is of type
136
+ * `BinaryTreeOptions<K, V, R>`. This type likely contains configuration options for creating a
137
+ * binary tree, such as the iteration type, whether the tree is in map mode, and functions for
138
+ * converting entries.
139
+ * @returns The `createTree` method is returning an instance of the `BinaryTree` class with the
140
+ * provided options. The method is creating a new `BinaryTree` object with an empty array as the
141
+ * initial data, and then setting various options such as `iterationType`, `isMapMode`, and
142
+ * `toEntryFn` based on the current object's properties and the provided `options`. Finally, it
134
143
  */
135
144
  createTree(options) {
136
145
  return new BinaryTree([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, toEntryFn: this._toEntryFn }, options));
137
146
  }
138
- /**
139
- * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
140
- * or returns null.
141
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
142
- * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
143
- * can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
144
- * node, an entry
145
- * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
146
- * an optional parameter of type `V`. It represents the value associated with the key in the node
147
- * being created. If a `value` is provided, it will be used when creating the node. If
148
- * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
149
- * (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
150
- * input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
151
- * value.
152
- */
153
- keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
154
- if (keyNodeEntryOrRaw === undefined)
155
- return [undefined, undefined];
156
- if (keyNodeEntryOrRaw === null)
157
- return [null, undefined];
158
- if (this.isNode(keyNodeEntryOrRaw))
159
- return [keyNodeEntryOrRaw, value];
160
- if (this.isEntry(keyNodeEntryOrRaw)) {
161
- const [key, entryValue] = keyNodeEntryOrRaw;
162
- if (key === undefined)
163
- return [undefined, undefined];
164
- else if (key === null)
165
- return [null, undefined];
166
- const finalValue = value !== null && value !== void 0 ? value : entryValue;
167
- return [this.createNode(key, finalValue), finalValue];
168
- }
169
- if (this.isRaw(keyNodeEntryOrRaw)) {
170
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
171
- const finalValue = value !== null && value !== void 0 ? value : entryValue;
172
- if (this.isKey(key))
173
- return [this.createNode(key, finalValue), finalValue];
174
- }
175
- if (this.isKey(keyNodeEntryOrRaw))
176
- return [this.createNode(keyNodeEntryOrRaw, value), value];
177
- return [undefined, undefined];
178
- }
179
147
  /**
180
148
  * Time Complexity: O(n)
181
149
  * Space Complexity: O(log n)
@@ -346,7 +314,7 @@ class BinaryTree extends base_1.IterableEntryBase {
346
314
  * key was found and the node was replaced instead of inserted.
347
315
  */
348
316
  add(keyNodeEntryOrRaw, value) {
349
- const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
317
+ const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
350
318
  if (newNode === undefined)
351
319
  return false;
352
320
  // If the tree is empty, directly set the new node as the root node
@@ -1499,7 +1467,7 @@ class BinaryTree extends base_1.IterableEntryBase {
1499
1467
  const newTree = this.createTree();
1500
1468
  let index = 0;
1501
1469
  for (const [key, value] of this) {
1502
- if (predicate.call(thisArg, value, key, index++, this)) {
1470
+ if (predicate.call(thisArg, key, value, index++, this)) {
1503
1471
  newTree.add([key, value]);
1504
1472
  }
1505
1473
  }
@@ -1509,34 +1477,29 @@ class BinaryTree extends base_1.IterableEntryBase {
1509
1477
  * Time Complexity: O(n)
1510
1478
  * Space Complexity: O(n)
1511
1479
  *
1512
- * The `map` function iterates over key-value pairs in a tree data structure, applies a callback
1513
- * function to each value, and returns a new tree with the updated values.
1514
- * @param callback - The `callback` parameter in the `map` method is a function that will be called
1515
- * on each entry in the tree. It takes four arguments:
1516
- * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is an optional parameter
1517
- * that specifies the value to be passed as `this` when executing the callback function. If provided,
1518
- * the `thisArg` value will be used as the `this` value within the callback function. If `thisArg
1519
- * @returns The `map` method is returning a new tree with the entries modified by the provided
1520
- * callback function. Each entry in the original tree is passed to the callback function, and the
1521
- * result of the callback function is added to the new tree.
1480
+ * The `map` function in TypeScript creates a new BinaryTree by applying a callback function to each
1481
+ * entry in the original BinaryTree.
1482
+ * @param callback - A function that will be called for each entry in the current binary tree. It
1483
+ * takes the key, value (which can be undefined), and an array containing the mapped key and value as
1484
+ * arguments.
1485
+ * @param [options] - The `options` parameter in the `map` method is of type `BinaryTreeOptions<MK,
1486
+ * MV, MR>`. It is an optional parameter that allows you to specify additional options for the binary
1487
+ * tree being created during the mapping process. These options could include things like custom
1488
+ * comparators, initial
1489
+ * @param {any} [thisArg] - The `thisArg` parameter in the `map` method is used to specify the value
1490
+ * of `this` when executing the `callback` function. It allows you to set the context (value of
1491
+ * `this`) within the callback function. If `thisArg` is provided, it will be passed
1492
+ * @returns The `map` function is returning a new `BinaryTree` instance filled with entries that are
1493
+ * the result of applying the provided `callback` function to each entry in the original tree.
1522
1494
  */
1523
- map(callback, thisArg) {
1524
- const newTree = this.createTree();
1495
+ map(callback, options, thisArg) {
1496
+ const newTree = new BinaryTree([], options);
1525
1497
  let index = 0;
1526
1498
  for (const [key, value] of this) {
1527
- newTree.add([key, callback.call(thisArg, value, key, index++, this)]);
1499
+ newTree.add(callback.call(thisArg, key, value, index++, this));
1528
1500
  }
1529
1501
  return newTree;
1530
1502
  }
1531
- // // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
1532
- // // map<NV>(callback: (entry: [K, V | undefined], tree: this) => NV) {
1533
- // // const newTree = this.createTree();
1534
- // // for (const [key, value] of this) {
1535
- // // newTree.add(key, callback([key, value], this));
1536
- // // }
1537
- // // return newTree;
1538
- // // }
1539
- //
1540
1503
  /**
1541
1504
  * Time Complexity: O(n)
1542
1505
  * Space Complexity: O(n)
@@ -1568,7 +1531,7 @@ class BinaryTree extends base_1.IterableEntryBase {
1568
1531
  if (opts.isShowRedBlackNIL)
1569
1532
  output += `S for Sentinel Node(NIL)\n`;
1570
1533
  const display = (root) => {
1571
- const [lines, , ,] = this._displayAux(root, opts);
1534
+ const [lines, ,] = this._displayAux(root, opts);
1572
1535
  let paragraph = '';
1573
1536
  for (const line of lines) {
1574
1537
  paragraph += line + '\n';
@@ -1596,6 +1559,47 @@ class BinaryTree extends base_1.IterableEntryBase {
1596
1559
  print(options, startNode = this._root) {
1597
1560
  console.log(this.toVisual(startNode, options));
1598
1561
  }
1562
+ /**
1563
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
1564
+ * or returns null.
1565
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
1566
+ * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
1567
+ * can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
1568
+ * node, an entry
1569
+ * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
1570
+ * an optional parameter of type `V`. It represents the value associated with the key in the node
1571
+ * being created. If a `value` is provided, it will be used when creating the node. If
1572
+ * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
1573
+ * (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
1574
+ * input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
1575
+ * value.
1576
+ */
1577
+ _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
1578
+ if (keyNodeEntryOrRaw === undefined)
1579
+ return [undefined, undefined];
1580
+ if (keyNodeEntryOrRaw === null)
1581
+ return [null, undefined];
1582
+ if (this.isNode(keyNodeEntryOrRaw))
1583
+ return [keyNodeEntryOrRaw, value];
1584
+ if (this.isEntry(keyNodeEntryOrRaw)) {
1585
+ const [key, entryValue] = keyNodeEntryOrRaw;
1586
+ if (key === undefined)
1587
+ return [undefined, undefined];
1588
+ else if (key === null)
1589
+ return [null, undefined];
1590
+ const finalValue = value !== null && value !== void 0 ? value : entryValue;
1591
+ return [this.createNode(key, finalValue), finalValue];
1592
+ }
1593
+ if (this.isRaw(keyNodeEntryOrRaw)) {
1594
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
1595
+ const finalValue = value !== null && value !== void 0 ? value : entryValue;
1596
+ if (this.isKey(key))
1597
+ return [this.createNode(key, finalValue), finalValue];
1598
+ }
1599
+ if (this.isKey(keyNodeEntryOrRaw))
1600
+ return [this.createNode(keyNodeEntryOrRaw, value), value];
1601
+ return [undefined, undefined];
1602
+ }
1599
1603
  /**
1600
1604
  * Time complexity: O(n)
1601
1605
  * Space complexity: O(n)
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BSTNested, BSTNodeNested, BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, IterationType, NodeCallback, NodePredicate, OptNode } from '../../types';
8
+ import { BSTNodeNested, BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNode } from '../../types';
9
9
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { Range } from '../../common';
@@ -47,32 +47,48 @@ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE>
47
47
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
48
48
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
49
49
  * @example
50
- * // Find kth smallest element
51
- * // Create a BST with some elements
52
- * const bst = new BST<number>([5, 3, 7, 1, 4, 6, 8]);
53
- * const sortedKeys = bst.dfs(node => node.key, 'IN');
50
+ * // Merge 3 sorted datasets
51
+ * const dataset1 = new BST<number, string>([
52
+ * [1, 'A'],
53
+ * [7, 'G']
54
+ * ]);
55
+ * const dataset2 = [
56
+ * [2, 'B'],
57
+ * [6, 'F']
58
+ * ];
59
+ * const dataset3 = new BST<number, string>([
60
+ * [3, 'C'],
61
+ * [5, 'E'],
62
+ * [4, 'D']
63
+ * ]);
54
64
  *
55
- * // Helper function to find kth smallest
56
- * const findKthSmallest = (k: number): number | undefined => {
57
- * return sortedKeys[k - 1];
58
- * };
65
+ * // Merge datasets into a single BinarySearchTree
66
+ * const merged = new BST<number, string>(dataset1);
67
+ * merged.addMany(dataset2);
68
+ * merged.merge(dataset3);
59
69
  *
60
- * // Assertions
61
- * console.log(findKthSmallest(1)); // 1
62
- * console.log(findKthSmallest(3)); // 4
63
- * console.log(findKthSmallest(7)); // 8
70
+ * // Verify merged dataset is in sorted order
71
+ * console.log([...merged.values()]); // ['A', 'B', 'C', 'D', 'E', 'F', 'G']
64
72
  * @example
65
73
  * // Find elements in a range
66
74
  * const bst = new BST<number>([10, 5, 15, 3, 7, 12, 18]);
67
75
  * console.log(bst.search(new Range(5, 10))); // [10, 5, 7]
68
- * console.log(bst.search(new Range(4, 12))); // [10, 12, 5, 7]
76
+ * console.log(bst.rangeSearch([4, 12], node => node.key.toString())); // ['10', '12', '5', '7']
69
77
  * console.log(bst.search(new Range(4, 12, true, false))); // [10, 5, 7]
70
- * console.log(bst.search(new Range(15, 20))); // [15, 18]
78
+ * console.log(bst.rangeSearch([15, 20])); // [15, 18]
71
79
  * console.log(bst.search(new Range(15, 20, false))); // [18]
72
80
  * @example
73
81
  * // Find lowest common ancestor
74
82
  * const bst = new BST<number>([20, 10, 30, 5, 15, 25, 35, 3, 7, 12, 18]);
75
83
  *
84
+ * // LCA helper function
85
+ * const findLCA = (num1: number, num2: number): number | undefined => {
86
+ * const path1 = bst.getPathToRoot(num1);
87
+ * const path2 = bst.getPathToRoot(num2);
88
+ * // Find the first common ancestor
89
+ * return findFirstCommon(path1, path2);
90
+ * };
91
+ *
76
92
  * function findFirstCommon(arr1: number[], arr2: number[]): number | undefined {
77
93
  * for (const num of arr1) {
78
94
  * if (arr2.indexOf(num) !== -1) {
@@ -82,20 +98,12 @@ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE>
82
98
  * return undefined;
83
99
  * }
84
100
  *
85
- * // LCA helper function
86
- * const findLCA = (num1: number, num2: number): number | undefined => {
87
- * const path1 = bst.getPathToRoot(num1);
88
- * const path2 = bst.getPathToRoot(num2);
89
- * // Find the first common ancestor
90
- * return findFirstCommon(path1, path2);
91
- * };
92
- *
93
101
  * // Assertions
94
102
  * console.log(findLCA(3, 10)); // 7
95
103
  * console.log(findLCA(5, 35)); // 15
96
104
  * console.log(findLCA(20, 30)); // 25
97
105
  */
98
- export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>> extends BinaryTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
106
+ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>> extends BinaryTree<K, V, R, NODE> implements IBinaryTree<K, V, R, NODE> {
99
107
  /**
100
108
  * This is the constructor function for a Binary Search Tree class in TypeScript.
101
109
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
@@ -118,6 +126,19 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
118
126
  * @returns The `isReverse` property of the object, which is a boolean value.
119
127
  */
120
128
  get isReverse(): boolean;
129
+ protected _comparator: Comparator<K>;
130
+ /**
131
+ * The function returns the value of the _comparator property.
132
+ * @returns The `_comparator` property is being returned.
133
+ */
134
+ get comparator(): Comparator<K>;
135
+ protected _specifyComparable?: (key: K) => Comparable;
136
+ /**
137
+ * This function returns the value of the `_specifyComparable` property.
138
+ * @returns The method `specifyComparable()` is being returned, which is a getter method for the
139
+ * `_specifyComparable` property.
140
+ */
141
+ get specifyComparable(): ((key: K) => Comparable) | undefined;
121
142
  /**
122
143
  * The function creates a new BSTNode with the given key and value and returns it.
123
144
  * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
@@ -128,23 +149,17 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
128
149
  */
129
150
  createNode(key: K, value?: V): NODE;
130
151
  /**
131
- * The function creates a new binary search tree with the specified options.
132
- * @param [options] - The `options` parameter is an optional object that allows you to customize the
133
- * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
134
- * following properties:
135
- * @returns a new instance of the BST class with the provided options.
136
- */
137
- createTree(options?: BSTOptions<K, V, R>): TREE;
138
- /**
139
- * The function overrides a method and converts a key, value pair or entry or raw element to a node.
140
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
141
- * type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
142
- * element.
143
- * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
144
- * value associated with a key in a key-value pair.
145
- * @returns either a NODE object or undefined.
152
+ * Time Complexity: O(1)
153
+ * Space Complexity: O(1)
154
+ *
155
+ * The `createTree` function in TypeScript overrides the default options with the provided options to
156
+ * create a new Binary Search Tree.
157
+ * @param [options] - The `options` parameter in the `createTree` method is an optional object that
158
+ * can contain the following properties:
159
+ * @returns A new instance of a Binary Search Tree (BST) is being returned with the specified options
160
+ * and properties inherited from the current instance.
146
161
  */
147
- keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): [OptNode<NODE>, V | undefined];
162
+ createTree(options?: BSTOptions<K, V, R>): BST<K, V, R, BSTNode<K, V, BSTNodeNested<K, V>>>;
148
163
  /**
149
164
  * Time Complexity: O(log n)
150
165
  * Space Complexity: O(log n)
@@ -221,7 +236,7 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
221
236
  * @param anotherTree - `anotherTree` is an instance of a Binary Search Tree (BST) with key type `K`,
222
237
  * value type `V`, return type `R`, node type `NODE`, and tree type `TREE`.
223
238
  */
224
- merge(anotherTree: BST<K, V, R, NODE, TREE>): void;
239
+ merge(anotherTree: this): void;
225
240
  /**
226
241
  * Time Complexity: O(log n)
227
242
  * Space Complexity: O(k + log n)
@@ -251,6 +266,28 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
251
266
  * collected in an array and returned as the output of the method.
252
267
  */
253
268
  search<C extends NodeCallback<NODE>>(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R | NodePredicate<NODE> | Range<K>, onlyOne?: boolean, callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
269
+ /**
270
+ * Time Complexity: O(log n)
271
+ * Space Complexity: O(n)
272
+ *
273
+ * The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
274
+ * @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
275
+ * either a `Range` object or an array of two elements representing the range boundaries.
276
+ * @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
277
+ * function that is used to process each node that is found within the specified range during the
278
+ * search operation. It is of type `NodeCallback<NODE>`, where `NODE` is the type of nodes in the
279
+ * data structure.
280
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `rangeSearch`
281
+ * function represents the node from which the search for nodes within the specified range will
282
+ * begin. It is the starting point for the range search operation.
283
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
284
+ * is used to specify the type of iteration to be performed during the search operation. It has a
285
+ * default value of `this.iterationType`, which suggests that it is likely a property of the class or
286
+ * object that the `rangeSearch`
287
+ * @returns The `rangeSearch` function is returning the result of calling the `search` method with
288
+ * the specified parameters.
289
+ */
290
+ rangeSearch<C extends NodeCallback<NODE>>(range: Range<K> | [K, K], callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
254
291
  /**
255
292
  * Time Complexity: O(log n)
256
293
  * Space Complexity: O(1)
@@ -378,19 +415,17 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
378
415
  * @returns a boolean value.
379
416
  */
380
417
  isAVLBalanced(iterationType?: IterationType): boolean;
381
- protected _comparator: Comparator<K>;
418
+ map<MK, MV, MR>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BSTOptions<MK, MV, MR>, thisArg?: any): BST<MK, MV, MR, BSTNode<MK, MV, BSTNodeNested<MK, MV>>>;
382
419
  /**
383
- * The function returns the value of the _comparator property.
384
- * @returns The `_comparator` property is being returned.
385
- */
386
- get comparator(): Comparator<K>;
387
- protected _extractComparable?: (key: K) => Comparable;
388
- /**
389
- * This function returns the value of the `_extractComparable` property.
390
- * @returns The method `extractComparable()` is being returned, which is a getter method for the
391
- * `_extractComparable` property.
420
+ * The function overrides a method and converts a key, value pair or entry or raw element to a node.
421
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
422
+ * type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
423
+ * element.
424
+ * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
425
+ * value associated with a key in a key-value pair.
426
+ * @returns either a NODE object or undefined.
392
427
  */
393
- get extractComparable(): ((key: K) => Comparable) | undefined;
428
+ protected _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): [OptNode<NODE>, V | undefined];
394
429
  /**
395
430
  * The function sets the root of a tree-like structure and updates the parent property of the new
396
431
  * root.