data-structure-typed 2.2.4 → 2.2.6
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/dist/cjs/index.cjs +327 -57
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +329 -57
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +327 -57
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +329 -57
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +14 -57
- package/dist/types/data-structures/binary-tree/bst.d.ts +110 -96
- package/dist/umd/data-structure-typed.js +329 -57
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -3
- package/src/common/index.ts +2 -4
- package/src/data-structures/base/iterable-entry-base.ts +9 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +3 -1
- package/src/data-structures/binary-tree/binary-tree.ts +67 -0
- package/src/data-structures/binary-tree/bst.ts +658 -71
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/bst.test.ts +1385 -318
- package/test/unit/data-structures/binary-tree/overall.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +13 -11
- package/tsup.config.js +6 -0
- package/tsup.leetcode.config.js +3 -0
- package/tsup.node.config.js +12 -0
|
@@ -58,7 +58,7 @@ describe('Overall BinaryTree Test', () => {
|
|
|
58
58
|
it('Should clone a BST works fine', () => {
|
|
59
59
|
const bst = new BST<number>([3, 6, 7, 1, 9], {
|
|
60
60
|
iterationType: 'RECURSIVE',
|
|
61
|
-
comparator: (a, b) => b - a
|
|
61
|
+
comparator: (a, b) => b - a
|
|
62
62
|
});
|
|
63
63
|
expect(bst.size).toBe(5);
|
|
64
64
|
expect(bst.root?.key).toBe(6);
|
|
@@ -100,7 +100,7 @@ describe('Overall BinaryTree Test', () => {
|
|
|
100
100
|
it('Should clone a AVLTree works fine', () => {
|
|
101
101
|
const avl = new AVLTree<number>([3, 6, 7, 1, 9], {
|
|
102
102
|
iterationType: 'RECURSIVE',
|
|
103
|
-
comparator: (a, b) => b - a
|
|
103
|
+
comparator: (a, b) => b - a
|
|
104
104
|
});
|
|
105
105
|
expect(avl.size).toBe(5);
|
|
106
106
|
avl.add(2);
|
|
@@ -821,7 +821,7 @@ describe('RedBlackTree - _deleteFixup', () => {
|
|
|
821
821
|
describe('real world data', () => {
|
|
822
822
|
it('cost of living', () => {
|
|
823
823
|
const indexedByRank = new RedBlackTree(costOfLiving, {
|
|
824
|
-
|
|
824
|
+
comparator: (a, b) => a.rank - b.rank,
|
|
825
825
|
toEntryFn: raw => [raw, undefined]
|
|
826
826
|
});
|
|
827
827
|
expect(indexedByRank.size).toBe(7);
|
|
@@ -820,7 +820,7 @@ describe('real world data', () => {
|
|
|
820
820
|
it('cost of living', () => {
|
|
821
821
|
const indexedByRank = new TreeMultiMap(costOfLiving, {
|
|
822
822
|
toEntryFn: raw => [raw, undefined],
|
|
823
|
-
comparator: (a, b) => a.rank - b.rank
|
|
823
|
+
comparator: (a, b) => a.rank - b.rank
|
|
824
824
|
});
|
|
825
825
|
expect(indexedByRank.size).toBe(7);
|
|
826
826
|
expect(indexedByRank.dfs(node => node?.key?.country)).toEqual([
|
|
@@ -1019,13 +1019,11 @@ function buildIndex(sample: Product[]): TreeMultiMap<number, Product, Product> {
|
|
|
1019
1019
|
|
|
1020
1020
|
// Helper: normalize getLeftMost/getRightMost return (key or node.key)
|
|
1021
1021
|
function leftKey(tmm: TreeMultiMap<number, Product, Product>): number | undefined {
|
|
1022
|
-
|
|
1023
|
-
return v == null ? undefined : typeof v === 'object' ? v.key : v;
|
|
1022
|
+
return tmm.getLeftMost();
|
|
1024
1023
|
}
|
|
1025
1024
|
|
|
1026
1025
|
function rightKey(tmm: TreeMultiMap<number, Product, Product>): number | undefined {
|
|
1027
|
-
|
|
1028
|
-
return v == null ? undefined : typeof v === 'object' ? v.key : v;
|
|
1026
|
+
return tmm.getRightMost();
|
|
1029
1027
|
}
|
|
1030
1028
|
|
|
1031
1029
|
describe('TreeMultiMap — rangeSearch-driven semantics', () => {
|
|
@@ -1083,13 +1081,17 @@ describe('TreeMultiMap — rangeSearch-driven semantics', () => {
|
|
|
1083
1081
|
const lo = tmm.getLeftMost(); // expected 12.9
|
|
1084
1082
|
const hi = tmm.getRightMost(); // expected 199
|
|
1085
1083
|
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1084
|
+
if (lo !== undefined && hi !== undefined) {
|
|
1085
|
+
const groups = tmm.rangeSearch(new Range(lo, hi, true, true), node => ({
|
|
1086
|
+
key: node.key,
|
|
1087
|
+
count: node.value!.length
|
|
1088
|
+
}));
|
|
1090
1089
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1090
|
+
// 12.9:1 | 35.5:2 | 79.9:2 | 99:1 | 120:1 | 199:1
|
|
1091
|
+
expect(groups.map(g => `${g.key}:${g.count}`).join(' | ')).toBe(
|
|
1092
|
+
'12.9:1 | 35.5:2 | 79.9:2 | 99:1 | 120:1 | 199:1'
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1093
1095
|
});
|
|
1094
1096
|
|
|
1095
1097
|
it('empty TreeMultiMap → rangeSearch returns empty results', () => {
|
package/tsup.config.js
CHANGED
|
@@ -12,6 +12,9 @@ export default defineConfig([
|
|
|
12
12
|
globalName: "dataStructureTyped",
|
|
13
13
|
platform: "browser",
|
|
14
14
|
outExtension: () => ({ js: '.min.js' }),
|
|
15
|
+
esbuildOptions(options) {
|
|
16
|
+
options.drop = ['debugger', 'console']
|
|
17
|
+
}
|
|
15
18
|
},
|
|
16
19
|
{
|
|
17
20
|
entry: { "data-structure-typed": "src/index.ts" },
|
|
@@ -24,5 +27,8 @@ export default defineConfig([
|
|
|
24
27
|
globalName: "dataStructureTyped",
|
|
25
28
|
platform: "browser",
|
|
26
29
|
outExtension: () => ({ js: '.js' }),
|
|
30
|
+
esbuildOptions(options) {
|
|
31
|
+
options.drop = ['debugger', 'console']
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
34
|
]);
|
package/tsup.leetcode.config.js
CHANGED
|
@@ -17,6 +17,9 @@ const commonConfig = {
|
|
|
17
17
|
outExtension() {
|
|
18
18
|
return { js: '.mjs' };
|
|
19
19
|
},
|
|
20
|
+
esbuildOptions(options) {
|
|
21
|
+
options.drop = ['debugger', 'console']
|
|
22
|
+
},
|
|
20
23
|
|
|
21
24
|
// The true ultimate solution: automatic cleaning up of comments after the build is complete
|
|
22
25
|
onSuccess: async () => {
|
package/tsup.node.config.js
CHANGED
|
@@ -15,6 +15,9 @@ export default defineConfig([
|
|
|
15
15
|
target: "es2022",
|
|
16
16
|
outExtension() {
|
|
17
17
|
return { js: ".mjs" };
|
|
18
|
+
},
|
|
19
|
+
esbuildOptions(options) {
|
|
20
|
+
options.drop = ['debugger', 'console']
|
|
18
21
|
}
|
|
19
22
|
},
|
|
20
23
|
|
|
@@ -32,6 +35,9 @@ export default defineConfig([
|
|
|
32
35
|
target: "es2018",
|
|
33
36
|
outExtension() {
|
|
34
37
|
return { js: ".mjs" };
|
|
38
|
+
},
|
|
39
|
+
esbuildOptions(options) {
|
|
40
|
+
options.drop = ['debugger', 'console']
|
|
35
41
|
}
|
|
36
42
|
},
|
|
37
43
|
|
|
@@ -49,6 +55,9 @@ export default defineConfig([
|
|
|
49
55
|
target: "es2022",
|
|
50
56
|
outExtension() {
|
|
51
57
|
return { js: ".cjs" };
|
|
58
|
+
},
|
|
59
|
+
esbuildOptions(options) {
|
|
60
|
+
options.drop = ['debugger', 'console']
|
|
52
61
|
}
|
|
53
62
|
},
|
|
54
63
|
|
|
@@ -66,6 +75,9 @@ export default defineConfig([
|
|
|
66
75
|
target: "es2018",
|
|
67
76
|
outExtension() {
|
|
68
77
|
return { js: ".cjs" };
|
|
78
|
+
},
|
|
79
|
+
esbuildOptions(options) {
|
|
80
|
+
options.drop = ['debugger', 'console']
|
|
69
81
|
}
|
|
70
82
|
}
|
|
71
83
|
]);
|