data-structure-typed 1.41.3 → 1.41.4

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 (49) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +57 -0
  3. package/benchmark/report.html +73 -0
  4. package/benchmark/report.json +237 -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 +5 -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 +24 -0
  14. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +25 -0
  15. package/test/performance/data-structures/binary-tree/bst.test.ts +24 -0
  16. package/test/performance/data-structures/heap/heap.test.ts +30 -0
  17. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +40 -0
  18. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +34 -0
  19. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +19 -0
  20. package/test/performance/data-structures/queue/deque.test.ts +8 -6
  21. package/test/performance/data-structures/queue/queue.test.ts +17 -12
  22. package/test/performance/reportor.ts +174 -0
  23. package/test/performance/types/index.ts +1 -0
  24. package/test/performance/types/reportor.ts +3 -0
  25. package/test/types/utils/index.ts +1 -0
  26. package/test/types/utils/json2html.ts +1 -0
  27. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +4 -4
  28. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +0 -23
  29. package/test/unit/data-structures/linked-list/linked-list.test.ts +3 -30
  30. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -21
  31. package/test/unit/data-structures/matrix/matrix2d.test.ts +1 -1
  32. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +0 -32
  33. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +2 -2
  34. package/test/unit/data-structures/queue/queue.test.ts +3 -39
  35. package/test/utils/array.ts +5 -0
  36. package/test/utils/big-o.ts +7 -7
  37. package/test/utils/console.ts +30 -0
  38. package/test/utils/index.ts +4 -0
  39. package/test/utils/is.ts +56 -0
  40. package/test/utils/json2html.ts +322 -0
  41. package/test/utils/number.ts +11 -1
  42. package/test/config.js +0 -4
  43. package/test/performance/index.ts +0 -47
  44. package/test/types/index.js +0 -29
  45. package/test/types/utils/big-o.js +0 -2
  46. package/test/types/utils/index.js +0 -29
  47. package/test/utils/big-o.js +0 -222
  48. package/test/utils/index.js +0 -30
  49. package/test/utils/number.js +0 -14
@@ -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 {PriorityQueue} from '../../../../src';
2
- import {getRandomInt} from '../../../utils';
2
+ import {randomInt} from '../../../utils';
3
3
 
4
4
  describe('PriorityQueue Operation Test', () => {
5
5
  it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
@@ -44,7 +44,7 @@ describe('PriorityQueue Operation Test', () => {
44
44
 
45
45
  describe('Priority Queue Performance Test', () => {
46
46
  it('should numeric heap work well', function () {
47
- const values = Array.from(new Array(10000), () => getRandomInt(1, 10000000));
47
+ const values = Array.from(new Array(10000), () => randomInt(1, 10000000));
48
48
  const minPriorityQueue = new PriorityQueue<number>({comparator: (a, b) => a - b});
49
49
  minPriorityQueue.refill(values);
50
50
  const sorted = minPriorityQueue.sort();
@@ -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
  });
@@ -0,0 +1,5 @@
1
+ import {randomInt} from './number';
2
+
3
+ export const randomIntArray = (length: number, min: number = -1000, max: number = 1000) => {
4
+ return new Array<number>(length).fill(0).map(() => randomInt(min, max));
5
+ };
@@ -2,15 +2,15 @@ import {AnyFunction} from '../types';
2
2
  import {isDebugTest} from '../config';
3
3
 
4
4
  const isDebug = isDebugTest;
5
- const orderReducedBy = 2; // reduction of bigO's order compared to the baseline bigO
5
+ const orderReducedBy = 1; // reduction of bigO's order compared to the baseline bigO
6
6
 
7
7
  export const magnitude = {
8
- CONSTANT: Math.floor(Number.MAX_SAFE_INTEGER / Math.pow(10, orderReducedBy)),
9
- LOG_N: Math.pow(10, 9 - orderReducedBy),
10
- LINEAR: Math.pow(10, 6 - orderReducedBy),
11
- N_LOG_N: Math.pow(10, 5 - orderReducedBy),
12
- SQUARED: Math.pow(10, 4 - orderReducedBy),
13
- CUBED: Math.pow(10, 3 - orderReducedBy),
8
+ CONSTANT: Math.pow(10, 9),
9
+ LOG_N: Math.pow(10, 8 - orderReducedBy),
10
+ LINEAR: Math.pow(10, 7 - orderReducedBy),
11
+ N_LOG_N: Math.pow(10, 4 - orderReducedBy),
12
+ SQUARED: Math.pow(10, 3 - orderReducedBy),
13
+ CUBED: Math.pow(10, 2 - orderReducedBy),
14
14
  FACTORIAL: 20 - orderReducedBy
15
15
  };
16
16
 
@@ -0,0 +1,30 @@
1
+ export const Color = {
2
+ END: '\x1b[0m',
3
+ BOLD: '\x1b[1m',
4
+ DIM: '\x1b[2m',
5
+ ITALIC: '\x1b[3m',
6
+ UNDERLINE: '\x1b[4m',
7
+ INVERSE: '\x1b[7m',
8
+ STRIKETHROUGH: '\x1b[9m',
9
+ NO_BOLD: '\x1b[22m',
10
+ NO_ITALIC: '\x1b[23m',
11
+ NO_UNDERLINE: '\x1b[24m',
12
+ NO_INVERSE: '\x1b[27m',
13
+ NO_STRIKETHROUGH: '\x1b[29m',
14
+ BLACK: '\x1b[30m',
15
+ RED: '\x1b[31m',
16
+ GREEN: '\x1b[32m',
17
+ YELLOW: '\x1b[33m',
18
+ BLUE: '\x1b[34m',
19
+ MAGENTA: '\x1b[35m',
20
+ CYAN: '\x1b[36m',
21
+ WHITE: '\x1b[37m',
22
+ BG_BLACK: '\x1b[40m',
23
+ BG_RED: '\x1b[41m',
24
+ BG_GREEN: '\x1b[42m',
25
+ BG_YELLOW: '\x1b[43m',
26
+ BG_BLUE: '\x1b[44m',
27
+ BG_MAGENTA: '\x1b[45m',
28
+ BG_CYAN: '\x1b[46m',
29
+ BG_WHITE: '\x1b[47m'
30
+ };
@@ -1,2 +1,6 @@
1
1
  export * from './number';
2
+ export * from './array';
2
3
  export * from './big-o';
4
+ export * from './json2html';
5
+ export * from './is';
6
+ export * from './console';
@@ -0,0 +1,56 @@
1
+ export const isNumber = (value: any) => {
2
+ return typeof value === 'number';
3
+ };
4
+ export const isString = (value: any) => {
5
+ return typeof value === 'string';
6
+ };
7
+ export const isBoolean = (value: any) => {
8
+ return typeof value === 'boolean';
9
+ };
10
+ export const isDate = (value: any) => {
11
+ return value instanceof Date;
12
+ };
13
+ export const isNull = (value: any) => {
14
+ return value === null;
15
+ };
16
+ export const isUndefined = (value: any) => {
17
+ return typeof value === 'undefined';
18
+ };
19
+ export const isFunction = (value: any) => {
20
+ return typeof value === 'function';
21
+ };
22
+ export const isObject = (value: any) => {
23
+ return typeof value === 'object';
24
+ };
25
+ export const isArray = (value: any) => {
26
+ return Array.isArray(value);
27
+ };
28
+
29
+ export const isEqual = (objA: any, objB: any): boolean => {
30
+ if (objA === objB) {
31
+ return true;
32
+ }
33
+
34
+ if (typeof objA !== 'object' || typeof objB !== 'object' || objA === null || objB === null) {
35
+ return false;
36
+ }
37
+
38
+ const keysA = Object.keys(objA);
39
+ const keysB = Object.keys(objB);
40
+
41
+ if (keysA.length !== keysB.length) {
42
+ return false;
43
+ }
44
+
45
+ for (const key of keysA) {
46
+ if (!keysB.includes(key)) {
47
+ return false;
48
+ }
49
+
50
+ if (!isEqual(objA[key], objB[key])) {
51
+ return false;
52
+ }
53
+ }
54
+
55
+ return true;
56
+ };
@@ -0,0 +1,322 @@
1
+ import * as _ from './is';
2
+ import {Json2htmlOptions} from '../types';
3
+
4
+ function toggleJS(options?: Json2htmlOptions): string {
5
+ if (options?.plainHtml) {
6
+ return '';
7
+ } else {
8
+ return 'onclick="json-to-html.toggleVisibility(this);return false"';
9
+ }
10
+ }
11
+
12
+ function makeLabelDiv(options: any, level: number, keyName: string | number, datatype?: string): string {
13
+ if (typeof keyName === 'number') {
14
+ return `<div class='index'><span class='json-to-html-label'>${keyName}&nbsp;</span></div>`;
15
+ } else if (typeof keyName === 'string') {
16
+ if (datatype === 'array') {
17
+ return `<div class='collapsible level${level}' ${toggleJS(
18
+ options
19
+ )}><span class='json-to-html-label'>${keyName}</span></div>`;
20
+ } else if (datatype === 'object') {
21
+ return `<div class='attribute collapsible level${level}' ${toggleJS(
22
+ options
23
+ )}><span class='json-to-html-label'>${keyName}:</span></div>`;
24
+ } else {
25
+ return `<div class='leaf level${level}'><span class='json-to-html-label'>${keyName}:</span></div>`;
26
+ }
27
+ } else {
28
+ return '';
29
+ }
30
+ }
31
+
32
+ function getContentClass(keyName: string | number): string {
33
+ if (typeof keyName === 'string') {
34
+ return 'content';
35
+ } else {
36
+ return '';
37
+ }
38
+ }
39
+
40
+ function isPlainObject(val: any): boolean {
41
+ let lastKey: string | undefined;
42
+ let lastOwnKey: string | undefined;
43
+ for (const key in val) {
44
+ if (val.hasOwnProperty(key)) {
45
+ lastOwnKey = key;
46
+ }
47
+ }
48
+ for (const key in val) {
49
+ lastKey = key;
50
+ }
51
+ return lastOwnKey === lastKey;
52
+ }
53
+
54
+ function isLeafValue(val: any): boolean {
55
+ return (
56
+ _.isNumber(val) ||
57
+ _.isString(val) ||
58
+ _.isBoolean(val) ||
59
+ _.isDate(val) ||
60
+ _.isNull(val) ||
61
+ _.isUndefined(val) ||
62
+ isNaN(val) ||
63
+ _.isFunction(val) ||
64
+ !isPlainObject(val)
65
+ );
66
+ }
67
+
68
+ function isLeafObject(obj: any): boolean {
69
+ if (!_.isObject(obj)) {
70
+ return false;
71
+ }
72
+ for (const key in obj) {
73
+ const val = obj[key];
74
+ if (!isLeafValue(val)) {
75
+ return false;
76
+ }
77
+ }
78
+ return true;
79
+ }
80
+
81
+ function isTable(arr: any[]): boolean {
82
+ if (!_.isArray(arr)) {
83
+ return false;
84
+ }
85
+ if (arr.length === 0 || !_.isObject(arr[0])) {
86
+ return false;
87
+ } else {
88
+ let nonCompliant = arr.find(row => !isLeafObject(row));
89
+ if (nonCompliant) {
90
+ return false;
91
+ } else {
92
+ const cols = Object.keys(arr[0]);
93
+ nonCompliant = arr.find((row: object) => !_.isEqual(cols, Object.keys(row)));
94
+ if (nonCompliant) {
95
+ return false;
96
+ } else {
97
+ return true;
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ function drawTable(arr: any[]): string {
104
+ function drawRow(headers: string[], rowObj: any): string {
105
+ return '<td>' + headers.map(header => rowObj[header]).join('</td><td>') + '</td>';
106
+ }
107
+
108
+ const cols = Object.keys(arr[0]);
109
+ const content = arr.map(rowObj => drawRow(cols, rowObj));
110
+ const headingHtml = '<tr><th>' + cols.join('</th><th>') + '</th></tr>';
111
+ const contentHtml = '<tr>' + content.join('</tr><tr>') + '</tr>';
112
+ return '<table>' + headingHtml + contentHtml + '</table>';
113
+ }
114
+
115
+ function _render(name: string, data: any, options: Json2htmlOptions, level: number, altRow: number): string {
116
+ const contentClass = getContentClass(name);
117
+ if (_.isArray(data)) {
118
+ const title = makeLabelDiv(options, level, `${name}`, 'array');
119
+ let subs: string;
120
+ if (isTable(data)) {
121
+ subs = drawTable(data);
122
+ } else {
123
+ subs =
124
+ "<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'>") +
128
+ '</div>';
129
+ }
130
+ return `<div class="json-to-html-collapse clearfix ${altRow}">
131
+ ${title}
132
+ <div class="${contentClass}">${subs}</div>
133
+ </div>`;
134
+ } else if (isLeafValue(data)) {
135
+ const title = makeLabelDiv(options, level, name);
136
+ if (_.isFunction(data)) {
137
+ return `${title}<span class='json-to-html-value'>&nbsp;&nbsp;-function() can't _render-</span>`;
138
+ } else if (!isPlainObject(data)) {
139
+ if (_.isFunction(data.toString)) {
140
+ return `${title}<span class='json-to-html-value'>&nbsp;&nbsp;${data.toString()}</span>`;
141
+ } else {
142
+ return `${title}<span class='json-to-html-value'>&nbsp;&nbsp;-instance object, can't render-</span>`;
143
+ }
144
+ } else {
145
+ return `${title}<span class='json-to-html-value'>&nbsp;&nbsp;${data}</span>`;
146
+ }
147
+ } else {
148
+ const title = makeLabelDiv(options, level, name, 'object');
149
+ let count = 0;
150
+ const subs =
151
+ '<div>' +
152
+ Object.entries(data)
153
+ .map(([key, val]) => _render(key, val, options, level + 1, count++ % 2))
154
+ .join('</div><div>') +
155
+ '</div>';
156
+ const inner = `<div class="json-to-html-expand clearfix ${altRow}">
157
+ ${title}
158
+ <div class="${contentClass}">${subs}</div>
159
+ </div>`;
160
+ return `${level === 0 ? "<div id='json-to-html'>" : ''}
161
+ ${inner}
162
+ ${level === 0 ? '</div>' : ''}`;
163
+ }
164
+ }
165
+
166
+ export function render(name: string, json: any, options: Json2htmlOptions): string {
167
+ // return `${head}${_render('', json, options, 0, 0)}`;
168
+ return `${_render(name, json, options, 0, 0)}`;
169
+ }
170
+
171
+ // const head = `<style>
172
+ // #json-to-html table {
173
+ // border-collapse: collapse;
174
+ // }
175
+ // #json-to-html th {
176
+ // color: #888;
177
+ // }
178
+ // #json-to-html table,th, td {
179
+ // border: 1px solid #DDD;
180
+ // padding: 10px 5px;
181
+ // }
182
+ // #json-to-html th, td {
183
+ // text-align: center;
184
+ // }
185
+ // #json-to-html .content {
186
+ // padding-left: 30px;
187
+ // font-family: Arial;
188
+ // }
189
+ //
190
+ // #json-to-html .index {
191
+ // font-size: 100%;
192
+ // color: #999;
193
+ // float: left;
194
+ // }
195
+ // #json-to-html .clearfix:after {
196
+ // content: ".";
197
+ // display: block;
198
+ // height: 0;
199
+ // clear: both;
200
+ // visibility: hidden;
201
+ // }
202
+ // #json-to-html .json-to-html-label {
203
+ // font-family: Helvetica Neue;
204
+ // color: #333;
205
+ // }
206
+ // #json-to-html .json-to-html-value {
207
+ // font-family: Arial;
208
+ // color: #777;
209
+ // }
210
+ // #json-to-html .collapsible > .json-to-html-label:hover {
211
+ // text-decoration: underline;
212
+ // }
213
+ // #json-to-html .collapsible > .json-to-html-label {
214
+ // color: #15C;
215
+ // }
216
+ // #json-to-html .json-to-html-collapse > div.content {
217
+ // display: none;
218
+ // }
219
+ // #json-to-html .json-to-html-collapse > .json-to-html-label {
220
+ // font-weight: bold;
221
+ // }
222
+ //
223
+ // #json-to-html .json-to-html-expand > div > .json-to-html-label, #json-to-html .json-to-html-collapse > div > .json-to-html-label {
224
+ // background-repeat: no-repeat;
225
+ // background-position: left;
226
+ // padding-left: 25px;
227
+ // margin: 5px 0px 5px 15px;
228
+ // display: inline-block;
229
+ // }
230
+ //
231
+ // #json-to-html .json-to-html-expand > div > .json-to-html-label {
232
+ // width: 30px;
233
+ // height: 30px;
234
+ // background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><polygon points="50,10 10,90 90,90" fill="blue" /></svg>');
235
+ // background-size: cover;
236
+ // background-position: center;
237
+ // }
238
+ //
239
+ // #json-to-html .json-to-html-collapse > div > .json-to-html-label {
240
+ // width: 30px;
241
+ // height: 30px;
242
+ // background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><polygon points="50,10 10,90 90,90" fill="blue" /></svg>');
243
+ // background-size: cover;
244
+ // background-position: center;
245
+ // }
246
+ //
247
+ // #json-to-html .json-to-html-collapse > span.collapsible:before {
248
+ // border-radius: 2px;
249
+ // border-color: #A44;
250
+ // border-style: solid;
251
+ // border-width: 1px;
252
+ // color: #A44;
253
+ // content: '+';
254
+ // display: inline-block;
255
+ // line-height: 7px;
256
+ // margin: 0 2px;
257
+ // overflow: hidden;
258
+ // padding: 1px;
259
+ // font-size: 11px;
260
+ // }
261
+ //
262
+ // #json-to-html .json-to-html-expand > span.collapsible:before {
263
+ // border: none;
264
+ // color: #A44;
265
+ // content: '-';
266
+ // display: inline-block;
267
+ // line-height: 7px;
268
+ // margin: 4px;
269
+ // overflow: hidden;
270
+ // padding: 1px;
271
+ // font-size: 11px;
272
+ // }
273
+ //
274
+ // #json-to-html.level0 {
275
+ // font-size: 25px;
276
+ // }
277
+ // #json-to-html .level1 {
278
+ // font-size: 22px;
279
+ // }
280
+ //
281
+ // #json-to-html .leaf {
282
+ // color: #666;
283
+ // display: inline;
284
+ // }
285
+ //
286
+ // #json-to-html .altRows:nth-child(odd) { background-color:#ddd; }
287
+ // #json-to-html .altRows:nth-child(even) { background-color:#fff; }
288
+ //
289
+ // #json-to-html tr:nth-child(odd) { background-color:#eee; }
290
+ // #json-to-html tr:nth-child(even) { background-color:#fff; }
291
+ // </style>
292
+ // <script type="text/javascript">
293
+ // json-to-html = {
294
+ // toggleVisibility: function(el, name) {
295
+ // json-to-html.toggleClass(el.parentElement,'json-to-html-collapse json-to-html-expand');
296
+ // },
297
+ // classRe: function(name) {
298
+ // return new RegExp('(?:^|\\s)'+name+'(?!\\S)');
299
+ // },
300
+ // addClass: function(el, name) {
301
+ // el.className += " "+name;
302
+ // },
303
+ // removeClass: function(el, name) {
304
+ // var re = json-to-html.classRe(name);
305
+ // el.className = el.className.replace(json-to-html.classRe(name) , '' )
306
+ // },
307
+ // hasClass: function(el, name) {
308
+ // var re = json-to-html.classRe(name);
309
+ // return json-to-html.classRe(name).exec(el.className);
310
+ // },
311
+ // toggleClass: function(el, name) {
312
+ // var names = name.split(/\s+/);
313
+ // for (n in names) {
314
+ // if (json-to-html.hasClass(el, names[n])) {
315
+ // json-to-html.removeClass(el, names[n]);
316
+ // } else {
317
+ // json-to-html.addClass(el, names[n]);
318
+ // }
319
+ // }
320
+ // }
321
+ // };
322
+ // </script>`;
@@ -1,3 +1,13 @@
1
- export function getRandomInt(min: number, max: number) {
1
+ export function randomInt(min: number, max: number) {
2
2
  return Math.floor(Math.random() * (max - min + 1)) + min;
3
3
  }
4
+
5
+ export function numberFix(num: number, decimalPlaces: number): string {
6
+ if (num > 10000 || num < 0.001) {
7
+ const [mantissa, exponent] = num.toExponential().split('e');
8
+ const formattedMantissa = Number(mantissa).toFixed(decimalPlaces);
9
+ return `${formattedMantissa}e${exponent}`;
10
+ } else {
11
+ return num.toFixed(decimalPlaces);
12
+ }
13
+ }
package/test/config.js DELETED
@@ -1,4 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', {value: true});
3
- exports.isDebugTest = void 0;
4
- exports.isDebugTest = false;
@@ -1,47 +0,0 @@
1
- import * as Benchmark from 'benchmark';
2
- import * as path from 'path';
3
- import * as fs from 'fs';
4
- import * as fastGlob from 'fast-glob';
5
-
6
- const reportDistPath = 'benchmark';
7
- const testDir = path.join(__dirname, 'data-structures');
8
- const testFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts'));
9
-
10
- const report: {[key: string] : any} = {};
11
-
12
- let i = 0;
13
- testFiles.forEach((file: string) => {
14
- i++;
15
- console.log(`testing file ${file}`);
16
- const testName = path.basename(file, '.test.ts');
17
- const testFunction = require(file);
18
- const {suite} = testFunction;
19
-
20
- if (suite) {
21
- suite.on('cycle', (event: any) => {
22
- console.log(String(event.target));
23
- });
24
-
25
- suite.on('complete', function (this: Benchmark.Suite) {
26
- console.log('Fastest is ' + this.filter('fastest').map('name'));
27
- report[testName] = this.map((test: Benchmark) => ({
28
- name: test.name,
29
- periodMS: test.times.period * 1000,
30
- hz: test.hz,
31
- count: test.count,
32
- mean: test.stats.mean,
33
- deviation: test.stats.deviation,
34
- }));
35
- // report[testName] = this;
36
- console.log('----i', i, testFiles.length)
37
- if (testFiles.length === i) {
38
- if (!fs.existsSync(reportDistPath)) fs.mkdirSync(reportDistPath, { recursive: true });
39
-
40
- const filePath = path.join(reportDistPath, 'report.json');
41
- fs.writeFileSync(filePath, JSON.stringify(report, null, 2));
42
- console.log('Performance test report file generated')
43
- }
44
- })
45
- .run({async: true});
46
- }
47
- });