[graph-tool] Using Inline for Search/Traversal
Tiago de Paula Peixoto
tiago at skewed.de
Fri Aug 26 00:16:00 CEST 2011
On 08/25/2011 10:12 PM, parvizp wrote:
> Is it possible to write the code for graph traversal in C++ rather than using
> the Python wrappers? I need the graph search to be as fast as possible.
> I tried something simple like this: http://pastebin.com/m2pwFQKy
> It looks like the typedefs for 'graph_graph_t' don't appear until after the
> support code: http://pastebin.com/itT73DxT
> Is there an example of how to achieve something similar?
Yes, this is possible. The idea is that the *_graph_t types will be
different, depending if your graph is directed, undirected, filtered,
reversed, etc. So it is not defined (typedef'd) before the type of your
graph known. This _could_ be pushed before the support code comes, I
suppose, but the way I use it is to define everything in the support
code as templates, so the actual type gets picked up automatically.
class MyVisitor : public boost::default_dfs_visitor
template <class Vertex, class Graph>
void discover_vertex(Vertex v, Graph& g)
std::cout << v << std::endl;
Then your code would be:
And there is no necessity of actually knowing the type of the
graph (but if you ever need it, it is there as a typedef).
> Thanks Tiago Peixoto for developing/maintaining this great library!
Tiago de Paula Peixoto <tiago at skewed.de>
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 554 bytes
Desc: OpenPGP digital signature
More information about the graph-tool