data-structure-typed 1.41.3 → 1.41.5

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 (52) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +561 -265
  3. package/benchmark/report.html +79 -0
  4. package/benchmark/report.json +343 -28
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.js +11 -10
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  7. package/dist/mjs/data-structures/binary-tree/binary-tree.js +11 -10
  8. package/dist/umd/data-structure-typed.min.js +1 -1
  9. package/dist/umd/data-structure-typed.min.js.map +1 -1
  10. package/package.json +8 -4
  11. package/src/data-structures/binary-tree/binary-tree.ts +12 -9
  12. package/test/config.ts +1 -1
  13. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +36 -0
  14. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +45 -0
  15. package/test/performance/data-structures/binary-tree/bst.test.ts +36 -0
  16. package/test/performance/data-structures/graph/directed-graph.test.ts +49 -0
  17. package/test/performance/data-structures/heap/heap.test.ts +30 -0
  18. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +40 -0
  19. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +34 -0
  20. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +19 -0
  21. package/test/performance/data-structures/queue/deque.test.ts +8 -6
  22. package/test/performance/data-structures/queue/queue.test.ts +17 -12
  23. package/test/performance/data-structures/trie/trie.test.ts +22 -0
  24. package/test/performance/reportor.ts +183 -0
  25. package/test/performance/types/index.ts +1 -0
  26. package/test/performance/types/reportor.ts +3 -0
  27. package/test/types/utils/index.ts +1 -0
  28. package/test/types/utils/json2html.ts +1 -0
  29. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +1 -1
  30. package/test/unit/data-structures/heap/heap.test.ts +5 -4
  31. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +0 -23
  32. package/test/unit/data-structures/linked-list/linked-list.test.ts +3 -30
  33. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -21
  34. package/test/unit/data-structures/matrix/matrix2d.test.ts +1 -1
  35. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +0 -32
  36. package/test/unit/data-structures/queue/queue.test.ts +3 -39
  37. package/test/utils/array.ts +5514 -0
  38. package/test/utils/big-o.ts +14 -8
  39. package/test/utils/console.ts +31 -0
  40. package/test/utils/index.ts +5 -0
  41. package/test/utils/is.ts +56 -0
  42. package/test/utils/json2html.ts +322 -0
  43. package/test/utils/number.ts +10 -0
  44. package/test/utils/string.ts +1 -0
  45. package/test/config.js +0 -4
  46. package/test/performance/index.ts +0 -47
  47. package/test/types/index.js +0 -29
  48. package/test/types/utils/big-o.js +0 -2
  49. package/test/types/utils/index.js +0 -29
  50. package/test/utils/big-o.js +0 -222
  51. package/test/utils/index.js +0 -30
  52. package/test/utils/number.js +0 -14
@@ -1,4 +1,4 @@
1
- import {RBTNColor, RBTreeNode, RedBlackTree, NIL} from '../../../../src';
1
+ import {NIL, RBTNColor, RBTreeNode, RedBlackTree} from '../../../../src';
2
2
  import {getRandomInt} from '../../../utils';
3
3
  import {isDebugTest} from '../../../config';
4
4
 
@@ -235,10 +235,11 @@ describe('FibonacciHeap Stress Test', () => {
235
235
  // 10, 100, 1000, 5000, 10000, 20000, 50000, 75000, 100000,
236
236
  // 150000, 200000, 250000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000
237
237
  // ].forEach(m => logBigOMetricsWrap<typeof testByMagnitude>(testByMagnitude, [m]));
238
- [
239
- 10, 100, 1000, 5000, 10000, 20000, 50000, 75000, 100000, 150000, 200000, 250000, 300000, 400000, 500000, 600000,
240
- 700000, 800000, 900000, 1000000
241
- ].forEach(m =>
238
+ // [
239
+ // 10, 100, 1000, 5000, 10000, 20000, 50000, 75000, 100000, 150000, 200000, 250000, 300000, 400000, 500000, 600000,
240
+ // 700000, 800000, 900000, 1000000
241
+ // ]
242
+ [10, 100, 1000, 5000].forEach(m =>
242
243
  logBigOMetricsWrap(
243
244
  (c: number) => {
244
245
  const result: number[] = [];
@@ -1,5 +1,4 @@
1
1
  import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src';
2
- import {bigO, magnitude} from '../../../utils';
3
2
 
4
3
  describe('DoublyLinkedListNode', () => {
5
4
  it('should DoublyLinkedListNode', () => {
@@ -399,25 +398,3 @@ describe('DoublyLinkedList Operation Test', () => {
399
398
  expect(shiftedObj).toBe(obj1);
400
399
  });
401
400
  });
402
-
403
- describe('DoublyLinkedList Performance Test', () => {
404
- it('should the push and pop methods adhere to a time complexity of O(n) and executed correctly under large scale data', () => {
405
- const list = new DoublyLinkedList<number>();
406
-
407
- const startPushTime = performance.now();
408
- for (let i = 0; i < magnitude.LINEAR; i++) {
409
- list.unshift(i);
410
- }
411
- expect(performance.now() - startPushTime).toBeLessThan(bigO.LINEAR * 20);
412
-
413
- expect(list.length).toBeGreaterThan(0);
414
- const startPopTime = performance.now();
415
- for (let i = 0; i < magnitude.LINEAR; i++) {
416
- list.shift();
417
- }
418
- expect(performance.now() - startPopTime).toBeLessThan(bigO.LINEAR * 100);
419
-
420
- expect(list.pop()).toBeUndefined();
421
- expect(list.length).toBe(0);
422
- });
423
- });
@@ -1,35 +1,8 @@
1
- import {DoublyLinkedList, DoublyLinkedListNode, SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
2
- import {bigO, magnitude} from '../../../utils';
1
+ // import {DoublyLinkedList, DoublyLinkedListNode, SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
2
+ // import {bigO, magnitude} from '../../../utils';
3
3
 
4
4
  describe('LinkedList Performance Test', () => {
5
5
  it('should DoublyLinkedList insertBefore faster than SinglyLinkedList', () => {
6
- const doublyList = new DoublyLinkedList<number>();
7
-
8
- const startPushTime = performance.now();
9
- let midNode: DoublyLinkedListNode | null = null;
10
- const midIndex = Math.floor(magnitude.SQUARED / 2);
11
- for (let i = 0; i < magnitude.SQUARED; i++) {
12
- doublyList.push(i);
13
- if (i === midIndex) {
14
- midNode = doublyList.getNode(i);
15
- } else if (i > midIndex && midNode) {
16
- doublyList.insertBefore(midNode, i);
17
- }
18
- }
19
- const doublyListPushCost = performance.now() - startPushTime;
20
-
21
- const singlyList = new SinglyLinkedList<number>();
22
- let midSinglyNode: SinglyLinkedListNode | null = null;
23
-
24
- for (let i = 0; i < magnitude.SQUARED; i++) {
25
- singlyList.push(i);
26
- if (i === midIndex) {
27
- midSinglyNode = singlyList.getNode(i);
28
- } else if (i > midIndex && midSinglyNode) {
29
- singlyList.insertBefore(midSinglyNode.value, i);
30
- }
31
- }
32
-
33
- expect(doublyListPushCost).toBeLessThan(bigO.SQUARED * 10);
6
+ expect(1).toBe(1);
34
7
  });
35
8
  });
@@ -1,5 +1,4 @@
1
1
  import {SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
2
- import {bigO, magnitude} from '../../../utils';
3
2
 
4
3
  describe('SinglyLinkedListNode', () => {
5
4
  it('should SinglyLinkedList', () => {
@@ -395,26 +394,6 @@ describe('SinglyLinkedList Operation Test', () => {
395
394
  });
396
395
  });
397
396
 
398
- describe('SinglyLinkedList Performance Test', () => {
399
- it('should the push and pop methods adhere to a time complexity of O(n) and executed correctly under large scale data', () => {
400
- const list = new SinglyLinkedList<number>();
401
-
402
- const startPushTime = performance.now();
403
- for (let i = 0; i < magnitude.LINEAR; i++) {
404
- list.push(i);
405
- }
406
- expect(performance.now() - startPushTime).toBeLessThan(bigO.LINEAR * 20);
407
-
408
- const startPopTime = performance.now();
409
-
410
- for (let i = 0; i < magnitude.LINEAR; i++) {
411
- list.pop();
412
- }
413
-
414
- // expect(performance.now() - startPopTime).toBeLessThan(bigO.LINEAR);
415
- expect(performance.now() - startPopTime).toBeLessThan(bigO.LINEAR * 400);
416
- });
417
- });
418
397
  describe('SinglyLinkedList', () => {
419
398
  let list: SinglyLinkedList<number>;
420
399
 
@@ -315,7 +315,7 @@ describe('Matrix2D', () => {
315
315
  it('should correctly rotate a matrix', () => {
316
316
  const radians = Math.PI / 4; // 45 degrees
317
317
  const rotationMatrix = Matrix2D.rotate(radians);
318
- console.log(JSON.stringify(rotationMatrix.m));
318
+ isDebug && console.log(JSON.stringify(rotationMatrix.m));
319
319
  expect(rotationMatrix.m).toEqual([
320
320
  [0.7071067811865476, -0.7071067811865475, 0],
321
321
  [0.7071067811865475, 0.7071067811865476, 0],
@@ -1,5 +1,4 @@
1
1
  import {MaxPriorityQueue} from '../../../../src';
2
- import {bigO, magnitude} from '../../../utils';
3
2
 
4
3
  describe('MaxPriorityQueue Operation Test', () => {
5
4
  it('should add elements and maintain heap property', () => {
@@ -72,34 +71,3 @@ describe('MaxPriorityQueue Operation Test', () => {
72
71
  expect(maxPQ.poll()?.keyA).toBe(1);
73
72
  });
74
73
  });
75
-
76
- describe('MaxPriorityQueue Performance Test', () => {
77
- it('should the poll method adheres to a time complexity of O(log n) and executed correctly under large scale distinct data', () => {
78
- const nodes = Array.from(
79
- new Set<number>(Array.from(new Array(magnitude.LINEAR), () => Math.floor(Math.random() * magnitude.LINEAR * 100)))
80
- );
81
- expect(nodes.length).toBeGreaterThan(magnitude.LINEAR / 2);
82
- const maxPQ = new MaxPriorityQueue<number>();
83
- maxPQ.refill(nodes);
84
- let prev = Number.MAX_SAFE_INTEGER;
85
- const startTime = performance.now();
86
- while (maxPQ.size > 0) {
87
- const polled = maxPQ.poll();
88
- if (polled) {
89
- prev = polled;
90
- }
91
- }
92
- const cost = performance.now() - startTime;
93
- expect(cost).toBeLessThan(bigO.LINEAR * 30);
94
- expect(prev).toBeGreaterThan(0);
95
- });
96
-
97
- it('should sorted.length to be the same as original data', () => {
98
- // const magnitude = 1000;
99
- // const maxPriorityQueue = new MaxPriorityQueue<number>({nodes: Array.from(new Array<number>(magnitude), () => Math.floor(Math.random() * magnitude))});
100
- // const nodeCount = maxPriorityQueue.getNodes().length;
101
- // const sorted = maxPriorityQueue.sort();
102
- //
103
- // expect(sorted.length).toBe(nodeCount); // TODO Plan to support sorting of duplicate elements.
104
- });
105
- });
@@ -1,5 +1,5 @@
1
1
  import {LinkedListQueue, Queue} from '../../../../src';
2
- import {bigO, magnitude} from '../../../utils';
2
+ import {bigO} from '../../../utils';
3
3
  import {isDebugTest} from '../../../config';
4
4
 
5
5
  const isDebug = isDebugTest;
@@ -17,23 +17,6 @@ describe('Queue Operation Test', () => {
17
17
  });
18
18
  });
19
19
 
20
- describe('Queue Performance Test', () => {
21
- it('should numeric queue performance well', function () {
22
- const queue = new Queue<number>();
23
- for (let i = 0; i < magnitude.LINEAR; i++) {
24
- queue.enqueue(i);
25
- }
26
- let last: number | undefined = 0;
27
-
28
- const startTime = performance.now();
29
- for (let i = 0; i < magnitude.LINEAR; i++) {
30
- last = queue.dequeue();
31
- }
32
- expect(last).toBe(magnitude.LINEAR - 1);
33
- expect(performance.now() - startTime).toBeLessThan(bigO.LINEAR * 100);
34
- });
35
- });
36
-
37
20
  describe('Queue', () => {
38
21
  let queue: Queue<number>;
39
22
 
@@ -51,24 +34,8 @@ describe('Queue', () => {
51
34
  expect(queue.peek()).toBe(1);
52
35
  expect(queue.size).toBe(2);
53
36
  });
54
-
55
- // it('should shift elements from the front of the queue', () => {
56
- // queue.push(1);
57
- // queue.push(2);
58
- // const shifted = queue.shift();
59
- // expect(shifted).toBe(1);
60
- // expect(queue.peek()).toBe(2);
61
- // expect(queue.size).toBe(1);
62
- // });
63
- //
64
- // it('should peek at the front of the queue', () => {
65
- // queue.push(1);
66
- // queue.push(2);
67
- // expect(queue.peek()).toBe(1);
68
- // });
69
-
70
- // Add more test cases for other methods of Queue.
71
37
  });
38
+
72
39
  describe('Queue', () => {
73
40
  let queue: Queue<number>;
74
41
 
@@ -196,8 +163,6 @@ describe('LinkedListQueue', () => {
196
163
  queue.enqueue('B');
197
164
  expect(queue.peek()).toBe('A');
198
165
  });
199
-
200
- // Add more test cases for other methods of LinkedListQueue.
201
166
  });
202
167
 
203
168
  describe('Queue Performance Test', () => {
@@ -224,7 +189,6 @@ describe('Queue Performance Test', () => {
224
189
  for (let i = 0; i < dataSize; i++) {
225
190
  queue2.shift();
226
191
  }
227
- console.log(`Array Performance Test: ${performance.now() - startTime2} ms`);
228
192
  expect(performance.now() - startTime2).toBeLessThan(bigO.CUBED * 100);
229
193
  });
230
194
 
@@ -237,7 +201,7 @@ describe('Queue Performance Test', () => {
237
201
  for (let i = 0; i < dataSize; i++) {
238
202
  queue.dequeue();
239
203
  }
240
- console.log(`LinkedListQueue Performance Test: ${performance.now() - startTime} ms`);
204
+ // console.log(`LinkedListQueue Performance Test: ${performance.now() - startTime} ms`);
241
205
  expect(performance.now() - startTime).toBeLessThan(bigO.LINEAR * 100);
242
206
  });
243
207
  });