The high performance graph library for Java
Home › Code samples

First of all, in development mode, start with this line. It enables the assertions, which are heavily used by Grph. Doing this makes the library more robust and slows downs it a bit. ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);

Creating a 4x4 grid and display it in a graphical view: Grph g = new InMemoryGrph(); g.grid(4, 4); g.display();

Computing the diameter of the graph: int d = g.getDiameter();

Writing it on disk, in a file named myfile.txt: RegularFile f = new RegularFile("myfile.txt"); f.setContent(g.toGrphText().getBytes());

Efficiently iterating on the vertices of the graph, using the cache: for (int v : g.getVertices().toArray()) { ... }

If the graph changes very often, you better avoid using the cache, like this: for (IntCursor vertexCursor : g.getVertices()) { int v = vertexCursor.value; ... }