data-structure-typed 1.45.0 → 1.45.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 (153) hide show
  1. package/.eslintrc.js +6 -6
  2. package/CHANGELOG.md +1 -1
  3. package/COMMANDS.md +6 -1
  4. package/README.md +18 -15
  5. package/benchmark/report.html +18 -15
  6. package/benchmark/report.json +157 -116
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  13. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  14. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  16. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  17. package/dist/cjs/data-structures/hash/hash-map.d.ts +58 -58
  18. package/dist/cjs/data-structures/hash/hash-map.js +73 -73
  19. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  20. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  21. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  22. package/dist/cjs/data-structures/heap/heap.js +21 -12
  23. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  24. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  25. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  28. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  29. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  30. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  31. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  32. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  33. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  34. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  35. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  36. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  37. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  38. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  39. package/dist/cjs/utils/utils.js.map +1 -1
  40. package/dist/mjs/data-structures/hash/hash-map.d.ts +58 -58
  41. package/dist/mjs/data-structures/hash/hash-map.js +76 -76
  42. package/dist/mjs/data-structures/heap/heap.js +21 -12
  43. package/dist/umd/data-structure-typed.js +83 -83
  44. package/dist/umd/data-structure-typed.min.js +1 -1
  45. package/dist/umd/data-structure-typed.min.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/data-structures/binary-tree/avl-tree.ts +7 -7
  48. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
  49. package/src/data-structures/binary-tree/binary-tree.ts +39 -31
  50. package/src/data-structures/binary-tree/bst.ts +12 -8
  51. package/src/data-structures/binary-tree/rb-tree.ts +17 -6
  52. package/src/data-structures/binary-tree/segment-tree.ts +1 -1
  53. package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
  54. package/src/data-structures/graph/abstract-graph.ts +46 -31
  55. package/src/data-structures/graph/directed-graph.ts +10 -5
  56. package/src/data-structures/graph/map-graph.ts +8 -8
  57. package/src/data-structures/graph/undirected-graph.ts +9 -9
  58. package/src/data-structures/hash/hash-map.ts +103 -103
  59. package/src/data-structures/hash/hash-table.ts +1 -1
  60. package/src/data-structures/hash/tree-map.ts +2 -1
  61. package/src/data-structures/hash/tree-set.ts +2 -1
  62. package/src/data-structures/heap/heap.ts +30 -17
  63. package/src/data-structures/heap/max-heap.ts +3 -3
  64. package/src/data-structures/heap/min-heap.ts +3 -3
  65. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  66. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  67. package/src/data-structures/matrix/matrix.ts +2 -2
  68. package/src/data-structures/matrix/matrix2d.ts +1 -1
  69. package/src/data-structures/matrix/navigator.ts +3 -3
  70. package/src/data-structures/matrix/vector2d.ts +2 -1
  71. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
  72. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
  73. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  74. package/src/data-structures/queue/deque.ts +5 -4
  75. package/src/data-structures/queue/queue.ts +2 -2
  76. package/src/data-structures/tree/tree.ts +1 -1
  77. package/src/data-structures/trie/trie.ts +1 -1
  78. package/src/interfaces/binary-tree.ts +2 -2
  79. package/src/interfaces/graph.ts +1 -1
  80. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
  81. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  82. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  83. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
  84. package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
  85. package/src/types/data-structures/hash/hash-map.ts +6 -6
  86. package/src/types/data-structures/matrix/navigator.ts +1 -1
  87. package/src/types/utils/utils.ts +1 -1
  88. package/src/types/utils/validate-type.ts +18 -4
  89. package/src/utils/utils.ts +6 -6
  90. package/test/integration/all-in-one.ts +1 -1
  91. package/test/integration/avl-tree.test.ts +1 -1
  92. package/test/integration/bst.test.ts +19 -19
  93. package/test/integration/heap.test.js +1 -1
  94. package/test/integration/index.html +7 -7
  95. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
  96. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +4 -4
  97. package/test/performance/data-structures/binary-tree/bst.test.ts +4 -4
  98. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -9
  99. package/test/performance/data-structures/comparation.test.ts +142 -0
  100. package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
  101. package/test/performance/data-structures/hash/hash-map.test.ts +8 -8
  102. package/test/performance/data-structures/heap/heap.test.ts +5 -5
  103. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +7 -7
  104. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -4
  105. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +7 -5
  106. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +8 -8
  107. package/test/performance/data-structures/queue/deque.test.ts +6 -6
  108. package/test/performance/data-structures/queue/queue.test.ts +7 -7
  109. package/test/performance/data-structures/stack/stack.test.ts +8 -8
  110. package/test/performance/data-structures/trie/trie.test.ts +4 -4
  111. package/test/performance/reportor.ts +48 -20
  112. package/test/performance/types/reportor.ts +1 -1
  113. package/test/types/utils/json2html.ts +1 -1
  114. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
  115. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +12 -12
  116. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -76
  117. package/test/unit/data-structures/binary-tree/bst.test.ts +44 -40
  118. package/test/unit/data-structures/binary-tree/overall.test.ts +17 -17
  119. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
  120. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
  121. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +35 -35
  122. package/test/unit/data-structures/graph/abstract-graph.test.ts +7 -7
  123. package/test/unit/data-structures/graph/directed-graph.test.ts +34 -14
  124. package/test/unit/data-structures/graph/map-graph.test.ts +1 -1
  125. package/test/unit/data-structures/graph/overall.test.ts +1 -1
  126. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  127. package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
  128. package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
  129. package/test/unit/data-structures/hash/hash-map.test.ts +10 -12
  130. package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
  131. package/test/unit/data-structures/heap/heap.test.ts +73 -23
  132. package/test/unit/data-structures/heap/max-heap.test.ts +2 -2
  133. package/test/unit/data-structures/heap/min-heap.test.ts +2 -2
  134. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +5 -5
  135. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +5 -5
  136. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  137. package/test/unit/data-structures/matrix/matrix.test.ts +5 -5
  138. package/test/unit/data-structures/matrix/matrix2d.test.ts +3 -3
  139. package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
  140. package/test/unit/data-structures/matrix/vector2d.test.ts +1 -1
  141. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -7
  142. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  143. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +19 -19
  144. package/test/unit/data-structures/queue/deque.test.ts +3 -3
  145. package/test/unit/data-structures/queue/queue.test.ts +3 -3
  146. package/test/unit/data-structures/stack/stack.test.ts +1 -1
  147. package/test/unit/data-structures/tree/tree.test.ts +1 -1
  148. package/test/unit/data-structures/trie/trie.test.ts +1 -1
  149. package/test/utils/array.ts +1 -1
  150. package/test/utils/big-o.ts +4 -4
  151. package/test/utils/index.ts +1 -0
  152. package/test/utils/json2html.ts +7 -3
  153. package/test/utils/performanc.ts +7 -0
@@ -1,6 +1,5 @@
1
- import {HashMap} from '../../../../src';
2
- import {getRandomInt, getRandomIntArray} from "../../../utils";
3
-
1
+ import { HashMap } from '../../../../src';
2
+ import { getRandomInt, getRandomIntArray } from '../../../utils';
4
3
 
5
4
  describe('HashMap', () => {
6
5
  let hashMap: HashMap<string, number>;
@@ -66,7 +65,6 @@ describe('HashMap', () => {
66
65
  // expect(entries).toContainEqual(['three', 3]);
67
66
  });
68
67
 
69
-
70
68
  it('should resize the table when load factor is exceeded', () => {
71
69
  // Set a small initial capacity for testing resizing
72
70
  hashMap = new HashMap<string, number>();
@@ -84,7 +82,6 @@ describe('HashMap', () => {
84
82
  });
85
83
 
86
84
  it('should allow using a custom hash function', () => {
87
-
88
85
  hashMap = new HashMap<string, number>();
89
86
 
90
87
  hashMap.set('one', 1);
@@ -115,14 +112,14 @@ describe('HashMap', () => {
115
112
  });
116
113
 
117
114
  it('should handle object keys correctly', () => {
118
- const keyObj = {id: 1};
115
+ const keyObj = { id: 1 };
119
116
  hashMap.set(keyObj, 'objectValue');
120
117
  expect(hashMap.get(keyObj)).toBe('objectValue');
121
118
  });
122
119
 
123
120
  it('should handle number keys correctly', () => {
124
- hashMap.set(999, {a: '999Value'});
125
- expect(hashMap.get(999)).toEqual({a: '999Value'});
121
+ hashMap.set(999, { a: '999Value' });
122
+ expect(hashMap.get(999)).toEqual({ a: '999Value' });
126
123
  });
127
124
 
128
125
  it('should update the value for an existing key', () => {
@@ -156,7 +153,10 @@ describe('HashMap', () => {
156
153
  for (const value of hashMap) {
157
154
  values.push(value);
158
155
  }
159
- expect(values).toEqual([['key1', 'value1'], ['key2', 'value2']]);
156
+ expect(values).toEqual([
157
+ ['key1', 'value1'],
158
+ ['key2', 'value2']
159
+ ]);
160
160
  });
161
161
 
162
162
  // test('should delete element at specific index', () => {
@@ -212,7 +212,6 @@ describe('HashMap', () => {
212
212
  hashMap.set('key2', 'value2');
213
213
  const iterator = hashMap.reverseBegin;
214
214
  expect(iterator.next().current).toEqual(['key1', 'value1']);
215
-
216
215
  });
217
216
 
218
217
  test('should return the last element', () => {
@@ -230,5 +229,4 @@ describe('HashMap', () => {
230
229
  hashMap.set('key2', 'value2');
231
230
  expect(hashMap.getAt(1)).toEqual(['key2', 'value2']);
232
231
  });
233
- })
234
-
232
+ });
@@ -1,4 +1,4 @@
1
- import {HashTable, HashTableNode} from '../../../../src';
1
+ import { HashTable, HashTableNode } from '../../../../src';
2
2
 
3
3
  describe('HashNode', () => {
4
4
  it('should create a HashNode with key and value', () => {
@@ -1,5 +1,5 @@
1
- import {FibonacciHeap, MaxHeap, MinHeap} from '../../../../src';
2
- import {logBigOMetricsWrap} from '../../../utils';
1
+ import { FibonacciHeap, MaxHeap, MinHeap } from '../../../../src';
2
+ import { logBigOMetricsWrap } from '../../../utils';
3
3
 
4
4
  describe('Heap Operation Test', () => {
5
5
  it('should numeric heap work well', function () {
@@ -22,34 +22,46 @@ describe('Heap Operation Test', () => {
22
22
  });
23
23
 
24
24
  it('should object heap work well', function () {
25
- const minHeap = new MinHeap<{ a: string; key: number }>({comparator: (a, b) => a.key - b.key});
26
- minHeap.add({key: 1, a: 'a1'});
27
- minHeap.add({key: 6, a: 'a6'});
28
- minHeap.add({key: 2, a: 'a2'});
29
- minHeap.add({key: 0, a: 'a0'});
30
-
31
- expect(minHeap.peek()).toEqual({a: 'a0', key: 0});
32
- expect(minHeap.toArray().map(item => ({a: item.a}))).toEqual([{a: 'a0'}, {a: 'a1'}, {a: 'a2'}, {a: 'a6'}]);
25
+ const minHeap = new MinHeap<{ a: string; key: number }>({ comparator: (a, b) => a.key - b.key });
26
+ minHeap.add({ key: 1, a: 'a1' });
27
+ minHeap.add({ key: 6, a: 'a6' });
28
+ minHeap.add({ key: 2, a: 'a2' });
29
+ minHeap.add({ key: 0, a: 'a0' });
30
+
31
+ expect(minHeap.peek()).toEqual({ a: 'a0', key: 0 });
32
+ expect(minHeap.toArray().map(item => ({ a: item.a }))).toEqual([
33
+ { a: 'a0' },
34
+ { a: 'a1' },
35
+ { a: 'a2' },
36
+ { a: 'a6' }
37
+ ]);
33
38
  let i = 0;
34
- const expectPolled = [{a: 'a0'}, {a: 'a1'}, {a: 'a2'}, {a: 'a6'}];
39
+ const expectPolled = [{ a: 'a0' }, { a: 'a1' }, { a: 'a2' }, { a: 'a6' }];
35
40
  while (minHeap.size > 0) {
36
- expect({a: minHeap.poll()?.a}).toEqual(expectPolled[i]);
41
+ expect({ a: minHeap.poll()?.a }).toEqual(expectPolled[i]);
37
42
  i++;
38
43
  }
39
44
 
40
- const maxHeap = new MaxHeap<{ key: number; a: string }>({comparator: (a, b) => b.key - a.key});
41
- maxHeap.add({key: 1, a: 'a1'});
42
- maxHeap.add({key: 6, a: 'a6'});
43
- maxHeap.add({key: 5, a: 'a5'});
44
- maxHeap.add({key: 2, a: 'a2'});
45
- maxHeap.add({key: 0, a: 'a0'});
46
- maxHeap.add({key: 9, a: 'a9'});
47
- expect(maxHeap.peek()).toEqual({a: 'a9', key: 9});
48
- expect(maxHeap.toArray().map(item => ({a: item.a}))).toEqual([{a: 'a9'}, {a: 'a2'}, {a: 'a6'}, {a: 'a1'}, {a: 'a0'}, {a: 'a5'}]);
49
- const maxExpectPolled = [{a: 'a9'}, {a: 'a6'}, {a: 'a5'}, {a: 'a2'}, {a: 'a1'}, {a: 'a0'}];
45
+ const maxHeap = new MaxHeap<{ key: number; a: string }>({ comparator: (a, b) => b.key - a.key });
46
+ maxHeap.add({ key: 1, a: 'a1' });
47
+ maxHeap.add({ key: 6, a: 'a6' });
48
+ maxHeap.add({ key: 5, a: 'a5' });
49
+ maxHeap.add({ key: 2, a: 'a2' });
50
+ maxHeap.add({ key: 0, a: 'a0' });
51
+ maxHeap.add({ key: 9, a: 'a9' });
52
+ expect(maxHeap.peek()).toEqual({ a: 'a9', key: 9 });
53
+ expect(maxHeap.toArray().map(item => ({ a: item.a }))).toEqual([
54
+ { a: 'a9' },
55
+ { a: 'a2' },
56
+ { a: 'a6' },
57
+ { a: 'a1' },
58
+ { a: 'a0' },
59
+ { a: 'a5' }
60
+ ]);
61
+ const maxExpectPolled = [{ a: 'a9' }, { a: 'a6' }, { a: 'a5' }, { a: 'a2' }, { a: 'a1' }, { a: 'a0' }];
50
62
  let maxI = 0;
51
63
  while (maxHeap.size > 0) {
52
- expect({a: maxHeap.poll()?.a}).toEqual(maxExpectPolled[maxI]);
64
+ expect({ a: maxHeap.poll()?.a }).toEqual(maxExpectPolled[maxI]);
53
65
  maxI++;
54
66
  }
55
67
  });
@@ -245,3 +257,41 @@ describe('FibonacciHeap Stress Test', () => {
245
257
  );
246
258
  });
247
259
  });
260
+
261
+ // describe('Competitor performance compare', () => {
262
+ // const minHeap = new MinHeap<number>();
263
+ // const cHeap = new CHeap<number>();
264
+ // const cPQ = new PriorityQueue<number>(undefined, (a, b) => a - b);
265
+ // const n = 10000;
266
+ //
267
+ // it('should add performance well', () => {
268
+ // const heapCost = calcRunTime(() => {
269
+ // for (let i = 0; i < n; i++) {
270
+ // minHeap.add(i);
271
+ // }
272
+ // })
273
+ //
274
+ // console.log(`heapCost: ${heapCost}`)
275
+ // });
276
+ //
277
+ // it('should add performance well', () => {
278
+ //
279
+ // const cHeapCost = calcRunTime(() => {
280
+ // for (let i = 0; i < n; i++) {
281
+ // cHeap.push(i);
282
+ // }
283
+ // })
284
+ //
285
+ // console.log(`cHeapCost: ${cHeapCost}`)
286
+ // });
287
+ //
288
+ // it('should add performance well', () => {
289
+ //
290
+ // const cPQCost = calcRunTime(() => {
291
+ // for (let i = 0; i < n; i++) {
292
+ // cPQ.push(i);
293
+ // }
294
+ // })
295
+ // console.log(`cPQCost: ${cPQCost}`)
296
+ // });
297
+ // });
@@ -1,11 +1,11 @@
1
- import {Comparator, MaxHeap} from '../../../../src';
1
+ import { Comparator, MaxHeap } from '../../../../src';
2
2
 
3
3
  describe('MaxHeap', () => {
4
4
  const numberComparator: Comparator<number> = (a, b) => b - a;
5
5
  let maxHeap: MaxHeap<number>;
6
6
 
7
7
  beforeEach(() => {
8
- maxHeap = new MaxHeap({comparator: numberComparator});
8
+ maxHeap = new MaxHeap({ comparator: numberComparator });
9
9
  });
10
10
 
11
11
  it('add and poll elements in descending order', () => {
@@ -1,11 +1,11 @@
1
- import {Comparator, MinHeap} from '../../../../src';
1
+ import { Comparator, MinHeap } from '../../../../src';
2
2
 
3
3
  describe('MinHeap', () => {
4
4
  const numberComparator: Comparator<number> = (a, b) => a - b;
5
5
  let minHeap: MinHeap<number>;
6
6
 
7
7
  beforeEach(() => {
8
- minHeap = new MinHeap({comparator: numberComparator});
8
+ minHeap = new MinHeap({ comparator: numberComparator });
9
9
  });
10
10
 
11
11
  it('add and poll elements in ascending order', () => {
@@ -1,4 +1,4 @@
1
- import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src';
1
+ import { DoublyLinkedList, DoublyLinkedListNode } from '../../../../src';
2
2
 
3
3
  describe('DoublyLinkedListNode', () => {
4
4
  it('should DoublyLinkedListNode', () => {
@@ -370,9 +370,9 @@ describe('DoublyLinkedList Operation Test', () => {
370
370
  });
371
371
 
372
372
  it('should insert and manipulate objects with numeric properties', () => {
373
- const obj1 = {keyA: 10};
374
- const obj2 = {keyA: 20};
375
- const obj3 = {keyA: 30};
373
+ const obj1 = { keyA: 10 };
374
+ const obj2 = { keyA: 20 };
375
+ const obj3 = { keyA: 30 };
376
376
 
377
377
  objectList.push(obj1);
378
378
  objectList.push(obj2);
@@ -380,7 +380,7 @@ describe('DoublyLinkedList Operation Test', () => {
380
380
 
381
381
  expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
382
382
 
383
- const newObj = {keyA: 25}; // Corrected newObj value
383
+ const newObj = { keyA: 25 }; // Corrected newObj value
384
384
  const insertSuccess = objectList.insertBefore(obj2, newObj);
385
385
  expect(insertSuccess).toBe(true);
386
386
 
@@ -1,4 +1,4 @@
1
- import {SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
1
+ import { SinglyLinkedList, SinglyLinkedListNode } from '../../../../src';
2
2
 
3
3
  describe('SinglyLinkedListNode', () => {
4
4
  it('should SinglyLinkedList', () => {
@@ -366,9 +366,9 @@ describe('SinglyLinkedList Operation Test', () => {
366
366
  });
367
367
 
368
368
  it('should insert and manipulate objects with numeric properties', () => {
369
- const obj1 = {keyA: 1};
370
- const obj2 = {keyA: 2};
371
- const obj3 = {keyA: 3};
369
+ const obj1 = { keyA: 1 };
370
+ const obj2 = { keyA: 2 };
371
+ const obj3 = { keyA: 3 };
372
372
 
373
373
  objectList.push(obj1);
374
374
  objectList.push(obj2);
@@ -376,7 +376,7 @@ describe('SinglyLinkedList Operation Test', () => {
376
376
 
377
377
  expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
378
378
 
379
- const newObj = {keyA: 2.5}; // Corrected newObj value
379
+ const newObj = { keyA: 2.5 }; // Corrected newObj value
380
380
  const insertSuccess = objectList.insertBefore(obj2, newObj);
381
381
  expect(insertSuccess).toBe(true);
382
382
 
@@ -1,4 +1,4 @@
1
- import {SkipList} from '../../../../src';
1
+ import { SkipList } from '../../../../src';
2
2
 
3
3
  describe('SkipList', () => {
4
4
  let skipList: SkipList<number, string>;
@@ -1,10 +1,10 @@
1
- import {MatrixNTI2D} from '../../../../src';
1
+ import { MatrixNTI2D } from '../../../../src';
2
2
 
3
3
  describe('MatrixNTI2D', () => {
4
4
  it('should initialize a matrix with rows and columns', () => {
5
5
  const numRows = 3;
6
6
  const numCols = 4;
7
- const matrix = new MatrixNTI2D({row: numRows, col: numCols});
7
+ const matrix = new MatrixNTI2D({ row: numRows, col: numCols });
8
8
 
9
9
  expect(matrix.toArray().length).toBe(numRows);
10
10
  expect(matrix.toArray()[0].length).toBe(numCols);
@@ -14,7 +14,7 @@ describe('MatrixNTI2D', () => {
14
14
  const numRows = 3;
15
15
  const numCols = 4;
16
16
  const initialValue = 42;
17
- const matrix = new MatrixNTI2D({row: numRows, col: numCols, initialVal: initialValue});
17
+ const matrix = new MatrixNTI2D({ row: numRows, col: numCols, initialVal: initialValue });
18
18
 
19
19
  const matrixArray = matrix.toArray();
20
20
  for (let i = 0; i < numRows; i++) {
@@ -27,7 +27,7 @@ describe('MatrixNTI2D', () => {
27
27
  it('should initialize all elements with 0 if no initial value is provided', () => {
28
28
  const numRows = 3;
29
29
  const numCols = 4;
30
- const matrix = new MatrixNTI2D({row: numRows, col: numCols});
30
+ const matrix = new MatrixNTI2D({ row: numRows, col: numCols });
31
31
 
32
32
  const matrixArray = matrix.toArray();
33
33
  for (let i = 0; i < numRows; i++) {
@@ -40,7 +40,7 @@ describe('MatrixNTI2D', () => {
40
40
  it('should convert the matrix to a two-dimensional array', () => {
41
41
  const numRows = 2;
42
42
  const numCols = 3;
43
- const matrix = new MatrixNTI2D({row: numRows, col: numCols, initialVal: 1});
43
+ const matrix = new MatrixNTI2D({ row: numRows, col: numCols, initialVal: 1 });
44
44
 
45
45
  const matrixArray = matrix.toArray();
46
46
  expect(matrixArray.length).toBe(numRows);
@@ -1,5 +1,5 @@
1
- import {Matrix2D, Vector2D} from '../../../../src';
2
- import {isDebugTest} from '../../../config';
1
+ import { Matrix2D, Vector2D } from '../../../../src';
2
+ import { isDebugTest } from '../../../config';
3
3
 
4
4
  const isDebug = isDebugTest;
5
5
  describe('Matrix2D', () => {
@@ -288,7 +288,7 @@ describe('Matrix2D', () => {
288
288
  const vector = new Vector2D(2, 3);
289
289
  const result = Matrix2D.multiplyByVector(matrix, vector);
290
290
  isDebug && console.log(JSON.stringify(result));
291
- expect(result).toEqual({x: 17, y: 35, w: 1});
291
+ expect(result).toEqual({ x: 17, y: 35, w: 1 });
292
292
  });
293
293
 
294
294
  it('should correctly create a view matrix', () => {
@@ -1,5 +1,5 @@
1
- import {Character, Navigator, NavigatorParams, Turning} from '../../../../src';
2
- import {isDebugTest} from '../../../config';
1
+ import { Character, Navigator, NavigatorParams, Turning } from '../../../../src';
2
+ import { isDebugTest } from '../../../config';
3
3
 
4
4
  const isDebug = isDebugTest;
5
5
  const exampleMatrix: number[][] = [
@@ -1,4 +1,4 @@
1
- import {Vector2D} from '../../../../src';
1
+ import { Vector2D } from '../../../../src';
2
2
 
3
3
  describe('Vector2D', () => {
4
4
  it('should create a vector with default values', () => {
@@ -1,4 +1,4 @@
1
- import {MaxPriorityQueue} from '../../../../src';
1
+ import { MaxPriorityQueue } from '../../../../src';
2
2
 
3
3
  describe('MaxPriorityQueue Operation Test', () => {
4
4
  it('should add elements and maintain heap property', () => {
@@ -16,9 +16,9 @@ describe('MaxPriorityQueue Operation Test', () => {
16
16
  });
17
17
 
18
18
  it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
19
- const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({comparator: (a, b) => b.keyA - a.keyA});
20
- priorityQueue.refill([{keyA: 5}, {keyA: 3}, {keyA: 1}]);
21
- priorityQueue.add({keyA: 7});
19
+ const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({ comparator: (a, b) => b.keyA - a.keyA });
20
+ priorityQueue.refill([{ keyA: 5 }, { keyA: 3 }, { keyA: 1 }]);
21
+ priorityQueue.add({ keyA: 7 });
22
22
 
23
23
  expect(priorityQueue.poll()?.keyA).toBe(7);
24
24
  expect(priorityQueue.poll()?.keyA).toBe(5);
@@ -52,7 +52,7 @@ describe('MaxPriorityQueue Operation Test', () => {
52
52
 
53
53
  it('should correctly heapify an array', () => {
54
54
  const array = [5, 3, 7, 1];
55
- const heap = MaxPriorityQueue.heapify<number>({nodes: array, comparator: (a, b) => b - a});
55
+ const heap = MaxPriorityQueue.heapify<number>({ nodes: array, comparator: (a, b) => b - a });
56
56
  heap.refill(array);
57
57
 
58
58
  expect(heap.poll()).toBe(7);
@@ -62,8 +62,8 @@ describe('MaxPriorityQueue Operation Test', () => {
62
62
  });
63
63
 
64
64
  it('should correctly heapify an object array', () => {
65
- const nodes = [{keyA: 5}, {keyA: 3}, {keyA: 7}, {keyA: 1}];
66
- const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>({nodes: nodes, comparator: (a, b) => b.keyA - a.keyA});
65
+ const nodes = [{ keyA: 5 }, { keyA: 3 }, { keyA: 7 }, { keyA: 1 }];
66
+ const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>({ nodes: nodes, comparator: (a, b) => b.keyA - a.keyA });
67
67
 
68
68
  expect(maxPQ.poll()?.keyA).toBe(7);
69
69
  expect(maxPQ.poll()?.keyA).toBe(5);
@@ -1,4 +1,4 @@
1
- import {MinPriorityQueue} from '../../../../src';
1
+ import { MinPriorityQueue } from '../../../../src';
2
2
 
3
3
  describe('MinPriorityQueue Operation Test', () => {
4
4
  it('should check if a node exists in the queue', () => {
@@ -1,11 +1,11 @@
1
- import {PriorityQueue} from '../../../../src';
2
- import {PriorityQueue as CPriorityQueue} from 'js-sdsl';
3
- import {isDebugTest} from '../../../config';
1
+ import { PriorityQueue } from '../../../../src';
2
+ import { PriorityQueue as CPriorityQueue } from 'js-sdsl';
3
+ import { isDebugTest } from '../../../config';
4
4
 
5
5
  const isDebug = isDebugTest;
6
6
  describe('PriorityQueue Operation Test', () => {
7
7
  it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
8
- const minPQ = new PriorityQueue<number>({comparator: (a, b) => a - b});
8
+ const minPQ = new PriorityQueue<number>({ comparator: (a, b) => a - b });
9
9
  minPQ.refill([5, 2, 3, 4, 6, 1]);
10
10
  expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]);
11
11
  minPQ.poll();
@@ -13,16 +13,16 @@ describe('PriorityQueue Operation Test', () => {
13
13
  minPQ.poll();
14
14
  expect(minPQ.toArray()).toEqual([4, 5, 6]);
15
15
  expect(minPQ.peek()).toBe(4);
16
- expect(PriorityQueue.heapify({
17
- nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
18
- comparator: (a, b) => a - b
19
- }).toArray()).toEqual([
20
- 1, 2, 3, 5, 6, 7, 8, 9, 10
21
- ]);
16
+ expect(
17
+ PriorityQueue.heapify({
18
+ nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
19
+ comparator: (a, b) => a - b
20
+ }).toArray()
21
+ ).toEqual([1, 2, 3, 5, 6, 7, 8, 9, 10]);
22
22
  });
23
23
 
24
24
  it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () {
25
- const maxPriorityQueue = new PriorityQueue<number>({comparator: (a, b) => b - a});
25
+ const maxPriorityQueue = new PriorityQueue<number>({ comparator: (a, b) => b - a });
26
26
  maxPriorityQueue.refill([5, 2, 3, 4, 6, 1]);
27
27
  expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]);
28
28
  maxPriorityQueue.poll();
@@ -30,16 +30,16 @@ describe('PriorityQueue Operation Test', () => {
30
30
  maxPriorityQueue.poll();
31
31
  expect(maxPriorityQueue.toArray()).toEqual([3, 2, 1]);
32
32
  expect(maxPriorityQueue.peek()).toBe(3);
33
- expect(PriorityQueue.heapify({
34
- nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
35
- comparator: (a, b) => a - b
36
- }).toArray()).toEqual([
37
- 1, 2, 3, 5, 6, 7, 8, 9, 10
38
- ]);
33
+ expect(
34
+ PriorityQueue.heapify({
35
+ nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
36
+ comparator: (a, b) => a - b
37
+ }).toArray()
38
+ ).toEqual([1, 2, 3, 5, 6, 7, 8, 9, 10]);
39
39
  });
40
40
 
41
41
  it('should PriorityQueue clone, sort, getNodes, dfs work well', function () {
42
- const minPQ1 = new PriorityQueue<number>({comparator: (a, b) => a - b});
42
+ const minPQ1 = new PriorityQueue<number>({ comparator: (a, b) => a - b });
43
43
  minPQ1.refill([2, 5, 8, 3, 1, 6, 7, 4]);
44
44
  const clonedPriorityQueue = minPQ1.clone();
45
45
  expect(clonedPriorityQueue.getNodes()).toEqual(minPQ1.getNodes());
@@ -52,7 +52,7 @@ describe('PriorityQueue Operation Test', () => {
52
52
 
53
53
  describe('Priority Queue Performance Test', () => {
54
54
  it('should numeric heap work well', function () {
55
- const pq = new PriorityQueue({comparator: (a, b) => b - a});
55
+ const pq = new PriorityQueue({ comparator: (a, b) => b - a });
56
56
 
57
57
  const tS = performance.now();
58
58
 
@@ -1,6 +1,6 @@
1
- import {ArrayDeque, Deque, ObjectDeque} from '../../../../src';
2
- import {bigO} from '../../../utils';
3
- import {isDebugTest} from '../../../config';
1
+ import { ArrayDeque, Deque, ObjectDeque } from '../../../../src';
2
+ import { bigO } from '../../../utils';
3
+ import { isDebugTest } from '../../../config';
4
4
 
5
5
  const isDebug = isDebugTest;
6
6
  describe('Deque Tests', () => {
@@ -1,6 +1,6 @@
1
- import {LinkedListQueue, Queue} from '../../../../src';
2
- import {bigO} from '../../../utils';
3
- import {isDebugTest} from '../../../config';
1
+ import { LinkedListQueue, Queue } from '../../../../src';
2
+ import { bigO } from '../../../utils';
3
+ import { isDebugTest } from '../../../config';
4
4
 
5
5
  const isDebug = isDebugTest;
6
6
  describe('Queue Operation Test', () => {
@@ -1,4 +1,4 @@
1
- import {Stack} from '../../../../src';
1
+ import { Stack } from '../../../../src';
2
2
 
3
3
  describe('Stack', () => {
4
4
  let stack: Stack<number>;
@@ -1,4 +1,4 @@
1
- import {TreeNode} from '../../../../src';
1
+ import { TreeNode } from '../../../../src';
2
2
 
3
3
  describe('TreeNode', () => {
4
4
  it('should create a TreeNode with the given key and value', () => {
@@ -1,4 +1,4 @@
1
- import {Trie, TrieNode} from '../../../../src';
1
+ import { Trie, TrieNode } from '../../../../src';
2
2
 
3
3
  describe('TrieNode', () => {
4
4
  it('should create a TrieNode with the given value', () => {
@@ -1,4 +1,4 @@
1
- import {getRandomInt} from './number';
1
+ import { getRandomInt } from './number';
2
2
 
3
3
  export function getRandomIntArray(length: number = 1000, min: number = -1000, max: number = 1000, isDistinct = true) {
4
4
  if (isDistinct) {
@@ -1,5 +1,5 @@
1
- import {AnyFunction} from '../types';
2
- import {isDebugTest} from '../config';
1
+ import { AnyFunction } from '../types';
2
+ import { isDebugTest } from '../config';
3
3
 
4
4
  const isDebug = isDebugTest;
5
5
  const orderReducedBy = 1; // reduction of bigO's order compared to the baseline bigO
@@ -32,7 +32,7 @@ export const bigO = {
32
32
 
33
33
  function findPotentialN(input: any): number {
34
34
  let longestArray: any[] = [];
35
- let mostProperties: {[key: string]: any} = {};
35
+ let mostProperties: { [key: string]: any } = {};
36
36
 
37
37
  function recurse(obj: any) {
38
38
  if (Array.isArray(obj)) {
@@ -81,7 +81,7 @@ function linearRegression(x: number[], y: number[]) {
81
81
 
82
82
  const rSquared = 1 - totalVariation / explainedVariation;
83
83
 
84
- return {slope, intercept, rSquared};
84
+ return { slope, intercept, rSquared };
85
85
  }
86
86
 
87
87
  function estimateBigO(runtimes: number[], dataSizes: number[]): string {
@@ -5,3 +5,4 @@ export * from './json2html';
5
5
  export * from './is';
6
6
  export * from './console';
7
7
  export * from './string';
8
+ export * from './performanc';
@@ -1,5 +1,5 @@
1
1
  import * as _ from './is';
2
- import {Json2htmlOptions} from '../types';
2
+ import { Json2htmlOptions } from '../types';
3
3
 
4
4
  function toggleJS(options?: Json2htmlOptions): string {
5
5
  if (options?.plainHtml) {
@@ -14,7 +14,9 @@ function makeLabelDiv(options: any, level: number, keyName: string | number, dat
14
14
  return `<div class='index'><span class='json-to-html-label'>${keyName}&nbsp;</span></div>`;
15
15
  } else if (typeof keyName === 'string') {
16
16
  if (datatype === 'array') {
17
- return `<div class='collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}</span></div>`;
17
+ return `<div class='collapsible level${level}' ${toggleJS(
18
+ options
19
+ )}><span class='json-to-html-label'>${keyName}</span></div>`;
18
20
  } else if (datatype === 'object') {
19
21
  return `<div class='attribute collapsible level${level}' ${toggleJS(
20
22
  options
@@ -120,7 +122,9 @@ function _render(name: string, data: any, options: Json2htmlOptions, level: numb
120
122
  } else {
121
123
  subs =
122
124
  "<div class='altRows'>" +
123
- data.map((val: any, idx: number) => _render(idx.toString(), val, options, level + 1, idx % 2)).join("</div><div class='altRows'>") +
125
+ data
126
+ .map((val: any, idx: number) => _render(idx.toString(), val, options, level + 1, idx % 2))
127
+ .join("</div><div class='altRows'>") +
124
128
  '</div>';
125
129
  }
126
130
  return `<div class="json-to-html-collapse clearfix ${altRow}">
@@ -0,0 +1,7 @@
1
+ import { performance } from 'perf_hooks';
2
+
3
+ export const calcRunTime = (callback: (...args: any[]) => any) => {
4
+ const startTime = performance.now();
5
+ callback();
6
+ return performance.now() - startTime;
7
+ }