Skip to content

Commit 2a92f3d

Browse files
committed
add label_for, doc changes
1 parent edd0b91 commit 2a92f3d

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/MetaGraphsNext.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ copy(g::T) where {T<:MetaGraph} = deepcopy(g)
324324
"""
325325
code_for(meta::MetaGraph, vertex_label)
326326
327-
Find the code for associated with a vertex with `vertex_label`. This can be useful to pass
327+
Find the code associated with a `vertex_label`. This can be useful to pass
328328
to methods inherited from `LightGraphs`. Note, however, that vertex codes could be
329329
reassigned after vertex deletion.
330330
@@ -347,6 +347,30 @@ function code_for(meta::MetaGraph, vertex_label)
347347
end
348348
export code_for
349349

350+
"""
351+
label_for(meta::MetaGraph, vertex_code)
352+
353+
Find the label associated with a `vertex_code`. This can be useful to interpret the results of methods
354+
inherited from `LightGraphs`. Note, however, that vertex codes could be reassigned after vertex deletion.
355+
356+
```jldoctest
357+
julia> using MetaGraphsNext
358+
359+
julia> using LightGraphs: Graph
360+
361+
julia> meta = MetaGraph(Graph());
362+
363+
julia> meta[:a] = nothing
364+
365+
julia> label_for(meta, 1)
366+
:a
367+
```
368+
"""
369+
function label_for(meta::MetaGraph, vertex_code)
370+
meta.metaindex[vertex_code]
371+
end
372+
export label_for
373+
350374
include("metadigraph.jl")
351375
include("overrides.jl")
352376
include("persistence.jl")

src/metagraph.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ julia> using LightGraphs
7474
7575
julia> using MetaGraphsNext
7676
77-
julia> colors = MetaGraph(Graph(), VertexMeta = Int, EdgeMeta = Symbol, gprops = "special")
78-
Meta graph based on a {0, 0} undirected simple Int64 graph with vertices indexed by Symbol(s), Int64(s) vertex metadata, Symbol(s) edge metadata, "special" as graph metadata, and default weight 1.0
77+
julia> colors = MetaGraph(Graph(), VertexMeta = String, EdgeMeta = Symbol, gprops = "special")
78+
Meta graph based on a {0, 0} undirected simple Int64 graph with vertices indexed by Symbol(s), String(s) vertex metadata, Symbol(s) edge metadata, "special" as graph metadata, and default weight 1.0
7979
```
8080
8181
Use `setindex!` to add a new vertex with the given metadata. If a vertex with the given
8282
index does not exist, it will be created automatically; otherwise, `setindex!` will modify
8383
the metadata for the existing vertex.
8484
8585
```jldoctest example
86-
julia> colors[:red] = 1;
86+
julia> colors[:red] = "warm";
8787
88-
julia> colors[:yellow] = 2;
88+
julia> colors[:yellow] = "warm";
8989
90-
julia> colors[:blue] = 3;
90+
julia> colors[:blue] = "cool";
9191
```
9292
9393
You can access and change the metadata using indexing: zero arguments for graph metadata,
@@ -97,10 +97,10 @@ one label for vertex metadata, and two labels for edge metadata.
9797
julia> colors[]
9898
"special"
9999
100-
julia> colors[:blue] = 4;
100+
julia> colors[:blue] = "very cool";
101101
102102
julia> colors[:blue]
103-
4
103+
"very cool"
104104
105105
julia> colors[:red, :yellow] = :orange;
106106
@@ -154,7 +154,7 @@ julia> nv(zero(colors))
154154
julia> ne(copy(colors))
155155
0
156156
157-
julia> add_vertex!(colors, :white, 4)
157+
julia> add_vertex!(colors, :white, "neutral")
158158
true
159159
160160
julia> add_edge!(colors, 1, 3, :pink)

0 commit comments

Comments
 (0)