@@ -24,7 +24,7 @@ Find the vertex code (or index) associated with label `label`.
24
24
25
25
This can be useful to pass to methods inherited from `Graphs`. Note, however, that vertex codes can be reassigned after vertex deletion.
26
26
"""
27
- code_for (g:: MetaGraph , label) = g. vertex_codes [label]
27
+ code_for (g:: MetaGraph , label) = g. vertex_properties [label][ 1 ]
28
28
29
29
"""
30
30
label_for(g::MetaGraph, v)
@@ -45,8 +45,9 @@ Set vertex metadata for `label` to `data`.
45
45
Return `true` if the operation succeeds, and `false` if `g` has no such vertex.
46
46
"""
47
47
function set_data! (g:: MetaGraph , label, data)
48
- if haskey (g. vertex_data, label)
49
- g. vertex_data[label] = data
48
+ if haskey (g. vertex_properties, label)
49
+ code, old_data = g. vertex_properties[label]
50
+ g. vertex_properties[label] = (code, data)
50
51
return true
51
52
else
52
53
return false
@@ -84,8 +85,7 @@ function Graphs.add_vertex!(g::MetaGraph, label, data)
84
85
if added
85
86
v = nv (g)
86
87
g. vertex_labels[v] = label
87
- g. vertex_codes[label] = v
88
- g. vertex_data[label] = data
88
+ g. vertex_properties[label] = (v, data)
89
89
end
90
90
return added
91
91
end
110
110
111
111
function _rem_vertex! (g:: MetaGraph , label, v)
112
112
vertex_labels = g. vertex_labels
113
- vertex_codes = g. vertex_codes
114
- vertex_data = g. vertex_data
113
+ vertex_properties = g. vertex_properties
115
114
edge_data = g. edge_data
116
115
lastv = nv (g)
117
116
for n in outneighbors (g, v)
@@ -124,13 +123,12 @@ function _rem_vertex!(g::MetaGraph, label, v)
124
123
if removed
125
124
if v != lastv # ignore if we're removing the last vertex.
126
125
lastl = vertex_labels[lastv]
127
- lastvprop = vertex_data [lastl]
126
+ lastvprop = vertex_properties [lastl]
128
127
vertex_labels[v] = lastl
129
- vertex_codes[lastl] = v
130
- vertex_data[lastl] = lastvprop
128
+ vertex_properties[lastl] = lastvprop
131
129
end
132
- delete! (vertex_data, label)
133
130
delete! (vertex_labels, lastv)
131
+ delete! (vertex_properties, label)
134
132
end
135
133
return removed
136
134
end
@@ -164,8 +162,7 @@ function Graphs.induced_subgraph(
164
162
newg = MetaGraph (
165
163
inducedgraph,
166
164
empty (g. vertex_labels),
167
- empty (g. vertex_codes),
168
- empty (g. vertex_data),
165
+ empty (g. vertex_properties),
169
166
empty (g. edge_data),
170
167
g. graph_data,
171
168
g. weight_function,
178
175
function Graphs. reverse (g:: MetaDiGraph )
179
176
rg = reverse (g. graph)
180
177
rvertex_labels = copy (g. vertex_labels)
181
- rvertex_codes = copy (g. vertex_codes)
182
- rvertex_data = copy (g. vertex_data)
178
+ rvertex_properties = copy (g. vertex_properties)
183
179
redge_data = empty (g. edge_data)
184
180
rgraph_data = g. graph_data
185
181
rweight_function = g. weight_function
@@ -192,8 +188,7 @@ function Graphs.reverse(g::MetaDiGraph)
192
188
rg = MetaGraph (
193
189
rg,
194
190
rvertex_labels,
195
- rvertex_codes,
196
- rvertex_data,
191
+ rvertex_properties,
197
192
redge_data,
198
193
rgraph_data,
199
194
rweight_function,
0 commit comments