[gephi-dev] Question on Graph object

1 view
Skip to first unread message

Sébastien Heymann

unread,
Oct 4, 2015, 11:15:51 AM10/4/15
to geph...@lists.gephi.org
Hi @devs,

I have a general question on the graph object. In modules we need most of the time to use specific interfaces like DirectedGraph, HierarchicalGraph, HierarchicalDirectedGraph etc.
We can use them in two ways, for instance:

DirectedGraph dg = graph.getGraphModel.getDirectedGraph();
dg.blah();

or

((DirectedGraph) graph).blah();


Which one is the best? As I understand, calling GraphModel.getXXGraph() creates a copy of the graph, which sounds not so good for memory usage...


Cheers,
Seb

Mathieu Bastian

unread,
Oct 4, 2015, 11:15:51 AM10/4/15
to Sébastien Heymann, geph...@lists.gephi.org
Hi,

None of the GraphModel.getXXGraph()  methods creates a copy of the graph, we can do better than that :) It creates a new Graph object, which  you can see as an accessor to the structure, but it doesn't touch the content.

At any time you can get any of these interface and work with. The graph has however a type and not all cast can be done. You can't do

DirectedGraph dg = graph.getGraphModel.getDirectedGraph();
UndirectedGraph ug = (UndirectedGraph)dg;

for example. The model behind serves either HierarchicalDirectedGraph, HierarchicalUndirectedGraph or HierarchicalMixedGraph. For API clarity, you can get simpler interfaces like Graph or DirectedGraph but you will aways have a hierarchical graph behind. So it's always safe to cast to HierarchicalGraph.

Hope this helps

Mathieu

_______________________________________________
gephi-dev mailing list
geph...@lists.gephi.org
http://gephi.org/mailman/listinfo/gephi-dev


Sébastien Heymann

unread,
Oct 4, 2015, 11:15:52 AM10/4/15
to Martin Skurla, geph...@lists.gephi.org
So should we recommend to make a cast after proper testing?

Seb

2010/12/15 Martin Skurla <buj...@gmail.com>
I looked at the implementation classes and there is one difference,
and that is possible ClassCastException on second command if you don't
carefully test it to proper type.

There is Hierarchical directed graph implementation which implements
both DirectedGraph and HierarchicalGraph interfaces, so you can cast
it without problems and nothing in memory changes.

2010/12/15 Sébastien Heymann <sebastie...@gephi.org>:
Reply all
Reply to author
Forward
0 new messages