D graph library -- update
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Thu Jul 11 15:35:47 PDT 2013
On 07/11/2013 08:27 PM, H. S. Teoh wrote:
> Yeah, constraining the number of vertices/edges at ctor time is not
> feasible. We need to have an implementation that allows modifying the
> graph post-construction, such as adding edges.
You can add as many edges as you like -- right now, the implementation doesn't
even constrain you from adding _the same edge_ multiple times. (I think that's
a feature rather than a bug -- it allows for support of multigraphs.)
You can also extend the number of vertices. Just use the addVertices() method,
although to be honest I think the easiest thing might be to just allow the user
to assign to the vertexCount @property, with some checks to make sure that they
don't reduce the total number of vertices below the largest head/tail value.
> (Deleting may not be as
> important, and may be tricky to implement, but there *are* use cases for
> that too.)
I am also concerned about complications related to deletion, but I'm sure it's
possible to address.
> Couldn't you just add vertices manually, since you already know what the
> edge is?
Before calling addEdge(head, tail), calculate m = max(head, tail). Then if m >=
vertexCount, set vertexCount = m + 1. Then add your edges.
This is easily done with wrappers. I think there's a benefit to the core class
being strict and _not_ just automatically extending the number of vertices, just
as an array doesn't automatically expand if you try and read/write from an index
beyond its current length.
More information about the Digitalmars-d
mailing list