data-structure-typed 2.0.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/COMMANDS.md +17 -0
- package/benchmark/report.html +13 -77
- package/benchmark/report.json +145 -177
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
- package/dist/cjs/data-structures/base/linear-base.js +137 -274
- package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +594 -865
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/cjs/data-structures/graph/map-graph.js +56 -59
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/cjs/data-structures/hash/hash-map.js +270 -457
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
- package/dist/cjs/data-structures/heap/heap.js +340 -349
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/cjs/data-structures/heap/max-heap.js +11 -66
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/cjs/data-structures/heap/min-heap.js +11 -66
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
- package/dist/cjs/data-structures/queue/deque.js +309 -348
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
- package/dist/cjs/data-structures/queue/queue.js +265 -248
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
- package/dist/cjs/data-structures/stack/stack.js +181 -125
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
- package/dist/cjs/data-structures/trie/trie.js +189 -172
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
- package/dist/cjs/interfaces/graph.d.ts +16 -0
- package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/cjs/types/utils/utils.d.ts +1 -0
- package/dist/cjs/utils/utils.d.ts +1 -1
- package/dist/cjs/utils/utils.js +2 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
- package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
- package/dist/esm/data-structures/base/linear-base.js +137 -274
- package/dist/esm/data-structures/base/linear-base.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/esm/data-structures/binary-tree/binary-tree.js +598 -874
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/esm/data-structures/binary-tree/bst.js +507 -487
- package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
- package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/esm/data-structures/graph/directed-graph.js +145 -233
- package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/esm/data-structures/graph/map-graph.js +56 -59
- package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
- package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
- package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/esm/data-structures/hash/hash-map.js +270 -457
- package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
- package/dist/esm/data-structures/heap/heap.d.ts +214 -289
- package/dist/esm/data-structures/heap/heap.js +329 -349
- package/dist/esm/data-structures/heap/heap.js.map +1 -1
- package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/esm/data-structures/heap/max-heap.js +11 -66
- package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
- package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/esm/data-structures/heap/min-heap.js +11 -66
- package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
- package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
- package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
- package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/esm/data-structures/queue/deque.d.ts +227 -254
- package/dist/esm/data-structures/queue/deque.js +313 -348
- package/dist/esm/data-structures/queue/deque.js.map +1 -1
- package/dist/esm/data-structures/queue/queue.d.ts +180 -201
- package/dist/esm/data-structures/queue/queue.js +263 -248
- package/dist/esm/data-structures/queue/queue.js.map +1 -1
- package/dist/esm/data-structures/stack/stack.d.ts +124 -102
- package/dist/esm/data-structures/stack/stack.js +181 -125
- package/dist/esm/data-structures/stack/stack.js.map +1 -1
- package/dist/esm/data-structures/trie/trie.d.ts +164 -165
- package/dist/esm/data-structures/trie/trie.js +193 -172
- package/dist/esm/data-structures/trie/trie.js.map +1 -1
- package/dist/esm/interfaces/binary-tree.d.ts +56 -6
- package/dist/esm/interfaces/graph.d.ts +16 -0
- package/dist/esm/types/data-structures/base/base.d.ts +1 -1
- package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/esm/types/utils/utils.d.ts +1 -0
- package/dist/esm/utils/utils.d.ts +1 -1
- package/dist/esm/utils/utils.js +2 -1
- package/dist/esm/utils/utils.js.map +1 -1
- package/dist/umd/data-structure-typed.js +4685 -6477
- package/dist/umd/data-structure-typed.min.js +8 -6
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +3 -4
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
- package/src/data-structures/binary-tree/avl-tree.ts +239 -206
- package/src/data-structures/binary-tree/binary-tree.ts +660 -889
- package/src/data-structures/binary-tree/bst.ts +568 -570
- package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
- package/src/data-structures/binary-tree/tree-counter.ts +199 -218
- package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
- package/test/integration/index.html +1 -1
- package/test/performance/benchmark-runner.ts +528 -0
- package/test/performance/reportor.mjs +43 -43
- package/test/performance/runner-config.json +39 -0
- package/test/performance/single-suite-runner.ts +69 -0
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
- package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
- package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +14 -21
- package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
- package/test/unit/data-structures/queue/queue.test.ts +4 -5
- package/test/unit/utils/utils.test.ts +0 -1
- package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
- package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
|
@@ -3,31 +3,31 @@ import * as fs from 'fs';
|
|
|
3
3
|
import fastGlob from 'fast-glob';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
|
|
6
|
-
const isNumber =
|
|
6
|
+
const isNumber = value => {
|
|
7
7
|
return typeof value === 'number';
|
|
8
8
|
};
|
|
9
|
-
const isString =
|
|
9
|
+
const isString = value => {
|
|
10
10
|
return typeof value === 'string';
|
|
11
11
|
};
|
|
12
|
-
const isBoolean =
|
|
12
|
+
const isBoolean = value => {
|
|
13
13
|
return typeof value === 'boolean';
|
|
14
14
|
};
|
|
15
|
-
const isDate =
|
|
15
|
+
const isDate = value => {
|
|
16
16
|
return value instanceof Date;
|
|
17
17
|
};
|
|
18
|
-
const isNull =
|
|
18
|
+
const isNull = value => {
|
|
19
19
|
return value === null;
|
|
20
20
|
};
|
|
21
|
-
const isUndefined =
|
|
21
|
+
const isUndefined = value => {
|
|
22
22
|
return typeof value === 'undefined';
|
|
23
23
|
};
|
|
24
|
-
const isFunction =
|
|
24
|
+
const isFunction = value => {
|
|
25
25
|
return typeof value === 'function';
|
|
26
26
|
};
|
|
27
|
-
const isObject =
|
|
27
|
+
const isObject = value => {
|
|
28
28
|
return typeof value === 'object';
|
|
29
29
|
};
|
|
30
|
-
const isArray =
|
|
30
|
+
const isArray = value => {
|
|
31
31
|
return Array.isArray(value);
|
|
32
32
|
};
|
|
33
33
|
const isEqual = (objA, objB) => {
|
|
@@ -56,38 +56,35 @@ const isEqual = (objA, objB) => {
|
|
|
56
56
|
function toggleJS(options) {
|
|
57
57
|
if (options === null || options === void 0 ? void 0 : options.plainHtml) {
|
|
58
58
|
return '';
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
59
|
+
} else {
|
|
61
60
|
return 'onclick="json-to-html.toggleVisibility(this);return false"';
|
|
62
61
|
}
|
|
63
62
|
}
|
|
63
|
+
|
|
64
64
|
function makeLabelDiv(options, level, keyName, datatype) {
|
|
65
65
|
if (typeof keyName === 'number') {
|
|
66
66
|
return `<div class='index'><span class='json-to-html-label'>${keyName} </span></div>`;
|
|
67
|
-
}
|
|
68
|
-
else if (typeof keyName === 'string') {
|
|
67
|
+
} else if (typeof keyName === 'string') {
|
|
69
68
|
if (datatype === 'array') {
|
|
70
69
|
return `<div class='collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}</span></div>`;
|
|
71
|
-
}
|
|
72
|
-
else if (datatype === 'object') {
|
|
70
|
+
} else if (datatype === 'object') {
|
|
73
71
|
return `<div class='attribute collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}:</span></div>`;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
72
|
+
} else {
|
|
76
73
|
return `<div class='leaf level${level}'><span class='json-to-html-label'>${keyName}:</span></div>`;
|
|
77
74
|
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
75
|
+
} else {
|
|
80
76
|
return '';
|
|
81
77
|
}
|
|
82
78
|
}
|
|
79
|
+
|
|
83
80
|
function getContentClass(keyName) {
|
|
84
81
|
if (typeof keyName === 'string') {
|
|
85
82
|
return 'content';
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
83
|
+
} else {
|
|
88
84
|
return '';
|
|
89
85
|
}
|
|
90
86
|
}
|
|
87
|
+
|
|
91
88
|
function isPlainObject(val) {
|
|
92
89
|
let lastKey;
|
|
93
90
|
let lastOwnKey;
|
|
@@ -101,8 +98,10 @@ function isPlainObject(val) {
|
|
|
101
98
|
}
|
|
102
99
|
return lastOwnKey === lastKey;
|
|
103
100
|
}
|
|
101
|
+
|
|
104
102
|
function isLeafValue(val) {
|
|
105
|
-
return (
|
|
103
|
+
return (
|
|
104
|
+
isNumber(val) ||
|
|
106
105
|
isString(val) ||
|
|
107
106
|
isBoolean(val) ||
|
|
108
107
|
isDate(val) ||
|
|
@@ -110,8 +109,10 @@ function isLeafValue(val) {
|
|
|
110
109
|
isUndefined(val) ||
|
|
111
110
|
isNaN(val) ||
|
|
112
111
|
isFunction(val) ||
|
|
113
|
-
!isPlainObject(val)
|
|
112
|
+
!isPlainObject(val)
|
|
113
|
+
);
|
|
114
114
|
}
|
|
115
|
+
|
|
115
116
|
function isLeafObject(obj) {
|
|
116
117
|
if (!isObject(obj)) {
|
|
117
118
|
return false;
|
|
@@ -124,35 +125,37 @@ function isLeafObject(obj) {
|
|
|
124
125
|
}
|
|
125
126
|
return true;
|
|
126
127
|
}
|
|
128
|
+
|
|
127
129
|
function isTable(arr) {
|
|
128
130
|
if (!isArray(arr)) {
|
|
129
131
|
return false;
|
|
130
132
|
}
|
|
131
133
|
if (arr.length === 0 || !isObject(arr[0])) {
|
|
132
134
|
return false;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
+
} else {
|
|
135
136
|
let nonCompliant = arr.find(row => !isLeafObject(row));
|
|
136
137
|
if (nonCompliant) {
|
|
137
138
|
return false;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
139
|
+
} else {
|
|
140
140
|
const cols = Object.keys(arr[0]);
|
|
141
|
-
nonCompliant = arr.find(
|
|
141
|
+
nonCompliant = arr.find(row => !isEqual(cols, Object.keys(row)));
|
|
142
142
|
return !nonCompliant;
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
+
|
|
146
147
|
function drawTable(arr) {
|
|
147
148
|
function drawRow(headers, rowObj) {
|
|
148
149
|
return '<td>' + headers.map(header => rowObj[header]).join('</td><td>') + '</td>';
|
|
149
150
|
}
|
|
151
|
+
|
|
150
152
|
const cols = Object.keys(arr[0]);
|
|
151
153
|
const content = arr.map(rowObj => drawRow(cols, rowObj));
|
|
152
154
|
const headingHtml = '<tr><th>' + cols.join('</th><th>') + '</th></tr>';
|
|
153
155
|
const contentHtml = '<tr>' + content.join('</tr><tr>') + '</tr>';
|
|
154
156
|
return '<table style="display: table; width:100%; table-layout: fixed;">' + headingHtml + contentHtml + '</table>';
|
|
155
157
|
}
|
|
158
|
+
|
|
156
159
|
function _render(name, data, options, level, altRow) {
|
|
157
160
|
const contentClass = getContentClass(name);
|
|
158
161
|
if (isArray(data)) {
|
|
@@ -160,8 +163,7 @@ function _render(name, data, options, level, altRow) {
|
|
|
160
163
|
let subs;
|
|
161
164
|
if (isTable(data)) {
|
|
162
165
|
subs = drawTable(data);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
166
|
+
} else {
|
|
165
167
|
subs =
|
|
166
168
|
"<div class='altRows'>" +
|
|
167
169
|
data
|
|
@@ -173,28 +175,24 @@ function _render(name, data, options, level, altRow) {
|
|
|
173
175
|
${title}
|
|
174
176
|
<div class="${contentClass}">${subs}</div>
|
|
175
177
|
</div>`;
|
|
176
|
-
}
|
|
177
|
-
else if (isLeafValue(data)) {
|
|
178
|
+
} else if (isLeafValue(data)) {
|
|
178
179
|
const title = makeLabelDiv(options, level, name);
|
|
179
180
|
if (isFunction(data)) {
|
|
180
181
|
return `${title}<span class='json-to-html-value'> -function() can't _render-</span>`;
|
|
181
|
-
}
|
|
182
|
-
else if (!isPlainObject(data)) {
|
|
182
|
+
} else if (!isPlainObject(data)) {
|
|
183
183
|
if (isFunction(data.toString)) {
|
|
184
184
|
return `${title}<span class='json-to-html-value'> ${data.toString()}</span>`;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
185
|
+
} else {
|
|
187
186
|
return `${title}<span class='json-to-html-value'> -instance object, can't render-</span>`;
|
|
188
187
|
}
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
188
|
+
} else {
|
|
191
189
|
return `${title}<span class='json-to-html-value'> ${data}</span>`;
|
|
192
190
|
}
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
191
|
+
} else {
|
|
195
192
|
const title = makeLabelDiv(options, level, name, 'object');
|
|
196
193
|
let count = 0;
|
|
197
|
-
const subs =
|
|
194
|
+
const subs =
|
|
195
|
+
'<div>' +
|
|
198
196
|
Object.entries(data)
|
|
199
197
|
.map(([key, val]) => _render(key, val, options, level + 1, count++ % 2))
|
|
200
198
|
.join('</div><div>') +
|
|
@@ -208,11 +206,11 @@ function _render(name, data, options, level, altRow) {
|
|
|
208
206
|
${level === 0 ? '</div>' : ''}`;
|
|
209
207
|
}
|
|
210
208
|
}
|
|
209
|
+
|
|
211
210
|
export function render(name, json, options) {
|
|
212
211
|
return `${_render(name, json, options, 0, 0)}`;
|
|
213
212
|
}
|
|
214
213
|
|
|
215
|
-
|
|
216
214
|
const __filename = fileURLToPath(import.meta.url);
|
|
217
215
|
const __dirname = path.dirname(__filename);
|
|
218
216
|
|
|
@@ -225,6 +223,7 @@ function numberFix(num, decimalPlaces) {
|
|
|
225
223
|
return num.toFixed(decimalPlaces);
|
|
226
224
|
}
|
|
227
225
|
}
|
|
226
|
+
|
|
228
227
|
const ConsoleColor = {
|
|
229
228
|
END: '\x1b[0m',
|
|
230
229
|
BOLD: '\x1b[1m',
|
|
@@ -278,7 +277,6 @@ const getRelativePath = file => {
|
|
|
278
277
|
return path.relative(__dirname, file);
|
|
279
278
|
};
|
|
280
279
|
const coloredLabeled = (label, file) => {
|
|
281
|
-
|
|
282
280
|
const relativeFilePath = getRelativePath(file);
|
|
283
281
|
const directory = path.dirname(relativeFilePath);
|
|
284
282
|
const fileName = path.basename(relativeFilePath);
|
|
@@ -414,6 +412,7 @@ const composeReport = () => {
|
|
|
414
412
|
fs.writeFileSync(htmlFilePath, html);
|
|
415
413
|
console.log(`Performance ${BOLD}${GREEN}report${END} file generated in file://${BOLD}${GREEN}${htmlFilePath}${END}`);
|
|
416
414
|
};
|
|
415
|
+
|
|
417
416
|
function replaceMarkdownContent(startMarker, endMarker, newText) {
|
|
418
417
|
const filePath = path.join(parentDirectory, 'README.md'); // Path to README.md file
|
|
419
418
|
fs.readFile(filePath, 'utf8', (err, data) => {
|
|
@@ -440,6 +439,7 @@ function replaceMarkdownContent(startMarker, endMarker, newText) {
|
|
|
440
439
|
});
|
|
441
440
|
});
|
|
442
441
|
}
|
|
442
|
+
|
|
443
443
|
const sortedPerformanceTests = (
|
|
444
444
|
isOnlyOrdered ? [...performanceTests].filter(test => runOrder.includes(test.testName)) : [...performanceTests]
|
|
445
445
|
).sort((a, b) => {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"label": "default-plan",
|
|
3
|
+
"include": [
|
|
4
|
+
"binary-tree/avl-tree.test.ts",
|
|
5
|
+
"binary-tree/binary-tree.test.ts",
|
|
6
|
+
"binary-tree/bst.test.ts",
|
|
7
|
+
"binary-tree/red-black-tree.test.ts",
|
|
8
|
+
"graph/directed-graph.test.ts",
|
|
9
|
+
"hash/hash-map.test.ts",
|
|
10
|
+
"heap/heap.test.ts",
|
|
11
|
+
"queue/queue.test.ts",
|
|
12
|
+
"queue/deque.test.ts",
|
|
13
|
+
"stack/**",
|
|
14
|
+
"trie/**"
|
|
15
|
+
],
|
|
16
|
+
"exclude": [
|
|
17
|
+
"**/experimental/**"
|
|
18
|
+
],
|
|
19
|
+
"order": [
|
|
20
|
+
"heap",
|
|
21
|
+
"avl-tree",
|
|
22
|
+
"red-black-tree",
|
|
23
|
+
"doubly-linked-list",
|
|
24
|
+
"linked-hash-map",
|
|
25
|
+
"hash-map",
|
|
26
|
+
"map-graph",
|
|
27
|
+
"graph",
|
|
28
|
+
"directed-graph",
|
|
29
|
+
"undirected-graph",
|
|
30
|
+
"queue",
|
|
31
|
+
"deque",
|
|
32
|
+
"priority-queue",
|
|
33
|
+
"singly-linked-list",
|
|
34
|
+
"binary-tree-overall",
|
|
35
|
+
"bst",
|
|
36
|
+
"trie",
|
|
37
|
+
"stack"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as url from 'url';
|
|
3
|
+
import * as Benchmark from 'benchmark';
|
|
4
|
+
import { numberFix } from '../utils';
|
|
5
|
+
|
|
6
|
+
function fileToURL(file: string) {
|
|
7
|
+
return url.pathToFileURL(file).href;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function loadTestModule(file: string): Promise<any> {
|
|
11
|
+
if (file.endsWith('.mjs')) {
|
|
12
|
+
return await import(fileToURL(file));
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
return require(file);
|
|
17
|
+
} catch (e: any) {
|
|
18
|
+
if (e && e.code === 'ERR_REQUIRE_ESM') {
|
|
19
|
+
return await import(fileToURL(file));
|
|
20
|
+
}
|
|
21
|
+
throw e;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const file = process.argv[2];
|
|
26
|
+
if (!file) {
|
|
27
|
+
console.error('single-suite-runner requires a test file path.');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
(async () => {
|
|
32
|
+
const testName = path.basename(file).replace(/\.test\.[^.]+$/, '');
|
|
33
|
+
const mod = await loadTestModule(file);
|
|
34
|
+
const suite: Benchmark.Suite | undefined = mod?.suite || mod?.default?.suite;
|
|
35
|
+
|
|
36
|
+
if (!suite) {
|
|
37
|
+
if (process.send) process.send({ testName, benchmarks: [], file });
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
suite.forEach((b: any) => {
|
|
43
|
+
if (typeof b.fn === 'function') b.fn.call(b);
|
|
44
|
+
});
|
|
45
|
+
} catch {}
|
|
46
|
+
|
|
47
|
+
if (global.gc) global.gc();
|
|
48
|
+
|
|
49
|
+
let runTime = 0;
|
|
50
|
+
suite
|
|
51
|
+
.on('complete', function (this: Benchmark.Suite) {
|
|
52
|
+
const benchmarks = this.map((benchmark: any) => {
|
|
53
|
+
runTime += benchmark.times.elapsed;
|
|
54
|
+
return {
|
|
55
|
+
'test name': benchmark.name,
|
|
56
|
+
'time taken (ms)': numberFix(benchmark.times.period * 1000, 2),
|
|
57
|
+
'sample mean (secs)': numberFix(benchmark.stats.mean, 2),
|
|
58
|
+
'sample deviation': numberFix(benchmark.stats.deviation, 2)
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
runTime = Number(runTime.toFixed(2));
|
|
62
|
+
if (process.send) process.send({ testName, benchmarks, runTime, file });
|
|
63
|
+
process.exit(0);
|
|
64
|
+
})
|
|
65
|
+
.run({ async: false });
|
|
66
|
+
})().catch(err => {
|
|
67
|
+
console.error(err);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AVLTreeCounter, AVLTreeCounterNode, AVLTreeNode, BinaryTreeNode, BSTNode } from '../../../../src';
|
|
1
|
+
import { AVLTreeCounter, AVLTreeCounterNode, AVLTreeNode, BinaryTreeNode, BSTNode, IBinaryTree } from '../../../../src';
|
|
2
2
|
import { isDebugTest } from '../../../config';
|
|
3
3
|
|
|
4
4
|
const isDebug = isDebugTest;
|
|
@@ -571,7 +571,7 @@ describe('AVLTreeCounter Performance test', function () {
|
|
|
571
571
|
});
|
|
572
572
|
|
|
573
573
|
it('should the clone method', () => {
|
|
574
|
-
function checkTreeStructure(avlCounter:
|
|
574
|
+
function checkTreeStructure(avlCounter: IBinaryTree<string, number>) {
|
|
575
575
|
expect(avlCounter.size).toBe(4);
|
|
576
576
|
expect(avlCounter.root?.key).toBe('2');
|
|
577
577
|
expect(avlCounter.root?.left?.key).toBe('1');
|
|
@@ -738,7 +738,7 @@ describe('AVLTreeCounter toEntryFn', () => {
|
|
|
738
738
|
{ obj: { id: 5 } }
|
|
739
739
|
])
|
|
740
740
|
).toThrowError(
|
|
741
|
-
`When comparing object types, a custom specifyComparable must be defined in the constructor's options
|
|
741
|
+
`When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
|
|
742
742
|
);
|
|
743
743
|
});
|
|
744
744
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../../src';
|
|
1
|
+
import { AVLTreeMultiMap, AVLTreeMultiMapNode, IBinaryTree } from '../../../../src';
|
|
2
2
|
// import { isDebugTest } from '../../../config';
|
|
3
3
|
|
|
4
4
|
// const isDebug = isDebugTest;
|
|
@@ -70,7 +70,7 @@ describe('AVLTreeMultiMap Test', () => {
|
|
|
70
70
|
|
|
71
71
|
expect(avlTmm.delete(avlTmm.getNode(11))[0].deleted?.key).toBe(11);
|
|
72
72
|
expect(avlTmm.isAVLBalanced()).toBe(true);
|
|
73
|
-
expect(node15 && avlTmm.getHeight(node15)).toBe(
|
|
73
|
+
expect(node15 && avlTmm.getHeight(node15)).toBe(1);
|
|
74
74
|
|
|
75
75
|
expect(avlTmm.delete(1)[0].deleted?.key).toBe(1);
|
|
76
76
|
expect(avlTmm.isAVLBalanced()).toBe(true);
|
|
@@ -198,7 +198,7 @@ describe('AVLTreeMultiMap Test recursively', () => {
|
|
|
198
198
|
|
|
199
199
|
expect(avlTmm.delete(11)[0].deleted?.key).toBe(11);
|
|
200
200
|
expect(avlTmm.isAVLBalanced()).toBe(true);
|
|
201
|
-
expect(node15 && avlTmm.getHeight(node15)).toBe(
|
|
201
|
+
expect(node15 && avlTmm.getHeight(node15)).toBe(1);
|
|
202
202
|
|
|
203
203
|
expect(avlTmm.delete(1)[0].deleted?.key).toBe(1);
|
|
204
204
|
expect(avlTmm.isAVLBalanced()).toBe(true);
|
|
@@ -286,7 +286,7 @@ describe('AVLTreeMultiMap APIs test', () => {
|
|
|
286
286
|
});
|
|
287
287
|
|
|
288
288
|
it('should the clone method', () => {
|
|
289
|
-
function checkTreeStructure(avlTmm:
|
|
289
|
+
function checkTreeStructure(avlTmm: IBinaryTree<string, number[]>) {
|
|
290
290
|
expect(avlTmm.size).toBe(4);
|
|
291
291
|
expect(avlTmm.root?.key).toBe('2');
|
|
292
292
|
expect(avlTmm.root?.left?.key).toBe('1');
|
|
@@ -399,7 +399,7 @@ describe('AVLTreeMultiMap', () => {
|
|
|
399
399
|
});
|
|
400
400
|
|
|
401
401
|
describe('AVLTreeMultiMap iterative methods test', () => {
|
|
402
|
-
let avlTmm: AVLTreeMultiMap<number, string, object
|
|
402
|
+
let avlTmm: AVLTreeMultiMap<number, string, object>;
|
|
403
403
|
beforeEach(() => {
|
|
404
404
|
avlTmm = new AVLTreeMultiMap();
|
|
405
405
|
avlTmm.add([1, ['a']]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AVLTree, AVLTreeNode, BinaryTreeNode, BSTNode } from '../../../../src';
|
|
1
|
+
import { AVLTree, AVLTreeNode, BinaryTreeNode, BSTNode, IBinaryTree } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('AVL Tree Test', () => {
|
|
4
4
|
it('should perform various operations on a AVL Tree', () => {
|
|
@@ -44,7 +44,7 @@ describe('AVL Tree Test', () => {
|
|
|
44
44
|
|
|
45
45
|
expect(avlTree.delete(avlTree.getNode(11))[0].deleted?.key).toBe(11);
|
|
46
46
|
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
47
|
-
expect(node15 && avlTree.getHeight(node15)).toBe(
|
|
47
|
+
expect(node15 && avlTree.getHeight(node15)).toBe(1);
|
|
48
48
|
|
|
49
49
|
expect(avlTree.delete(1)[0].deleted?.key).toBe(1);
|
|
50
50
|
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
@@ -172,7 +172,7 @@ describe('AVL Tree Test recursively', () => {
|
|
|
172
172
|
|
|
173
173
|
expect(avlTree.delete(11)[0].deleted?.key).toBe(11);
|
|
174
174
|
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
175
|
-
expect(node15 && avlTree.getHeight(node15)).toBe(
|
|
175
|
+
expect(node15 && avlTree.getHeight(node15)).toBe(1);
|
|
176
176
|
|
|
177
177
|
expect(avlTree.delete(1)[0].deleted?.key).toBe(1);
|
|
178
178
|
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
@@ -258,7 +258,7 @@ describe('AVLTree APIs test', () => {
|
|
|
258
258
|
});
|
|
259
259
|
|
|
260
260
|
it('should the clone method', () => {
|
|
261
|
-
function checkTreeStructure(avlTree:
|
|
261
|
+
function checkTreeStructure(avlTree: IBinaryTree<string, number>) {
|
|
262
262
|
expect(avlTree.size).toBe(4);
|
|
263
263
|
expect(avlTree.root?.key).toBe('2');
|
|
264
264
|
expect(avlTree.root?.left?.key).toBe('1');
|