avl-tree-typed 2.2.6 → 2.2.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 (29) hide show
  1. package/dist/cjs/index.cjs +67 -69
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +67 -69
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +67 -69
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +67 -69
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +1 -1
  10. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +10 -10
  12. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +22 -23
  13. package/dist/types/data-structures/binary-tree/bst.d.ts +11 -11
  14. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
  17. package/dist/umd/avl-tree-typed.js +67 -69
  18. package/dist/umd/avl-tree-typed.js.map +1 -1
  19. package/dist/umd/avl-tree-typed.min.js +3 -3
  20. package/dist/umd/avl-tree-typed.min.js.map +1 -1
  21. package/package.json +2 -2
  22. package/src/data-structures/binary-tree/avl-tree-counter.ts +6 -6
  23. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -13
  24. package/src/data-structures/binary-tree/avl-tree.ts +15 -15
  25. package/src/data-structures/binary-tree/binary-tree.ts +53 -55
  26. package/src/data-structures/binary-tree/bst.ts +21 -22
  27. package/src/data-structures/binary-tree/red-black-tree.ts +3 -3
  28. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  29. package/src/data-structures/binary-tree/tree-multi-map.ts +13 -13
@@ -204,7 +204,7 @@ export class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R
204
204
  options?: TreeCounterOptions<K, V, R>
205
205
  ) {
206
206
  super([], options);
207
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
207
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
208
208
  }
209
209
 
210
210
  protected _count = 0;
@@ -255,14 +255,14 @@ export class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R
255
255
  * @param [count] - How much to increase the node's count (default 1).
256
256
  * @returns True if inserted/updated; false if ignored.
257
257
  */
258
- override add(
258
+ override set(
259
259
  keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
260
260
  value?: V,
261
261
  count = 1
262
262
  ): boolean {
263
263
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
264
264
  const orgCount = newNode?.count || 0;
265
- const isSuccessAdded = super.add(newNode, newValue);
265
+ const isSuccessAdded = super.set(newNode, newValue);
266
266
  if (isSuccessAdded) {
267
267
  this._count += orgCount;
268
268
  return true;
@@ -437,7 +437,7 @@ export class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R
437
437
 
438
438
  let index = 0;
439
439
  for (const [key, value] of this) {
440
- out.add(callback.call(thisArg, value, key, index++, this));
440
+ out.set(callback.call(thisArg, value, key, index++, this));
441
441
  }
442
442
  return out;
443
443
  }
@@ -364,7 +364,7 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
364
364
  ) {
365
365
  super([], { ...options });
366
366
  if (keysNodesEntriesOrRaws) {
367
- this.addMany(keysNodesEntriesOrRaws);
367
+ this.setMany(keysNodesEntriesOrRaws);
368
368
  }
369
369
  }
370
370
 
@@ -385,29 +385,29 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
385
385
  return keyNodeOrEntry instanceof TreeMultiMapNode;
386
386
  }
387
387
 
388
- override add(
388
+ override set(
389
389
  keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
390
390
  ): boolean;
391
391
 
392
- override add(key: K, value: V): boolean;
392
+ override set(key: K, value: V): boolean;
393
393
 
394
394
  /**
395
395
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
396
396
  * @remarks Time O(log N + M), Space O(1)
397
397
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
398
- * @param [value] - Single value to add when a bare key is provided.
398
+ * @param [value] - Single value to set when a bare key is provided.
399
399
  * @returns True if inserted or appended; false if ignored.
400
400
  */
401
- override add(
401
+ override set(
402
402
  keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined,
403
403
  value?: V
404
404
  ): boolean {
405
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
405
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
406
406
 
407
407
  const _commonAdd = (key?: BTNOptKeyOrNull<K>, values?: V[]) => {
408
408
  if (key === undefined || key === null) return false;
409
409
 
410
- const _addToValues = () => {
410
+ const _setToValues = () => {
411
411
  const existingValues = this.get(key);
412
412
  if (existingValues !== undefined && values !== undefined) {
413
413
  for (const value of values) existingValues.push(value);
@@ -416,12 +416,12 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
416
416
  return false;
417
417
  };
418
418
 
419
- const _addByNode = () => {
419
+ const _setByNode = () => {
420
420
  const existingNode = this.getNode(key);
421
421
  if (this.isRealNode(existingNode)) {
422
422
  const existingValues = this.get(existingNode);
423
423
  if (existingValues === undefined) {
424
- super.add(key, values);
424
+ super.set(key, values);
425
425
  return true;
426
426
  }
427
427
  if (values !== undefined) {
@@ -431,14 +431,14 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
431
431
  return false;
432
432
  }
433
433
  } else {
434
- return super.add(key, values);
434
+ return super.set(key, values);
435
435
  }
436
436
  };
437
437
 
438
438
  if (this._isMapMode) {
439
- return _addByNode() || _addToValues();
439
+ return _setByNode() || _setToValues();
440
440
  }
441
- return _addToValues() || _addByNode();
441
+ return _setToValues() || _setByNode();
442
442
  };
443
443
 
444
444
  if (this.isEntry(keyNodeOrEntry)) {
@@ -503,7 +503,7 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
503
503
  ): RedBlackTree<MK, MV, MR> {
504
504
  const out = this._createLike<MK, MV, MR>([], options);
505
505
  let i = 0;
506
- for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
506
+ for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
507
507
  return out;
508
508
  }
509
509