Skip to content

Commit f546d96

Browse files
authored
Merge pull request #45 from JuliaGraphs/dev
Type-stable constructors
2 parents cbbdb25 + b8fda45 commit f546d96

18 files changed

+504
-195
lines changed

.github/workflows/permanent.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches:
55
- 'master'
6+
pull_request:
67
jobs:
78
document:
89
runs-on: ubuntu-latest

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: test
22
on:
3-
- push
4-
- pull_request
3+
push:
4+
branches:
5+
- 'master'
6+
pull_request:
57
jobs:
68
test:
79
name: ${{ matrix.version }}

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ julia = "1.6"
1717
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
1818
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1919
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
20+
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
2021
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2122

2223
[targets]
23-
test = ["Aqua", "Documenter", "JuliaFormatter", "Test"]
24+
test = ["Aqua", "Documenter", "JuliaFormatter", "MetaGraphs", "Test"]

docs/Manifest.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.8.5"
44
manifest_format = "2.0"
5-
project_hash = "f82c2777847a88fb4979a0b1e71456c8301bca98"
5+
project_hash = "580b7ffaff126fd1040a2c45d9e0166b2dd82fd9"
66

77
[[deps.ANSIColoredPrinters]]
88
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
@@ -159,11 +159,17 @@ deps = ["Artifacts", "Libdl"]
159159
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
160160
version = "2.28.0+0"
161161

162+
[[deps.MetaGraphs]]
163+
deps = ["Graphs", "JLD2", "Random"]
164+
git-tree-sha1 = "1130dbe1d5276cb656f6e1094ce97466ed700e5a"
165+
uuid = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
166+
version = "0.7.2"
167+
162168
[[deps.MetaGraphsNext]]
163-
deps = ["Graphs", "JLD2"]
169+
deps = ["Graphs", "JLD2", "SimpleTraits"]
164170
path = ".."
165171
uuid = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
166-
version = "0.4.1"
172+
version = "0.5.0"
167173

168174
[[deps.Mmap]]
169175
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
44
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
5+
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
56
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"

docs/make.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ makedocs(;
5656
assets=String[],
5757
edit_link=:commit,
5858
),
59+
checkdocs=:all,
60+
linkcheck=true,
61+
strict=true,
5962
)
6063

6164
deploydocs(; repo="github.com/JuliaGraphs/MetaGraphsNext.jl.git")

src/MetaGraphsNext.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ using Graphs
55
using SimpleTraits
66

77
export MetaGraph
8-
export label_for, code_for, set_data!
8+
export label_for, code_for, labels
9+
export set_data!
910
export weighttype, default_weight, get_weight_function
1011
export MGFormat, DOTFormat
1112

src/dict_utils.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,3 @@ function _copy_props!(old_meta_graph::MetaGraph, new_meta_graph::MetaGraph, code
120120
end
121121
return nothing
122122
end
123-
124-
# TODO - It would be nice to be able to apply a function to properties.
125-
# Not sure how this might work, but if the property is a vector,
126-
# a generic way to append to it would be a good thing.

src/directedness.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
function Graphs.is_directed(::MetaGraph{Code,Graph}) where {Code,Graph<:AbstractGraph}
2+
return is_directed(Graph)
3+
end
4+
5+
function Graphs.is_directed(
6+
::Type{<:MetaGraph{Code,Graph}}
7+
) where {Code,Graph<:AbstractGraph}
8+
return is_directed(Graph)
9+
end
10+
111
"""
212
arrange(graph, label_1, label_2)
313
@@ -6,14 +16,14 @@ Sort two vertex labels in a default order (useful to uniquely express undirected
616
function arrange end
717

818
@traitfn function arrange(
9-
::AG::IsDirected, label_1, label_2, _drop...
10-
) where {T,AG<:AbstractGraph{T}}
19+
::MG, label_1, label_2, _drop...
20+
) where {MG <: MetaGraph; IsDirected{MG}}
1121
return label_1, label_2
1222
end
1323

1424
@traitfn function arrange(
15-
::AG::(!IsDirected), label_1, label_2, code_1, code_2
16-
) where {T,AG<:AbstractGraph{T}}
25+
::MG, label_1, label_2, code_1, code_2
26+
) where {MG <: MetaGraph; !IsDirected{MG}}
1727
if code_1 < code_2
1828
(label_1, label_2)
1929
else
@@ -22,8 +32,8 @@ end
2232
end
2333

2434
@traitfn function arrange(
25-
meta_graph::AG::(!IsDirected), label_1, label_2
26-
) where {T,AG<:AbstractGraph{T}}
35+
meta_graph::MG, label_1, label_2
36+
) where {MG <: MetaGraph; !IsDirected{MG}}
2737
return arrange(
2838
meta_graph,
2939
label_1,

src/graphs.jl

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,35 @@ end
1010
function Graphs.edgetype(meta_graph::MetaGraph)
1111
return edgetype(meta_graph.graph)
1212
end
13+
1314
function Graphs.nv(meta_graph::MetaGraph)
1415
return nv(meta_graph.graph)
1516
end
17+
1618
function Graphs.ne(meta_graph::MetaGraph)
1719
return ne(meta_graph.graph)
1820
end
21+
1922
function Graphs.vertices(meta_graph::MetaGraph)
2023
return vertices(meta_graph.graph)
2124
end
25+
2226
function Graphs.edges(meta_graph::MetaGraph)
2327
return edges(meta_graph.graph)
2428
end
2529

2630
function Graphs.has_vertex(meta_graph::MetaGraph, code::Integer)
2731
return has_vertex(meta_graph.graph, code)
2832
end
33+
2934
function Graphs.has_edge(meta_graph::MetaGraph, code_1::Integer, code_2::Integer)
3035
return has_edge(meta_graph.graph, code_1, code_2)
3136
end
3237

3338
function Graphs.inneighbors(meta_graph::MetaGraph, code::Integer)
3439
return inneighbors(meta_graph.graph, code)
3540
end
41+
3642
function Graphs.outneighbors(meta_graph::MetaGraph, code::Integer)
3743
return outneighbors(meta_graph.graph, code)
3844
end
@@ -41,42 +47,6 @@ function Base.issubset(meta_graph::MetaGraph, h::MetaGraph)
4147
return issubset(meta_graph.graph, h.graph)
4248
end
4349

44-
function Graphs.is_directed(
45-
::MetaGraph{Code,Label,Graph}
46-
) where {Code,Label,Graph<:AbstractGraph}
47-
return is_directed(Graph)
48-
end
49-
50-
function Graphs.is_directed(
51-
::Type{<:MetaGraph{Code,Label,Graph}}
52-
) where {Code,Label,Graph<:AbstractGraph}
53-
return is_directed(Graph)
54-
end
55-
56-
## Link between graph codes and metagraph labels
57-
58-
"""
59-
code_for(meta_graph::MetaGraph, label)
60-
61-
Find the vertex code (or index) associated with label `label`.
62-
63-
This can be useful to pass to methods inherited from `Graphs`. Note, however, that vertex codes can be reassigned after vertex deletion.
64-
"""
65-
function code_for(meta_graph::MetaGraph, label)
66-
return meta_graph.vertex_properties[label][1]
67-
end
68-
69-
"""
70-
label_for(meta_graph::MetaGraph, code)
71-
72-
Find the label associated with code `code`.
73-
74-
This can be useful to interpret the results of methods inherited from `Graphs`. Note, however, that vertex codes can be reassigned after vertex deletion.
75-
"""
76-
function label_for(meta_graph::MetaGraph, code::Integer)
77-
return meta_graph.vertex_labels[code]
78-
end
79-
8050
## Set vertex and edge data
8151

8252
"""
@@ -207,6 +177,22 @@ end
207177

208178
## Miscellaneous
209179

180+
function Base.copy(meta_graph::MetaGraph)
181+
return deepcopy(meta_graph)
182+
end
183+
184+
function Base.zero(meta_graph::MetaGraph)
185+
return MetaGraph(
186+
zero(meta_graph.graph),
187+
empty(meta_graph.vertex_labels),
188+
empty(meta_graph.vertex_properties),
189+
empty(meta_graph.edge_data),
190+
deepcopy(meta_graph.graph_data),
191+
deepcopy(meta_graph.weight_function),
192+
deepcopy(meta_graph.default_weight),
193+
)
194+
end
195+
210196
function Graphs.induced_subgraph(
211197
meta_graph::MetaGraph, vertex_codes::AbstractVector{<:Integer}
212198
)
@@ -224,7 +210,7 @@ function Graphs.induced_subgraph(
224210
return new_graph, code_map
225211
end
226212

227-
@traitfn function Graphs.reverse(meta_graph::MetaGraph::IsDirected)
213+
@traitfn function Graphs.reverse(meta_graph::MG) where {MG <: MetaGraph; IsDirected{MG}}
228214
edge_data = meta_graph.edge_data
229215
reverse_edge_data = empty(edge_data)
230216
for (label_1, label_2) in keys(edge_data)

0 commit comments

Comments
 (0)