Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e8a013d

Browse files
committedJun 10, 2025·
renamed variables to f/badjlist and added tests for graphs over Int8,...,UInt128
1 parent d525f46 commit e8a013d

File tree

4 files changed

+276
-25
lines changed

4 files changed

+276
-25
lines changed
 

‎Manifest.toml

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
julia_version = "1.12.0-beta4"
4+
manifest_format = "2.0"
5+
project_hash = "bcaf375c0caf49e051cc266bfbea08524def119d"
6+
7+
[[deps.ArnoldiMethod]]
8+
deps = ["LinearAlgebra", "Random", "StaticArrays"]
9+
git-tree-sha1 = "d57bd3762d308bded22c3b82d033bff85f6195c6"
10+
uuid = "ec485272-7323-5ecc-a04f-4719b315124d"
11+
version = "0.4.0"
12+
13+
[[deps.Artifacts]]
14+
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
15+
version = "1.11.0"
16+
17+
[[deps.Base64]]
18+
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
19+
version = "1.11.0"
20+
21+
[[deps.CSTParser]]
22+
deps = ["Tokenize"]
23+
git-tree-sha1 = "0157e592151e39fa570645e2b2debcdfb8a0f112"
24+
uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
25+
version = "3.4.3"
26+
27+
[[deps.CommonMark]]
28+
deps = ["Crayons", "PrecompileTools"]
29+
git-tree-sha1 = "5fdf00d1979fd4883b44b754fc3423175c9504b4"
30+
uuid = "a80b9123-70ca-4bc0-993e-6e3bcb318db6"
31+
version = "0.8.16"
32+
33+
[[deps.Compat]]
34+
deps = ["TOML", "UUIDs"]
35+
git-tree-sha1 = "8ae8d32e09f0dcf42a36b90d4e17f5dd2e4c4215"
36+
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
37+
version = "4.16.0"
38+
weakdeps = ["Dates", "LinearAlgebra"]
39+
40+
[deps.Compat.extensions]
41+
CompatLinearAlgebraExt = "LinearAlgebra"
42+
43+
[[deps.CompilerSupportLibraries_jll]]
44+
deps = ["Artifacts", "Libdl"]
45+
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
46+
version = "1.3.0+1"
47+
48+
[[deps.Crayons]]
49+
git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15"
50+
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
51+
version = "4.1.1"
52+
53+
[[deps.DataStructures]]
54+
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
55+
git-tree-sha1 = "4e1fe97fdaed23e9dc21d4d664bea76b65fc50a0"
56+
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
57+
version = "0.18.22"
58+
59+
[[deps.Dates]]
60+
deps = ["Printf"]
61+
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
62+
version = "1.11.0"
63+
64+
[[deps.Distributed]]
65+
deps = ["Random", "Serialization", "Sockets"]
66+
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
67+
version = "1.11.0"
68+
69+
[[deps.Glob]]
70+
git-tree-sha1 = "97285bbd5230dd766e9ef6749b80fc617126d496"
71+
uuid = "c27321d9-0574-5035-807b-f59d2c89b15c"
72+
version = "1.3.1"
73+
74+
[[deps.Graphs]]
75+
deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"]
76+
path = "."
77+
uuid = "86223c79-3864-5bf0-83f7-82e725a168b6"
78+
version = "1.13.0"
79+
80+
[[deps.Inflate]]
81+
git-tree-sha1 = "d1b1b796e47d94588b3757fe84fbf65a5ec4a80d"
82+
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
83+
version = "0.1.5"
84+
85+
[[deps.InteractiveUtils]]
86+
deps = ["Markdown"]
87+
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
88+
version = "1.11.0"
89+
90+
[[deps.JuliaFormatter]]
91+
deps = ["CSTParser", "CommonMark", "DataStructures", "Glob", "PrecompileTools", "TOML", "Tokenize"]
92+
git-tree-sha1 = "59cf7ad64f1b0708a4fa4369879d33bad3239b56"
93+
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
94+
version = "1.0.62"
95+
96+
[[deps.JuliaSyntaxHighlighting]]
97+
deps = ["StyledStrings"]
98+
uuid = "ac6e5ff7-fb65-4e79-a425-ec3bc9c03011"
99+
version = "1.12.0"
100+
101+
[[deps.Libdl]]
102+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
103+
version = "1.11.0"
104+
105+
[[deps.LinearAlgebra]]
106+
deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
107+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
108+
version = "1.12.0"
109+
110+
[[deps.MacroTools]]
111+
git-tree-sha1 = "1e0228a030642014fe5cfe68c2c0a818f9e3f522"
112+
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
113+
version = "0.5.16"
114+
115+
[[deps.Markdown]]
116+
deps = ["Base64", "JuliaSyntaxHighlighting", "StyledStrings"]
117+
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
118+
version = "1.11.0"
119+
120+
[[deps.Mmap]]
121+
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
122+
version = "1.11.0"
123+
124+
[[deps.OpenBLAS_jll]]
125+
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
126+
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
127+
version = "0.3.29+0"
128+
129+
[[deps.OrderedCollections]]
130+
git-tree-sha1 = "05868e21324cede2207c6f0f466b4bfef6d5e7ee"
131+
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
132+
version = "1.8.1"
133+
134+
[[deps.PrecompileTools]]
135+
deps = ["Preferences"]
136+
git-tree-sha1 = "516f18f048a195409d6e072acf879a9f017d3900"
137+
uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
138+
version = "1.3.2"
139+
140+
[[deps.Preferences]]
141+
deps = ["TOML"]
142+
git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6"
143+
uuid = "21216c6a-2e73-6563-6e65-726566657250"
144+
version = "1.4.3"
145+
146+
[[deps.Printf]]
147+
deps = ["Unicode"]
148+
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
149+
version = "1.11.0"
150+
151+
[[deps.Random]]
152+
deps = ["SHA"]
153+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
154+
version = "1.11.0"
155+
156+
[[deps.SHA]]
157+
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
158+
version = "0.7.0"
159+
160+
[[deps.Serialization]]
161+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
162+
version = "1.11.0"
163+
164+
[[deps.SharedArrays]]
165+
deps = ["Distributed", "Mmap", "Random", "Serialization"]
166+
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
167+
version = "1.11.0"
168+
169+
[[deps.SimpleTraits]]
170+
deps = ["InteractiveUtils", "MacroTools"]
171+
git-tree-sha1 = "5d7e3f4e11935503d3ecaf7186eac40602e7d231"
172+
uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
173+
version = "0.9.4"
174+
175+
[[deps.Sockets]]
176+
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
177+
version = "1.11.0"
178+
179+
[[deps.SparseArrays]]
180+
deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"]
181+
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
182+
version = "1.12.0"
183+
184+
[[deps.StaticArrays]]
185+
deps = ["LinearAlgebra", "PrecompileTools", "Random", "StaticArraysCore"]
186+
git-tree-sha1 = "0feb6b9031bd5c51f9072393eb5ab3efd31bf9e4"
187+
uuid = "90137ffa-7385-5640-81b9-e52037218182"
188+
version = "1.9.13"
189+
190+
[deps.StaticArrays.extensions]
191+
StaticArraysChainRulesCoreExt = "ChainRulesCore"
192+
StaticArraysStatisticsExt = "Statistics"
193+
194+
[deps.StaticArrays.weakdeps]
195+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
196+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
197+
198+
[[deps.StaticArraysCore]]
199+
git-tree-sha1 = "192954ef1208c7019899fbf8049e717f92959682"
200+
uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
201+
version = "1.4.3"
202+
203+
[[deps.Statistics]]
204+
deps = ["LinearAlgebra"]
205+
git-tree-sha1 = "ae3bb1eb3bba077cd276bc5cfc337cc65c3075c0"
206+
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
207+
version = "1.11.1"
208+
weakdeps = ["SparseArrays"]
209+
210+
[deps.Statistics.extensions]
211+
SparseArraysExt = ["SparseArrays"]
212+
213+
[[deps.StyledStrings]]
214+
uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b"
215+
version = "1.11.0"
216+
217+
[[deps.SuiteSparse_jll]]
218+
deps = ["Artifacts", "Libdl", "libblastrampoline_jll"]
219+
uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c"
220+
version = "7.8.3+2"
221+
222+
[[deps.TOML]]
223+
deps = ["Dates"]
224+
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
225+
version = "1.0.3"
226+
227+
[[deps.Tokenize]]
228+
git-tree-sha1 = "468b4685af4abe0e9fd4d7bf495a6554a6276e75"
229+
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
230+
version = "0.5.29"
231+
232+
[[deps.UUIDs]]
233+
deps = ["Random", "SHA"]
234+
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
235+
version = "1.11.0"
236+
237+
[[deps.Unicode]]
238+
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
239+
version = "1.11.0"
240+
241+
[[deps.libblastrampoline_jll]]
242+
deps = ["Artifacts", "Libdl"]
243+
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
244+
version = "5.12.0+0"

‎Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ArnoldiMethod = "ec485272-7323-5ecc-a04f-4719b315124d"
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
88
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
99
Inflate = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
10+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
1011
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1112
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1213
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

‎src/operators.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ function merge_vertices!(g::Graph{T}, vs::Vector{U} where {U<:Integer}) where {T
881881
end
882882

883883
"""
884-
line_graph(g::SimpleGraph)
884+
line_graph(g::SimpleGraph) ::SimpleGraph
885885
Given a graph `g`, return the graph `lg`, whose vertices are integers that enumerate the
886886
edges in `g`, and two vertices in `lg` form an edge iff the corresponding edges in `g`
887887
share a common endpoint. In other words, edges in `lg` are length-2 paths in `g`.
@@ -897,7 +897,7 @@ julia> lg = line_graph(g)
897897
{4, 3} undirected simple Int64 graph
898898
```
899899
"""
900-
function line_graph(g::SimpleGraph)::SimpleGraph
900+
function line_graph(g::SimpleGraph)
901901
vertex_to_edges = [Int[] for _ in 1:nv(g)]
902902
for (i, e) in enumerate(edges(g))
903903
s, d = src(e), dst(e)
@@ -906,24 +906,24 @@ function line_graph(g::SimpleGraph)::SimpleGraph
906906
push!(vertex_to_edges[d], i)
907907
end
908908

909-
edge_to_neighbors = [Int[] for _ in 1:ne(g)]
909+
fadjlist = [Int[] for _ in 1:ne(g)] # edge to neighbors adjacency in lg
910910
m = 0 # number of edges in the line-graph
911911
for es in vertex_to_edges
912912
n = length(es)
913913
for i in 1:(n - 1), j in (i + 1):n # iterate through pairs of edges with same endpoint
914914
ei, ej = es[i], es[j]
915915
m += 1
916-
push!(edge_to_neighbors[ei], ej)
917-
push!(edge_to_neighbors[ej], ei)
916+
push!(fadjlist[ei], ej)
917+
push!(fadjlist[ej], ei)
918918
end
919919
end
920920

921-
foreach(sort!, edge_to_neighbors)
922-
return SimpleGraph(m, edge_to_neighbors)
921+
foreach(sort!, fadjlist)
922+
return SimpleGraph(m, fadjlist)
923923
end
924924

925925
"""
926-
line_graph(g::SimpleDiGraph)
926+
line_graph(g::SimpleDiGraph) ::SimpleDiGraph
927927
Given a digraph `g`, return the digraph `lg`, whose vertices are integers that enumerate
928928
the edges in `g`, and there is an edge in `lg` from `Edge(a,b)` to `Edge(c,d)` iff b==c.
929929
In other words, edges in `lg` are length-2 directed paths in `g`.
@@ -939,7 +939,7 @@ julia> lg = line_graph(g)
939939
{5, 5} directed simple Int64 graph
940940
```
941941
"""
942-
function line_graph(g::SimpleDiGraph)::SimpleDiGraph
942+
function line_graph(g::SimpleDiGraph)
943943
vertex_to_edgesout = [Int[] for _ in 1:nv(g)]
944944
vertex_to_edgesin = [Int[] for _ in 1:nv(g)]
945945
for (i, e) in enumerate(edges(g))
@@ -948,19 +948,19 @@ function line_graph(g::SimpleDiGraph)::SimpleDiGraph
948948
push!(vertex_to_edgesin[d], i)
949949
end
950950

951-
edge_to_neighborsout = [Int[] for _ in 1:ne(g)]
952-
edge_to_neighborsin = [Int[] for _ in 1:ne(g)]
951+
fadjilist = [Int[] for _ in 1:ne(g)] # edge to neighbors forward adjacency in lg
952+
badjilist = [Int[] for _ in 1:ne(g)] # edge to neighbors backward adjacency in lg
953953
m = 0 # number of edges in the line-graph
954954
for (e_i, e_o) in zip(vertex_to_edgesin, vertex_to_edgesout)
955955
for ei in e_i, eo in e_o # iterate through length-2 directed paths
956956
ei == eo && continue # a self-loop in g does not induce a self-loop in lg
957957
m += 1
958-
push!(edge_to_neighborsout[ei], eo)
959-
push!(edge_to_neighborsin[eo], ei)
958+
push!(fadjilist[ei], eo)
959+
push!(badjilist[eo], ei)
960960
end
961961
end
962962

963-
foreach(sort!, edge_to_neighborsout)
964-
foreach(sort!, edge_to_neighborsin)
965-
return SimpleDiGraph(m, edge_to_neighborsout, edge_to_neighborsin)
963+
foreach(sort!, fadjilist)
964+
foreach(sort!, badjilist)
965+
return SimpleDiGraph(m, fadjilist, badjilist)
966966
end

‎test/operators.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,13 @@
387387
end
388388

389389
@testset "Undirected Self-loops" begin
390-
g = SimpleGraph(2, [[2], [1, 2], Int[]])
391-
lg = line_graph(g)
392-
@test nv(lg) == 2 # only 2 edges (self-loop counts once)
393-
@test ne(lg) == 1 # only connection between edge 1-2 and self-loop 2-2
390+
for T in
391+
(Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128)
392+
g = SimpleGraph{T}(2, [T[2], T[1, 2], T[]])
393+
lg = line_graph(g)
394+
@test nv(lg) == 2 # only 2 edges (self-loop counts once)
395+
@test ne(lg) == 1 # only connection between edge 1-2 and self-loop 2-2
396+
end
394397
end
395398
end
396399

@@ -437,11 +440,14 @@
437440
end
438441

439442
@testset "Directed Self-loops" begin
440-
g = SimpleDiGraph(2, [[1, 2], Int[], Int[]], [[1], [1], Int[]])
441-
lg = line_graph(g)
442-
@test nv(lg) == 2
443-
@test ne(lg) == 1
444-
@test has_edge(lg, 1, 2)
443+
for T in
444+
(Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128)
445+
g = SimpleDiGraph{T}(2, [T[1, 2], T[], T[]], [T[1], T[1], T[]])
446+
lg = line_graph(g)
447+
@test nv(lg) == 2
448+
@test ne(lg) == 1
449+
@test has_edge(lg, 1, 2)
450+
end
445451
end
446452
end
447453
end

0 commit comments

Comments
 (0)
Please sign in to comment.