[Networkit] allowing algorithms access to graph data structure internals

Moritz von Looz moritz.looz-corswarem at kit.edu
Tue Jul 15 20:11:33 CEST 2014


Hi Christian,

I had exactly the same problem today! I'm paralellizing my graph
generator and wanted to modify the adjacencies of single nodes.

My solution was to add a method addHalfEdge(u,v), which only modifies u.
The caller has to ensure each call addHalfEdge(u,v) is followed by one
addHalfEdge(v,u). Since the direction is unclear, it is only supported
for undirected graphs.

This avoids exposing the internals.

Best regards,
Moritz

Am 15.07.2014 16:46, schrieb Christian Staudt:
> Hi NetworKit team,
> I need some help with the following C++ question:
> 
> If the adjacencies of each node are to be written in parallel, we cannot do this 
> using the normal addEdge method, because it writes data globally. I want to 
> write an algorithm that constructs the core data structure in parallel and later 
> ensures consistency of the Graph object. To let the algorithm access the 
> internals of Graph, my first idea was to declare it as a friend class of Graph. 
> However, the algorithm class itself includes and uses Graph, which I believe is 
> the cause of the compiler errors I am getting.
> 
> Adding
> friend class ParallelPartitionCoarsening;
> 
> to Graph gives me:
> 
> *src/cpp/graph/../coarsening/ParallelPartitionCoarsening.h:24:20: error: 'Graph' 
> was not declared in this scope*
> *  virtual std::pair<Graph, std::vector<node> > run(const Graph& G, const 
> Partition& zeta);*
> *
> *
> I never used friend classes before - am I making a simple error here? How can I 
> grant a class access to the private members of Graph?
> 
> Best regards,
> Christian
> 



More information about the NetworKit mailing list