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.
- package/CHANGELOG.md +1 -1
- package/README.md +561 -265
- package/benchmark/report.html +79 -0
- package/benchmark/report.json +343 -28
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +11 -10
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +11 -10
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +8 -4
- package/src/data-structures/binary-tree/binary-tree.ts +12 -9
- package/test/config.ts +1 -1
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +36 -0
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +45 -0
- package/test/performance/data-structures/binary-tree/bst.test.ts +36 -0
- package/test/performance/data-structures/graph/directed-graph.test.ts +49 -0
- package/test/performance/data-structures/heap/heap.test.ts +30 -0
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +40 -0
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +34 -0
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +19 -0
- package/test/performance/data-structures/queue/deque.test.ts +8 -6
- package/test/performance/data-structures/queue/queue.test.ts +17 -12
- package/test/performance/data-structures/trie/trie.test.ts +22 -0
- package/test/performance/reportor.ts +183 -0
- package/test/performance/types/index.ts +1 -0
- package/test/performance/types/reportor.ts +3 -0
- package/test/types/utils/index.ts +1 -0
- package/test/types/utils/json2html.ts +1 -0
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +5 -4
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +0 -23
- package/test/unit/data-structures/linked-list/linked-list.test.ts +3 -30
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -21
- package/test/unit/data-structures/matrix/matrix2d.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +0 -32
- package/test/unit/data-structures/queue/queue.test.ts +3 -39
- package/test/utils/array.ts +5514 -0
- package/test/utils/big-o.ts +14 -8
- package/test/utils/console.ts +31 -0
- package/test/utils/index.ts +5 -0
- package/test/utils/is.ts +56 -0
- package/test/utils/json2html.ts +322 -0
- package/test/utils/number.ts +10 -0
- package/test/utils/string.ts +1 -0
- package/test/config.js +0 -4
- package/test/performance/index.ts +0 -47
- package/test/types/index.js +0 -29
- package/test/types/utils/big-o.js +0 -2
- package/test/types/utils/index.js +0 -29
- package/test/utils/big-o.js +0 -222
- package/test/utils/index.js +0 -30
- package/test/utils/number.js +0 -14
package/test/utils/big-o.ts
CHANGED
|
@@ -2,16 +2,22 @@ import {AnyFunction} from '../types';
|
|
|
2
2
|
import {isDebugTest} from '../config';
|
|
3
3
|
|
|
4
4
|
const isDebug = isDebugTest;
|
|
5
|
-
const orderReducedBy =
|
|
5
|
+
const orderReducedBy = 1; // reduction of bigO's order compared to the baseline bigO
|
|
6
6
|
|
|
7
7
|
export const magnitude = {
|
|
8
|
-
CONSTANT: Math.
|
|
9
|
-
LOG_N: Math.pow(10,
|
|
10
|
-
LINEAR: Math.pow(10,
|
|
11
|
-
N_LOG_N: Math.pow(10,
|
|
12
|
-
SQUARED: Math.pow(10,
|
|
13
|
-
CUBED: Math.pow(10,
|
|
14
|
-
FACTORIAL: 20 - 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
|
+
FACTORIAL: 20 - orderReducedBy,
|
|
15
|
+
THOUSAND: 1000,
|
|
16
|
+
TEN_THOUSAND: 10000,
|
|
17
|
+
HUNDRED_THOUSAND: 100000,
|
|
18
|
+
MILLION: 1000000,
|
|
19
|
+
TEN_MILLION: 10000000,
|
|
20
|
+
BILLION: 100000000
|
|
15
21
|
};
|
|
16
22
|
|
|
17
23
|
export const bigO = {
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
GRAY: '\x1b[90m',
|
|
21
|
+
CYAN: '\x1b[36m',
|
|
22
|
+
WHITE: '\x1b[37m',
|
|
23
|
+
BG_BLACK: '\x1b[40m',
|
|
24
|
+
BG_RED: '\x1b[41m',
|
|
25
|
+
BG_GREEN: '\x1b[42m',
|
|
26
|
+
BG_YELLOW: '\x1b[43m',
|
|
27
|
+
BG_BLUE: '\x1b[44m',
|
|
28
|
+
BG_MAGENTA: '\x1b[45m',
|
|
29
|
+
BG_CYAN: '\x1b[46m',
|
|
30
|
+
BG_WHITE: '\x1b[47m'
|
|
31
|
+
};
|
package/test/utils/index.ts
CHANGED
package/test/utils/is.ts
ADDED
|
@@ -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} </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'> -function() can't _render-</span>`;
|
|
138
|
+
} else if (!isPlainObject(data)) {
|
|
139
|
+
if (_.isFunction(data.toString)) {
|
|
140
|
+
return `${title}<span class='json-to-html-value'> ${data.toString()}</span>`;
|
|
141
|
+
} else {
|
|
142
|
+
return `${title}<span class='json-to-html-value'> -instance object, can't render-</span>`;
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
return `${title}<span class='json-to-html-value'> ${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>`;
|
package/test/utils/number.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
export function getRandomInt(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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/test/config.js
DELETED
|
@@ -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
|
-
});
|
package/test/types/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __createBinding =
|
|
3
|
-
(this && this.__createBinding) ||
|
|
4
|
-
(Object.create
|
|
5
|
-
? function (o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return m[k];
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(o, k2, desc);
|
|
17
|
-
}
|
|
18
|
-
: function (o, m, k, k2) {
|
|
19
|
-
if (k2 === undefined) k2 = k;
|
|
20
|
-
o[k2] = m[k];
|
|
21
|
-
});
|
|
22
|
-
var __exportStar =
|
|
23
|
-
(this && this.__exportStar) ||
|
|
24
|
-
function (m, exports) {
|
|
25
|
-
for (var p in m)
|
|
26
|
-
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, '__esModule', {value: true});
|
|
29
|
-
__exportStar(require('./utils'), exports);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __createBinding =
|
|
3
|
-
(this && this.__createBinding) ||
|
|
4
|
-
(Object.create
|
|
5
|
-
? function (o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return m[k];
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(o, k2, desc);
|
|
17
|
-
}
|
|
18
|
-
: function (o, m, k, k2) {
|
|
19
|
-
if (k2 === undefined) k2 = k;
|
|
20
|
-
o[k2] = m[k];
|
|
21
|
-
});
|
|
22
|
-
var __exportStar =
|
|
23
|
-
(this && this.__exportStar) ||
|
|
24
|
-
function (m, exports) {
|
|
25
|
-
for (var p in m)
|
|
26
|
-
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, '__esModule', {value: true});
|
|
29
|
-
__exportStar(require('./big-o'), exports);
|