Skip to content

Generalize constructors beyond Dictionary for vertex data #11

@mtfishman

Description

@mtfishman

For example:

julia> DataGraph(grid((4,)), ["X", "Y", "Z", "W"])
ERROR: MethodError: no method matching DataGraph(::SimpleGraph{Int64}, ::Vector{String})
Closest candidates are:
  DataGraph(::AbstractGraph) at ~/.julia/dev/DataGraphs/src/datagraph.jl:117
  DataGraph(::AbstractGraph, ::Dictionary) at ~/.julia/dev/DataGraphs/src/datagraph.jl:117
  DataGraph(::AbstractGraph, ::Dictionary, ::Dictionary) at ~/.julia/dev/DataGraphs/src/datagraph.jl:117
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[29]:1

This could automatically convert to a Dictionary, i.e. get converted internally to:

julia> DataGraph(grid((4,)), Dictionary(["X", "Y", "Z", "W"]))
DataGraph{Int64, String, Any, SimpleGraph{Int64}, Graphs.SimpleGraphs.SimpleEdge{Int64}} with 4 vertices:
Base.OneTo(4)

and 3 edge(s):
Edge 1 => 2
Edge 2 => 3
Edge 3 => 4

with vertex data:
4-element Dictionary{Int64, String}
 1"X"
 2"Y"
 3"Z"
 4"W"

and edge data:
0-element Dictionary{Graphs.SimpleGraphs.SimpleEdge{Int64}, Any}

This would only make sense for vertices with linear indexing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions