Skip to content

Conversation

@jack-dunham
Copy link

@jack-dunham jack-dunham commented Dec 3, 2025

This PR introduces a change to the DataGraphs interface. The following functions must now be overloaded for a graph to behave like a data graph:

underlying_graph(::AbstractDataGraph) = not_implemented()

has_vertex_data(::AbstractDataGraph, vertex) = not_implemented()
has_edge_data(::AbstractDataGraph, edge) = not_implemented()

get_vertex_data(::AbstractDataGraph, vertex) = not_implemented()
get_edge_data(::AbstractDataGraph, edge) = not_implemented()

set_vertex_data!(::AbstractDataGraph, data, vertex) = not_implemented()
set_edge_data!(::AbstractDataGraph, data, edge) = not_implemented()

unset_vertex_data!(::AbstractDataGraph, vertex) = not_implemented()
unset_edge_data!(::AbstractDataGraph, edge) = not_implemented()

The functions getindex , setindex! get! etc are all defined in terms of those. It is a bit more verbose than just having a function vertex_data etc that returns a mutable dictionary, but I think it is ultimately more generic. The return value of vertex_data etc is now constructed on the fly, so doing setindex!(vertex_data(g), val, vertex) will not modify the underlying graph.

To rename vertices, one must also overload:

GraphsExtensions.rename_vertices(f, ::AbstractDataGraph) = not_implemented()

The benefit of this change is that one no longer require the data on the vertices and edges to be stored as a mutable field; it can be generated on the fly. This then results in constant behavior when defining views of vertex/edge data. One can still use a mutable dictionary to store the data for a given concrete AbstractDataGraph subtype.

Other Changes

  • AbstractDataGraph now subtypes AbstractNamedGraph. This greatly reduces required method overloads.

To do

  • DataGraph allows an AbstractSimpleGraph as its underlying graph. This will result in mismatched vertices between the underlying graph vertices and the vertex data dictionary if one removes or adds a vertex from the data graph.
  • Bump version number
  • VertexDataView etc

…btype `AbstractNamedGraph`

- Interface now no longer assumes vertex and edge date stored as mutable
field. Instead, requires overloading setters and getters.
- Subtyping `AbstractNamedGraph` cuts down on the method forwarding
almost entirely.
@jack-dunham
Copy link
Author

Closing as superseded by #55.

@jack-dunham jack-dunham closed this Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant