> Trying to write a bit more about D on my blog now. To start, I've written
> about a proof-of-concept range-based API for graph search.
> http://poita.org/2014/01/09/range-based-graph-search-in-d.html
> I'd greatly appreciate any feedback on the design. As we don't yet have a
> graph library for D, it would be interesting to discuss APIs in general.

I really like it, very elegant! Certain lines brought a smile to my
lips :-) (using anonymous functions as graph parameters, for example).
Much more elegant than my own graph code :)

You wanted suggestions, here are a few. They come from my use of
graphs: not so much as search-based, but as a way to store and modify
'relationships' (call graphs, import graphs) or to use them as support
for state machines.

* I sometimes have to use graphs with more than just `weight` on edges
(names as strings, chars, for example for a state machine, etc). Do
you think you could extend your design to allow parameterization on
edges? Of course, to use the search algorithms, the user should
provide an way to get a priority from the edges. Or any user-defined
type could be used, ideally, as long as it provides a way to get a

* I'd like a way to map on a graph (keeping the edge structure, but
changing the nodes contents). I know I can map on your search result,
but 1) I want a graph after mapping, not a range and 2) I don't want
to search, I want to affect all nodes.

* I'd like a way to iterate seeing only edges, not nodes.

* I'd like a way to concatenate/link different graphs (a bit like
chain for ranges). I sometimes have graphs that are assembled from
many different small graphs, bottom-up style. Typically, if you
assemble automata (from regexes, for example), you do it bottom-up.

* Of course, I'd like a way to build a graph from nothing, putting
nodes and then edges in them.

* I sometimes need to extract some global information from a graph:
number of nodes, number of edges, etc.

* Does you design allow for backward iteration? (I mean, inverting the
edges). Some graph algorithms ask for this kind of magic.

* Getting strongly connected components is a very interesting algorithm to have.

* you should define some template constraints on your types
(Graph...), but I understand they can be added later on.

Re-reading my suggestions, I see they would push your code toward my
own attempts :-) I guess I'm biased.

I have some (years old!) code in there:

As for my (age old) vision on graph iteration, here it is:


But yet again, nothing as elegant as your own code.

Reply via email to