undirected-graph-typed 1.52.5 → 1.52.8

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 (77) hide show
  1. package/dist/constants/index.d.ts +4 -0
  2. package/dist/constants/index.js +8 -0
  3. package/dist/data-structures/base/iterable-element-base.d.ts +8 -1
  4. package/dist/data-structures/base/iterable-element-base.js +10 -1
  5. package/dist/data-structures/base/iterable-entry-base.d.ts +8 -1
  6. package/dist/data-structures/base/iterable-entry-base.js +10 -10
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +23 -24
  10. package/dist/data-structures/binary-tree/avl-tree.js +71 -64
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  12. package/dist/data-structures/binary-tree/binary-tree.d.ts +534 -402
  13. package/dist/data-structures/binary-tree/binary-tree.js +669 -598
  14. package/dist/data-structures/binary-tree/bst.d.ts +72 -65
  15. package/dist/data-structures/binary-tree/bst.js +115 -113
  16. package/dist/data-structures/binary-tree/rb-tree.d.ts +21 -24
  17. package/dist/data-structures/binary-tree/rb-tree.js +40 -39
  18. package/dist/data-structures/binary-tree/segment-tree.d.ts +2 -2
  19. package/dist/data-structures/binary-tree/segment-tree.js +2 -2
  20. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  21. package/dist/data-structures/binary-tree/tree-multi-map.js +44 -43
  22. package/dist/data-structures/graph/abstract-graph.d.ts +2 -2
  23. package/dist/data-structures/graph/abstract-graph.js +7 -4
  24. package/dist/data-structures/graph/directed-graph.d.ts +2 -2
  25. package/dist/data-structures/graph/directed-graph.js +4 -2
  26. package/dist/data-structures/graph/undirected-graph.d.ts +2 -2
  27. package/dist/data-structures/hash/hash-map.d.ts +2 -2
  28. package/dist/data-structures/hash/hash-map.js +1 -1
  29. package/dist/data-structures/heap/heap.js +3 -3
  30. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  31. package/dist/data-structures/linked-list/doubly-linked-list.js +7 -7
  32. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  33. package/dist/data-structures/linked-list/singly-linked-list.js +6 -6
  34. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  35. package/dist/data-structures/matrix/matrix.d.ts +2 -2
  36. package/dist/data-structures/matrix/navigator.d.ts +2 -2
  37. package/dist/data-structures/matrix/navigator.js +4 -2
  38. package/dist/data-structures/queue/deque.d.ts +3 -3
  39. package/dist/data-structures/queue/deque.js +29 -29
  40. package/dist/data-structures/queue/queue.d.ts +1 -1
  41. package/dist/data-structures/stack/stack.d.ts +2 -2
  42. package/dist/data-structures/trie/trie.d.ts +2 -2
  43. package/dist/data-structures/trie/trie.js +1 -1
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +1 -0
  46. package/dist/interfaces/binary-tree.d.ts +2 -2
  47. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  48. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -6
  49. package/package.json +2 -2
  50. package/src/constants/index.ts +4 -0
  51. package/src/data-structures/base/iterable-element-base.ts +11 -1
  52. package/src/data-structures/base/iterable-entry-base.ts +11 -19
  53. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
  54. package/src/data-structures/binary-tree/avl-tree.ts +69 -71
  55. package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
  56. package/src/data-structures/binary-tree/binary-tree.ts +698 -726
  57. package/src/data-structures/binary-tree/bst.ts +123 -129
  58. package/src/data-structures/binary-tree/rb-tree.ts +44 -46
  59. package/src/data-structures/binary-tree/segment-tree.ts +2 -2
  60. package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
  61. package/src/data-structures/graph/abstract-graph.ts +6 -6
  62. package/src/data-structures/graph/directed-graph.ts +4 -4
  63. package/src/data-structures/graph/undirected-graph.ts +2 -2
  64. package/src/data-structures/hash/hash-map.ts +3 -3
  65. package/src/data-structures/heap/heap.ts +3 -3
  66. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
  67. package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
  68. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  69. package/src/data-structures/matrix/matrix.ts +2 -2
  70. package/src/data-structures/matrix/navigator.ts +4 -4
  71. package/src/data-structures/queue/deque.ts +31 -31
  72. package/src/data-structures/queue/queue.ts +1 -1
  73. package/src/data-structures/stack/stack.ts +2 -2
  74. package/src/data-structures/trie/trie.ts +3 -3
  75. package/src/index.ts +2 -1
  76. package/src/interfaces/binary-tree.ts +3 -3
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
@@ -0,0 +1,4 @@
1
+ export declare enum DFSOperation {
2
+ VISIT = 0,
3
+ PROCESS = 1
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DFSOperation = void 0;
4
+ var DFSOperation;
5
+ (function (DFSOperation) {
6
+ DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
7
+ DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
8
+ })(DFSOperation = exports.DFSOperation || (exports.DFSOperation = {}));
@@ -125,7 +125,14 @@ export declare abstract class IterableElementBase<E, R, C> {
125
125
  *
126
126
  * The print function logs the elements of an array to the console.
127
127
  */
128
- print(): E[];
128
+ toVisual(): E[];
129
+ /**
130
+ * Time Complexity: O(n)
131
+ * Space Complexity: O(n)
132
+ *
133
+ * The print function logs the elements of an array to the console.
134
+ */
135
+ print(): void;
129
136
  abstract isEmpty(): boolean;
130
137
  abstract clear(): void;
131
138
  abstract clone(): C;
@@ -182,8 +182,17 @@ class IterableElementBase {
182
182
  *
183
183
  * The print function logs the elements of an array to the console.
184
184
  */
185
- print() {
185
+ toVisual() {
186
186
  return [...this];
187
187
  }
188
+ /**
189
+ * Time Complexity: O(n)
190
+ * Space Complexity: O(n)
191
+ *
192
+ * The print function logs the elements of an array to the console.
193
+ */
194
+ print() {
195
+ console.log(this.toVisual());
196
+ }
188
197
  }
189
198
  exports.IterableElementBase = IterableElementBase;
@@ -151,7 +151,14 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
151
151
  *
152
152
  * The print function logs the elements of an array to the console.
153
153
  */
154
- print(): [K, V][] | string;
154
+ toVisual(): [K, V][] | string;
155
+ /**
156
+ * Time Complexity: O(n)
157
+ * Space Complexity: O(n)
158
+ *
159
+ * The print function logs the elements of an array to the console.
160
+ */
161
+ print(): void;
155
162
  abstract isEmpty(): boolean;
156
163
  abstract clear(): void;
157
164
  abstract clone(): any;
@@ -2,15 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IterableEntryBase = void 0;
4
4
  class IterableEntryBase {
5
- // protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
6
- //
7
- // /**
8
- // * The function returns the value of the _toEntryFn property.
9
- // * @returns The function being returned is `this._toEntryFn`.
10
- // */
11
- // get toEntryFn() {
12
- // return this._toEntryFn;
13
- // }
14
5
  /**
15
6
  * Time Complexity: O(n)
16
7
  * Space Complexity: O(1)
@@ -233,8 +224,17 @@ class IterableEntryBase {
233
224
  *
234
225
  * The print function logs the elements of an array to the console.
235
226
  */
236
- print() {
227
+ toVisual() {
237
228
  return [...this];
238
229
  }
230
+ /**
231
+ * Time Complexity: O(n)
232
+ * Space Complexity: O(n)
233
+ *
234
+ * The print function logs the elements of an array to the console.
235
+ */
236
+ print() {
237
+ console.log(this.toVisual());
238
+ }
239
239
  }
240
240
  exports.IterableEntryBase = IterableEntryBase;
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNKeyOrNodeOrEntry, IterationType } from '../../types';
9
- import { BTNEntry } from '../../types';
8
+ import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, BTNEntry } from '../../types';
10
9
  import { IBinaryTree } from '../../interfaces';
11
10
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
11
  export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
@@ -40,13 +39,13 @@ export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeM
40
39
  export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
41
40
  /**
42
41
  * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
43
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
42
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
44
43
  * iterable object that can contain either keys, nodes, entries, or raw elements.
45
44
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
46
45
  * behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
47
46
  * `compareValues` functions to define custom comparison logic for keys and values, respectively.
48
47
  */
49
- constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
48
+ constructor(keysOrNodesOrEntriesOrRaws?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
50
49
  protected _count: number;
51
50
  /**
52
51
  * The function calculates the sum of the count property of all nodes in a tree using depth-first
@@ -85,17 +84,17 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
85
84
  createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE;
86
85
  /**
87
86
  * The function checks if the input is an instance of AVLTreeMultiMapNode.
88
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
89
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
90
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
87
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
88
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
89
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
91
90
  * an instance of the `AVLTreeMultiMapNode` class.
92
91
  */
93
- isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
92
+ isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
94
93
  /**
95
94
  * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
96
95
  * a node object.
97
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
98
- * `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
96
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
97
+ * `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
99
98
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
100
99
  * `override` function. It represents the value associated with the key in the data structure. If no
101
100
  * value is provided, it will default to `undefined`.
@@ -103,15 +102,15 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
103
102
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
104
103
  * @returns either a NODE object or undefined.
105
104
  */
106
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
105
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): NODE | undefined;
107
106
  /**
108
107
  * Time Complexity: O(log n)
109
108
  * Space Complexity: O(1)
110
109
  *
111
110
  * The function overrides the add method of a TypeScript class to add a new node to a data structure
112
111
  * and update the count.
113
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
114
- * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
112
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
113
+ * `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
115
114
  * can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
116
115
  * entry, or raw element
117
116
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
@@ -121,27 +120,27 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
121
120
  * be added once. However, you can specify a different value for `count` if you want to add
122
121
  * @returns a boolean value.
123
122
  */
124
- add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
123
+ add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): boolean;
125
124
  /**
126
125
  * Time Complexity: O(log n)
127
126
  * Space Complexity: O(1)
128
127
  *
129
- * The `delete` function in a binary tree data structure deletes a node based on its identifier and
130
- * returns the deleted node along with the parent node that needs to be balanced.
131
- * @param identifier - The identifier parameter is the value used to identify the node that needs to
132
- * be deleted from the binary tree. It can be of any type and is the return type of the callback
133
- * function.
134
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
135
- * equality of nodes in the binary tree. It is optional and has a default value of
136
- * `this._DEFAULT_CALLBACK`. The `callback` function takes a single argument, which is the identifier
137
- * of a node, and returns a value that
138
- * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
139
- * being deleted. If set to true, the count of the node will not be considered and the node will be
140
- * deleted regardless of its count. If set to false (default), the count of the node will be taken
141
- * into account and the node
142
- * @returns an array of `BinaryTreeDeleteResult<NODE>`.
143
- */
144
- delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
128
+ * The function overrides the delete method in a binary tree data structure, handling deletion of
129
+ * nodes and maintaining balance in the tree.
130
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
131
+ * parameter in the `delete` method is used to specify the condition for deleting a node from the
132
+ * binary tree. It can be a key, node, entry, or a custom predicate function that determines which
133
+ * node(s) should be deleted.
134
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
135
+ * boolean flag that determines whether to ignore the count of the node being deleted. If
136
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
137
+ * `ignoreCount` is set to
138
+ * @returns The `delete` method overrides the default delete behavior in a binary tree data
139
+ * structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
140
+ * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
141
+ * deleted node and whether balancing is needed in the tree.
142
+ */
143
+ delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
145
144
  /**
146
145
  * Time Complexity: O(1)
147
146
  * Space Complexity: O(1)
@@ -41,17 +41,17 @@ exports.AVLTreeMultiMapNode = AVLTreeMultiMapNode;
41
41
  class AVLTreeMultiMap extends avl_tree_1.AVLTree {
42
42
  /**
43
43
  * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
44
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
44
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
45
45
  * iterable object that can contain either keys, nodes, entries, or raw elements.
46
46
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
47
47
  * behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
48
48
  * `compareValues` functions to define custom comparison logic for keys and values, respectively.
49
49
  */
50
- constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
50
+ constructor(keysOrNodesOrEntriesOrRaws = [], options) {
51
51
  super([], options);
52
52
  this._count = 0;
53
- if (keysOrNodesOrEntriesOrRawElements)
54
- this.addMany(keysOrNodesOrEntriesOrRawElements);
53
+ if (keysOrNodesOrEntriesOrRaws)
54
+ this.addMany(keysOrNodesOrEntriesOrRaws);
55
55
  }
56
56
  /**
57
57
  * The function calculates the sum of the count property of all nodes in a tree using depth-first
@@ -96,23 +96,23 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
96
96
  * object.
97
97
  */
98
98
  createTree(options) {
99
- return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this.comparator }, options));
99
+ return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
100
100
  }
101
101
  /**
102
102
  * The function checks if the input is an instance of AVLTreeMultiMapNode.
103
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
104
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
105
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
103
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
104
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
105
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
106
106
  * an instance of the `AVLTreeMultiMapNode` class.
107
107
  */
108
- isNode(keyOrNodeOrEntryOrRawElement) {
109
- return keyOrNodeOrEntryOrRawElement instanceof AVLTreeMultiMapNode;
108
+ isNode(keyOrNodeOrEntryOrRaw) {
109
+ return keyOrNodeOrEntryOrRaw instanceof AVLTreeMultiMapNode;
110
110
  }
111
111
  /**
112
112
  * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
113
113
  * a node object.
114
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
115
- * `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
114
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
115
+ * `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
116
116
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
117
117
  * `override` function. It represents the value associated with the key in the data structure. If no
118
118
  * value is provided, it will default to `undefined`.
@@ -120,25 +120,25 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
120
120
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
121
121
  * @returns either a NODE object or undefined.
122
122
  */
123
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count = 1) {
124
- if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null)
123
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
124
+ if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null)
125
125
  return;
126
- if (this.isNode(keyOrNodeOrEntryOrRawElement))
127
- return keyOrNodeOrEntryOrRawElement;
128
- if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
129
- const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
126
+ if (this.isNode(keyOrNodeOrEntryOrRaw))
127
+ return keyOrNodeOrEntryOrRaw;
128
+ if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
129
+ const [key, entryValue] = keyOrNodeOrEntryOrRaw;
130
130
  if (key === undefined || key === null)
131
131
  return;
132
132
  if (this.isKey(key))
133
133
  return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, count);
134
134
  }
135
- if (this.toEntryFn) {
136
- const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
135
+ if (this._toEntryFn) {
136
+ const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
137
137
  if (this.isKey(key))
138
138
  return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, count);
139
139
  }
140
- if (this.isKey(keyOrNodeOrEntryOrRawElement))
141
- return this.createNode(keyOrNodeOrEntryOrRawElement, value, count);
140
+ if (this.isKey(keyOrNodeOrEntryOrRaw))
141
+ return this.createNode(keyOrNodeOrEntryOrRaw, value, count);
142
142
  return;
143
143
  }
144
144
  /**
@@ -147,8 +147,8 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
147
147
  *
148
148
  * The function overrides the add method of a TypeScript class to add a new node to a data structure
149
149
  * and update the count.
150
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
151
- * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
150
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
151
+ * `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
152
152
  * can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
153
153
  * entry, or raw element
154
154
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
@@ -158,8 +158,8 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
158
158
  * be added once. However, you can specify a different value for `count` if you want to add
159
159
  * @returns a boolean value.
160
160
  */
161
- add(keyOrNodeOrEntryOrRawElement, value, count = 1) {
162
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
161
+ add(keyOrNodeOrEntryOrRaw, value, count = 1) {
162
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
163
163
  if (newNode === undefined)
164
164
  return false;
165
165
  const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
@@ -173,28 +173,27 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
173
173
  * Time Complexity: O(log n)
174
174
  * Space Complexity: O(1)
175
175
  *
176
- * The `delete` function in a binary tree data structure deletes a node based on its identifier and
177
- * returns the deleted node along with the parent node that needs to be balanced.
178
- * @param identifier - The identifier parameter is the value used to identify the node that needs to
179
- * be deleted from the binary tree. It can be of any type and is the return type of the callback
180
- * function.
181
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
182
- * equality of nodes in the binary tree. It is optional and has a default value of
183
- * `this._DEFAULT_CALLBACK`. The `callback` function takes a single argument, which is the identifier
184
- * of a node, and returns a value that
185
- * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
186
- * being deleted. If set to true, the count of the node will not be considered and the node will be
187
- * deleted regardless of its count. If set to false (default), the count of the node will be taken
188
- * into account and the node
189
- * @returns an array of `BinaryTreeDeleteResult<NODE>`.
176
+ * The function overrides the delete method in a binary tree data structure, handling deletion of
177
+ * nodes and maintaining balance in the tree.
178
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
179
+ * parameter in the `delete` method is used to specify the condition for deleting a node from the
180
+ * binary tree. It can be a key, node, entry, or a custom predicate function that determines which
181
+ * node(s) should be deleted.
182
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
183
+ * boolean flag that determines whether to ignore the count of the node being deleted. If
184
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
185
+ * `ignoreCount` is set to
186
+ * @returns The `delete` method overrides the default delete behavior in a binary tree data
187
+ * structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
188
+ * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
189
+ * deleted node and whether balancing is needed in the tree.
190
190
  */
191
- delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
191
+ delete(predicate, ignoreCount = false) {
192
192
  var _a;
193
193
  const deletedResult = [];
194
194
  if (!this.root)
195
195
  return deletedResult;
196
- callback = this._ensureCallback(identifier, callback);
197
- const curr = (_a = this.getNode(identifier, callback)) !== null && _a !== void 0 ? _a : undefined;
196
+ const curr = (_a = this.getNode(predicate)) !== null && _a !== void 0 ? _a : undefined;
198
197
  if (!curr)
199
198
  return deletedResult;
200
199
  const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : undefined;
@@ -236,7 +235,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
236
235
  }
237
236
  }
238
237
  }
239
- this._size = this.size - 1;
238
+ this._size = this._size - 1;
240
239
  // TODO How to handle when the count of target node is lesser than current node's count
241
240
  if (orgCurrent)
242
241
  this._count -= orgCurrent.count;
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNKeyOrNodeOrEntry } from '../../types';
10
- import { BTNEntry } from '../../types';
9
+ import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, BTNEntry } from '../../types';
11
10
  import { IBinaryTree } from '../../interfaces';
12
11
  export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
13
12
  /**
@@ -45,7 +44,7 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
45
44
  /**
46
45
  * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
47
46
  * entries, or raw elements.
48
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
47
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
49
48
  * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
50
49
  * be used to initialize the AVLTree.
51
50
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
@@ -53,7 +52,7 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
53
52
  * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
54
53
  * `nodeBuilder` (
55
54
  */
56
- constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeOptions<K, V, R>);
55
+ constructor(keysOrNodesOrEntriesOrRaws?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeOptions<K, V, R>);
57
56
  /**
58
57
  * The function creates a new AVL tree node with the given key and value.
59
58
  * @param {K} key - The key parameter is of type K, which represents the key of the node being
@@ -74,40 +73,40 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
74
73
  createTree(options?: AVLTreeOptions<K, V, R>): TREE;
75
74
  /**
76
75
  * The function checks if the input is an instance of AVLTreeNode.
77
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
78
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
79
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
76
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
77
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
78
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
80
79
  * an instance of the `AVLTreeNode` class.
81
80
  */
82
- isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
81
+ isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
83
82
  /**
84
83
  * Time Complexity: O(log n)
85
84
  * Space Complexity: O(1)
86
85
  *
87
86
  * The function overrides the add method of a class and inserts a key-value pair into a data
88
87
  * structure, then balances the path.
89
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
90
- * `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
88
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
89
+ * `keyOrNodeOrEntryOrRaw` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
91
90
  * `RawElement`.
92
91
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
93
92
  * the key or node being added to the data structure.
94
93
  * @returns The method is returning a boolean value.
95
94
  */
96
- add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
95
+ add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): boolean;
97
96
  /**
98
97
  * Time Complexity: O(log n)
99
98
  * Space Complexity: O(1)
100
99
  *
101
- * The function overrides the delete method of a binary tree class and performs additional operations
102
- * to balance the tree after deletion.
103
- * @param identifier - The `identifier` parameter is the value or condition used to identify the
104
- * node(s) to be deleted from the binary tree. It can be of any type that is compatible with the
105
- * binary tree's node type.
106
- * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
107
- * node should be deleted or not. It is optional and has a default value of `this._DEFAULT_CALLBACK`.
108
- * @returns The method is returning an array of BinaryTreeDeleteResult<NODE> objects.
100
+ * The function overrides the delete method in a TypeScript class, performs deletion, and then
101
+ * balances the tree if necessary.
102
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
103
+ * parameter in the `override delete` method can be one of the following types:
104
+ * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
105
+ * method from the superclass (presumably a parent class) with the provided `predicate`, which could
106
+ * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
107
+ * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
109
108
  */
110
- delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeleteResult<NODE>[];
109
+ delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
111
110
  /**
112
111
  * Time Complexity: O(1)
113
112
  * Space Complexity: O(1)
@@ -180,10 +179,10 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
180
179
  *
181
180
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
182
181
  * to restore balance in an AVL tree after inserting a node.
183
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
182
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
184
183
  * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
185
184
  */
186
- protected _balancePath(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): void;
185
+ protected _balancePath(node: BTNKeyOrNodeOrEntry<K, V, NODE> | R): void;
187
186
  /**
188
187
  * Time Complexity: O(1)
189
188
  * Space Complexity: O(1)