data-structure-typed 2.2.0 → 2.2.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/README.md +1511 -840
  3. package/benchmark/report.html +1 -1
  4. package/benchmark/report.json +145 -169
  5. package/dist/cjs/index.cjs +20 -20
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs-legacy/index.cjs +20 -20
  8. package/dist/cjs-legacy/index.cjs.map +1 -1
  9. package/dist/esm/index.mjs +20 -20
  10. package/dist/esm/index.mjs.map +1 -1
  11. package/dist/esm-legacy/index.mjs +20 -20
  12. package/dist/esm-legacy/index.mjs.map +1 -1
  13. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -1
  14. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  15. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -0
  16. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +1 -0
  17. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
  18. package/dist/types/types/data-structures/base/base.d.ts +1 -1
  19. package/dist/umd/data-structure-typed.js +20 -20
  20. package/dist/umd/data-structure-typed.js.map +1 -1
  21. package/dist/umd/data-structure-typed.min.js +2 -2
  22. package/dist/umd/data-structure-typed.min.js.map +1 -1
  23. package/package.json +2 -2
  24. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  25. package/src/data-structures/binary-tree/avl-tree-counter.ts +1 -1
  26. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  27. package/src/data-structures/binary-tree/avl-tree.ts +4 -2
  28. package/src/data-structures/binary-tree/binary-tree.ts +3 -2
  29. package/src/data-structures/binary-tree/bst.ts +2 -1
  30. package/src/data-structures/binary-tree/red-black-tree.ts +2 -1
  31. package/src/data-structures/binary-tree/tree-counter.ts +1 -1
  32. package/src/data-structures/binary-tree/tree-multi-map.ts +2 -1
  33. package/src/data-structures/graph/abstract-graph.ts +3 -3
  34. package/src/data-structures/hash/hash-map.ts +4 -4
  35. package/src/types/data-structures/base/base.ts +1 -1
  36. package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +39 -36
  37. package/test/performance/runner-config.json +4 -4
  38. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  39. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +3 -3
  40. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
  41. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -4
  42. package/test/unit/data-structures/binary-tree/bst.test.ts +3 -3
  43. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +3 -3
  44. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +3 -3
  45. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  46. package/test/unit/data-structures/graph/directed-graph.test.ts +3 -3
  47. package/test/unit/data-structures/hash/hash-map.test.ts +14 -14
  48. package/test/performance/reportor.mjs +0 -505
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Standard data structure",
5
5
  "browser": "dist/umd/data-structure-typed.min.js",
6
6
  "umd:main": "dist/umd/data-structure-typed.min.js",
@@ -99,7 +99,7 @@
99
99
  "benchmark": "^2.1.4",
100
100
  "binary-tree-typed": "^1.54.3",
101
101
  "bst-typed": "^1.54.3",
102
- "data-structure-typed": "^2.1.2",
102
+ "data-structure-typed": "^2.2.1",
103
103
  "dependency-cruiser": "^16.5.0",
104
104
  "doctoc": "^2.2.1",
105
105
  "eslint": "^9.13.0",
@@ -66,7 +66,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
66
66
  every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
67
67
  let index = 0;
68
68
  for (const item of this) {
69
- if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
69
+ if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
70
70
  return false;
71
71
  }
72
72
  }
@@ -83,7 +83,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
83
83
  some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
84
84
  let index = 0;
85
85
  for (const item of this) {
86
- if (predicate.call(thisArg, item[0], item[1], index++, this)) {
86
+ if (predicate.call(thisArg, item[1], item[0], index++, this)) {
87
87
  return true;
88
88
  }
89
89
  }
@@ -100,7 +100,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
100
100
  let index = 0;
101
101
  for (const item of this) {
102
102
  const [key, value] = item;
103
- callbackfn.call(thisArg, key, value, index++, this);
103
+ callbackfn.call(thisArg, value, key, index++, this);
104
104
  }
105
105
  }
106
106
 
@@ -115,7 +115,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
115
115
  let index = 0;
116
116
  for (const item of this) {
117
117
  const [key, value] = item;
118
- if (callbackfn.call(thisArg, key, value, index++, this)) return item;
118
+ if (callbackfn.call(thisArg, value, key, index++, this)) return item;
119
119
  }
120
120
  return;
121
121
  }
@@ -411,7 +411,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
411
411
 
412
412
  let index = 0;
413
413
  for (const [key, value] of this) {
414
- out.add(callback.call(thisArg, key, value, index++, this));
414
+ out.add(callback.call(thisArg, value, key, index++, this));
415
415
  }
416
416
  return out;
417
417
  }
@@ -393,7 +393,7 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
393
393
  ): AVLTree<MK, MV, MR> {
394
394
  const out = this._createLike<MK, MV, MR>([], options);
395
395
  let i = 0;
396
- for (const [k, v] of this) out.add(callback.call(thisArg, k, v, i++, this));
396
+ for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
397
397
  return out;
398
398
  }
399
399
 
@@ -195,7 +195,9 @@ export class AVLTreeNode<K = any, V = any> {
195
195
  * 4. Order Preservation: Maintains the binary search tree property where left child values are less than the parent, and right child values are greater.
196
196
  * 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
197
197
  * 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
198
- * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.@example
198
+ * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
199
+ *
200
+ * @example
199
201
  * // Find elements in a range
200
202
  * // In interval queries, AVL trees, with their strictly balanced structure and lower height, offer better query efficiency, making them ideal for frequent and high-performance interval queries. In contrast, Red-Black trees, with lower update costs, are more suitable for scenarios involving frequent insertions and deletions where the requirements for interval queries are less demanding.
201
203
  * type Datum = { timestamp: Date; temperature: number };
@@ -403,7 +405,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
403
405
  // Iterates in-order
404
406
  for (const [key, value] of this) {
405
407
  // `add` on the new tree will be O(log N) and will self-balance.
406
- out.add(callback.call(thisArg, key, value, index++, this));
408
+ out.add(callback.call(thisArg, value, key, index++, this));
407
409
  }
408
410
  return out;
409
411
  }
@@ -203,6 +203,7 @@ export class BinaryTreeNode<K = any, V = any> {
203
203
  * 3. Depth and Height: Depth is the number of edges from the root to a node; height is the maximum depth in the tree.
204
204
  * 4. Subtrees: Each child of a node forms the root of a subtree.
205
205
  * 5. Leaf Nodes: Nodes without children are leaves.
206
+ *
206
207
  * @example
207
208
  * // determine loan approval using a decision tree
208
209
  * // Decision tree structure
@@ -1673,7 +1674,7 @@ export class BinaryTree<K = any, V = any, R = any>
1673
1674
  filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this {
1674
1675
  const out = this._createInstance<K, V, R>();
1675
1676
  let i = 0;
1676
- for (const [k, v] of this) if (predicate.call(thisArg, k, v, i++, this)) out.add([k, v]);
1677
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
1677
1678
  return out;
1678
1679
  }
1679
1680
 
@@ -1696,7 +1697,7 @@ export class BinaryTree<K = any, V = any, R = any>
1696
1697
  ): BinaryTree<MK, MV, MR> {
1697
1698
  const out = this._createLike<MK, MV, MR>([], options);
1698
1699
  let i = 0;
1699
- for (const [k, v] of this) out.add(cb.call(thisArg, k, v, i++, this));
1700
+ for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
1700
1701
  return out;
1701
1702
  }
1702
1703
 
@@ -199,6 +199,7 @@ export class BSTNode<K = any, V = any> {
199
199
  * 5. Logarithmic Operations: Ideal operations like insertion, deletion, and searching are O(log n) time-efficient.
200
200
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
201
201
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
202
+ *
202
203
  * @example
203
204
  * // Merge 3 sorted datasets
204
205
  * const dataset1 = new BST<number, string>([
@@ -908,7 +909,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
908
909
  let index = 0;
909
910
  // Iterates in-order
910
911
  for (const [key, value] of this) {
911
- out.add(callback.call(thisArg, key, value, index++, this));
912
+ out.add(callback.call(thisArg, value, key, index++, this));
912
913
  }
913
914
  return out;
914
915
  }
@@ -186,6 +186,7 @@ export class RedBlackTreeNode<K = any, V = any> {
186
186
  * @template R
187
187
  * 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high, but the query efficiency is slightly lower.
188
188
  * 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
189
+ *
189
190
  * @example
190
191
  * // using Red-Black Tree as a price-based index for stock data
191
192
  * // Define the structure of individual stock records
@@ -420,7 +421,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
420
421
 
421
422
  let index = 0;
422
423
  for (const [key, value] of this) {
423
- out.add(callback.call(thisArg, key, value, index++, this));
424
+ out.add(callback.call(thisArg, value, key, index++, this));
424
425
  }
425
426
  return out;
426
427
  }
@@ -439,7 +439,7 @@ export class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R
439
439
 
440
440
  let index = 0;
441
441
  for (const [key, value] of this) {
442
- out.add(callback.call(thisArg, key, value, index++, this));
442
+ out.add(callback.call(thisArg, value, key, index++, this));
443
443
  }
444
444
  return out;
445
445
  }
@@ -183,6 +183,7 @@ export class TreeMultiMapNode<K = any, V = any> {
183
183
  * @template K
184
184
  * @template V
185
185
  * @template R
186
+ *
186
187
  * @example
187
188
  * // players ranked by score with their equipment
188
189
  * type Equipment = {
@@ -503,7 +504,7 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
503
504
  ): RedBlackTree<MK, MV, MR> {
504
505
  const out = this._createLike<MK, MV, MR>([], options);
505
506
  let i = 0;
506
- for (const [k, v] of this) out.add(callback.call(thisArg, k, v, i++, this));
507
+ for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
507
508
  return out;
508
509
  }
509
510
 
@@ -897,7 +897,7 @@ export abstract class AbstractGraph<
897
897
  const filtered: [VertexKey, V | undefined][] = [];
898
898
  let index = 0;
899
899
  for (const [key, value] of this) {
900
- if (predicate.call(thisArg, key, value, index, this)) {
900
+ if (predicate.call(thisArg, value, key, index, this)) {
901
901
  filtered.push([key, value]);
902
902
  }
903
903
  index++;
@@ -916,7 +916,7 @@ export abstract class AbstractGraph<
916
916
  const filtered: [VertexKey, V | undefined][] = [];
917
917
  let index = 0;
918
918
  for (const [key, value] of this) {
919
- if (predicate.call(thisArg, key, value, index, this)) {
919
+ if (predicate.call(thisArg, value, key, index, this)) {
920
920
  filtered.push([key, value]);
921
921
  }
922
922
  index++;
@@ -928,7 +928,7 @@ export abstract class AbstractGraph<
928
928
  const mapped: T[] = [];
929
929
  let index = 0;
930
930
  for (const [key, value] of this) {
931
- mapped.push(callback.call(thisArg, key, value, index, this));
931
+ mapped.push(callback.call(thisArg, value, key, index, this));
932
932
  index++;
933
933
  }
934
934
  return mapped;
@@ -290,7 +290,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
290
290
  map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): any {
291
291
  const out = this._createLike<K, VM, [K, VM]>();
292
292
  let index = 0;
293
- for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, key, value, index++, this));
293
+ for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, value, key, index++, this));
294
294
  return out;
295
295
  }
296
296
 
@@ -305,7 +305,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
305
305
  filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): any {
306
306
  const out = this._createLike<K, V, [K, V]>();
307
307
  let index = 0;
308
- for (const [key, value] of this) if (predicate.call(thisArg, key, value, index++, this)) out.set(key, value);
308
+ for (const [key, value] of this) if (predicate.call(thisArg, value, key, index++, this)) out.set(key, value);
309
309
  return out;
310
310
  }
311
311
 
@@ -677,7 +677,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
677
677
  const out = this._createLike<K, V, [K, V]>();
678
678
  let index = 0;
679
679
  for (const [key, value] of this) {
680
- if (predicate.call(thisArg, key, value, index, this)) out.set(key, value);
680
+ if (predicate.call(thisArg, value, key, index, this)) out.set(key, value);
681
681
  index++;
682
682
  }
683
683
  return out;
@@ -696,7 +696,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
696
696
  const out = this._createLike<MK, MV, [MK, MV]>();
697
697
  let index = 0;
698
698
  for (const [key, value] of this) {
699
- const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
699
+ const [newKey, newValue] = callback.call(thisArg, value, key, index, this);
700
700
  out.set(newKey, newValue);
701
701
  index++;
702
702
  }
@@ -1,7 +1,7 @@
1
1
  import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
2
2
  import { LinearBase } from '../../../data-structures/base/linear-base';
3
3
 
4
- export type EntryCallback<K, V, R> = (key: K, value: V, index: number, original: IterableEntryBase<K, V>) => R;
4
+ export type EntryCallback<K, V, R> = (value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
5
5
  export type ElementCallback<E, R, RT> = (element: E, index: number, original: IterableElementBase<E, R>) => RT;
6
6
  export type ReduceEntryCallback<K, V, R> = (
7
7
  accumulator: R,
@@ -2,57 +2,60 @@ import { RedBlackTree } from '../../../../src';
2
2
  import * as Benchmark from 'benchmark';
3
3
  import { getRandomIntArray, magnitude } from '../../../utils';
4
4
  import { OrderedMap } from 'js-sdsl';
5
- import { isCompetitor } from '../../../config';
6
5
 
7
6
  const suite = new Benchmark.Suite();
8
7
  const rbTree = new RedBlackTree<number>();
9
- const rbTreeNodeMode = new RedBlackTree<number>([], { isMapMode: false });
8
+ // const rbTreeNodeMode = new RedBlackTree<number>([], { isMapMode: false });
10
9
 
11
- const { HUNDRED_THOUSAND } = magnitude;
12
- const randomArray = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND - 1, true);
10
+ const { MILLION } = magnitude;
11
+ const randomArray = getRandomIntArray(MILLION, 0, MILLION - 1, true);
13
12
  const cOrderedMap = new OrderedMap<number, number>();
14
13
 
15
14
  suite
16
- .add(`${HUNDRED_THOUSAND.toLocaleString()} add randomly`, () => {
17
- rbTree.clear();
18
- for (let i = 0; i < randomArray.length; i++) rbTree.add(randomArray[i]);
19
- })
20
- .add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
15
+ // .add(`${MILLION.toLocaleString()} add randomly`, () => {
16
+ // rbTree.clear();
17
+ // for (let i = 0; i < randomArray.length; i++) rbTree.add(randomArray[i]);
18
+ // })
19
+ .add(`${MILLION.toLocaleString()} add`, () => {
21
20
  rbTree.clear();
22
21
  for (let i = 0; i < randomArray.length; i++) rbTree.add(i);
23
22
  })
24
- .add(`${HUNDRED_THOUSAND.toLocaleString()} get`, () => {
23
+ .add(`${MILLION.toLocaleString()} get`, () => {
25
24
  for (let i = 0; i < randomArray.length; i++) rbTree.get(randomArray[i]);
26
25
  })
27
- .add(`${HUNDRED_THOUSAND.toLocaleString()} getNode`, () => {
28
- for (let i = 0; i < randomArray.length; i++) rbTree.getNode(randomArray[i]);
29
- })
30
- .add(`${HUNDRED_THOUSAND.toLocaleString()} node mode add randomly`, () => {
31
- rbTreeNodeMode.clear();
32
- for (let i = 0; i < randomArray.length; i++) rbTreeNodeMode.add(randomArray[i]);
33
- })
34
- .add(`${HUNDRED_THOUSAND.toLocaleString()} node mode get`, () => {
35
- for (let i = 0; i < randomArray.length; i++) rbTreeNodeMode.get(randomArray[i]);
36
- })
37
- .add(`${HUNDRED_THOUSAND.toLocaleString()} iterator`, () => {
26
+ // .add(`${MILLION.toLocaleString()} getNode`, () => {
27
+ // for (let i = 0; i < randomArray.length; i++) rbTree.getNode(randomArray[i]);
28
+ // })
29
+ // .add(`${MILLION.toLocaleString()} node mode add randomly`, () => {
30
+ // rbTreeNodeMode.clear();
31
+ // for (let i = 0; i < randomArray.length; i++) rbTreeNodeMode.add(randomArray[i]);
32
+ // })
33
+ // .add(`${MILLION.toLocaleString()} node mode get`, () => {
34
+ // for (let i = 0; i < randomArray.length; i++) rbTreeNodeMode.get(randomArray[i]);
35
+ // })
36
+ .add(`${MILLION.toLocaleString()} iterator`, () => {
38
37
  const entries = [...rbTree];
39
- return entries.length === HUNDRED_THOUSAND;
40
- })
41
- .add(`${HUNDRED_THOUSAND.toLocaleString()} add & delete orderly`, () => {
42
- rbTree.clear();
43
- for (let i = 0; i < randomArray.length; i++) rbTree.add(i);
44
- for (let i = 0; i < randomArray.length; i++) rbTree.delete(i);
45
- })
46
- .add(`${HUNDRED_THOUSAND.toLocaleString()} add & delete randomly`, () => {
47
- rbTree.clear();
48
- for (let i = 0; i < randomArray.length; i++) rbTree.add(randomArray[i]);
49
- for (let i = 0; i < randomArray.length; i++) rbTree.delete(randomArray[i]);
38
+ return entries.length === MILLION;
50
39
  });
40
+ // .add(`${MILLION.toLocaleString()} add & delete orderly`, () => {
41
+ // rbTree.clear();
42
+ // for (let i = 0; i < randomArray.length; i++) rbTree.add(i);
43
+ // for (let i = 0; i < randomArray.length; i++) rbTree.delete(i);
44
+ // })
45
+ // .add(`${MILLION.toLocaleString()} add & delete randomly`, () => {
46
+ // rbTree.clear();
47
+ // for (let i = 0; i < randomArray.length; i++) rbTree.add(randomArray[i]);
48
+ // for (let i = 0; i < randomArray.length; i++) rbTree.delete(randomArray[i]);
49
+ // });
51
50
 
52
- if (isCompetitor) {
53
- suite.add(`CPT ${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
54
- for (let i = 0; i < randomArray.length; i++) cOrderedMap.setElement(randomArray[i], randomArray[i]);
55
- });
51
+ if (true) {
52
+ suite
53
+ .add(`CPT ${MILLION.toLocaleString()} add`, () => {
54
+ for (let i = 0; i < randomArray.length; i++) cOrderedMap.setElement(randomArray[i], randomArray[i]);
55
+ })
56
+ .add(`CPT ${MILLION.toLocaleString()} add`, () => {
57
+ for (let i = 0; i < randomArray.length; i++) cOrderedMap.getElementByKey(randomArray[i]);
58
+ });
56
59
  }
57
60
 
58
61
  export { suite };
@@ -17,20 +17,20 @@
17
17
  "**/experimental/**"
18
18
  ],
19
19
  "order": [
20
+ "red-black-tree",
21
+ "queue",
22
+ "deque",
20
23
  "heap",
21
24
  "avl-tree",
22
- "red-black-tree",
23
25
  "doubly-linked-list",
26
+ "singly-linked-list",
24
27
  "linked-hash-map",
25
28
  "hash-map",
26
29
  "map-graph",
27
30
  "graph",
28
31
  "directed-graph",
29
32
  "undirected-graph",
30
- "queue",
31
- "deque",
32
33
  "priority-queue",
33
- "singly-linked-list",
34
34
  "binary-tree-overall",
35
35
  "bst",
36
36
  "trie",
@@ -627,7 +627,7 @@ describe('AVLTreeCounter iterative methods test', () => {
627
627
 
628
628
  it('forEach should iterate over all elements', () => {
629
629
  const mockCallback = jest.fn();
630
- avlCounter.forEach((key, value) => {
630
+ avlCounter.forEach((value, key) => {
631
631
  mockCallback(key, value);
632
632
  });
633
633
 
@@ -638,7 +638,7 @@ describe('AVLTreeCounter iterative methods test', () => {
638
638
  });
639
639
 
640
640
  it('filter should return a new avlCounter with filtered elements', () => {
641
- const filteredTree = avlCounter.filter(key => key > 1);
641
+ const filteredTree = avlCounter.filter((_value, key) => key > 1);
642
642
  expect(filteredTree.size).toBe(2);
643
643
  expect([...filteredTree]).toEqual([
644
644
  [2, 'b'],
@@ -647,7 +647,7 @@ describe('AVLTreeCounter iterative methods test', () => {
647
647
  });
648
648
 
649
649
  it('map should return a new avlCounter with modified elements', () => {
650
- const avlCounterMapped = avlCounter.map((key, value) => [(key * 2).toString(), value]);
650
+ const avlCounterMapped = avlCounter.map((value, key) => [(key * 2).toString(), value]);
651
651
  expect(avlCounterMapped.size).toBe(3);
652
652
  expect([...avlCounterMapped]).toEqual([
653
653
  ['2', 'a'],
@@ -415,7 +415,7 @@ describe('AVLTreeMultiMap iterative methods test', () => {
415
415
 
416
416
  it('forEach should iterate over all elements', () => {
417
417
  const mockCallback = jest.fn();
418
- avlTmm.forEach((key, value) => {
418
+ avlTmm.forEach((value, key) => {
419
419
  mockCallback(key, value);
420
420
  });
421
421
 
@@ -426,7 +426,7 @@ describe('AVLTreeMultiMap iterative methods test', () => {
426
426
  });
427
427
 
428
428
  it('filter should return a new avlTmm with filtered elements', () => {
429
- const filteredTree = avlTmm.filter(key => key > 1);
429
+ const filteredTree = avlTmm.filter((_value, key) => key > 1);
430
430
  expect(filteredTree.size).toBe(2);
431
431
  expect([...filteredTree]).toEqual([
432
432
  [2, ['b']],
@@ -435,7 +435,7 @@ describe('AVLTreeMultiMap iterative methods test', () => {
435
435
  });
436
436
 
437
437
  it('map should return a new avlTmm with modified elements', () => {
438
- const avlTmmMapped = avlTmm.map((key, value) => [(key * 2).toString(), value ? value : []]);
438
+ const avlTmmMapped = avlTmm.map((value, key) => [(key * 2).toString(), value ? value : []]);
439
439
  expect(avlTmmMapped.size).toBe(3);
440
440
  expect([...avlTmmMapped]).toEqual([
441
441
  ['2', ['a']],
@@ -386,7 +386,7 @@ describe('AVLTree iterative methods test', () => {
386
386
 
387
387
  it('forEach should iterate over all elements', () => {
388
388
  const mockCallback = jest.fn();
389
- avlTree.forEach((key, value) => {
389
+ avlTree.forEach((value, key) => {
390
390
  mockCallback(key, value);
391
391
  });
392
392
 
@@ -397,7 +397,7 @@ describe('AVLTree iterative methods test', () => {
397
397
  });
398
398
 
399
399
  it('filter should return a new avlTree with filtered elements', () => {
400
- const filteredTree = avlTree.filter(key => key > 1);
400
+ const filteredTree = avlTree.filter((_value, key) => key > 1);
401
401
  expect(filteredTree.size).toBe(2);
402
402
  expect([...filteredTree]).toEqual([
403
403
  [2, 'b'],
@@ -406,7 +406,7 @@ describe('AVLTree iterative methods test', () => {
406
406
  });
407
407
 
408
408
  it('map should return a new avlTree with modified elements', () => {
409
- const mappedTree = avlTree.map((key, value) => [(key * 2).toString(), value]);
409
+ const mappedTree = avlTree.map((value, key) => [(key * 2).toString(), value]);
410
410
  expect(mappedTree.size).toBe(3);
411
411
  expect([...mappedTree]).toEqual([
412
412
  ['2', 'a'],
@@ -1308,7 +1308,7 @@ describe('BinaryTree (map mode) - higher-order & iteration', () => {
1308
1308
 
1309
1309
  it('forEach(): iterates all entries', () => {
1310
1310
  const mockCallback = jest.fn();
1311
- binaryTree.forEach((key, value) => {
1311
+ binaryTree.forEach((value, key) => {
1312
1312
  mockCallback(key, value);
1313
1313
  });
1314
1314
 
@@ -1319,7 +1319,7 @@ describe('BinaryTree (map mode) - higher-order & iteration', () => {
1319
1319
  });
1320
1320
 
1321
1321
  it('filter(): returns new tree with filtered entries', () => {
1322
- const filteredTree = binaryTree.filter(key => key > 1);
1322
+ const filteredTree = binaryTree.filter((_value, key) => key > 1);
1323
1323
  expect(filteredTree.size).toBe(2);
1324
1324
  expect([...filteredTree]).toEqual([
1325
1325
  [3, 'c'],
@@ -1328,7 +1328,7 @@ describe('BinaryTree (map mode) - higher-order & iteration', () => {
1328
1328
  });
1329
1329
 
1330
1330
  it('map(): returns new tree with transformed keys/values', () => {
1331
- const mappedTree = binaryTree.map((key, value) => [(key * 2).toString(), value]);
1331
+ const mappedTree = binaryTree.map((value, key) => [(key * 2).toString(), value]);
1332
1332
  expect(mappedTree.size).toBe(3);
1333
1333
  expect([...mappedTree]).toEqual([
1334
1334
  ['2', 'a'],
@@ -1578,7 +1578,7 @@ describe('Coverage boosters - close remaining uncovered branches', () => {
1578
1578
  [1, 'a'],
1579
1579
  [2, 'b']
1580
1580
  ]);
1581
- const mapped = t.map((k, v) => [String(k), (v ?? '').toUpperCase()], { iterationType: 'RECURSIVE' } as any);
1581
+ const mapped = t.map((v, k) => [String(k), (v ?? '').toUpperCase()], { iterationType: 'RECURSIVE' } as any);
1582
1582
  expect(Array.from(mapped)).toEqual([
1583
1583
  ['1', 'A'],
1584
1584
  ['2', 'B']
@@ -1109,7 +1109,7 @@ describe('BST iterative methods test', () => {
1109
1109
 
1110
1110
  it('forEach should iterate over all elements', () => {
1111
1111
  const mockCallback = jest.fn();
1112
- bst.forEach((key, value) => {
1112
+ bst.forEach((value, key) => {
1113
1113
  mockCallback(key, value);
1114
1114
  });
1115
1115
 
@@ -1120,7 +1120,7 @@ describe('BST iterative methods test', () => {
1120
1120
  });
1121
1121
 
1122
1122
  it('filter should return a new tree with filtered elements', () => {
1123
- const filteredTree = bst.filter(key => key > 1);
1123
+ const filteredTree = bst.filter((_value, key) => key > 1);
1124
1124
  expect(filteredTree.size).toBe(2);
1125
1125
  expect([...filteredTree]).toEqual([
1126
1126
  [2, 'b'],
@@ -1129,7 +1129,7 @@ describe('BST iterative methods test', () => {
1129
1129
  });
1130
1130
 
1131
1131
  it('map should return a new tree with modified elements', () => {
1132
- const mappedTree = bst.map((key, value) => [(key * 2).toString(), value]);
1132
+ const mappedTree = bst.map((value, key) => [(key * 2).toString(), value]);
1133
1133
  expect(mappedTree.size).toBe(3);
1134
1134
  expect([...mappedTree]).toEqual([
1135
1135
  ['2', 'a'],
@@ -648,7 +648,7 @@ describe('RedBlackTree 2', () => {
648
648
 
649
649
  it('forEach should iterate over all elements', () => {
650
650
  const mockCallback = jest.fn();
651
- rbTree.forEach((key, value) => {
651
+ rbTree.forEach((value, key) => {
652
652
  mockCallback(key, value);
653
653
  });
654
654
 
@@ -659,7 +659,7 @@ describe('RedBlackTree 2', () => {
659
659
  });
660
660
 
661
661
  it('filter should return a new rbTree with filtered elements', () => {
662
- const filteredTree = rbTree.filter(key => key > 1);
662
+ const filteredTree = rbTree.filter((_value, key) => key > 1);
663
663
  expect(filteredTree.size).toBe(2);
664
664
  expect([...filteredTree]).toEqual([
665
665
  [2, 'b'],
@@ -668,7 +668,7 @@ describe('RedBlackTree 2', () => {
668
668
  });
669
669
 
670
670
  it('map should return a new rbTree with modified elements', () => {
671
- const rbTreeMapped = rbTree.map((key, value) => [(key * 2).toString(), value]);
671
+ const rbTreeMapped = rbTree.map((value, key) => [(key * 2).toString(), value]);
672
672
  expect(rbTreeMapped.size).toBe(3);
673
673
  expect([...rbTreeMapped]).toEqual([
674
674
  ['2', 'a'],
@@ -765,7 +765,7 @@ describe('TreeCounter iterative methods test', () => {
765
765
 
766
766
  it('forEach should iterate over all elements', () => {
767
767
  const mockCallback = jest.fn();
768
- treeCounter.forEach((key, value) => {
768
+ treeCounter.forEach((value, key) => {
769
769
  mockCallback(key, value);
770
770
  });
771
771
 
@@ -776,7 +776,7 @@ describe('TreeCounter iterative methods test', () => {
776
776
  });
777
777
 
778
778
  it('filter should return a new tree with filtered elements', () => {
779
- const filteredTree = treeCounter.filter(key => key > 1);
779
+ const filteredTree = treeCounter.filter((_value, key) => key > 1);
780
780
  expect(filteredTree.size).toBe(2);
781
781
  expect([...filteredTree]).toEqual([
782
782
  [2, 'b'],
@@ -785,7 +785,7 @@ describe('TreeCounter iterative methods test', () => {
785
785
  });
786
786
 
787
787
  it('map should return a new tree with modified elements', () => {
788
- const treeCounterMapped = treeCounter.map((key, value) => [(key * 2).toString(), value]);
788
+ const treeCounterMapped = treeCounter.map((value, key) => [(key * 2).toString(), value]);
789
789
  expect(treeCounterMapped.size).toBe(3);
790
790
  expect([...treeCounterMapped]).toEqual([
791
791
  ['2', 'a'],
@@ -643,7 +643,7 @@ describe('TreeMultiMap 2', () => {
643
643
 
644
644
  it('forEach should iterate over all elements', () => {
645
645
  const mockCallback = jest.fn();
646
- tmm.forEach((key, value) => {
646
+ tmm.forEach((value, key) => {
647
647
  mockCallback(key, value);
648
648
  });
649
649
 
@@ -654,7 +654,7 @@ describe('TreeMultiMap 2', () => {
654
654
  });
655
655
 
656
656
  it('filter should return a new tmm with filtered elements', () => {
657
- const filteredTree = tmm.filter(key => key > 1);
657
+ const filteredTree = tmm.filter((_value, key) => key > 1);
658
658
  expect(filteredTree.size).toBe(2);
659
659
  expect([...filteredTree]).toEqual([
660
660
  [2, ['b']],
@@ -663,7 +663,7 @@ describe('TreeMultiMap 2', () => {
663
663
  });
664
664
 
665
665
  it('map should return a new tmm with modified elements', () => {
666
- const tmmMapped = tmm.map((key, value) => [(key * 2).toString(), value ? value : []]);
666
+ const tmmMapped = tmm.map((value, key) => [(key * 2).toString(), value ? value : []]);
667
667
  expect(tmmMapped.size).toBe(3);
668
668
  expect([...tmmMapped]).toEqual([
669
669
  ['2', ['a']],
@@ -680,12 +680,12 @@ describe('DirectedGraph iterative Methods', () => {
680
680
 
681
681
  it('forEach should apply a function to each vertex', () => {
682
682
  const result: VertexKey[] = [];
683
- graph.forEach(key => key && result.push(key));
683
+ graph.forEach((_value, key) => key && result.push(key));
684
684
  expect(result).toEqual(vertexMap);
685
685
  });
686
686
 
687
687
  it('filter should return vertexMap that satisfy the condition', () => {
688
- const filtered = graph.filterEntries(key => key === 'A' || key === 'B');
688
+ const filtered = graph.filterEntries((_value, key) => key === 'A' || key === 'B');
689
689
  expect(filtered).toEqual([
690
690
  ['A', undefined],
691
691
  ['B', undefined]
@@ -693,7 +693,7 @@ describe('DirectedGraph iterative Methods', () => {
693
693
  });
694
694
 
695
695
  it('map should apply a function to each vertex and return a new array', () => {
696
- const mapped = graph.map(vertex => vertex + '_mapped');
696
+ const mapped = graph.map((_value, vertex) => vertex + '_mapped');
697
697
  expect(mapped).toEqual(vertexMap.map(key => key + '_mapped'));
698
698
  });
699
699