This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
Proposal: Relax restriction on vertex IDs #1572
Labels
discussion
requires in-depth discussion - participation encouraged
I've been thinking about API design changes that would make the
AbstractGraph
interface more generic and make it easier to create graphs with meta-data. I was thinking about something along the lines ofwhere
L
is a vertex label type,V
is a vertex (or vertex meta-data) type, andE
is an edge (or edge meta-data) type, with some associated machinery for handling vertex labels.However, after thinking about it for a while, I think that would actually be more restrictive than what we need. I think there are basically only two things that we need in order to make the
AbstractGraph
API more generic:AbstractGraph
to choose its own vertex label typeL
.AbstractGraph
could allow the user to decide the type of the vertex label, for example, a graph typeNotSimpleGraph{L, V, E}
.add_vertex!
,rem_vertex!
,add_edge!
, andrem_edge!
as optional parts of the API that should be implemented for mutable graphs.I think including the graph modifying verbs in the API would allow individual graphs to decide whether or not they want to use consecutive integer labels (or, of course, non-integer labels).
In order to allow for arbitrary vertex label types, the signature for
add_vertex!
would have to change to this:add_vertex!(g, v)
I don't think that would be too much of an imposition for
SimpleGraphs
, since under the current API I have to immediately callnv(g)
in order to figure out the integer code for the newly added vertex. So the usage pattern forSimpleGraphs
would change from this:to this:
Although I guess then you would need to manually check for integer overflow in
nv(g) + 1
... 🤔With the
add_vertex!(g, v)
version of the API,v
is meant to be a vertex label, so this might be a stretch of the API definition, but perhaps there could be aSimpleGraph
method likeadd_vertex(g, Increment())
, which at least maintains the arity ofadd_vertex!
.Or maybe
SimpleGraph
s could leave checking for integer overflow to the user.typemax(Int64) ≈ 9.2 * 10^19
, so that seems big enough for most use cases. Then the API foradd_vertex!(g, v)
could be the following:v
already exists ing
, thenadd_vertex!(g, v)
is a no-op.v
does not already exist ing
and is a valid label, thenv
is added tog
.SimpleGraph{T}
, the only valid label isnv(g) + T(1)
.SimpleGraph{T}
, it's possible to havenv(g) + T(1) <= 0
, which would probably result in aBoundsError
, but it's up to the user to worry about that.Question: With the above change to the
add_vertex!
API, would we still need to returnfalse
whenadd_vertex!(g, v)
is a no-op? Or could we always returnnothing
fromadd_vertex!(g, v)
?I realize this would be a pretty big change to the codebase. But this is a feature that I would definitely like to have, so I might be able to find some time to help contribute it.
The text was updated successfully, but these errors were encountered: