Skip to content

Commit af3f853

Browse files
committed
Rename fields and types
1 parent 706b7da commit af3f853

File tree

10 files changed

+138
-131
lines changed

10 files changed

+138
-131
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
[![Build Status](https://github.com/JuliaGraphs/MetaGraphsNext.jl/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/JuliaGraphs/MetaGraphsNext.jl/actions/workflows/test.yml?query=branch%3Amaster)
55
[![CodeCov](https://codecov.io/gh/JuliaGraphs/MetaGraphsNext.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaGraphs/MetaGraphsNext.jl)
66

7-
Welcome to `MetaGraphsNext.jl`, an experimental, type-stable replacement for [MetaGraphs](https://github.com/JuliaGraphs/MetaGraphs.jl). Take a look at the [documentation](https://juliagraphs.org/MetaGraphsNext.jl/dev/) to know more!
7+
Welcome to MetaGraphsNext, an experimental, type-stable replacement for [MetaGraphs](https://github.com/JuliaGraphs/MetaGraphs.jl). This package will let you store metadata on the vertices and edges of your graphs. Take a look at the [documentation](https://juliagraphs.org/MetaGraphsNext.jl/dev/) to learn more!

docs/src/tutorial_basics.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ julia> using MetaGraphsNext
1111
We provide a default constructor in which you only need to specify types:
1212

1313
```jldoctest example
14-
julia> colors = MetaGraph( Graph(), VertexMeta = String, EdgeMeta = Symbol, gprops = "graph_of_colors")
14+
julia> colors = MetaGraph( Graph(), VertexData = String, EdgeData = Symbol, graph_data = "graph_of_colors")
1515
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
1616
```
1717

@@ -109,19 +109,19 @@ julia> label_for(colors, 3)
109109
The most simple way to add edge weights is to speficy a default weight for all of them.
110110

111111
```jldoctest example
112-
julia> weighted_default = MetaGraph(Graph(), defaultweight = 2);
112+
julia> weighted_default = MetaGraph(Graph(), default_weight = 2);
113113
114-
julia> defaultweight(weighted_default)
114+
julia> default_weight(weighted_default)
115115
2
116116
117117
julia> weighttype(weighted_default)
118118
Int64
119119
```
120120

121-
You can use the `weightfunction` keyword to specify a function which will transform edge metadata into a weight. This weight must always be the same type as the `defaultweight`.
121+
You can use the `weight_function` keyword to specify a function which will transform edge metadata into a weight. This weight must always be the same type as the `default_weight`.
122122

123123
```jldoctest example
124-
julia> weighted = MetaGraph(Graph(), EdgeMeta = Float64, weightfunction = identity);
124+
julia> weighted = MetaGraph(Graph(), EdgeData = Float64, weight_function = identity);
125125
126126
julia> weighted[:red] = nothing; weighted[:blue] = nothing; weighted[:yellow] = nothing;
127127
@@ -136,7 +136,7 @@ julia> size(weight_matrix)
136136
julia> weight_matrix[1, 3]
137137
1.0
138138
139-
julia> weightfunction(weighted)(0)
139+
julia> weight_function(weighted)(0)
140140
0
141141
```
142142

docs/src/tutorial_files.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ graph T {
2424
}
2525
2626
julia> complicated = MetaGraph(DiGraph(),
27-
VertexMeta = Dict{Symbol, Int},
28-
EdgeMeta = Dict{Symbol, Int},
29-
gprops = (tagged = true,)
27+
VertexData = Dict{Symbol, Int},
28+
EdgeData = Dict{Symbol, Int},
29+
graph_data = (tagged = true,)
3030
);
3131
3232
julia> complicated[:a] = Dict(:code_1 => 1, :code_2 => 2);

docs/src/tutorial_graphs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Note that vertex codes get reassigned after `rem_vertex!` operations to remain c
1515
We can make `MetaGraph`s based on (undirected) `Graph`s.
1616

1717
```jldoctest graphs
18-
julia> cities = MetaGraph(Graph(), VertexMeta = String, EdgeMeta = Int, gprops = nothing, weightfunction = identity, defaultweight = 0);
18+
julia> cities = MetaGraph(Graph(), VertexData = String, EdgeData = Int, weight_function = identity, default_weight = 0);
1919
```
2020

2121
Let us add some cities and the distance between them:
@@ -127,7 +127,7 @@ false
127127
We can make `MetaGraph`s based on `DiGraph`s as well.
128128

129129
```jldoctest graphs
130-
julia> rock_paper_scissors = MetaGraph(DiGraph(), Label = Symbol, EdgeMeta = Symbol);
130+
julia> rock_paper_scissors = MetaGraph(DiGraph(), Label = Symbol, EdgeData = Symbol);
131131
132132
julia> for label in [:rock, :paper, :scissors]; rock_paper_scissors[label] = nothing; end;
133133

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, defaultweight, weightfunction
8+
export weighttype, default_weight, weight_function
99
export MGFormat, DOTFormat
1010

1111
include("metagraph.jl")

src/dict_utils.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
44
Return graph metadata.
55
"""
6-
Base.getindex(g::MetaGraph) = g.gprops
6+
Base.getindex(g::MetaGraph) = g.graph_data
77

88
"""
99
getindex(g, label)
1010
1111
Return vertex metadata for `label`.
1212
"""
13-
Base.getindex(g::MetaGraph, label) = g.vprops[label]
13+
Base.getindex(g::MetaGraph, label) = g.vertex_data[label]
1414

1515
"""
1616
getindex(g, label_1, label_2)
1717
1818
Return edge metadata for the edge between `label_1` and `label_2`.
1919
"""
20-
Base.getindex(g::MetaGraph, label_1, label_2) = g.eprops[arrange(g, label_1, label_2)]
20+
Base.getindex(g::MetaGraph, label_1, label_2) = g.edge_data[arrange(g, label_1, label_2)]
2121

2222
"""
2323
haskey(g, label)
2424
2525
Determine whether a graph `g` contains the vertex `label`.
2626
"""
27-
Base.haskey(g::MetaGraph, label) = haskey(g.vprops, label)
27+
Base.haskey(g::MetaGraph, label) = haskey(g.vertex_data, label)
2828

2929
"""
3030
haskey(g, label_1, label_2)
@@ -37,7 +37,7 @@ function Base.haskey(g::MetaGraph, label_1, label_2)
3737
return (
3838
haskey(g, label_1) &&
3939
haskey(g, label_2) &&
40-
haskey(g.eprops, arrange(g, label_1, label_2))
40+
haskey(g.edge_data, arrange(g, label_1, label_2))
4141
)
4242
end
4343

@@ -100,18 +100,18 @@ Copy properties from `oldg` to `newg` following vertex map `vmap`.
100100
"""
101101
function _copy_props!(oldg::G, newg::G, vmap) where {G<:MetaGraph}
102102
for (newv, oldv) in enumerate(vmap)
103-
oldl = oldg.labels[oldv]
104-
data = oldg.vprops[oldl]
105-
newg.labels[newv] = oldl
106-
newg.vcodes[oldl] = newv
107-
newg.vprops[oldl] = data
103+
oldl = oldg.vertex_labels[oldv]
104+
data = oldg.vertex_data[oldl]
105+
newg.vertex_labels[newv] = oldl
106+
newg.vertex_codes[oldl] = newv
107+
newg.vertex_data[oldl] = data
108108
end
109109
for newe in edges(newg.graph)
110-
labels = newg.labels
110+
vertex_labels = newg.vertex_labels
111111
v1, v2 = Tuple(newe)
112-
label_1 = labels[v1]
113-
label_2 = labels[v2]
114-
newg.eprops[arrange(newg, label_1, label_2, v1, v2)] = oldg.eprops[arrange(
112+
label_1 = vertex_labels[v1]
113+
label_2 = vertex_labels[v2]
114+
newg.edge_data[arrange(newg, label_1, label_2, v1, v2)] = oldg.edge_data[arrange(
115115
oldg, label_1, label_2
116116
)]
117117
end

src/graphs.jl

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Find the vertex code (or index) associated with label `label`.
2424
2525
This can be useful to pass to methods inherited from `Graphs`. Note, however, that vertex codes can be reassigned after vertex deletion.
2626
"""
27-
code_for(g::MetaGraph, label) = g.vcodes[label]
27+
code_for(g::MetaGraph, label) = g.vertex_codes[label]
2828

2929
"""
3030
label_for(g::MetaGraph, v)
@@ -33,7 +33,7 @@ Find the label associated with code `v`.
3333
3434
This can be useful to interpret the results of methods inherited from `Graphs`. Note, however, that vertex codes can be reassigned after vertex deletion.
3535
"""
36-
label_for(g::MetaGraph, v::Integer) = g.labels[v]
36+
label_for(g::MetaGraph, v::Integer) = g.vertex_labels[v]
3737

3838
## Set vertex and edge data
3939

@@ -45,8 +45,8 @@ Set vertex metadata for `label` to `data`.
4545
Return `true` if the operation succeeds, and `false` if `g` has no such vertex.
4646
"""
4747
function set_data!(g::MetaGraph, label, data)
48-
if haskey(g.vprops, label)
49-
g.vprops[label] = data
48+
if haskey(g.vertex_data, label)
49+
g.vertex_data[label] = data
5050
return true
5151
else
5252
return false
@@ -62,8 +62,8 @@ Return `true` if the operation succeeds, and `false` if `g` has no such edge.
6262
"""
6363
function set_data!(g::MetaGraph, label_1, label_2, data)
6464
edge_labels = arrange(g, label_1, label_2)
65-
if haskey(g.eprops, edge_labels)
66-
g.eprops[edge_labels] = data
65+
if haskey(g.edge_data, edge_labels)
66+
g.edge_data[edge_labels] = data
6767
return true
6868
else
6969
return false
@@ -83,9 +83,9 @@ function Graphs.add_vertex!(g::MetaGraph, label, data)
8383
added = add_vertex!(g.graph)
8484
if added
8585
v = nv(g)
86-
g.labels[v] = label
87-
g.vcodes[label] = v
88-
g.vprops[label] = data
86+
g.vertex_labels[v] = label
87+
g.vertex_codes[label] = v
88+
g.vertex_data[label] = data
8989
end
9090
return added
9191
end
@@ -101,36 +101,36 @@ function Graphs.add_edge!(g::MetaGraph, label_1, label_2, data)
101101
v1, v2 = code_for(g, label_1), code_for(g, label_2)
102102
added = add_edge!(g.graph, v1, v2)
103103
if added
104-
g.eprops[arrange(g, label_1, label_2, v1, v2)] = data
104+
g.edge_data[arrange(g, label_1, label_2, v1, v2)] = data
105105
end
106106
return added
107107
end
108108

109109
## Remove vertex
110110

111111
function _rem_vertex!(g::MetaGraph, label, v)
112-
labels = g.labels
113-
vcodes = g.vcodes
114-
vprops = g.vprops
115-
eprops = g.eprops
112+
vertex_labels = g.vertex_labels
113+
vertex_codes = g.vertex_codes
114+
vertex_data = g.vertex_data
115+
edge_data = g.edge_data
116116
lastv = nv(g)
117117
for n in outneighbors(g, v)
118-
delete!(eprops, arrange(g, label, labels[n], v, n))
118+
delete!(edge_data, arrange(g, label, vertex_labels[n], v, n))
119119
end
120120
for n in inneighbors(g, v)
121-
delete!(eprops, arrange(g, labels[n], label, n, v))
121+
delete!(edge_data, arrange(g, vertex_labels[n], label, n, v))
122122
end
123123
removed = rem_vertex!(g.graph, v)
124124
if removed
125125
if v != lastv # ignore if we're removing the last vertex.
126-
lastl = labels[lastv]
127-
lastvprop = vprops[lastl]
128-
labels[v] = lastl
129-
vcodes[lastl] = v
130-
vprops[lastl] = lastvprop
126+
lastl = vertex_labels[lastv]
127+
lastvprop = vertex_data[lastl]
128+
vertex_labels[v] = lastl
129+
vertex_codes[lastl] = v
130+
vertex_data[lastl] = lastvprop
131131
end
132-
delete!(vprops, label)
133-
delete!(labels, lastv)
132+
delete!(vertex_data, label)
133+
delete!(vertex_labels, lastv)
134134
end
135135
return removed
136136
end
@@ -150,7 +150,7 @@ function Graphs.rem_edge!(g::MetaGraph, v1::Integer, v2::Integer)
150150
removed = rem_edge!(g.graph, v1, v2)
151151
if removed
152152
label_1, label_2 = label_for(g, v1), label_for(g, v2)
153-
delete!(g.eprops, arrange(g, label_1, label_2, v1, v2))
153+
delete!(g.edge_data, arrange(g, label_1, label_2, v1, v2))
154154
end
155155
return removed
156156
end
@@ -163,34 +163,41 @@ function Graphs.induced_subgraph(
163163
inducedgraph, vmap = induced_subgraph(g.graph, v)
164164
newg = MetaGraph(
165165
inducedgraph,
166-
empty(g.labels),
167-
empty(g.vcodes),
168-
empty(g.vprops),
169-
empty(g.eprops),
170-
g.gprops,
171-
g.weightfunction,
172-
g.defaultweight,
166+
empty(g.vertex_labels),
167+
empty(g.vertex_codes),
168+
empty(g.vertex_data),
169+
empty(g.edge_data),
170+
g.graph_data,
171+
g.weight_function,
172+
g.default_weight,
173173
)
174174
_copy_props!(g, newg, vmap)
175175
return newg, vmap
176176
end
177177

178178
function Graphs.reverse(g::MetaDiGraph)
179179
rg = reverse(g.graph)
180-
rlabels = copy(g.labels)
181-
rvcodes = copy(g.vcodes)
182-
rvprops = copy(g.vprops)
183-
reprops = empty(g.eprops)
184-
rgprops = g.gprops
185-
rweightfunction = g.weightfunction
186-
rdefaultweight = g.defaultweight
187-
188-
for (u, v) in keys(g.eprops)
189-
reprops[(v, u)] = g.eprops[(u, v)]
180+
rvertex_labels = copy(g.vertex_labels)
181+
rvertex_codes = copy(g.vertex_codes)
182+
rvertex_data = copy(g.vertex_data)
183+
redge_data = empty(g.edge_data)
184+
rgraph_data = g.graph_data
185+
rweight_function = g.weight_function
186+
rdefault_weight = g.default_weight
187+
188+
for (u, v) in keys(g.edge_data)
189+
redge_data[(v, u)] = g.edge_data[(u, v)]
190190
end
191191

192192
rg = MetaGraph(
193-
rg, rlabels, rvcodes, rvprops, reprops, rgprops, rweightfunction, rdefaultweight
193+
rg,
194+
rvertex_labels,
195+
rvertex_codes,
196+
rvertex_data,
197+
redge_data,
198+
rgraph_data,
199+
rweight_function,
200+
rdefault_weight,
194201
)
195202

196203
return rg

0 commit comments

Comments
 (0)