data-structure-typed 1.12.11 → 1.12.21

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 (64) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +14 -5
  2. package/dist/data-structures/binary-tree/avl-tree.js +15 -6
  3. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +11 -2
  4. package/dist/data-structures/binary-tree/binary-indexed-tree.js +11 -2
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +26 -17
  6. package/dist/data-structures/binary-tree/binary-tree.js +72 -62
  7. package/dist/data-structures/binary-tree/bst.d.ts +92 -5
  8. package/dist/data-structures/binary-tree/bst.js +89 -5
  9. package/dist/data-structures/binary-tree/segment-tree.d.ts +41 -2
  10. package/dist/data-structures/binary-tree/segment-tree.js +41 -2
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +34 -3
  12. package/dist/data-structures/binary-tree/tree-multiset.js +35 -4
  13. package/dist/data-structures/graph/abstract-graph.d.ts +5 -0
  14. package/dist/data-structures/graph/abstract-graph.js +12 -4
  15. package/dist/data-structures/graph/directed-graph.d.ts +18 -4
  16. package/dist/data-structures/graph/directed-graph.js +24 -37
  17. package/dist/data-structures/graph/undirected-graph.d.ts +13 -0
  18. package/dist/data-structures/graph/undirected-graph.js +18 -2
  19. package/dist/data-structures/hash/coordinate-map.d.ts +5 -2
  20. package/dist/data-structures/hash/coordinate-map.js +5 -2
  21. package/dist/data-structures/hash/coordinate-set.d.ts +5 -2
  22. package/dist/data-structures/hash/coordinate-set.js +5 -2
  23. package/dist/data-structures/heap/heap.d.ts +9 -6
  24. package/dist/data-structures/heap/heap.js +8 -8
  25. package/dist/data-structures/heap/max-heap.d.ts +5 -2
  26. package/dist/data-structures/heap/max-heap.js +5 -2
  27. package/dist/data-structures/heap/min-heap.d.ts +5 -2
  28. package/dist/data-structures/heap/min-heap.js +5 -2
  29. package/dist/data-structures/index.d.ts +1 -0
  30. package/dist/data-structures/index.js +1 -0
  31. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  32. package/dist/data-structures/linked-list/doubly-linked-list.js +4 -4
  33. package/dist/data-structures/linked-list/singly-linked-list.d.ts +5 -2
  34. package/dist/data-structures/linked-list/singly-linked-list.js +5 -2
  35. package/dist/data-structures/matrix/matrix.d.ts +5 -2
  36. package/dist/data-structures/matrix/matrix.js +5 -2
  37. package/dist/data-structures/matrix/matrix2d.d.ts +5 -2
  38. package/dist/data-structures/matrix/matrix2d.js +5 -2
  39. package/dist/data-structures/matrix/navigator.d.ts +5 -2
  40. package/dist/data-structures/matrix/vector2d.d.ts +5 -2
  41. package/dist/data-structures/matrix/vector2d.js +5 -2
  42. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +5 -2
  43. package/dist/data-structures/priority-queue/max-priority-queue.js +5 -2
  44. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +5 -2
  45. package/dist/data-structures/priority-queue/min-priority-queue.js +5 -2
  46. package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -4
  47. package/dist/data-structures/priority-queue/priority-queue.js +2 -2
  48. package/dist/data-structures/queue/deque.d.ts +12 -9
  49. package/dist/data-structures/queue/deque.js +12 -9
  50. package/dist/data-structures/queue/queue.d.ts +4 -4
  51. package/dist/data-structures/queue/queue.js +4 -4
  52. package/dist/data-structures/stack/stack.d.ts +1 -1
  53. package/dist/data-structures/stack/stack.js +1 -1
  54. package/dist/data-structures/trie/trie.d.ts +6 -3
  55. package/dist/data-structures/trie/trie.js +7 -4
  56. package/dist/utils/index.d.ts +1 -0
  57. package/dist/utils/index.js +1 -0
  58. package/dist/utils/types/utils.d.ts +8 -10
  59. package/dist/utils/types/utils.js +0 -1
  60. package/dist/utils/utils.d.ts +18 -8
  61. package/dist/utils/utils.js +93 -47
  62. package/package.json +1 -1
  63. package/dist/utils/trampoline.d.ts +0 -14
  64. package/dist/utils/trampoline.js +0 -130
@@ -1,18 +1,27 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import { BST, BSTNode } from './bst';
6
9
  import type { AVLTreeDeleted, BinaryTreeNodeId } from '../types';
7
10
  export declare class AVLTreeNode<T> extends BSTNode<T> {
11
+ /**
12
+ * The function overrides the clone method of the AVLTreeNode class to create a new AVLTreeNode object with the same
13
+ * id, value, and count.
14
+ * @returns The method is returning a new instance of the AVLTreeNode class with the same id, val, and count values as
15
+ * the current instance.
16
+ */
8
17
  clone(): AVLTreeNode<T>;
9
18
  }
10
19
  export declare class AVLTree<T> extends BST<T> {
11
20
  createNode(id: BinaryTreeNodeId, val: T, count?: number): AVLTreeNode<T>;
12
21
  /**
13
- * The function overrides the put method of a Binary Search Tree to insert a node with a given id and value, and then
22
+ * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
14
23
  * balances the tree.
15
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to put or
24
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
16
25
  * update in the AVL tree.
17
26
  * @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
18
27
  * `id`. It can be of type `T` (the generic type) or `null`.
@@ -21,7 +30,7 @@ export declare class AVLTree<T> extends BST<T> {
21
30
  * to `1`, indicating that the value should be inserted once.
22
31
  * @returns The method is returning either an AVLTreeNode<T> object or null.
23
32
  */
24
- put(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null;
33
+ add(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null;
25
34
  /**
26
35
  * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
27
36
  * then balances the tree if necessary.
@@ -28,8 +28,11 @@ var __values = (this && this.__values) || function(o) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.AVLTree = exports.AVLTreeNode = void 0;
30
30
  /**
31
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
32
- * @license MIT
31
+ * data-structure-typed
32
+ *
33
+ * @author Tyler Zeng
34
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
35
+ * @license MIT License
33
36
  */
34
37
  var bst_1 = require("./bst");
35
38
  var AVLTreeNode = /** @class */ (function (_super) {
@@ -37,6 +40,12 @@ var AVLTreeNode = /** @class */ (function (_super) {
37
40
  function AVLTreeNode() {
38
41
  return _super !== null && _super.apply(this, arguments) || this;
39
42
  }
43
+ /**
44
+ * The function overrides the clone method of the AVLTreeNode class to create a new AVLTreeNode object with the same
45
+ * id, value, and count.
46
+ * @returns The method is returning a new instance of the AVLTreeNode class with the same id, val, and count values as
47
+ * the current instance.
48
+ */
40
49
  AVLTreeNode.prototype.clone = function () {
41
50
  return new AVLTreeNode(this.id, this.val, this.count);
42
51
  };
@@ -52,9 +61,9 @@ var AVLTree = /** @class */ (function (_super) {
52
61
  return new AVLTreeNode(id, val, count);
53
62
  };
54
63
  /**
55
- * The function overrides the put method of a Binary Search Tree to insert a node with a given id and value, and then
64
+ * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
56
65
  * balances the tree.
57
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to put or
66
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
58
67
  * update in the AVL tree.
59
68
  * @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
60
69
  * `id`. It can be of type `T` (the generic type) or `null`.
@@ -63,8 +72,8 @@ var AVLTree = /** @class */ (function (_super) {
63
72
  * to `1`, indicating that the value should be inserted once.
64
73
  * @returns The method is returning either an AVLTreeNode<T> object or null.
65
74
  */
66
- AVLTree.prototype.put = function (id, val, count) {
67
- var inserted = _super.prototype.put.call(this, id, val, count);
75
+ AVLTree.prototype.add = function (id, val, count) {
76
+ var inserted = _super.prototype.add.call(this, id, val, count);
68
77
  if (inserted)
69
78
  this.balancePath(inserted);
70
79
  return inserted;
@@ -1,9 +1,18 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  export declare class BinaryIndexedTree {
6
9
  private readonly _sumTree;
10
+ /**
11
+ * The constructor initializes an array with a specified length and fills it with zeros.
12
+ * @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
13
+ * sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
14
+ * The size of the sum tree array is `n + 1` because
15
+ */
7
16
  constructor(n: number);
8
17
  static lowBit(x: number): number;
9
18
  /**
@@ -2,10 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BinaryIndexedTree = void 0;
4
4
  /**
5
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
7
10
  */
8
11
  var BinaryIndexedTree = /** @class */ (function () {
12
+ /**
13
+ * The constructor initializes an array with a specified length and fills it with zeros.
14
+ * @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
15
+ * sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
16
+ * The size of the sum tree array is `n + 1` because
17
+ */
9
18
  function BinaryIndexedTree(n) {
10
19
  this._sumTree = new Array(n + 1).fill(0);
11
20
  }
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import type { BinaryTreeDeleted, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName, ResultsByProperty } from '../types';
6
9
  export declare enum FamilyPosition {
@@ -8,6 +11,12 @@ export declare enum FamilyPosition {
8
11
  left = 1,
9
12
  right = 2
10
13
  }
14
+ /**
15
+ * Enum representing different loop types.
16
+ *
17
+ * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
18
+ * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
19
+ */
11
20
  export declare enum LoopType {
12
21
  iterative = 1,
13
22
  recursive = 2
@@ -93,34 +102,34 @@ export declare class BinaryTree<T> {
93
102
  */
94
103
  isEmpty(): boolean;
95
104
  /**
96
- * The function inserts a new node into a binary tree as the left or right child of a given parent node.
97
- * @param {BinaryTreeNode<T> | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
98
- * `null`. It represents the node that needs to be inserted into the binary tree.
99
- * @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
100
- * will be inserted as a child.
101
- * @returns The method returns the newly inserted node, either as the left child or the right child of the parent node.
102
- */
103
- putTo(newNode: BinaryTreeNode<T> | null, parent: BinaryTreeNode<T>): BinaryTreeNode<T> | null | undefined;
104
- /**
105
- * The `put` function inserts a new node with a given ID and value into a binary tree, updating the count if the node
105
+ * The `add` function inserts a new node with a given ID and value into a binary tree, updating the count if the node
106
106
  * already exists.
107
107
  * @param {BinaryTreeNodeId} id - The id parameter is the identifier of the binary tree node. It is used to uniquely
108
108
  * identify each node in the binary tree.
109
109
  * @param {T} val - The value to be inserted into the binary tree.
110
110
  * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
111
111
  * value should be inserted into the binary tree. If not provided, it defaults to 1.
112
- * @returns The function `put` returns a `BinaryTreeNode<T>` object if a new node is inserted, or `null` if no new node
112
+ * @returns The function `add` returns a `BinaryTreeNode<T>` object if a new node is inserted, or `null` if no new node
113
113
  * is inserted, or `undefined` if the insertion fails.
114
114
  */
115
- put(id: BinaryTreeNodeId, val: T, count?: number): BinaryTreeNode<T> | null | undefined;
115
+ add(id: BinaryTreeNodeId, val: T, count?: number): BinaryTreeNode<T> | null | undefined;
116
+ /**
117
+ * The function inserts a new node into a binary tree as the left or right child of a given parent node.
118
+ * @param {BinaryTreeNode<T> | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
119
+ * `null`. It represents the node that needs to be inserted into the binary tree.
120
+ * @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
121
+ * will be inserted as a child.
122
+ * @returns The method returns the newly inserted node, either as the left child or the right child of the parent node.
123
+ */
124
+ addTo(newNode: BinaryTreeNode<T> | null, parent: BinaryTreeNode<T>): BinaryTreeNode<T> | null | undefined;
116
125
  /**
117
- * The `insertMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
126
+ * The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
118
127
  * null/undefined values.
119
128
  * @param {T[] | BinaryTreeNode<T>[]} data - The `data` parameter can be either an array of elements of type `T` or an
120
129
  * array of `BinaryTreeNode<T>` objects.
121
- * @returns The function `insertMany` returns an array of `BinaryTreeNode<T>`, `null`, or `undefined` values.
130
+ * @returns The function `addMany` returns an array of `BinaryTreeNode<T>`, `null`, or `undefined` values.
122
131
  */
123
- insertMany(data: T[] | BinaryTreeNode<T>[]): (BinaryTreeNode<T> | null | undefined)[];
132
+ addMany(data: T[] | BinaryTreeNode<T>[]): (BinaryTreeNode<T> | null | undefined)[];
124
133
  /**
125
134
  * The `fill` function clears the current data and inserts new data, returning a boolean indicating if the insertion
126
135
  * was successful.
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  /**
3
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
4
- * @license MIT
3
+ * data-structure-typed
4
+ *
5
+ * @author Tyler Zeng
6
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
5
8
  */
6
9
  var __values = (this && this.__values) || function(o) {
7
10
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
@@ -32,13 +35,20 @@ var __read = (this && this.__read) || function (o, n) {
32
35
  };
33
36
  Object.defineProperty(exports, "__esModule", { value: true });
34
37
  exports.BinaryTree = exports.BinaryTreeNode = exports.LoopType = exports.FamilyPosition = void 0;
35
- var trampoline_1 = require("../../utils/trampoline");
38
+ var utils_1 = require("../../utils");
39
+ /* This enumeration defines the position of a node within a family tree composed of three associated nodes, where 'root' represents the root node of the family tree, 'left' represents the left child node, and 'right' represents the right child node. */
36
40
  var FamilyPosition;
37
41
  (function (FamilyPosition) {
38
42
  FamilyPosition[FamilyPosition["root"] = 0] = "root";
39
43
  FamilyPosition[FamilyPosition["left"] = 1] = "left";
40
44
  FamilyPosition[FamilyPosition["right"] = 2] = "right";
41
45
  })(FamilyPosition = exports.FamilyPosition || (exports.FamilyPosition = {}));
46
+ /**
47
+ * Enum representing different loop types.
48
+ *
49
+ * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
50
+ * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
51
+ */
42
52
  var LoopType;
43
53
  (function (LoopType) {
44
54
  LoopType[LoopType["iterative"] = 1] = "iterative";
@@ -255,60 +265,17 @@ var BinaryTree = /** @class */ (function () {
255
265
  return this.size === 0;
256
266
  };
257
267
  /**
258
- * The function inserts a new node into a binary tree as the left or right child of a given parent node.
259
- * @param {BinaryTreeNode<T> | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
260
- * `null`. It represents the node that needs to be inserted into the binary tree.
261
- * @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
262
- * will be inserted as a child.
263
- * @returns The method returns the newly inserted node, either as the left child or the right child of the parent node.
264
- */
265
- BinaryTree.prototype.putTo = function (newNode, parent) {
266
- var _a, _b;
267
- if (parent) {
268
- if (parent.left === undefined) {
269
- if (newNode) {
270
- newNode.parent = parent;
271
- newNode.familyPosition = FamilyPosition.left;
272
- }
273
- parent.left = newNode;
274
- if (newNode !== null) {
275
- this.size++;
276
- this.count += (_a = newNode === null || newNode === void 0 ? void 0 : newNode.count) !== null && _a !== void 0 ? _a : 0;
277
- }
278
- return parent.left;
279
- }
280
- else if (parent.right === undefined) {
281
- if (newNode) {
282
- newNode.parent = parent;
283
- newNode.familyPosition = FamilyPosition.right;
284
- }
285
- parent.right = newNode;
286
- if (newNode !== null) {
287
- this.size++;
288
- this.count += (_b = newNode === null || newNode === void 0 ? void 0 : newNode.count) !== null && _b !== void 0 ? _b : 0;
289
- }
290
- return parent.right;
291
- }
292
- else {
293
- return;
294
- }
295
- }
296
- else {
297
- return;
298
- }
299
- };
300
- /**
301
- * The `put` function inserts a new node with a given ID and value into a binary tree, updating the count if the node
268
+ * The `add` function inserts a new node with a given ID and value into a binary tree, updating the count if the node
302
269
  * already exists.
303
270
  * @param {BinaryTreeNodeId} id - The id parameter is the identifier of the binary tree node. It is used to uniquely
304
271
  * identify each node in the binary tree.
305
272
  * @param {T} val - The value to be inserted into the binary tree.
306
273
  * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
307
274
  * value should be inserted into the binary tree. If not provided, it defaults to 1.
308
- * @returns The function `put` returns a `BinaryTreeNode<T>` object if a new node is inserted, or `null` if no new node
275
+ * @returns The function `add` returns a `BinaryTreeNode<T>` object if a new node is inserted, or `null` if no new node
309
276
  * is inserted, or `undefined` if the insertion fails.
310
277
  */
311
- BinaryTree.prototype.put = function (id, val, count) {
278
+ BinaryTree.prototype.add = function (id, val, count) {
312
279
  var _this = this;
313
280
  count = count !== null && count !== void 0 ? count : 1;
314
281
  var _bfs = function (root, newNode) {
@@ -316,7 +283,7 @@ var BinaryTree = /** @class */ (function () {
316
283
  while (queue.length > 0) {
317
284
  var cur = queue.shift();
318
285
  if (cur) {
319
- var inserted_1 = _this.putTo(newNode, cur);
286
+ var inserted_1 = _this.addTo(newNode, cur);
320
287
  if (inserted_1 !== undefined)
321
288
  return inserted_1;
322
289
  if (cur.left)
@@ -356,13 +323,56 @@ var BinaryTree = /** @class */ (function () {
356
323
  return inserted;
357
324
  };
358
325
  /**
359
- * The `insertMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
326
+ * The function inserts a new node into a binary tree as the left or right child of a given parent node.
327
+ * @param {BinaryTreeNode<T> | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
328
+ * `null`. It represents the node that needs to be inserted into the binary tree.
329
+ * @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
330
+ * will be inserted as a child.
331
+ * @returns The method returns the newly inserted node, either as the left child or the right child of the parent node.
332
+ */
333
+ BinaryTree.prototype.addTo = function (newNode, parent) {
334
+ var _a, _b;
335
+ if (parent) {
336
+ if (parent.left === undefined) {
337
+ if (newNode) {
338
+ newNode.parent = parent;
339
+ newNode.familyPosition = FamilyPosition.left;
340
+ }
341
+ parent.left = newNode;
342
+ if (newNode !== null) {
343
+ this.size++;
344
+ this.count += (_a = newNode === null || newNode === void 0 ? void 0 : newNode.count) !== null && _a !== void 0 ? _a : 0;
345
+ }
346
+ return parent.left;
347
+ }
348
+ else if (parent.right === undefined) {
349
+ if (newNode) {
350
+ newNode.parent = parent;
351
+ newNode.familyPosition = FamilyPosition.right;
352
+ }
353
+ parent.right = newNode;
354
+ if (newNode !== null) {
355
+ this.size++;
356
+ this.count += (_b = newNode === null || newNode === void 0 ? void 0 : newNode.count) !== null && _b !== void 0 ? _b : 0;
357
+ }
358
+ return parent.right;
359
+ }
360
+ else {
361
+ return;
362
+ }
363
+ }
364
+ else {
365
+ return;
366
+ }
367
+ };
368
+ /**
369
+ * The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
360
370
  * null/undefined values.
361
371
  * @param {T[] | BinaryTreeNode<T>[]} data - The `data` parameter can be either an array of elements of type `T` or an
362
372
  * array of `BinaryTreeNode<T>` objects.
363
- * @returns The function `insertMany` returns an array of `BinaryTreeNode<T>`, `null`, or `undefined` values.
373
+ * @returns The function `addMany` returns an array of `BinaryTreeNode<T>`, `null`, or `undefined` values.
364
374
  */
365
- BinaryTree.prototype.insertMany = function (data) {
375
+ BinaryTree.prototype.addMany = function (data) {
366
376
  var e_1, _a, e_2, _b;
367
377
  var _c;
368
378
  var inserted = [];
@@ -387,33 +397,33 @@ var BinaryTree = /** @class */ (function () {
387
397
  var item = data_2_1.value;
388
398
  var count = this._isDuplicatedVal ? 1 : map.get(item);
389
399
  if (item instanceof BinaryTreeNode) {
390
- inserted.push(this.put(item.id, item.val, item.count));
400
+ inserted.push(this.add(item.id, item.val, item.count));
391
401
  }
392
402
  else if (typeof item === 'number' && !this._autoIncrementId) {
393
403
  if (!this._isDuplicatedVal) {
394
404
  if (map.get(item) !== undefined) {
395
- inserted.push(this.put(item, item, count));
405
+ inserted.push(this.add(item, item, count));
396
406
  map.delete(item);
397
407
  }
398
408
  }
399
409
  else {
400
- inserted.push(this.put(item, item, 1));
410
+ inserted.push(this.add(item, item, 1));
401
411
  }
402
412
  }
403
413
  else {
404
414
  if (item !== null) {
405
415
  if (!this._isDuplicatedVal) {
406
416
  if (map.get(item) !== undefined) {
407
- inserted.push(this.put(++this._maxId, item, count));
417
+ inserted.push(this.add(++this._maxId, item, count));
408
418
  map.delete(item);
409
419
  }
410
420
  }
411
421
  else {
412
- inserted.push(this.put(++this._maxId, item, 1));
422
+ inserted.push(this.add(++this._maxId, item, 1));
413
423
  }
414
424
  }
415
425
  else {
416
- inserted.push(this.put(Number.MAX_SAFE_INTEGER, item, 0));
426
+ inserted.push(this.add(Number.MAX_SAFE_INTEGER, item, 0));
417
427
  }
418
428
  }
419
429
  }
@@ -436,7 +446,7 @@ var BinaryTree = /** @class */ (function () {
436
446
  */
437
447
  BinaryTree.prototype.fill = function (data) {
438
448
  this.clear();
439
- return data.length === this.insertMany(data).length;
449
+ return data.length === this.addMany(data).length;
440
450
  };
441
451
  /**
442
452
  * The function removes a node from a binary tree and returns information about the deleted node.
@@ -718,7 +728,7 @@ var BinaryTree = /** @class */ (function () {
718
728
  }
719
729
  else {
720
730
  // Indirect implementation of iteration using tail recursion optimization
721
- var _traverse_3 = (0, trampoline_1.trampoline)(function (cur) {
731
+ var _traverse_3 = (0, utils_1.trampoline)(function (cur) {
722
732
  if (!cur.left)
723
733
  return cur;
724
734
  return _traverse_3.cont(cur.left);
@@ -748,7 +758,7 @@ var BinaryTree = /** @class */ (function () {
748
758
  }
749
759
  else {
750
760
  // Indirect implementation of iteration using tail recursion optimization
751
- var _traverse_5 = (0, trampoline_1.trampoline)(function (cur) {
761
+ var _traverse_5 = (0, utils_1.trampoline)(function (cur) {
752
762
  if (!cur.right)
753
763
  return cur;
754
764
  return _traverse_5.cont(cur.right);
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult } from '../types';
6
9
  import { BinaryTree, BinaryTreeNode, LoopType } from './binary-tree';
@@ -13,13 +16,17 @@ export declare class BSTNode<T> extends BinaryTreeNode<T> {
13
16
  clone(): BSTNode<T>;
14
17
  }
15
18
  export declare class BST<T> extends BinaryTree<T> {
19
+ /**
20
+ * The constructor function accepts an optional options object and sets the comparator property if provided.
21
+ * @param [options] - An optional object that can contain the following properties:
22
+ */
16
23
  constructor(options?: {
17
24
  comparator?: BSTComparator;
18
25
  loopType?: LoopType;
19
26
  });
20
27
  createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
21
28
  /**
22
- * The `put` function inserts a new node into a binary search tree, updating the count and value of an existing node if
29
+ * The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
23
30
  * the ID matches, and returns the inserted node.
24
31
  * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
25
32
  * determine the position of the node in the binary search tree.
@@ -28,17 +35,97 @@ export declare class BST<T> extends BinaryTree<T> {
28
35
  * @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
29
36
  * the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
30
37
  * inserted once.
31
- * @returns The method `put` returns a `BSTNode<T>` object or `null`.
38
+ * @returns The method `add` returns a `BSTNode<T>` object or `null`.
39
+ */
40
+ add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
41
+ /**
42
+ * The `get` function returns the first node in a binary search tree that matches the given property value or name.
43
+ * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
44
+ * generic type `T`. It represents the value of the property that you want to search for in the binary search tree.
45
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
46
+ * specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
47
+ * `'id'`.
48
+ * @returns The method is returning a BSTNode<T> object or null.
32
49
  */
33
- put(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
34
50
  get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BSTNode<T> | null;
51
+ /**
52
+ * The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
53
+ * leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
54
+ * @returns The function `lastKey()` returns the ID of the rightmost node in a binary tree. If the comparison between
55
+ * the first two elements in the tree is less than, it returns the ID of the rightmost node. If the comparison is
56
+ * greater than, it returns the ID of the leftmost node. Otherwise, it also returns the ID of the rightmost node. If
57
+ * there are no nodes in
58
+ */
35
59
  lastKey(): number;
60
+ /**
61
+ * The `remove` function in this TypeScript code removes a node from a binary search tree and returns information about
62
+ * the deleted node and any nodes that need to be balanced.
63
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that needs to be removed
64
+ * from the binary search tree.
65
+ * @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
66
+ * set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
67
+ * set to false or not provided, the count of the node will be taken into account and the
68
+ * @returns an array of `BSTDeletedResult<T>` objects.
69
+ */
36
70
  remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<T>[];
71
+ /**
72
+ * The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
73
+ * option to specify the property name and whether to return only one node.
74
+ * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
75
+ * generic type `T`. It represents the property value that you want to search for in the binary search tree.
76
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
77
+ * specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
78
+ * `'id'`.
79
+ * @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
80
+ * nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
81
+ * to false or not provided, the function will return all nodes that match the given nodeProperty.
82
+ * @returns an array of BSTNode<T> objects.
83
+ */
37
84
  getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): BSTNode<T>[];
85
+ /**
86
+ * The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in
87
+ * a binary search tree.
88
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node for which you want to
89
+ * calculate the lesser sum.
90
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
91
+ * specifies the property of the binary tree node to use for calculating the sum. If not provided, it defaults to 'id'.
92
+ * @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
93
+ * binary search tree that have a property value lesser than the given `id`.
94
+ */
38
95
  lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
96
+ /**
97
+ * The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
98
+ * that have a greater value than a given node.
99
+ * @param node - The `node` parameter is of type `BSTNode<T>`, which represents a node in a binary search tree. It
100
+ * contains properties such as `id` and `count`.
101
+ * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
102
+ * each node should be increased.
103
+ * @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
104
+ * property of the BSTNode to be modified. It can be either 'id' or 'count'. If propertyName is not provided, it
105
+ * defaults to 'id'.
106
+ * @returns a boolean value.
107
+ */
39
108
  allGreaterNodesAdd(node: BSTNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
109
+ /**
110
+ * The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a
111
+ * recursive or iterative approach.
112
+ * @returns The `balance()` function returns a boolean value.
113
+ */
40
114
  balance(): boolean;
115
+ /**
116
+ * The function `isAVLBalanced` checks if a binary search tree is balanced according to the AVL tree property.
117
+ * @returns The function `isAVLBalanced()` returns a boolean value. It returns `true` if the binary search tree (BST)
118
+ * is balanced according to the AVL tree property, and `false` otherwise.
119
+ */
41
120
  isAVLBalanced(): boolean;
42
121
  protected _comparator: BSTComparator;
122
+ /**
123
+ * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
124
+ * greater than, less than, or equal to the second ID.
125
+ * @param {BinaryTreeNodeId} a - a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
126
+ * @param {BinaryTreeNodeId} b - The parameter "b" in the above code refers to a BinaryTreeNodeId.
127
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
128
+ * than), or CP.eq (equal).
129
+ */
43
130
  protected _compare(a: BinaryTreeNodeId, b: BinaryTreeNodeId): CP;
44
131
  }