data-structure-typed 1.50.2 → 1.50.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.
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -13
- package/CHANGELOG.md +1 -1
- package/README.md +23 -21
- package/README_zh-CN.md +7 -7
- package/SPECIFICATION.md +56 -0
- package/SPONSOR-zh-CN.md +90 -0
- package/SPONSOR.md +54 -0
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +149 -155
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/cjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +50 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/cjs/data-structures/binary-tree/bst.js +51 -20
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/cjs/data-structures/binary-tree/index.js +2 -1
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +90 -24
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +400 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -189
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js +126 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/cjs/data-structures/hash/hash-map.js +196 -62
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/cjs/data-structures/heap/heap.js +29 -20
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +83 -25
- 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 +26 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +34 -3
- 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 +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- 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 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- 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 +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/cjs/data-structures/queue/deque.js +100 -16
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/cjs/data-structures/queue/queue.js +65 -45
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/cjs/data-structures/stack/stack.js +36 -22
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/cjs/data-structures/tree/tree.js +77 -11
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/cjs/data-structures/trie/trie.js +115 -36
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js +2 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/binary-tree/{tree-multimap.js → tree-multi-map.js} +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/mjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/mjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +46 -9
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +34 -2
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/mjs/data-structures/binary-tree/bst.js +51 -20
- package/dist/mjs/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/mjs/data-structures/binary-tree/index.js +2 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +91 -25
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +397 -0
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -188
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/mjs/data-structures/graph/undirected-graph.js +127 -19
- package/dist/mjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/mjs/data-structures/hash/hash-map.js +204 -70
- package/dist/mjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/mjs/data-structures/heap/heap.js +29 -20
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +86 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +36 -5
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/mjs/data-structures/matrix/matrix.js +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/mjs/data-structures/queue/deque.js +105 -21
- package/dist/mjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/mjs/data-structures/queue/queue.js +65 -45
- package/dist/mjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/mjs/data-structures/stack/stack.js +36 -22
- package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/mjs/data-structures/tree/tree.js +80 -14
- package/dist/mjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/mjs/data-structures/trie/trie.js +118 -39
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/mjs/types/data-structures/binary-tree/index.js +2 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.js +1 -0
- package/dist/umd/data-structure-typed.js +1876 -656
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +59 -58
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +51 -19
- package/src/data-structures/binary-tree/index.ts +2 -1
- package/src/data-structures/binary-tree/rb-tree.ts +99 -28
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
- package/src/types/data-structures/binary-tree/index.ts +2 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
- package/test/integration/index.html +2 -2
- package/test/performance/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/{tree-multimap.test.ts → avl-tree-multi-map.test.ts} +55 -55
- package/test/unit/data-structures/binary-tree/overall.test.ts +24 -25
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +706 -0
- package/test/unit/data-structures/graph/abstract-graph.test.ts +3 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +189 -253
- package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
- package/test/unit/data-structures/queue/queue.test.ts +2 -0
- package/test/unit/unrestricted-interconversion.test.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.js.map +0 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
- /package/dist/mjs/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
|
@@ -78,7 +78,7 @@ describe('DirectedGraph Operation Test', () => {
|
|
|
78
78
|
expect(graph.outDegreeOf(vertexC)).toBe(0);
|
|
79
79
|
expect(graph.edgesOf(vertexC)?.length).toBe(1);
|
|
80
80
|
|
|
81
|
-
expect(graph.tarjan(
|
|
81
|
+
expect(graph.tarjan().dfnMap.size).toBe(3);
|
|
82
82
|
expect(graph.bellmanFord(vertexC, true, true, true)?.paths.length).toBe(3);
|
|
83
83
|
expect(graph.getMinPathBetween('B', 'C', true)?.length).toBe(2);
|
|
84
84
|
expect(graph.setEdgeWeight('B', 'C', 100)).toBe(true);
|
|
@@ -634,14 +634,14 @@ describe('cycles, strongly connected components, bridges, articular points in Di
|
|
|
634
634
|
graph.addEdge('H', 'F');
|
|
635
635
|
const cycles = graph.getCycles();
|
|
636
636
|
const scCs = graph.getSCCs();
|
|
637
|
-
const bridges = graph.getBridges();
|
|
638
|
-
const
|
|
637
|
+
// const bridges = graph.getBridges();
|
|
638
|
+
// const cutVertices = graph.getCutVertices();
|
|
639
639
|
const dfnMap = graph.getDFNMap();
|
|
640
640
|
const lowMap = graph.getLowMap();
|
|
641
641
|
expect(cycles.length).toBe(2);
|
|
642
642
|
expect(scCs.size).toBe(5);
|
|
643
|
-
expect(bridges.length).toBe(4);
|
|
644
|
-
expect(
|
|
643
|
+
// expect(bridges.length).toBe(4);
|
|
644
|
+
// expect(cutVertices.length).toBe(4);
|
|
645
645
|
expect(dfnMap.size).toBe(8);
|
|
646
646
|
expect(lowMap.size).toBe(8);
|
|
647
647
|
});
|
|
@@ -811,251 +811,187 @@ describe('DirectedGraph getCycles', () => {
|
|
|
811
811
|
});
|
|
812
812
|
});
|
|
813
813
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
// ['H', 'J', 'K'],
|
|
999
|
-
// ['E', 'F', 'G'],
|
|
1000
|
-
// ['B', 'C', 'H', 'I', 'D']
|
|
1001
|
-
// ]);
|
|
1002
|
-
// });
|
|
1003
|
-
//
|
|
1004
|
-
// test('should more cuttable graph tarjan SCCs return correct result', () => {
|
|
1005
|
-
// const graph = createExampleGraph4();
|
|
1006
|
-
// const sccs = graph.tarjan(false, false, true, false).SCCs;
|
|
1007
|
-
// expect(sccs.size).toBe(3);
|
|
1008
|
-
// expect(getAsVerticesArrays(sccs)).toEqual([['A'], ['B', 'C', 'D', 'H', 'I', 'J', 'K'], ['E', 'F', 'G']]);
|
|
1009
|
-
// });
|
|
1010
|
-
//
|
|
1011
|
-
// test('should more cuttable graph tarjan cut vertexes return correct result', () => {
|
|
1012
|
-
// const graph = createExampleGraph4();
|
|
1013
|
-
// const cutVertexes = graph.tarjan(true, false, false, false).cutVertexes;
|
|
1014
|
-
// expect(cutVertexes.length).toBe(4);
|
|
1015
|
-
// expect(cutVertexes.map(cv => cv.key)).toEqual(['B', 'E', 'A', 'H']);
|
|
1016
|
-
// });
|
|
1017
|
-
//
|
|
1018
|
-
// test('should more cuttable graph tarjan bridges return correct result', () => {
|
|
1019
|
-
// const graph = createExampleGraph4();
|
|
1020
|
-
// const bridges = graph.tarjan(false, true, false, false).bridges;
|
|
1021
|
-
// expect(bridges.length).toBe(2);
|
|
1022
|
-
// expect(bridges.map(b => '' + b.src + b.dest)).toEqual(['AB', 'AE']);
|
|
1023
|
-
// });
|
|
1024
|
-
//
|
|
1025
|
-
// function createExampleGraph5() {
|
|
1026
|
-
// const graph = createExampleGraph4();
|
|
1027
|
-
// graph.addEdge('F', 'H');
|
|
1028
|
-
// return graph;
|
|
1029
|
-
// }
|
|
1030
|
-
//
|
|
1031
|
-
// test('should uncuttable graph tarjan cycles return correct result', () => {
|
|
1032
|
-
// const graph = createExampleGraph5();
|
|
1033
|
-
// const cycles = graph.tarjan(false, false, false, true).cycles;
|
|
1034
|
-
// expect(cycles.size).toBe(4);
|
|
1035
|
-
// expect(getAsVerticesArrays(cycles)).toEqual([
|
|
1036
|
-
// ['B', 'C', 'D'],
|
|
1037
|
-
// ['H', 'J', 'K'],
|
|
1038
|
-
// ['E', 'F', 'G'],
|
|
1039
|
-
// ['B', 'C', 'H', 'I', 'D']
|
|
1040
|
-
// ]);
|
|
1041
|
-
// });
|
|
1042
|
-
//
|
|
1043
|
-
// test('should uncuttable graph tarjan SCCs return correct result', () => {
|
|
1044
|
-
// const graph = createExampleGraph5();
|
|
1045
|
-
// const sccs = graph.tarjan(false, false, true, false).SCCs;
|
|
1046
|
-
// expect(sccs.size).toBe(3);
|
|
1047
|
-
// expect(getAsVerticesArrays(sccs)).toEqual([['A'], ['B', 'C', 'D', 'H', 'I', 'J', 'K'], ['E', 'F', 'G']]);
|
|
1048
|
-
// });
|
|
1049
|
-
//
|
|
1050
|
-
// test('should uncuttable graph tarjan cut vertexes return correct result', () => {
|
|
1051
|
-
// const graph = createExampleGraph5();
|
|
1052
|
-
// const cutVertexes = graph.tarjan(true, false, false, false).cutVertexes;
|
|
1053
|
-
// expect(cutVertexes.length).toBe(0);
|
|
1054
|
-
// });
|
|
1055
|
-
//
|
|
1056
|
-
// test('should uncuttable graph tarjan bridges return correct result', () => {
|
|
1057
|
-
// const graph = createExampleGraph5();
|
|
1058
|
-
// const bridges = graph.tarjan(false, true, false, false).bridges;
|
|
1059
|
-
// expect(bridges.length).toBe(0);
|
|
1060
|
-
// });
|
|
1061
|
-
// });
|
|
814
|
+
describe('DirectedGraph tarjan', () => {
|
|
815
|
+
test('should simple cycles graph tarjan cycles return correct result', () => {
|
|
816
|
+
const graph = new DirectedGraph();
|
|
817
|
+
|
|
818
|
+
graph.addVertex('A');
|
|
819
|
+
graph.addVertex('B');
|
|
820
|
+
graph.addVertex('C');
|
|
821
|
+
graph.addVertex('D');
|
|
822
|
+
|
|
823
|
+
graph.addEdge('A', 'B');
|
|
824
|
+
graph.addEdge('B', 'C');
|
|
825
|
+
graph.addEdge('C', 'A');
|
|
826
|
+
graph.addEdge('A', 'D');
|
|
827
|
+
graph.addEdge('D', 'C');
|
|
828
|
+
const cycles = graph.getCycles();
|
|
829
|
+
expect(cycles.length).toBe(2);
|
|
830
|
+
expect(cycles).toEqual([
|
|
831
|
+
['A', 'B', 'C'],
|
|
832
|
+
['A', 'D', 'C']
|
|
833
|
+
]);
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
function getAsVerticesArrays(vss: Map<number, DirectedVertex<any>[]>) {
|
|
837
|
+
return [...vss.values()].map(vs => vs.map(vertex => vertex.key));
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function createExampleGraph1() {
|
|
841
|
+
const graph = new DirectedGraph();
|
|
842
|
+
graph.addVertex('A');
|
|
843
|
+
graph.addVertex('B');
|
|
844
|
+
graph.addVertex('C');
|
|
845
|
+
graph.addVertex('D');
|
|
846
|
+
graph.addVertex('E');
|
|
847
|
+
graph.addEdge('A', 'B');
|
|
848
|
+
graph.addEdge('A', 'C');
|
|
849
|
+
graph.addEdge('B', 'D');
|
|
850
|
+
graph.addEdge('C', 'D');
|
|
851
|
+
graph.addEdge('D', 'E');
|
|
852
|
+
graph.addEdge('E', 'B');
|
|
853
|
+
return graph;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
test('should tarjan cycles return correct result', () => {
|
|
857
|
+
const graph = createExampleGraph1();
|
|
858
|
+
const cycles = graph.getCycles();
|
|
859
|
+
expect(cycles.length).toBe(1);
|
|
860
|
+
expect(cycles).toEqual([['B', 'D', 'E']]);
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
test('should tarjan SCCs return correct result', () => {
|
|
864
|
+
const graph = createExampleGraph1();
|
|
865
|
+
const sccs = graph.tarjan().SCCs;
|
|
866
|
+
expect(sccs.size).toBe(3);
|
|
867
|
+
expect(getAsVerticesArrays(sccs)).toEqual([['E', 'D', 'B'], ['C'], ['A']]);
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
function createExampleGraph2() {
|
|
871
|
+
const graph = createExampleGraph1();
|
|
872
|
+
graph.addVertex('F');
|
|
873
|
+
graph.addVertex('G');
|
|
874
|
+
graph.addEdge('B', 'F');
|
|
875
|
+
graph.addEdge('F', 'E');
|
|
876
|
+
graph.addEdge('C', 'G');
|
|
877
|
+
graph.addEdge('G', 'A');
|
|
878
|
+
return graph;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
test('should 3 cycles graph tarjan cycles return correct result', () => {
|
|
882
|
+
const graph = createExampleGraph2();
|
|
883
|
+
const cycles = graph.getCycles();
|
|
884
|
+
expect(cycles.length).toBe(3);
|
|
885
|
+
expect(cycles).toEqual([
|
|
886
|
+
['A', 'C', 'G'],
|
|
887
|
+
['B', 'D', 'E'],
|
|
888
|
+
['B', 'F', 'E']
|
|
889
|
+
]);
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
test('should 3 cycles graph tarjan SCCs return correct result', () => {
|
|
893
|
+
const graph = createExampleGraph2();
|
|
894
|
+
const sccs = graph.tarjan().SCCs;
|
|
895
|
+
expect(sccs.size).toBe(2);
|
|
896
|
+
expect(getAsVerticesArrays(sccs)).toEqual([
|
|
897
|
+
['F', 'E', 'D', 'B'],
|
|
898
|
+
['G', 'C', 'A']
|
|
899
|
+
]);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
function createExampleGraph3() {
|
|
903
|
+
const graph = new DirectedGraph();
|
|
904
|
+
graph.addVertex('A');
|
|
905
|
+
graph.addVertex('B');
|
|
906
|
+
graph.addVertex('C');
|
|
907
|
+
graph.addVertex('D');
|
|
908
|
+
graph.addVertex('E');
|
|
909
|
+
graph.addVertex('F');
|
|
910
|
+
graph.addVertex('G');
|
|
911
|
+
graph.addEdge('A', 'B');
|
|
912
|
+
graph.addEdge('B', 'C');
|
|
913
|
+
graph.addEdge('C', 'D');
|
|
914
|
+
graph.addEdge('D', 'B');
|
|
915
|
+
graph.addEdge('A', 'E');
|
|
916
|
+
graph.addEdge('E', 'F');
|
|
917
|
+
graph.addEdge('F', 'G');
|
|
918
|
+
graph.addEdge('G', 'E');
|
|
919
|
+
return graph;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
test('should cuttable graph tarjan cycles return correct result', () => {
|
|
923
|
+
const graph = createExampleGraph3();
|
|
924
|
+
const cycles = graph.getCycles();
|
|
925
|
+
expect(cycles.length).toBe(2);
|
|
926
|
+
expect(cycles).toEqual([
|
|
927
|
+
['B', 'C', 'D'],
|
|
928
|
+
['E', 'F', 'G']
|
|
929
|
+
]);
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
test('should cuttable graph tarjan SCCs return correct result', () => {
|
|
933
|
+
const graph = createExampleGraph3();
|
|
934
|
+
const sccs = graph.tarjan().SCCs;
|
|
935
|
+
expect(sccs.size).toBe(3);
|
|
936
|
+
expect(getAsVerticesArrays(sccs)).toEqual([['D', 'C', 'B'], ['G', 'F', 'E'], ['A']]);
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
function createExampleGraph4() {
|
|
940
|
+
const graph = createExampleGraph3();
|
|
941
|
+
graph.addVertex('H');
|
|
942
|
+
graph.addVertex('I');
|
|
943
|
+
graph.addVertex('J');
|
|
944
|
+
graph.addVertex('K');
|
|
945
|
+
graph.addEdge('C', 'H');
|
|
946
|
+
graph.addEdge('H', 'I');
|
|
947
|
+
graph.addEdge('I', 'D');
|
|
948
|
+
graph.addEdge('H', 'J');
|
|
949
|
+
graph.addEdge('J', 'K');
|
|
950
|
+
graph.addEdge('K', 'H');
|
|
951
|
+
return graph;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
test('should more cuttable graph tarjan cycles return correct result', () => {
|
|
955
|
+
const graph = createExampleGraph4();
|
|
956
|
+
const cycles = graph.getCycles();
|
|
957
|
+
expect(cycles.length).toBe(4);
|
|
958
|
+
expect(cycles).toEqual([
|
|
959
|
+
['B', 'C', 'D'],
|
|
960
|
+
['B', 'C', 'H', 'I', 'D'],
|
|
961
|
+
['E', 'F', 'G'],
|
|
962
|
+
['H', 'J', 'K']
|
|
963
|
+
]);
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
test('should more cuttable graph tarjan SCCs return correct result', () => {
|
|
967
|
+
const graph = createExampleGraph4();
|
|
968
|
+
const sccs = graph.tarjan().SCCs;
|
|
969
|
+
expect(sccs.size).toBe(3);
|
|
970
|
+
expect(getAsVerticesArrays(sccs)).toEqual([['K', 'J', 'I', 'H', 'D', 'C', 'B'], ['G', 'F', 'E'], ['A']]);
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
function createExampleGraph5() {
|
|
974
|
+
const graph = createExampleGraph4();
|
|
975
|
+
graph.addEdge('F', 'H');
|
|
976
|
+
return graph;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
test('should uncuttable graph tarjan cycles return correct result', () => {
|
|
980
|
+
const graph = createExampleGraph5();
|
|
981
|
+
const cycles = graph.getCycles();
|
|
982
|
+
expect(cycles.length).toBe(4);
|
|
983
|
+
expect(cycles).toEqual([
|
|
984
|
+
['B', 'C', 'D'],
|
|
985
|
+
['B', 'C', 'H', 'I', 'D'],
|
|
986
|
+
['E', 'F', 'G'],
|
|
987
|
+
['H', 'J', 'K']
|
|
988
|
+
]);
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
test('should uncuttable graph tarjan SCCs return correct result', () => {
|
|
992
|
+
const graph = createExampleGraph5();
|
|
993
|
+
const sccs = graph.tarjan().SCCs;
|
|
994
|
+
expect(sccs.size).toBe(3);
|
|
995
|
+
expect(getAsVerticesArrays(sccs)).toEqual([['K', 'J', 'I', 'H', 'D', 'C', 'B'], ['G', 'F', 'E'], ['A']]);
|
|
996
|
+
});
|
|
997
|
+
});
|