data-structure-typed 2.1.2 → 2.2.1
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/CONTRIBUTING.md +4 -0
- package/README.md +66 -21
- package/benchmark/report.html +1 -1
- package/benchmark/report.json +145 -169
- package/dist/cjs/index.cjs +1173 -583
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +13623 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +1173 -583
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +13545 -0
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +61 -5
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +58 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +59 -4
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -3
- package/dist/types/types/data-structures/base/base.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +614 -53
- 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 +20 -2
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-counter.ts +103 -12
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
- package/src/data-structures/binary-tree/avl-tree.ts +109 -16
- package/src/data-structures/binary-tree/binary-tree.ts +3 -2
- package/src/data-structures/binary-tree/bst.ts +104 -12
- package/src/data-structures/binary-tree/red-black-tree.ts +110 -19
- package/src/data-structures/binary-tree/tree-counter.ts +102 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +124 -12
- package/src/data-structures/graph/abstract-graph.ts +8 -8
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/types/data-structures/base/base.ts +1 -1
- package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +39 -36
- package/test/performance/runner-config.json +4 -4
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +8 -7
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/bst.test.ts +5 -5
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +8 -7
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +7 -7
- package/test/unit/data-structures/graph/directed-graph.test.ts +3 -3
- package/test/unit/data-structures/hash/hash-map.test.ts +14 -14
- package/tsup.node.config.js +40 -6
- package/test/performance/reportor.mjs +0 -505
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBinaryTree, RedBlackTree, RedBlackTreeNode } from '../../../../src';
|
|
2
2
|
import { getRandomInt, getRandomIntArray, magnitude } from '../../../utils';
|
|
3
3
|
import { OrderedMap } from 'js-sdsl';
|
|
4
4
|
|
|
@@ -641,14 +641,14 @@ describe('RedBlackTree 2', () => {
|
|
|
641
641
|
|
|
642
642
|
it('The node obtained by get Node should match the node type', () => {
|
|
643
643
|
const node3 = rbTree.getNode(3);
|
|
644
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
645
|
-
expect(node3).toBeInstanceOf(BSTNode);
|
|
644
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
645
|
+
// expect(node3).toBeInstanceOf(BSTNode);
|
|
646
646
|
expect(node3).toBeInstanceOf(RedBlackTreeNode);
|
|
647
647
|
});
|
|
648
648
|
|
|
649
649
|
it('forEach should iterate over all elements', () => {
|
|
650
650
|
const mockCallback = jest.fn();
|
|
651
|
-
rbTree.forEach((
|
|
651
|
+
rbTree.forEach((value, key) => {
|
|
652
652
|
mockCallback(key, value);
|
|
653
653
|
});
|
|
654
654
|
|
|
@@ -659,7 +659,7 @@ describe('RedBlackTree 2', () => {
|
|
|
659
659
|
});
|
|
660
660
|
|
|
661
661
|
it('filter should return a new rbTree with filtered elements', () => {
|
|
662
|
-
const filteredTree = rbTree.filter(key => key > 1);
|
|
662
|
+
const filteredTree = rbTree.filter((_value, key) => key > 1);
|
|
663
663
|
expect(filteredTree.size).toBe(2);
|
|
664
664
|
expect([...filteredTree]).toEqual([
|
|
665
665
|
[2, 'b'],
|
|
@@ -668,7 +668,7 @@ describe('RedBlackTree 2', () => {
|
|
|
668
668
|
});
|
|
669
669
|
|
|
670
670
|
it('map should return a new rbTree with modified elements', () => {
|
|
671
|
-
const rbTreeMapped = rbTree.map((
|
|
671
|
+
const rbTreeMapped = rbTree.map((value, key) => [(key * 2).toString(), value]);
|
|
672
672
|
expect(rbTreeMapped.size).toBe(3);
|
|
673
673
|
expect([...rbTreeMapped]).toEqual([
|
|
674
674
|
['2', 'a'],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBinaryTree, TreeCounter, TreeCounterNode } from '../../../../src';
|
|
2
2
|
import { isDebugTest } from '../../../config';
|
|
3
3
|
import { getRandomInt } from '../../../utils';
|
|
4
4
|
|
|
@@ -757,14 +757,15 @@ describe('TreeCounter iterative methods test', () => {
|
|
|
757
757
|
|
|
758
758
|
it('The node obtained by get Node should match the node type', () => {
|
|
759
759
|
const node3 = treeCounter.getNode(3);
|
|
760
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
761
|
-
expect(node3).toBeInstanceOf(BSTNode);
|
|
762
|
-
expect(node3).toBeInstanceOf(RedBlackTreeNode);
|
|
760
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
761
|
+
// expect(node3).toBeInstanceOf(BSTNode);
|
|
762
|
+
// expect(node3).toBeInstanceOf(RedBlackTreeNode);
|
|
763
|
+
expect(node3).toBeInstanceOf(TreeCounterNode);
|
|
763
764
|
});
|
|
764
765
|
|
|
765
766
|
it('forEach should iterate over all elements', () => {
|
|
766
767
|
const mockCallback = jest.fn();
|
|
767
|
-
treeCounter.forEach((
|
|
768
|
+
treeCounter.forEach((value, key) => {
|
|
768
769
|
mockCallback(key, value);
|
|
769
770
|
});
|
|
770
771
|
|
|
@@ -775,7 +776,7 @@ describe('TreeCounter iterative methods test', () => {
|
|
|
775
776
|
});
|
|
776
777
|
|
|
777
778
|
it('filter should return a new tree with filtered elements', () => {
|
|
778
|
-
const filteredTree = treeCounter.filter(key => key > 1);
|
|
779
|
+
const filteredTree = treeCounter.filter((_value, key) => key > 1);
|
|
779
780
|
expect(filteredTree.size).toBe(2);
|
|
780
781
|
expect([...filteredTree]).toEqual([
|
|
781
782
|
[2, 'b'],
|
|
@@ -784,7 +785,7 @@ describe('TreeCounter iterative methods test', () => {
|
|
|
784
785
|
});
|
|
785
786
|
|
|
786
787
|
it('map should return a new tree with modified elements', () => {
|
|
787
|
-
const treeCounterMapped = treeCounter.map((
|
|
788
|
+
const treeCounterMapped = treeCounter.map((value, key) => [(key * 2).toString(), value]);
|
|
788
789
|
expect(treeCounterMapped.size).toBe(3);
|
|
789
790
|
expect([...treeCounterMapped]).toEqual([
|
|
790
791
|
['2', 'a'],
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBinaryTree, Range, TreeMultiMap, TreeMultiMapNode } from '../../../../src';
|
|
2
2
|
import { getRandomInt } from '../../../utils';
|
|
3
|
-
import { Range } from '../../../../src';
|
|
4
3
|
import { isDebugTest } from '../../../config';
|
|
5
4
|
import { costOfLiving } from './data/cost-of-living-by-country';
|
|
6
5
|
|
|
@@ -637,14 +636,14 @@ describe('TreeMultiMap 2', () => {
|
|
|
637
636
|
|
|
638
637
|
it('The node obtained by get Node should match the node type', () => {
|
|
639
638
|
const node3 = tmm.getNode(3);
|
|
640
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
641
|
-
expect(node3).toBeInstanceOf(BSTNode);
|
|
639
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
640
|
+
// expect(node3).toBeInstanceOf(BSTNode);
|
|
642
641
|
expect(node3).toBeInstanceOf(TreeMultiMapNode);
|
|
643
642
|
});
|
|
644
643
|
|
|
645
644
|
it('forEach should iterate over all elements', () => {
|
|
646
645
|
const mockCallback = jest.fn();
|
|
647
|
-
tmm.forEach((
|
|
646
|
+
tmm.forEach((value, key) => {
|
|
648
647
|
mockCallback(key, value);
|
|
649
648
|
});
|
|
650
649
|
|
|
@@ -655,7 +654,7 @@ describe('TreeMultiMap 2', () => {
|
|
|
655
654
|
});
|
|
656
655
|
|
|
657
656
|
it('filter should return a new tmm with filtered elements', () => {
|
|
658
|
-
const filteredTree = tmm.filter(key => key > 1);
|
|
657
|
+
const filteredTree = tmm.filter((_value, key) => key > 1);
|
|
659
658
|
expect(filteredTree.size).toBe(2);
|
|
660
659
|
expect([...filteredTree]).toEqual([
|
|
661
660
|
[2, ['b']],
|
|
@@ -664,7 +663,7 @@ describe('TreeMultiMap 2', () => {
|
|
|
664
663
|
});
|
|
665
664
|
|
|
666
665
|
it('map should return a new tmm with modified elements', () => {
|
|
667
|
-
const tmmMapped = tmm.map((
|
|
666
|
+
const tmmMapped = tmm.map((value, key) => [(key * 2).toString(), value ? value : []]);
|
|
668
667
|
expect(tmmMapped.size).toBe(3);
|
|
669
668
|
expect([...tmmMapped]).toEqual([
|
|
670
669
|
['2', ['a']],
|
|
@@ -1023,6 +1022,7 @@ function leftKey(tmm: TreeMultiMap<number, Product, Product>): number | undefine
|
|
|
1023
1022
|
const v = tmm.getLeftMost();
|
|
1024
1023
|
return v == null ? undefined : typeof v === 'object' ? v.key : v;
|
|
1025
1024
|
}
|
|
1025
|
+
|
|
1026
1026
|
function rightKey(tmm: TreeMultiMap<number, Product, Product>): number | undefined {
|
|
1027
1027
|
const v = tmm.getRightMost();
|
|
1028
1028
|
return v == null ? undefined : typeof v === 'object' ? v.key : v;
|
|
@@ -680,12 +680,12 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
680
680
|
|
|
681
681
|
it('forEach should apply a function to each vertex', () => {
|
|
682
682
|
const result: VertexKey[] = [];
|
|
683
|
-
graph.forEach(key => key && result.push(key));
|
|
683
|
+
graph.forEach((_value, key) => key && result.push(key));
|
|
684
684
|
expect(result).toEqual(vertexMap);
|
|
685
685
|
});
|
|
686
686
|
|
|
687
687
|
it('filter should return vertexMap that satisfy the condition', () => {
|
|
688
|
-
const filtered = graph.filterEntries(key => key === 'A' || key === 'B');
|
|
688
|
+
const filtered = graph.filterEntries((_value, key) => key === 'A' || key === 'B');
|
|
689
689
|
expect(filtered).toEqual([
|
|
690
690
|
['A', undefined],
|
|
691
691
|
['B', undefined]
|
|
@@ -693,7 +693,7 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
693
693
|
});
|
|
694
694
|
|
|
695
695
|
it('map should apply a function to each vertex and return a new array', () => {
|
|
696
|
-
const mapped = graph.map(vertex => vertex + '_mapped');
|
|
696
|
+
const mapped = graph.map((_value, vertex) => vertex + '_mapped');
|
|
697
697
|
expect(mapped).toEqual(vertexMap.map(key => key + '_mapped'));
|
|
698
698
|
});
|
|
699
699
|
|
|
@@ -328,7 +328,7 @@ describe('HashMap', () => {
|
|
|
328
328
|
});
|
|
329
329
|
|
|
330
330
|
it('some() returns true if any element matches the condition', () => {
|
|
331
|
-
expect(hashMap.some(key => key === 'key1')).toBe(true);
|
|
331
|
+
expect(hashMap.some((_value, key) => key === 'key1')).toBe(true);
|
|
332
332
|
});
|
|
333
333
|
|
|
334
334
|
it('forEach() should execute a function for each element', () => {
|
|
@@ -338,12 +338,12 @@ describe('HashMap', () => {
|
|
|
338
338
|
});
|
|
339
339
|
|
|
340
340
|
it('map() should transform each element', () => {
|
|
341
|
-
const newHashMap = hashMap.map(
|
|
341
|
+
const newHashMap = hashMap.map(value => value.toUpperCase());
|
|
342
342
|
expect(newHashMap.get('key1')).toBe('VALUE1');
|
|
343
343
|
});
|
|
344
344
|
|
|
345
345
|
it('filter() should remove elements that do not match the condition', () => {
|
|
346
|
-
const filteredHashMap = hashMap.filter(key => key !== 'key1');
|
|
346
|
+
const filteredHashMap = hashMap.filter((_, key) => key !== 'key1');
|
|
347
347
|
expect(filteredHashMap.has('key1')).toBe(false);
|
|
348
348
|
});
|
|
349
349
|
|
|
@@ -361,28 +361,28 @@ describe('HashMap', () => {
|
|
|
361
361
|
});
|
|
362
362
|
|
|
363
363
|
it('should find', () => {
|
|
364
|
-
const found = hashMap.find(
|
|
364
|
+
const found = hashMap.find(value => value === 'value1');
|
|
365
365
|
expect(found).toEqual(['key1', 'value1']);
|
|
366
366
|
const notFound = hashMap.find(value => value === 'value6');
|
|
367
367
|
expect(notFound).toEqual(undefined);
|
|
368
368
|
});
|
|
369
369
|
|
|
370
370
|
it('should every', () => {
|
|
371
|
-
const isEvery = hashMap.every(
|
|
371
|
+
const isEvery = hashMap.every(value => value.substring(0, 5) === 'value');
|
|
372
372
|
expect(isEvery).toEqual(true);
|
|
373
|
-
const isEvery4 = hashMap.every(
|
|
373
|
+
const isEvery4 = hashMap.every(value => value.substring(0, 4) === 'value');
|
|
374
374
|
expect(isEvery4).toEqual(false);
|
|
375
375
|
});
|
|
376
376
|
|
|
377
377
|
it('should some', () => {
|
|
378
|
-
const isSome = hashMap.some(
|
|
378
|
+
const isSome = hashMap.some(value => value.substring(5, 6) === '2');
|
|
379
379
|
expect(isSome).toEqual(true);
|
|
380
|
-
const isSome4 = hashMap.some(
|
|
380
|
+
const isSome4 = hashMap.some(value => value.substring(0, 5) === 'value');
|
|
381
381
|
expect(isSome4).toEqual(true);
|
|
382
382
|
});
|
|
383
383
|
|
|
384
384
|
it('should forEach', () => {
|
|
385
|
-
hashMap.forEach((
|
|
385
|
+
hashMap.forEach((value, key, index) => expect(value.substring(5, 6)).toBe(String(index + 1)));
|
|
386
386
|
});
|
|
387
387
|
|
|
388
388
|
it('should entries', () => {
|
|
@@ -817,7 +817,7 @@ describe('LinkedHashMap', () => {
|
|
|
817
817
|
});
|
|
818
818
|
|
|
819
819
|
it('some() returns true if any element matches the condition', () => {
|
|
820
|
-
expect(hashMap.some(key => key === 'key1')).toBe(true);
|
|
820
|
+
expect(hashMap.some((_value, key) => key === 'key1')).toBe(true);
|
|
821
821
|
});
|
|
822
822
|
|
|
823
823
|
it('forEach() should execute a function for each element', () => {
|
|
@@ -827,12 +827,12 @@ describe('LinkedHashMap', () => {
|
|
|
827
827
|
});
|
|
828
828
|
|
|
829
829
|
it('map() should transform each element', () => {
|
|
830
|
-
const newHashMap = hashMap.map((
|
|
830
|
+
const newHashMap = hashMap.map((value, key) => [key, value.toUpperCase()]);
|
|
831
831
|
expect(newHashMap.get('key1')).toBe('VALUE1');
|
|
832
832
|
});
|
|
833
833
|
|
|
834
834
|
it('filter() should remove elements that do not match the condition', () => {
|
|
835
|
-
const filteredHashMap = hashMap.filter(key => key !== 'key1');
|
|
835
|
+
const filteredHashMap = hashMap.filter((_v, key) => key !== 'key1');
|
|
836
836
|
expect(filteredHashMap.has('key1')).toBe(false);
|
|
837
837
|
});
|
|
838
838
|
|
|
@@ -893,7 +893,7 @@ describe('classic uses', () => {
|
|
|
893
893
|
linkedHashMap.set(2, 'B');
|
|
894
894
|
linkedHashMap.set(3, 'C');
|
|
895
895
|
|
|
896
|
-
const filteredMap = linkedHashMap.filter(
|
|
896
|
+
const filteredMap = linkedHashMap.filter(value => value !== 'B');
|
|
897
897
|
|
|
898
898
|
const result = Array.from(filteredMap);
|
|
899
899
|
expect(result).toEqual([
|
|
@@ -907,7 +907,7 @@ describe('classic uses', () => {
|
|
|
907
907
|
linkedHashMap.set(1, 'A');
|
|
908
908
|
linkedHashMap.set(2, 'B');
|
|
909
909
|
|
|
910
|
-
const mappedMap = linkedHashMap.map((
|
|
910
|
+
const mappedMap = linkedHashMap.map((value, key) => [value, key]);
|
|
911
911
|
|
|
912
912
|
const result = Array.from(mappedMap);
|
|
913
913
|
expect(result).toEqual([
|
package/tsup.node.config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineConfig } from "tsup";
|
|
2
2
|
|
|
3
3
|
export default defineConfig([
|
|
4
|
-
// ESM
|
|
4
|
+
// ESM (modern) - ES2022
|
|
5
5
|
{
|
|
6
6
|
entry: { index: "src/index.ts" },
|
|
7
7
|
format: ["esm"],
|
|
@@ -12,13 +12,30 @@ export default defineConfig([
|
|
|
12
12
|
keepNames: true,
|
|
13
13
|
treeshake: true,
|
|
14
14
|
clean: true,
|
|
15
|
+
target: "es2022",
|
|
16
|
+
outExtension() {
|
|
17
|
+
return { js: ".mjs" };
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// ESM (legacy) - ES2018
|
|
22
|
+
{
|
|
23
|
+
entry: { index: "src/index.ts" },
|
|
24
|
+
format: ["esm"],
|
|
25
|
+
outDir: "dist/esm-legacy",
|
|
26
|
+
splitting: false,
|
|
27
|
+
sourcemap: true,
|
|
28
|
+
minify: false,
|
|
29
|
+
keepNames: true,
|
|
30
|
+
treeshake: true,
|
|
31
|
+
clean: false,
|
|
15
32
|
target: "es2018",
|
|
16
33
|
outExtension() {
|
|
17
|
-
return { js: ".mjs" }
|
|
18
|
-
}
|
|
34
|
+
return { js: ".mjs" };
|
|
35
|
+
}
|
|
19
36
|
},
|
|
20
37
|
|
|
21
|
-
// CJS
|
|
38
|
+
// CJS (modern) - ES2022
|
|
22
39
|
{
|
|
23
40
|
entry: { index: "src/index.ts" },
|
|
24
41
|
format: ["cjs"],
|
|
@@ -29,9 +46,26 @@ export default defineConfig([
|
|
|
29
46
|
keepNames: true,
|
|
30
47
|
treeshake: true,
|
|
31
48
|
clean: false,
|
|
32
|
-
target: "
|
|
49
|
+
target: "es2022",
|
|
33
50
|
outExtension() {
|
|
34
51
|
return { js: ".cjs" };
|
|
35
|
-
}
|
|
52
|
+
}
|
|
36
53
|
},
|
|
54
|
+
|
|
55
|
+
// CJS (legacy) - ES2018
|
|
56
|
+
{
|
|
57
|
+
entry: { index: "src/index.ts" },
|
|
58
|
+
format: ["cjs"],
|
|
59
|
+
outDir: "dist/cjs-legacy",
|
|
60
|
+
splitting: false,
|
|
61
|
+
sourcemap: true,
|
|
62
|
+
minify: false,
|
|
63
|
+
keepNames: true,
|
|
64
|
+
treeshake: true,
|
|
65
|
+
clean: false,
|
|
66
|
+
target: "es2018",
|
|
67
|
+
outExtension() {
|
|
68
|
+
return { js: ".cjs" };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
37
71
|
]);
|