avl-tree-typed 1.53.0 → 1.53.2

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.
@@ -86,7 +86,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
86
86
  * @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
87
87
  */
88
88
  createNode(key, value, count) {
89
- return new AVLTreeMultiMapNode(key, value, count);
89
+ return new AVLTreeMultiMapNode(key, this._isMapMode ? undefined : value, count);
90
90
  }
91
91
  /**
92
92
  * The function creates a new AVLTreeMultiMap object with the specified options and returns it.
@@ -75,7 +75,7 @@ class AVLTree extends bst_1.BST {
75
75
  * type NODE.
76
76
  */
77
77
  createNode(key, value) {
78
- return new AVLTreeNode(key, value);
78
+ return new AVLTreeNode(key, this._isMapMode ? undefined : value);
79
79
  }
80
80
  /**
81
81
  * The function creates a new AVL tree with the specified options and returns it.
@@ -75,7 +75,7 @@ class BinaryTree extends base_1.IterableEntryBase {
75
75
  constructor(keysNodesEntriesOrRaws = [], options) {
76
76
  super();
77
77
  this.iterationType = 'ITERATIVE';
78
- this._isMapMode = false;
78
+ this._isMapMode = true;
79
79
  this._store = new Map();
80
80
  this._size = 0;
81
81
  this._NIL = new BinaryTreeNode(NaN);
@@ -122,7 +122,7 @@ class BinaryTree extends base_1.IterableEntryBase {
122
122
  * as NODE.
123
123
  */
124
124
  createNode(key, value) {
125
- return new BinaryTreeNode(key, value);
125
+ return new BinaryTreeNode(key, this._isMapMode ? undefined : value);
126
126
  }
127
127
  /**
128
128
  * The function creates a binary tree with the specified options.
@@ -106,7 +106,7 @@ class BST extends binary_tree_1.BinaryTree {
106
106
  * @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
107
107
  */
108
108
  createNode(key, value) {
109
- return new BSTNode(key, value);
109
+ return new BSTNode(key, this._isMapMode ? undefined : value);
110
110
  }
111
111
  /**
112
112
  * The function creates a new binary search tree with the specified options.
@@ -128,10 +128,10 @@ class BST extends binary_tree_1.BinaryTree {
128
128
  * @returns either a NODE object or undefined.
129
129
  */
130
130
  keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
131
- const [node, tValue] = super.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
131
+ const [node, entryValue] = super.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
132
132
  if (node === null)
133
133
  return [undefined, undefined];
134
- return [node, tValue !== null && tValue !== void 0 ? tValue : value];
134
+ return [node, value !== null && value !== void 0 ? value : entryValue];
135
135
  }
136
136
  /**
137
137
  * Time Complexity: O(log n)
@@ -199,6 +199,8 @@ class BST extends binary_tree_1.BinaryTree {
199
199
  while (current !== undefined) {
200
200
  if (this.comparator(current.key, newNode.key) === 0) {
201
201
  this._replaceNode(current, newNode);
202
+ if (this._isMapMode)
203
+ this._setValue(current.key, newValue);
202
204
  return true;
203
205
  }
204
206
  else if (this.comparator(current.key, newNode.key) > 0) {
@@ -74,7 +74,7 @@ class RedBlackTree extends bst_1.BST {
74
74
  * returned.
75
75
  */
76
76
  createNode(key, value, color = 'BLACK') {
77
- return new RedBlackTreeNode(key, value, color);
77
+ return new RedBlackTreeNode(key, this._isMapMode ? undefined : value, color);
78
78
  }
79
79
  /**
80
80
  * The function creates a new Red-Black Tree with the specified options.
@@ -177,8 +177,12 @@ class RedBlackTree extends bst_1.BST {
177
177
  this._size++;
178
178
  return true;
179
179
  }
180
- else
181
- return insertStatus === 'UPDATED';
180
+ if (insertStatus === 'UPDATED') {
181
+ if (this._isMapMode)
182
+ this._setValue(newNode.key, newValue);
183
+ return true;
184
+ }
185
+ return false;
182
186
  }
183
187
  /**
184
188
  * Time Complexity: O(log n)
@@ -88,7 +88,7 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
88
88
  * @returns A new instance of the TreeMultiMapNode class, casted as NODE.
89
89
  */
90
90
  createNode(key, value, color = 'BLACK', count) {
91
- return new TreeMultiMapNode(key, value, count, color);
91
+ return new TreeMultiMapNode(key, this._isMapMode ? undefined : value, count, color);
92
92
  }
93
93
  /**
94
94
  * The function creates a new instance of a TreeMultiMap with the specified options and returns it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avl-tree-typed",
3
- "version": "1.53.0",
3
+ "version": "1.53.2",
4
4
  "description": "AVLTree(Adelson-Velsky and Landis Tree). Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -163,6 +163,6 @@
163
163
  "typescript": "^4.9.5"
164
164
  },
165
165
  "dependencies": {
166
- "data-structure-typed": "^1.53.0"
166
+ "data-structure-typed": "^1.53.2"
167
167
  }
168
168
  }
@@ -129,7 +129,7 @@ export class AVLTreeMultiMap<
129
129
  * @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
130
130
  */
131
131
  override createNode(key: K, value?: V, count?: number): NODE {
132
- return new AVLTreeMultiMapNode(key, value, count) as NODE;
132
+ return new AVLTreeMultiMapNode(key, this._isMapMode ? undefined : value, count) as NODE;
133
133
  }
134
134
 
135
135
  /**
@@ -99,7 +99,7 @@ export class AVLTree<
99
99
  * type NODE.
100
100
  */
101
101
  override createNode(key: K, value?: V): NODE {
102
- return new AVLTreeNode<K, V, NODE>(key, value) as NODE;
102
+ return new AVLTreeNode<K, V, NODE>(key, this._isMapMode ? undefined : value) as NODE;
103
103
  }
104
104
 
105
105
  /**
@@ -135,7 +135,7 @@ export class BinaryTree<
135
135
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
136
136
  }
137
137
 
138
- protected _isMapMode = false;
138
+ protected _isMapMode = true;
139
139
 
140
140
  get isMapMode() {
141
141
  return this._isMapMode;
@@ -181,7 +181,7 @@ export class BinaryTree<
181
181
  * as NODE.
182
182
  */
183
183
  createNode(key: K, value?: V): NODE {
184
- return new BinaryTreeNode<K, V, NODE>(key, value) as NODE;
184
+ return new BinaryTreeNode<K, V, NODE>(key, this._isMapMode ? undefined : value) as NODE;
185
185
  }
186
186
 
187
187
  /**
@@ -141,7 +141,7 @@ export class BST<
141
141
  * @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
142
142
  */
143
143
  override createNode(key: K, value?: V): NODE {
144
- return new BSTNode<K, V, NODE>(key, value) as NODE;
144
+ return new BSTNode<K, V, NODE>(key, this._isMapMode ? undefined : value) as NODE;
145
145
  }
146
146
 
147
147
  /**
@@ -174,9 +174,9 @@ export class BST<
174
174
  keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R,
175
175
  value?: V
176
176
  ): [OptNode<NODE>, V | undefined] {
177
- const [node, tValue] = super.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
177
+ const [node, entryValue] = super.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
178
178
  if (node === null) return [undefined, undefined];
179
- return [node, tValue ?? value];
179
+ return [node, value ?? entryValue];
180
180
  }
181
181
 
182
182
  /**
@@ -250,6 +250,7 @@ export class BST<
250
250
  while (current !== undefined) {
251
251
  if (this.comparator(current.key, newNode.key) === 0) {
252
252
  this._replaceNode(current, newNode);
253
+ if (this._isMapMode) this._setValue(current.key, newValue);
253
254
  return true;
254
255
  } else if (this.comparator(current.key, newNode.key) > 0) {
255
256
  if (current.left === undefined) {
@@ -106,7 +106,7 @@ export class RedBlackTree<
106
106
  * returned.
107
107
  */
108
108
  override createNode(key: K, value?: V, color: RBTNColor = 'BLACK'): NODE {
109
- return new RedBlackTreeNode<K, V, NODE>(key, value, color) as NODE;
109
+ return new RedBlackTreeNode<K, V, NODE>(key, this._isMapMode ? undefined : value, color) as NODE;
110
110
  }
111
111
 
112
112
  /**
@@ -218,7 +218,12 @@ export class RedBlackTree<
218
218
  if (this._isMapMode) this._setValue(newNode.key, newValue);
219
219
  this._size++;
220
220
  return true;
221
- } else return insertStatus === 'UPDATED';
221
+ }
222
+ if (insertStatus === 'UPDATED') {
223
+ if (this._isMapMode) this._setValue(newNode.key, newValue);
224
+ return true;
225
+ }
226
+ return false;
222
227
  }
223
228
 
224
229
  /**
@@ -124,7 +124,7 @@ export class TreeMultiMap<
124
124
  * @returns A new instance of the TreeMultiMapNode class, casted as NODE.
125
125
  */
126
126
  override createNode(key: K, value?: V, color: RBTNColor = 'BLACK', count?: number): NODE {
127
- return new TreeMultiMapNode(key, value, count, color) as NODE;
127
+ return new TreeMultiMapNode(key, this._isMapMode ? undefined : value, count, color) as NODE;
128
128
  }
129
129
 
130
130
  /**
@@ -9,9 +9,9 @@ export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> =
9
9
  export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
10
10
 
11
11
  export type BinaryTreeOptions<K, V, R> = {
12
- iterationType?: IterationType;
13
- toEntryFn?: ToEntryFn<K, V, R>;
14
- isMapMode?: boolean;
12
+ iterationType?: IterationType;
13
+ toEntryFn?: ToEntryFn<K, V, R>;
14
+ isMapMode?: boolean;
15
15
  }
16
16
 
17
17
  export type BinaryTreePrintOptions = { isShowUndefined?: boolean; isShowNull?: boolean; isShowRedBlackNIL?: boolean };
@@ -7,7 +7,7 @@ export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTN
7
7
  export type BSTNested<K, V, R, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
8
8
 
9
9
  export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
10
- comparator?: Comparator<K>
10
+ comparator?: Comparator<K>
11
11
  }
12
12
 
13
13
  export type BSTNOptKey<K> = K | undefined;