Skip to content

Commit 1539095

Browse files
authored
Merge pull request #35 from JuliaGraphs/cleanup
cleanup
2 parents 485c256 + 7d2eb5f commit 1539095

File tree

13 files changed

+340
-285
lines changed

13 files changed

+340
-285
lines changed

.JuliaFormatter.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
always_for_in = true
2+
whitespace_typedefs = true
3+
whitespace_ops_in_indices = true
4+
remove_extra_newlines = true
5+
import_to_using = true
6+
short_to_long_function_def = true

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
version:
12-
- '1.0'
12+
- '1.6'
1313
- '1'
1414
- 'nightly'
1515
steps:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
99
[compat]
1010
Graphs = "1.4.1"
1111
JLD2 = "0.1.11, 0.2, 0.3, 0.4"
12-
julia = "1"
12+
julia = "1.6"
1313

1414
[extras]
1515
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ makedocs(
1818
"Reading / writing" => "tutorial_files.md",
1919
],
2020
"API reference" => "api.md",
21-
]
21+
],
2222
)
2323

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

docs/src/tutorial_basics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ We provide a default constructor in which you only need to specify types:
1212

1313
```jldoctest example
1414
julia> colors = MetaGraph( Graph(), VertexData = String, EdgeData = Symbol, graph_data = "graph_of_colors")
15-
Meta graph based on a {0, 0} undirected simple Int64 graph with vertex labels of type Symbol, vertex metadata of type String, edge metadata of type Symbol, graph metadata given by "graph_of_colors", and default weight 1.0
15+
Meta graph based on a Graphs.SimpleGraphs.SimpleGraph{Int64}(0, Vector{Int64}[]) with vertex labels of type Symbol, vertex metadata of type String, edge metadata of type Symbol, graph metadata given by "graph_of_colors", and default weight 1.0
1616
```
1717

1818
## Modifying the graph
@@ -136,7 +136,7 @@ julia> size(weight_matrix)
136136
julia> weight_matrix[1, 3]
137137
1.0
138138
139-
julia> weight_function(weighted)(0)
139+
julia> get_weight_function(weighted)(0)
140140
0
141141
```
142142

src/MetaGraphsNext.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Graphs
55

66
export MetaGraph, MetaDiGraph, MetaUndirectedGraph
77
export label_for, code_for, set_data
8-
export weighttype, default_weight, weight_function
8+
export weighttype, default_weight, get_weight_function
99
export MGFormat, DOTFormat
1010

1111
include("metagraph.jl")

src/dict_utils.jl

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,123 @@
11
"""
2-
getindex(g)
2+
getindex(meta_graph)
33
4-
Return graph metadata.
4+
Return meta_graph metadata.
55
"""
6-
Base.getindex(g::MetaGraph) = g.graph_data
6+
function Base.getindex(meta_graph::MetaGraph)
7+
meta_graph.graph_data
8+
end
79

810
"""
9-
getindex(g, label)
11+
getindex(meta_graph, label)
1012
1113
Return vertex metadata for `label`.
1214
"""
13-
Base.getindex(g::MetaGraph, label) = g.vertex_properties[label][2]
15+
function Base.getindex(meta_graph::MetaGraph, label)
16+
meta_graph.vertex_properties[label][2]
17+
end
1418

1519
"""
16-
getindex(g, label_1, label_2)
20+
getindex(meta_graph, label_1, label_2)
1721
1822
Return edge metadata for the edge between `label_1` and `label_2`.
1923
"""
20-
Base.getindex(g::MetaGraph, label_1, label_2) = g.edge_data[arrange(g, label_1, label_2)]
24+
function Base.getindex(meta_graph::MetaGraph, label_1, label_2)
25+
meta_graph.edge_data[arrange(meta_graph, label_1, label_2)]
26+
end
2127

2228
"""
23-
haskey(g, label)
29+
haskey(meta_graph, label)
2430
25-
Determine whether a graph `g` contains the vertex `label`.
31+
Determine whether a meta_graph `meta_graph` contains the vertex `label`.
2632
"""
27-
Base.haskey(g::MetaGraph, label) = haskey(g.vertex_properties, label)
33+
function Base.haskey(meta_graph::MetaGraph, label)
34+
haskey(meta_graph.vertex_properties, label)
35+
end
2836

2937
"""
30-
haskey(g, label_1, label_2)
38+
haskey(meta_graph, label_1, label_2)
3139
32-
Determine whether a graph `g` contains an edge from `label_1` to `label_2`.
40+
Determine whether a meta_graph `meta_graph` contains an edge from `label_1` to `label_2`.
3341
34-
The order of `label_1` and `label_2` only matters if `g` is a digraph.
42+
The order of `label_1` and `label_2` only matters if `meta_graph` is a digraph.
3543
"""
36-
function Base.haskey(g::MetaGraph, label_1, label_2)
37-
return (
38-
haskey(g, label_1) &&
39-
haskey(g, label_2) &&
40-
haskey(g.edge_data, arrange(g, label_1, label_2))
41-
)
44+
function Base.haskey(meta_graph::MetaGraph, label_1, label_2)
45+
haskey(meta_graph, label_1) &&
46+
haskey(meta_graph, label_2) &&
47+
haskey(meta_graph.edge_data, arrange(meta_graph, label_1, label_2))
4248
end
4349

4450
"""
45-
setindex!(g, data, label)
51+
setindex!(meta_graph, data, label)
4652
4753
Set vertex metadata for `label` to `data`.
4854
"""
49-
function Base.setindex!(g::MetaGraph, data, label)
50-
if haskey(g, label)
51-
set_data!(g, label, data)
55+
function Base.setindex!(meta_graph::MetaGraph, data, label)
56+
if haskey(meta_graph, label)
57+
set_data!(meta_graph, label, data)
5258
else
53-
add_vertex!(g, label, data)
59+
add_vertex!(meta_graph, label, data)
5460
end
55-
return nothing
61+
nothing
5662
end
5763

5864
"""
59-
setindex!(g, data, label_1, label_2)
65+
setindex!(meta_graph, data, label_1, label_2)
6066
6167
Set edge metadata for `(label_1, label_2)` to `data`.
6268
"""
63-
function Base.setindex!(g::MetaGraph, data, label_1, label_2)
64-
if haskey(g, label_1, label_2)
65-
set_data!(g, label_1, label_2, data)
69+
function Base.setindex!(meta_graph::MetaGraph, data, label_1, label_2)
70+
if haskey(meta_graph, label_1, label_2)
71+
set_data!(meta_graph, label_1, label_2, data)
6672
else
67-
add_edge!(g, label_1, label_2, data)
73+
add_edge!(meta_graph, label_1, label_2, data)
6874
end
69-
return nothing
75+
nothing
7076
end
7177

7278
"""
73-
delete!(g, label)
79+
delete!(meta_graph, label)
7480
7581
Delete vertex `label`.
7682
"""
77-
function Base.delete!(g::MetaGraph, label)
78-
if haskey(g, label)
79-
v = code_for(g, label)
80-
_rem_vertex!(g, label, v)
83+
function Base.delete!(meta_graph::MetaGraph, label)
84+
if haskey(meta_graph, label)
85+
_rem_vertex!(meta_graph, label, code_for(meta_graph, label))
8186
end
82-
return nothing
87+
nothing
8388
end
8489

8590
"""
86-
delete!(g, label_1, label_2)
91+
delete!(meta_graph, label_1, label_2)
8792
8893
Delete edge `(label_1, label_2)`.
8994
"""
90-
function Base.delete!(g::MetaGraph, label_1, label_2)
91-
v1, v2 = code_for(g, label_1), code_for(g, label_2)
92-
rem_edge!(g, v1, v2)
93-
return nothing
95+
function Base.delete!(meta_graph::MetaGraph, label_1, label_2)
96+
rem_edge!(meta_graph, code_for(meta_graph, label_1), code_for(meta_graph, label_2))
97+
nothing
9498
end
9599

96100
"""
97-
_copy_props!(oldg, newg, vmap)
101+
_copy_props!(old_meta_graph, new_meta_graph, code_map)
98102
99-
Copy properties from `oldg` to `newg` following vertex map `vmap`.
103+
Copy properties from `old_meta_graph` to `new_meta_graph` following vertex map `code_map`.
100104
"""
101-
function _copy_props!(oldg::G, newg::G, vmap) where {G<:MetaGraph}
102-
for (newv, oldv) in enumerate(vmap)
103-
oldl = oldg.vertex_labels[oldv]
104-
_, data = oldg.vertex_properties[oldl]
105-
newg.vertex_labels[newv] = oldl
106-
newg.vertex_properties[oldl] = (newv, data)
105+
function _copy_props!(old_meta_graph::MetaGraph, new_meta_graph::MetaGraph, code_map)
106+
for (new_code, old_code) in enumerate(code_map)
107+
old_label = old_meta_graph.vertex_labels[old_code]
108+
_, data = old_meta_graph.vertex_properties[old_label]
109+
new_meta_graph.vertex_labels[new_code] = old_label
110+
new_meta_graph.vertex_properties[old_label] = (new_code, data)
107111
end
108-
for newe in edges(newg.graph)
109-
vertex_labels = newg.vertex_labels
110-
v1, v2 = Tuple(newe)
111-
label_1 = vertex_labels[v1]
112-
label_2 = vertex_labels[v2]
113-
newg.edge_data[arrange(newg, label_1, label_2, v1, v2)] = oldg.edge_data[arrange(
114-
oldg, label_1, label_2
115-
)]
112+
for new_edge in edges(new_meta_graph.graph)
113+
vertex_labels = new_meta_graph.vertex_labels
114+
code_1, code_2 = Tuple(new_edge)
115+
label_1 = vertex_labels[code_1]
116+
label_2 = vertex_labels[code_2]
117+
new_meta_graph.edge_data[arrange(new_meta_graph, label_1, label_2, code_1, code_2)] =
118+
old_meta_graph.edge_data[arrange(old_meta_graph, label_1, label_2)]
116119
end
117-
return nothing
120+
nothing
118121
end
119122

120123
# TODO - It would be nice to be able to apply a function to properties.

0 commit comments

Comments
 (0)