@@ -24,7 +24,7 @@ Find the vertex code (or index) associated with label `label`.
2424
2525This 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. vertex_codes [label]
27+ code_for (g:: MetaGraph , label) = g. vertex_properties [label][ 1 ]
2828
2929"""
3030 label_for(g::MetaGraph, v)
@@ -45,8 +45,9 @@ Set vertex metadata for `label` to `data`.
4545Return `true` if the operation succeeds, and `false` if `g` has no such vertex.
4646"""
4747function 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)
5051 return true
5152 else
5253 return false
@@ -84,8 +85,7 @@ function Graphs.add_vertex!(g::MetaGraph, label, data)
8485 if added
8586 v = nv (g)
8687 g. vertex_labels[v] = label
87- g. vertex_codes[label] = v
88- g. vertex_data[label] = data
88+ g. vertex_properties[label] = (v, data)
8989 end
9090 return added
9191end
110110
111111function _rem_vertex! (g:: MetaGraph , label, v)
112112 vertex_labels = g. vertex_labels
113- vertex_codes = g. vertex_codes
114- vertex_data = g. vertex_data
113+ vertex_properties = g. vertex_properties
115114 edge_data = g. edge_data
116115 lastv = nv (g)
117116 for n in outneighbors (g, v)
@@ -124,13 +123,12 @@ function _rem_vertex!(g::MetaGraph, label, v)
124123 if removed
125124 if v != lastv # ignore if we're removing the last vertex.
126125 lastl = vertex_labels[lastv]
127- lastvprop = vertex_data [lastl]
126+ lastvprop = vertex_properties [lastl]
128127 vertex_labels[v] = lastl
129- vertex_codes[lastl] = v
130- vertex_data[lastl] = lastvprop
128+ vertex_properties[lastl] = lastvprop
131129 end
132- delete! (vertex_data, label)
133130 delete! (vertex_labels, lastv)
131+ delete! (vertex_properties, label)
134132 end
135133 return removed
136134end
@@ -164,8 +162,7 @@ function Graphs.induced_subgraph(
164162 newg = MetaGraph (
165163 inducedgraph,
166164 empty (g. vertex_labels),
167- empty (g. vertex_codes),
168- empty (g. vertex_data),
165+ empty (g. vertex_properties),
169166 empty (g. edge_data),
170167 g. graph_data,
171168 g. weight_function,
178175function Graphs. reverse (g:: MetaDiGraph )
179176 rg = reverse (g. graph)
180177 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)
183179 redge_data = empty (g. edge_data)
184180 rgraph_data = g. graph_data
185181 rweight_function = g. weight_function
@@ -192,8 +188,7 @@ function Graphs.reverse(g::MetaDiGraph)
192188 rg = MetaGraph (
193189 rg,
194190 rvertex_labels,
195- rvertex_codes,
196- rvertex_data,
191+ rvertex_properties,
197192 redge_data,
198193 rgraph_data,
199194 rweight_function,
0 commit comments