Add VertexDataGraph and EdgeDataGraph as concrete subtypes of AbstractVertexOrEdgeDataGraph#121
Add VertexDataGraph and EdgeDataGraph as concrete subtypes of AbstractVertexOrEdgeDataGraph#121jack-dunham wants to merge 28 commits into
VertexDataGraph and EdgeDataGraph as concrete subtypes of AbstractVertexOrEdgeDataGraph#121Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #121 +/- ##
==========================================
+ Coverage 59.89% 62.02% +2.13%
==========================================
Files 10 12 +2
Lines 566 848 +282
==========================================
+ Hits 339 526 +187
- Misses 227 322 +95
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…hrow(); end; ...`
…eturn similar types.
|
FYI something you can do to temporarily get the tests passing in this PR is to add a |
07854cc to
71fbb01
Compare
d1089dd to
b91cd71
Compare
| function Base.copy(graph::AbstractVertexOrEdgeDataGraph) | ||
| graph_dst = similar_graph(graph) | ||
| # Allow copies of graphs with undefined data. | ||
| copyto!(graph_dst, graph, filter(key -> isassigned(graph, key), keys(graph))) | ||
| return graph_dst | ||
| end | ||
|
|
||
| function Base.copyto!(graph_dst::AbstractVertexOrEdgeDataGraph, src) | ||
| copyto!(graph_dst, src, keys(src)) | ||
| return graph_dst | ||
| end | ||
|
|
||
| Base.iterate(graph::AbstractVertexOrEdgeDataGraph) = iterate(index_data(graph)) | ||
| function Base.iterate(graph::AbstractVertexOrEdgeDataGraph, state) | ||
| return iterate(index_data(graph), state) | ||
| end |
There was a problem hiding this comment.
These all become more subtle if we really embrace the idea that keys(::AbstractEdgeDataGraph) outputs all possible edges. I think it would be ok if we just had different implementations for AbstractEdgeDataGraph and AbstractVertexDataGraph, but it is something to think about. I don't think it is unreasonable to use edges(g) and iterate(EdgeDataView(g)) for iterating over just the edges/edge data. But overall I think we should either fully embrace the abstraction of an edge data graph as a sparse matrix, or treat it fully as a dictionary from edges to edge data, and not have the design be halfway in between those two abstractions.
This point of this abstract interface is to allow the partial implementation of the
Dictionaries.jlinterface, on these graph types.VertexDataGraphandEdgeDataGraphas concrete subtypes ofAbstractVertexOrEdgeDataGraphAbstractVertexDataGraphandAbstractEdgeDataGraphinterfaces.insert_vertex_datathat should be overloaded if a givenAbstractVertexDataGraphgraphisinsertable. See below as to why the analogous interface function doesn't exist forAbstractEdgeDataGraph.A subtype of
AbstractVertexOrEdgeDataGraphimplements a stricter indexing interface, inline with the one used byDictionaries.jl, that issetindex!strictly sets existing indices (doesn't add a vertex/edge that isn't already in the graph). One should useinsert!to strictly add a new vertex/edge with data, andset!to perform anupsert(previous behavior ofsetindex!.Eventually, this interface will be applied to
AbstractDataGraph, but to avoid breaking changes this is deferred until a later date.Subtleties
Difference in
setindex!for vertex and edge dataThe
setindex!function on anAbstractEdgeDataGraphshould add an edge if doesn't exist already. This is unlikesetindex!for anAbstractVertexDataGraph, which errors if there vertex is not present. This is in analogy to SparseArrays:For an edge data graph,
setindex!will only error if the vertices associated to an edge aren't present (irrespective of the existence of an edge).Difference in
insert!anddelete!for vertex and edge dataFor a vertex data graph, the function
insert!inserts a vertex with data, erroring if it already exits. For an edge data graph,insert!also inserts the required vertices and then adds the edge with data, erroring if both vertices are already present. That is,insert!errors wheresetindex!would not error. The functiondelete!deletes the edge and data only, leaving the data untouched.Interface differences
For a settable and insertable vertex data graph, one must define:
An edge data graph only needs:
As
insert!is defined in terms ofadd_vertex!andset!(which can create edges).