data-structure-typed 1.49.8 → 1.50.0

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 (54) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/benchmark/report.html +1 -37
  3. package/benchmark/report.json +22 -370
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -7
  5. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -9
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +5 -22
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js +9 -80
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.d.ts +89 -27
  11. package/dist/cjs/data-structures/binary-tree/bst.js +131 -46
  12. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +0 -7
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js +1 -10
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +0 -7
  17. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +2 -11
  18. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  19. package/dist/cjs/data-structures/hash/hash-map.d.ts +16 -12
  20. package/dist/cjs/data-structures/hash/hash-map.js +36 -15
  21. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  22. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +2 -1
  23. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -7
  24. package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -9
  25. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +5 -22
  26. package/dist/mjs/data-structures/binary-tree/binary-tree.js +9 -80
  27. package/dist/mjs/data-structures/binary-tree/bst.d.ts +89 -27
  28. package/dist/mjs/data-structures/binary-tree/bst.js +131 -46
  29. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +0 -7
  30. package/dist/mjs/data-structures/binary-tree/rb-tree.js +1 -10
  31. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -7
  32. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +2 -11
  33. package/dist/mjs/data-structures/hash/hash-map.d.ts +16 -12
  34. package/dist/mjs/data-structures/hash/hash-map.js +36 -15
  35. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +2 -1
  36. package/dist/umd/data-structure-typed.js +176 -165
  37. package/dist/umd/data-structure-typed.min.js +2 -2
  38. package/dist/umd/data-structure-typed.min.js.map +1 -1
  39. package/package.json +1 -1
  40. package/src/data-structures/binary-tree/avl-tree.ts +0 -10
  41. package/src/data-structures/binary-tree/binary-tree.ts +104 -141
  42. package/src/data-structures/binary-tree/bst.ts +153 -49
  43. package/src/data-structures/binary-tree/rb-tree.ts +1 -11
  44. package/src/data-structures/binary-tree/tree-multimap.ts +2 -12
  45. package/src/data-structures/hash/hash-map.ts +42 -16
  46. package/src/types/data-structures/hash/hash-map.ts +2 -1
  47. package/test/integration/all-in-one.test.ts +1 -1
  48. package/test/integration/index.html +2 -2
  49. package/test/performance/data-structures/queue/deque.test.ts +8 -2
  50. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
  51. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +38 -9
  52. package/test/unit/data-structures/binary-tree/bst.test.ts +8 -12
  53. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +4 -4
  54. package/test/unit/data-structures/hash/hash-map.test.ts +17 -1
@@ -21,29 +21,46 @@ import { isWeakKey, rangeCheck } from '../../utils';
21
21
  * 3. Unique Keys: Keys are unique. If you try to insert another entry with the same key, the old entry will be replaced by the new one.
22
22
  * 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
23
23
  */
24
- export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
24
+ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
25
25
  protected _store: { [key: string]: HashMapStoreItem<K, V> } = {};
26
26
  protected _objMap: Map<object, V> = new Map();
27
27
 
28
28
  /**
29
- * The constructor function initializes a new instance of a class with optional entries and options.
30
- * @param entries - The `entries` parameter is an iterable containing key-value pairs `[K, V]`. It
31
- * is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with
32
- * key-value pairs.
33
- * @param [options] - The `options` parameter is an optional object that can contain additional
34
- * configuration options for the constructor. In this case, it has one property:
29
+ * The constructor function initializes a HashMap object with an optional initial collection and
30
+ * options.
31
+ * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type
32
+ * `T`. It is an optional parameter and its default value is an empty array `[]`.
33
+ * @param [options] - The `options` parameter is an optional object that can contain two properties:
35
34
  */
36
- constructor(entries: Iterable<[K, V]> = [], options?: HashMapOptions<K>) {
35
+ constructor(rawCollection: Iterable<R> = [], options?: HashMapOptions<K, V, R>) {
37
36
  super();
38
37
  if (options) {
39
- const { hashFn } = options;
38
+ const { hashFn, toEntryFn } = options;
40
39
  if (hashFn) {
41
40
  this._hashFn = hashFn;
42
41
  }
42
+ if (toEntryFn) {
43
+ this._toEntryFn = toEntryFn;
44
+ }
43
45
  }
44
- if (entries) {
45
- this.setMany(entries);
46
+ if (rawCollection) {
47
+ this.setMany(rawCollection);
48
+ }
49
+ }
50
+
51
+ protected _toEntryFn: (rawElement: R) => [K, V] = (rawElement: R) => {
52
+ if (this.isEntry(rawElement)) {
53
+ // TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
54
+ return rawElement;
55
+ } else {
56
+ throw new Error(
57
+ "If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified."
58
+ );
46
59
  }
60
+ };
61
+
62
+ get toEntryFn() {
63
+ return this._toEntryFn;
47
64
  }
48
65
 
49
66
  protected _size = 0;
@@ -52,6 +69,10 @@ export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
52
69
  return this._size;
53
70
  }
54
71
 
72
+ isEntry(rawElement: any): rawElement is [K, V] {
73
+ return Array.isArray(rawElement) && rawElement.length === 2;
74
+ }
75
+
55
76
  isEmpty(): boolean {
56
77
  return this.size === 0;
57
78
  }
@@ -88,13 +109,18 @@ export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
88
109
  }
89
110
 
90
111
  /**
91
- * The function "setMany" sets multiple key-value pairs in a map.
92
- * @param entries - The `entries` parameter is an iterable containing key-value pairs. Each
93
- * key-value pair is represented as an array with two entries: the key and the value.
112
+ * The function `setMany` takes an iterable collection of objects, maps each object to a key-value
113
+ * pair using a mapping function, and sets each key-value pair in the current object.
114
+ * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type
115
+ * `T`.
116
+ * @returns The `setMany` function is returning an array of booleans.
94
117
  */
95
- setMany(entries: Iterable<[K, V]>): boolean[] {
118
+ setMany(rawCollection: Iterable<R>): boolean[] {
96
119
  const results: boolean[] = [];
97
- for (const [key, value] of entries) results.push(this.set(key, value));
120
+ for (const rawEle of rawCollection) {
121
+ const [key, value] = this.toEntryFn(rawEle);
122
+ results.push(this.set(key, value));
123
+ }
98
124
  return results;
99
125
  }
100
126
 
@@ -10,8 +10,9 @@ export type LinkedHashMapOptions<K> = {
10
10
  objHashFn?: (key: K) => object;
11
11
  };
12
12
 
13
- export type HashMapOptions<K> = {
13
+ export type HashMapOptions<K, V, T> = {
14
14
  hashFn?: (key: K) => string;
15
+ toEntryFn?: (rawElement: T) => [K, V];
15
16
  };
16
17
 
17
18
  export type HashMapStoreItem<K, V> = { key: K; value: V };
@@ -23,7 +23,7 @@ describe('AVL Tree Test from data-structure-typed', () => {
23
23
  expect(getMinNodeBySpecificNode?.key).toBe(12);
24
24
 
25
25
  let subTreeSum = 0;
26
- node15 && tree.subTreeTraverse(node => (subTreeSum += node.key), 15);
26
+ node15 && tree.dfs(node => (subTreeSum += node.key), 'pre', 15);
27
27
  expect(subTreeSum).toBe(70);
28
28
 
29
29
  let lesserSum = 0;
@@ -4,8 +4,8 @@
4
4
  <meta charset='UTF-8'>
5
5
  <title>CDN Test</title>
6
6
  <!-- <script src="../../dist/umd/data-structure-typed.min.js"></script>-->
7
- <script src="../../dist/umd/data-structure-typed.js"></script>
8
- <!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>-->
7
+ <script src="../../dist/umd/data-structure-typed.js"></script>
8
+ <!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>-->
9
9
  <!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.42.2/dist/umd/data-structure-typed.min.js'></script>-->
10
10
  <!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.43.3/dist/umd/data-structure-typed.min.js'></script>-->
11
11
  <!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.44.0/dist/umd/data-structure-typed.min.js'></script>-->
@@ -1,11 +1,11 @@
1
1
  import { Deque } from '../../../../src';
2
2
  import { Deque as CDeque } from 'js-sdsl';
3
3
  import * as Benchmark from 'benchmark';
4
- import { magnitude } from '../../../utils';
4
+ import { getRandomInt, magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  export const suite = new Benchmark.Suite();
8
- const { MILLION, HUNDRED_THOUSAND } = magnitude;
8
+ const { MILLION, HUNDRED_THOUSAND, TEN_THOUSAND } = magnitude;
9
9
 
10
10
  suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const deque = new Deque<number>();
@@ -20,6 +20,12 @@ if (isCompetitor) {
20
20
  }
21
21
 
22
22
  suite
23
+ .add(`${TEN_THOUSAND.toLocaleString()} push & delete`, () => {
24
+ const _deque = new Deque<number>();
25
+
26
+ for (let i = 0; i < TEN_THOUSAND; i++) _deque.push(i);
27
+ for (let i = 0; i < TEN_THOUSAND; i++) _deque.delete(getRandomInt(0, TEN_THOUSAND - 1));
28
+ })
23
29
  .add(`${MILLION.toLocaleString()} push & pop`, () => {
24
30
  const _deque = new Deque<number>();
25
31
 
@@ -24,7 +24,7 @@ describe('AVL Tree Test', () => {
24
24
  expect(getMinNodeBySpecificNode?.key).toBe(12);
25
25
 
26
26
  let subTreeSum = 0;
27
- node15 && tree.subTreeTraverse(node => (subTreeSum += node.key), node15);
27
+ node15 && tree.dfs(node => (subTreeSum += node.key), 'pre', node15);
28
28
  expect(subTreeSum).toBe(70);
29
29
 
30
30
  let lesserSum = 0;
@@ -132,7 +132,7 @@ describe('AVL Tree Test recursively', () => {
132
132
  expect(getMinNodeBySpecificNode?.key).toBe(12);
133
133
 
134
134
  let subTreeSum = 0;
135
- node15 && tree.subTreeTraverse(node => (subTreeSum += node.key), node15);
135
+ node15 && tree.dfs(node => (subTreeSum += node.key), 'pre', node15);
136
136
  expect(subTreeSum).toBe(70);
137
137
 
138
138
  let lesserSum = 0;
@@ -238,16 +238,45 @@ describe('BinaryTree', () => {
238
238
  expect(tree.getNodes(tree.getNodeByKey(2), undefined, false, tree.root)).toEqual([tree.getNodeByKey(2)]);
239
239
  });
240
240
 
241
- it('should subTreeTraverse', () => {
241
+ // it('should subTreeTraverse', () => {
242
+ // tree.addMany([4, 2, 6, null, 1, 3, null, 5, null, 7]);
243
+ // expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.ITERATIVE)).toEqual([6, 3, 7]);
244
+ // expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.ITERATIVE, false)).toEqual([6, 3, 7]);
245
+ // expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.RECURSIVE)).toEqual([6, 3, 7]);
246
+ // expect(
247
+ // tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.ITERATIVE, true)
248
+ // ).toEqual([6, 3, 7, null]);
249
+ // expect(
250
+ // tree.subTreeTraverse(node => (node ? node.key : node), tree.getNode(6), IterationType.ITERATIVE, true)
251
+ // ).toEqual([6, 3, 7, null]);
252
+ // expect(
253
+ // tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.RECURSIVE, true)
254
+ // ).toEqual([6, 3, 7, null]);
255
+ // });
256
+
257
+ it('should sub tree traverse', () => {
242
258
  tree.addMany([4, 2, 6, null, 1, 3, null, 5, null, 7]);
243
- expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.ITERATIVE)).toEqual([6, 3, 7]);
244
- expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.RECURSIVE)).toEqual([6, 3, 7]);
245
- expect(
246
- tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.ITERATIVE, true)
247
- ).toEqual([6, 3, 7, null]);
248
- expect(
249
- tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.RECURSIVE, true)
250
- ).toEqual([6, 3, 7, null]);
259
+ expect(tree.dfs(node => node.key, 'pre', tree.getNode(6), IterationType.ITERATIVE)).toEqual([6, 3, 7]);
260
+ expect(tree.dfs(node => node.key, 'pre', tree.getNode(6), IterationType.ITERATIVE, false)).toEqual([6, 3, 7]);
261
+ expect(tree.dfs(node => node.key, 'pre', tree.getNode(6), IterationType.RECURSIVE)).toEqual([6, 3, 7]);
262
+ expect(tree.dfs(node => (node ? node.key : null), 'pre', tree.getNode(6), IterationType.ITERATIVE, true)).toEqual([
263
+ 6,
264
+ 3,
265
+ 7,
266
+ null
267
+ ]);
268
+ expect(tree.dfs(node => (node ? node.key : node), 'pre', tree.getNode(6), IterationType.ITERATIVE, true)).toEqual([
269
+ 6,
270
+ 3,
271
+ 7,
272
+ null
273
+ ]);
274
+ expect(tree.dfs(node => (node ? node.key : null), 'pre', tree.getNode(6), IterationType.RECURSIVE, true)).toEqual([
275
+ 6,
276
+ 3,
277
+ 7,
278
+ null
279
+ ]);
251
280
  });
252
281
 
253
282
  it('should clear the tree', () => {
@@ -54,7 +54,7 @@ describe('BST operations test', () => {
54
54
  expect(minNodeBySpecificNode?.key).toBe(12);
55
55
 
56
56
  let subTreeSum = 0;
57
- node15 && bst.subTreeTraverse(node => (subTreeSum += node.key), 15);
57
+ node15 && bst.dfs(node => (subTreeSum += node.key), 'pre', 15);
58
58
  expect(subTreeSum).toBe(70);
59
59
 
60
60
  let lesserSum = 0;
@@ -257,7 +257,7 @@ describe('BST operations test', () => {
257
257
  expect(minNodeBySpecificNode?.key).toBe(12);
258
258
 
259
259
  let subTreeSum = 0;
260
- node15 && objBST.subTreeTraverse(node => (subTreeSum += node.key), node15);
260
+ node15 && objBST.dfs(node => (subTreeSum += node.key), 'pre', node15);
261
261
  expect(subTreeSum).toBe(70);
262
262
 
263
263
  let lesserSum = 0;
@@ -444,7 +444,7 @@ describe('BST operations test recursively', () => {
444
444
  expect(minNodeBySpecificNode?.key).toBe(12);
445
445
 
446
446
  let subTreeSum = 0;
447
- node15 && bst.subTreeTraverse(node => (subTreeSum += node.key), 15);
447
+ node15 && bst.dfs(node => (subTreeSum += node.key), 'pre', 15);
448
448
  expect(subTreeSum).toBe(70);
449
449
 
450
450
  let lesserSum = 0;
@@ -645,7 +645,7 @@ describe('BST operations test recursively', () => {
645
645
  expect(minNodeBySpecificNode?.key).toBe(12);
646
646
 
647
647
  let subTreeSum = 0;
648
- node15 && objBST.subTreeTraverse(node => (subTreeSum += node.key), node15);
648
+ node15 && objBST.dfs(node => (subTreeSum += node.key), 'pre', node15);
649
649
  expect(subTreeSum).toBe(70);
650
650
 
651
651
  let lesserSum = 0;
@@ -868,14 +868,10 @@ describe('BST Performance test', function () {
868
868
  it('should subTreeTraverse, null should be ignored', () => {
869
869
  const bst = new BST();
870
870
  bst.addMany([4, 2, 6, 1, 3, 5, 7]);
871
- expect(bst.subTreeTraverse(node => node.key, bst.getNode(6), IterationType.ITERATIVE)).toEqual([6, 5, 7]);
872
- expect(bst.subTreeTraverse(node => node.key, bst.getNode(6), IterationType.RECURSIVE)).toEqual([6, 5, 7]);
873
- expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.ITERATIVE, true)).toEqual([
874
- 6, 5, 7
875
- ]);
876
- expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.RECURSIVE, true)).toEqual([
877
- 6, 5, 7
878
- ]);
871
+ expect(bst.dfs(node => node.key, 'pre', bst.getNode(6), IterationType.ITERATIVE)).toEqual([6, 5, 7]);
872
+ expect(bst.dfs(node => node.key, 'pre', bst.getNode(6), IterationType.RECURSIVE)).toEqual([6, 5, 7]);
873
+ expect(bst.dfs(node => node?.key ?? undefined, 'pre', bst.getNode(6), IterationType.ITERATIVE)).toEqual([6, 5, 7]);
874
+ expect(bst.dfs(node => node?.key ?? undefined, 'pre', bst.getNode(6), IterationType.RECURSIVE)).toEqual([6, 5, 7]);
879
875
  });
880
876
  });
881
877
 
@@ -96,7 +96,7 @@ describe('TreeMultimap operations test1', () => {
96
96
  expect(minNodeBySpecificNode?.key).toBe(15);
97
97
 
98
98
  let subTreeSum = 0;
99
- node15 && treeMultimap.subTreeTraverse((node: TreeMultimapNode<number>) => (subTreeSum += node.key), 15);
99
+ node15 && treeMultimap.dfs(node => (subTreeSum += node.key), 'pre', 15);
100
100
  expect(subTreeSum).toBe(31);
101
101
  let lesserSum = 0;
102
102
  treeMultimap.lesserOrGreaterTraverse((node: TreeMultimapNode<number>) => (lesserSum += node.key), CP.lt, 10);
@@ -104,7 +104,7 @@ describe('TreeMultimap operations test1', () => {
104
104
 
105
105
  expect(node15 instanceof TreeMultimapNode);
106
106
  if (node15 instanceof TreeMultimapNode) {
107
- const subTreeAdd = treeMultimap.subTreeTraverse((node: TreeMultimapNode<number>) => (node.count += 1), 15);
107
+ const subTreeAdd = treeMultimap.dfs(node => (node.count += 1), 'pre', 15);
108
108
  expect(subTreeAdd);
109
109
  }
110
110
  const node11 = treeMultimap.getNode(11);
@@ -350,7 +350,7 @@ describe('TreeMultimap operations test recursively1', () => {
350
350
  expect(minNodeBySpecificNode?.key).toBe(15);
351
351
 
352
352
  let subTreeSum = 0;
353
- node15 && treeMultimap.subTreeTraverse((node: TreeMultimapNode<number>) => (subTreeSum += node.key), 15);
353
+ node15 && treeMultimap.dfs(node => (subTreeSum += node.key), 'pre', 15);
354
354
  expect(subTreeSum).toBe(31);
355
355
  let lesserSum = 0;
356
356
  treeMultimap.lesserOrGreaterTraverse((node: TreeMultimapNode<number>) => (lesserSum += node.key), CP.lt, 10);
@@ -358,7 +358,7 @@ describe('TreeMultimap operations test recursively1', () => {
358
358
 
359
359
  expect(node15 instanceof TreeMultimapNode);
360
360
  if (node15 instanceof TreeMultimapNode) {
361
- const subTreeAdd = treeMultimap.subTreeTraverse((node: TreeMultimapNode<number>) => (node.count += 1), 15);
361
+ const subTreeAdd = treeMultimap.dfs(node => (node.count += 1), 'pre', 15);
362
362
  expect(subTreeAdd);
363
363
  }
364
364
  const node11 = treeMultimap.getNode(11);
@@ -110,6 +110,8 @@ describe('HashMap Test2', () => {
110
110
 
111
111
  test('Inheritability test', () => {
112
112
  class ExtendedHashMap<K, V> extends HashMap<K, V> {
113
+ someOtherParam?: string;
114
+
113
115
  constructor(
114
116
  elements: Iterable<[K, V]> = [],
115
117
  options?: {
@@ -118,8 +120,8 @@ describe('HashMap Test2', () => {
118
120
  }
119
121
  ) {
120
122
  const { someOtherParam, ...restOptions } = options || {};
121
- // do something with someOtherParam
122
123
  super(elements, restOptions);
124
+ this.someOtherParam = someOtherParam;
123
125
  }
124
126
  }
125
127
 
@@ -128,6 +130,20 @@ describe('HashMap Test2', () => {
128
130
  expect(eHM.get('one')).toBe(1);
129
131
  });
130
132
 
133
+ test('should raw elements toEntry', () => {
134
+ const rawCollection = [
135
+ { id: 1, name: 'item 1' },
136
+ { id: 2, name: 'item 2' }
137
+ ];
138
+ const hm = new HashMap<number, string, { id: number; name: string }>(rawCollection, {
139
+ toEntryFn: rawElement => [rawElement.id, rawElement.name]
140
+ });
141
+
142
+ expect(hm.has(1)).toBe(true);
143
+ expect(hm.get(2)).toBe('item 2');
144
+ expect(hm.size).toBe(2);
145
+ });
146
+
131
147
  it('should update the value for an existing key', () => {
132
148
  hashMap.set('key1', 'value1');
133
149
  hashMap.set('key1', 'newValue');