Skip to content

Commit ef62f95

Browse files
authored
Merge pull request #7 from JuliaGraphs/bramtayl_code_for
Add code_for
2 parents 58d03ab + cdbb9a1 commit ef62f95

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/MetaGraphsNext.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,32 @@ end
321321

322322
copy(g::T) where {T<:MetaGraph} = deepcopy(g)
323323

324+
"""
325+
code_for(meta::MetaGraph, vertex_label)
326+
327+
Find the code for associated with a vertex with `vertex_label`. This can be useful to pass
328+
to methods inherited from `LightGraphs`. Note, however, that vertex codes could be
329+
reassigned after vertex deletion.
330+
331+
```jldoctest
332+
julia> using MetaGraphsNext
333+
334+
julia> using LightGraphs: Graph
335+
336+
julia> meta = MetaGraph(Graph());
337+
338+
julia> meta[:a] = nothing
339+
340+
julia> code_for(meta, :a)
341+
1
342+
```
343+
"""
344+
function code_for(meta::MetaGraph, vertex_label)
345+
code, _ = meta.vprops[vertex_label]
346+
code
347+
end
348+
export code_for
349+
324350
include("metadigraph.jl")
325351
include("overrides.jl")
326352
include("persistence.jl")

0 commit comments

Comments
 (0)