bst-typed 1.52.6 → 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 +668 -597
  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 +697 -725
  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
@@ -37,7 +37,7 @@ exports.RedBlackTreeNode = RedBlackTreeNode;
37
37
  class RedBlackTree extends bst_1.BST {
38
38
  /**
39
39
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
40
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
40
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
41
41
  * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
42
42
  * initialize the RBTree with the provided elements.
43
43
  * @param [options] - The `options` parameter is an optional object that can be passed to the
@@ -45,11 +45,11 @@ class RedBlackTree extends bst_1.BST {
45
45
  * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
46
46
  * depend on the implementation
47
47
  */
48
- constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
48
+ constructor(keysOrNodesOrEntriesOrRaws = [], options) {
49
49
  super([], options);
50
50
  this._root = this.NIL;
51
- if (keysOrNodesOrEntriesOrRawElements) {
52
- this.addMany(keysOrNodesOrEntriesOrRawElements);
51
+ if (keysOrNodesOrEntriesOrRaws) {
52
+ this.addMany(keysOrNodesOrEntriesOrRaws);
53
53
  }
54
54
  }
55
55
  /**
@@ -83,20 +83,20 @@ class RedBlackTree extends bst_1.BST {
83
83
  * @returns a new instance of a RedBlackTree object.
84
84
  */
85
85
  createTree(options) {
86
- return new RedBlackTree([], Object.assign({ iterationType: this.iterationType }, options));
86
+ return new RedBlackTree([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
87
87
  }
88
88
  /**
89
89
  * Time Complexity: O(1)
90
90
  * Space Complexity: O(1)
91
91
  *
92
92
  * The function checks if the input is an instance of the RedBlackTreeNode class.
93
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
94
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
95
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
93
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
94
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
95
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
96
96
  * an instance of the `RedBlackTreeNode` class.
97
97
  */
98
- isNode(keyOrNodeOrEntryOrRawElement) {
99
- return keyOrNodeOrEntryOrRawElement instanceof RedBlackTreeNode;
98
+ isNode(keyOrNodeOrEntryOrRaw) {
99
+ return keyOrNodeOrEntryOrRaw instanceof RedBlackTreeNode;
100
100
  }
101
101
  // /**
102
102
  // * Time Complexity: O(1)
@@ -109,27 +109,27 @@ class RedBlackTree extends bst_1.BST {
109
109
  // *
110
110
  // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
111
111
  // * valid, otherwise it returns undefined.
112
- // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
113
- // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
112
+ // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRaw - The key, value, or entry to convert.
113
+ // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRaw` is a key).
114
114
  // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
115
115
  // */
116
- // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
116
+ // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): NODE | undefined {
117
117
  //
118
- // if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
119
- // if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
118
+ // if (keyOrNodeOrEntryOrRaw === null || keyOrNodeOrEntryOrRaw === undefined) return;
119
+ // if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
120
120
  //
121
- // if (this.toEntryFn) {
122
- // const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
121
+ // if (this._toEntryFn) {
122
+ // const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
123
123
  // if (this.isKey(key)) return this.createNode(key, entryValue ?? value, 'RED');
124
124
  // }
125
125
  //
126
- // if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
127
- // const [key, value] = keyOrNodeOrEntryOrRawElement;
126
+ // if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
127
+ // const [key, value] = keyOrNodeOrEntryOrRaw;
128
128
  // if (key === undefined || key === null) return;
129
129
  // else return this.createNode(key, value, 'RED');
130
130
  // }
131
131
  //
132
- // if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'RED');
132
+ // if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, 'RED');
133
133
  //
134
134
  // return ;
135
135
  // }
@@ -150,8 +150,8 @@ class RedBlackTree extends bst_1.BST {
150
150
  *
151
151
  * The function adds a new node to a binary search tree and returns true if the node was successfully
152
152
  * added.
153
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
154
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
153
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
154
+ * `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
155
155
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
156
156
  * the key in the data structure. It represents the value that you want to add or update in the data
157
157
  * structure.
@@ -159,8 +159,8 @@ class RedBlackTree extends bst_1.BST {
159
159
  * the method returns true. If the node already exists and its value is updated, the method also
160
160
  * returns true. If the node cannot be added or updated, the method returns false.
161
161
  */
162
- add(keyOrNodeOrEntryOrRawElement, value) {
163
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
162
+ add(keyOrNodeOrEntryOrRaw, value) {
163
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
164
164
  if (!this.isRealNode(newNode))
165
165
  return false;
166
166
  const insertStatus = this._insert(newNode);
@@ -182,24 +182,25 @@ class RedBlackTree extends bst_1.BST {
182
182
  * Time Complexity: O(log n)
183
183
  * Space Complexity: O(1)
184
184
  *
185
- * The function overrides the delete method of a binary tree data structure, allowing for the
186
- * deletion of a node and maintaining the balance of the tree.
187
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
188
- * that identifies the node to be deleted from the binary tree. It can be of any type that is
189
- * returned by the callback function `C`. It can also be `null` or `undefined` if there is no node to
190
- * delete.
191
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
192
- * equality of nodes in the binary tree. It is optional and has a default value of
193
- * `this._DEFAULT_CALLBACK`. The type of the `callback` parameter is `C`, which is a generic type
194
- * that extends the `BTNCallback
195
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
185
+ * The function overrides the delete method in a binary tree data structure to remove a node based on
186
+ * a given predicate and maintain the binary search tree properties.
187
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
188
+ * parameter in the `override delete` method is used to specify the condition or key based on which a
189
+ * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
190
+ * function that determines which node(s) should be deleted.
191
+ * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
192
+ * objects. Each object in the array contains information about the deleted node and whether
193
+ * balancing is needed.
196
194
  */
197
- delete(identifier, callback = this._DEFAULT_CALLBACK) {
198
- if (identifier === null)
195
+ delete(predicate) {
196
+ if (predicate === null)
199
197
  return [];
200
198
  const results = [];
201
- callback = this._ensureCallback(identifier, callback);
202
- const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
199
+ let nodeToDelete;
200
+ if (this._isPredicated(predicate))
201
+ nodeToDelete = this.getNode(predicate);
202
+ else
203
+ nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
203
204
  if (!nodeToDelete) {
204
205
  return results;
205
206
  }
@@ -1,8 +1,8 @@
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 type { SegmentTreeNodeVal } from '../../types';
@@ -2,8 +2,8 @@
2
2
  /**
3
3
  * data-structure-typed
4
4
  *
5
- * @author Tyler Zeng
6
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
5
+ * @author Pablo Zeng
6
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
7
7
  * @license MIT License
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNKeyOrNodeOrEntry, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
9
- import { BTNEntry } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions, BTNEntry } from '../../types';
10
9
  import { IBinaryTree } from '../../interfaces';
11
10
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
12
11
  export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
@@ -39,14 +38,14 @@ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMa
39
38
  export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
40
39
  /**
41
40
  * The constructor function initializes a TreeMultiMap object with optional initial data.
42
- * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
41
+ * @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
43
42
  * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
44
43
  * TreeMultiMap with initial data.
45
44
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
46
45
  * behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
47
46
  * `compareValues`, which are functions used to compare keys and values respectively.
48
47
  */
49
- constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
48
+ constructor(keysOrNodesOrEntriesOrRaws?: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<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 structure.
@@ -88,8 +87,8 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
88
87
  /**
89
88
  * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
90
89
  * node based on the input.
91
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
92
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
90
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
91
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
93
92
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
94
93
  * associated with the key in the node. It is used when creating a new node or updating the value of
95
94
  * an existing node.
@@ -97,23 +96,23 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
97
96
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
98
97
  * @returns either a NODE object or undefined.
99
98
  */
100
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
99
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): NODE | undefined;
101
100
  /**
102
101
  * The function checks if the input is an instance of the TreeMultiMapNode class.
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
102
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
103
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
104
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
106
105
  * an instance of the `TreeMultiMapNode` class.
107
106
  */
108
- isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
107
+ isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
109
108
  /**
110
109
  * Time Complexity: O(log n)
111
110
  * Space Complexity: O(1)
112
111
  *
113
112
  * The function overrides the add method of a class and adds a new node to a data structure, updating
114
113
  * the count and returning a boolean indicating success.
115
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
116
- * `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
114
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
115
+ * `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
117
116
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
118
117
  * data structure. It is an optional parameter, so it can be omitted if not needed.
119
118
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
@@ -122,26 +121,24 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
122
121
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
123
122
  * was successful, and false otherwise.
124
123
  */
125
- add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
124
+ add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): boolean;
126
125
  /**
127
126
  * Time Complexity: O(log n)
128
127
  * Space Complexity: O(1)
129
128
  *
130
- * The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
131
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
132
- * key that is used to identify the node that needs to be deleted from the binary tree. It can be of
133
- * any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
134
- * the node to be deleted
135
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
136
- * equality of nodes in the binary tree. It is optional and has a default value of
137
- * `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
138
- * specific node or when performing other operations on the
139
- * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
140
- * being deleted. If set to true, the count of the node will not be taken into account when deleting
141
- * it. If set to false, the count of the node will be decremented by 1 before deleting it.
142
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
143
- */
144
- delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
129
+ * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
130
+ * structure, handling cases where nodes have children and maintaining balance in the tree.
131
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
132
+ * parameter in the `delete` method is used to specify the condition or key based on which a node
133
+ * should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
134
+ * function.
135
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
136
+ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
137
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
138
+ * `ignoreCount` is `false
139
+ * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
140
+ */
141
+ delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
145
142
  /**
146
143
  * Time Complexity: O(1)
147
144
  * Space Complexity: O(1)
@@ -40,18 +40,18 @@ exports.TreeMultiMapNode = TreeMultiMapNode;
40
40
  class TreeMultiMap extends rb_tree_1.RedBlackTree {
41
41
  /**
42
42
  * The constructor function initializes a TreeMultiMap object with optional initial data.
43
- * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
43
+ * @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
44
44
  * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
45
45
  * TreeMultiMap with initial data.
46
46
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
47
47
  * behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
48
48
  * `compareValues`, which are functions used to compare 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
  // TODO the _count is not accurate after nodes count modified
57
57
  /**
@@ -99,13 +99,13 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
99
99
  * existing `iterationType` property. The returned value is casted as `TREE`.
100
100
  */
101
101
  createTree(options) {
102
- return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType }, options));
102
+ return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
103
103
  }
104
104
  /**
105
105
  * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
106
106
  * node based on the input.
107
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
108
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
107
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
108
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
109
109
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
110
110
  * associated with the key in the node. It is used when creating a new node or updating the value of
111
111
  * an existing node.
@@ -113,36 +113,36 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
113
113
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
114
114
  * @returns either a NODE object or undefined.
115
115
  */
116
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count = 1) {
117
- if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null)
116
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
117
+ if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null)
118
118
  return;
119
- if (this.isNode(keyOrNodeOrEntryOrRawElement))
120
- return keyOrNodeOrEntryOrRawElement;
121
- if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
122
- const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
119
+ if (this.isNode(keyOrNodeOrEntryOrRaw))
120
+ return keyOrNodeOrEntryOrRaw;
121
+ if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
122
+ const [key, entryValue] = keyOrNodeOrEntryOrRaw;
123
123
  if (key === undefined || key === null)
124
124
  return;
125
125
  if (this.isKey(key))
126
126
  return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, 'BLACK', count);
127
127
  }
128
- if (this.toEntryFn) {
129
- const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
128
+ if (this._toEntryFn) {
129
+ const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
130
130
  if (this.isKey(key))
131
131
  return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, 'BLACK', count);
132
132
  }
133
- if (this.isKey(keyOrNodeOrEntryOrRawElement))
134
- return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'BLACK', count);
133
+ if (this.isKey(keyOrNodeOrEntryOrRaw))
134
+ return this.createNode(keyOrNodeOrEntryOrRaw, value, 'BLACK', count);
135
135
  return;
136
136
  }
137
137
  /**
138
138
  * The function checks if the input is an instance of the TreeMultiMapNode class.
139
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
140
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
141
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
139
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
140
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
141
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
142
142
  * an instance of the `TreeMultiMapNode` class.
143
143
  */
144
- isNode(keyOrNodeOrEntryOrRawElement) {
145
- return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
144
+ isNode(keyOrNodeOrEntryOrRaw) {
145
+ return keyOrNodeOrEntryOrRaw instanceof TreeMultiMapNode;
146
146
  }
147
147
  /**
148
148
  * Time Complexity: O(log n)
@@ -150,8 +150,8 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
150
150
  *
151
151
  * The function overrides the add method of a class and adds a new node to a data structure, updating
152
152
  * the count and returning a boolean indicating success.
153
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
154
- * `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
153
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
154
+ * `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
155
155
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
156
156
  * data structure. It is an optional parameter, so it can be omitted if not needed.
157
157
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
@@ -160,8 +160,8 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
160
160
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
161
161
  * was successful, and false otherwise.
162
162
  */
163
- add(keyOrNodeOrEntryOrRawElement, value, count = 1) {
164
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
163
+ add(keyOrNodeOrEntryOrRaw, value, count = 1) {
164
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
165
165
  const orgCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
166
166
  const isSuccessAdded = super.add(newNode);
167
167
  if (isSuccessAdded) {
@@ -176,26 +176,27 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
176
176
  * Time Complexity: O(log n)
177
177
  * Space Complexity: O(1)
178
178
  *
179
- * The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
180
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
181
- * key that is used to identify the node that needs to be deleted from the binary tree. It can be of
182
- * any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
183
- * the node to be deleted
184
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
185
- * equality of nodes in the binary tree. It is optional and has a default value of
186
- * `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
187
- * specific node or when performing other operations on the
188
- * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
189
- * being deleted. If set to true, the count of the node will not be taken into account when deleting
190
- * it. If set to false, the count of the node will be decremented by 1 before deleting it.
191
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
179
+ * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
180
+ * structure, handling cases where nodes have children and maintaining balance in the tree.
181
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
182
+ * parameter in the `delete` method is used to specify the condition or key based on which a node
183
+ * should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
184
+ * function.
185
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
186
+ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
187
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
188
+ * `ignoreCount` is `false
189
+ * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
192
190
  */
193
- delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
194
- if (identifier === null)
191
+ delete(predicate, ignoreCount = false) {
192
+ if (predicate === null)
195
193
  return [];
196
194
  const results = [];
197
- callback = this._ensureCallback(identifier, callback);
198
- const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
195
+ let nodeToDelete;
196
+ if (this._isPredicated(predicate))
197
+ nodeToDelete = this.getNode(predicate);
198
+ else
199
+ nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
199
200
  if (!nodeToDelete) {
200
201
  return results;
201
202
  }
@@ -1,8 +1,8 @@
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 type { DijkstraResult, EntryCallback, VertexKey } from '../../types';
@@ -461,7 +461,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
461
461
  }
462
462
  }
463
463
  }
464
- getMinDist &&
464
+ if (getMinDist)
465
465
  distMap.forEach((d, v) => {
466
466
  if (v !== srcVertex) {
467
467
  if (d < minDist) {
@@ -471,7 +471,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
471
471
  }
472
472
  }
473
473
  });
474
- genPaths && getPaths(minDest);
474
+ if (genPaths)
475
+ getPaths(minDest);
475
476
  return { distMap, preMap, seen, paths, minDist, minPath };
476
477
  }
477
478
  /**
@@ -644,7 +645,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
644
645
  if (sWeight !== undefined && dWeight !== undefined) {
645
646
  if (distMap.get(s) !== Infinity && sWeight + weight < dWeight) {
646
647
  distMap.set(d, sWeight + weight);
647
- genPath && preMap.set(d, s);
648
+ if (genPath)
649
+ preMap.set(d, s);
648
650
  }
649
651
  }
650
652
  }
@@ -769,7 +771,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
769
771
  visited.add(vertex);
770
772
  currentPath.push(vertex.key);
771
773
  for (const neighbor of this.getNeighbors(vertex)) {
772
- neighbor && dfs(neighbor, currentPath, visited);
774
+ if (neighbor)
775
+ dfs(neighbor, currentPath, visited);
773
776
  }
774
777
  visited.delete(vertex);
775
778
  currentPath.pop();
@@ -1,8 +1,8 @@
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 type { VertexKey } from '../../types';
@@ -220,8 +220,10 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
220
220
  if (v1 && v2) {
221
221
  const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
222
222
  const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
223
- v1ToV2 && removed.push(v1ToV2);
224
- v2ToV1 && removed.push(v2ToV1);
223
+ if (v1ToV2)
224
+ removed.push(v1ToV2);
225
+ if (v2ToV1)
226
+ removed.push(v2ToV1);
225
227
  }
226
228
  return removed;
227
229
  }
@@ -1,8 +1,8 @@
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 type { VertexKey } from '../../types';
@@ -1,8 +1,8 @@
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 type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem, LinkedHashMapOptions } from '../../types';
@@ -88,7 +88,7 @@ class HashMap extends base_1.IterableEntryBase {
88
88
  * @returns A boolean value indicating whether the size of the object is 0 or not.
89
89
  */
90
90
  isEmpty() {
91
- return this.size === 0;
91
+ return this._size === 0;
92
92
  }
93
93
  /**
94
94
  * The clear() function resets the state of an object by clearing its internal store, object map, and
@@ -573,7 +573,7 @@ class FibonacciHeap {
573
573
  * @returns The top element or undefined if the heap is empty.
574
574
  */
575
575
  pop() {
576
- if (this.size === 0)
576
+ if (this._size === 0)
577
577
  return undefined;
578
578
  const z = this.min;
579
579
  if (z.child) {
@@ -706,7 +706,7 @@ class FibonacciHeap {
706
706
  * @protected
707
707
  */
708
708
  _consolidate() {
709
- const A = new Array(this.size);
709
+ const A = new Array(this._size);
710
710
  const elements = this.consumeLinkedList(this.root);
711
711
  let x, y, d, t;
712
712
  for (const node of elements) {
@@ -725,7 +725,7 @@ class FibonacciHeap {
725
725
  }
726
726
  A[d] = x;
727
727
  }
728
- for (let i = 0; i < this.size; i++) {
728
+ for (let i = 0; i < this._size; i++) {
729
729
  if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
730
730
  this._min = A[i];
731
731
  }
@@ -1,8 +1,8 @@
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 type { DoublyLinkedListOptions, ElementCallback } from '../../types';