This is a demo repository that shows my attempt at adapting Bazel's Digraph class to Guava's Graph interface.
Why? Because I'm interested in easy-to-use graph data structures in Java, and I thought this would be a fun exercise. 😄
-
I made
Digraph'sNodeclass private and changedDigraph's API accordingly to make the class compatible with Guava'sGraphinterface. -
I expanded the original tests that the Bazel authors wrote for
Digraph(which can be found in fileDigraphTests.javain this repo) to assert thatDigraph#getTopologicalOrderreturns a series of nodes that satisfies the general definition of "topological ordering", rather than a specific sequence of nodes which is itself a valid topological ordering but not the only one.This means that one could, in theory, change the algorithm that
Digraph#topologicalOrderinguses from reversed depth-first post order to e.g. Kahn's algorithm without having to change the test suite.
Install Java 8+, put it on your PATH, and then run the following commands through your terminal:
git clone https://github.com/jbduncan/bazel-digraph.gitcd bazel-digraph./gradlew check
Run ./gradlew build -x test. The library can then be found at build/libs/bazel-digraph-1.0-SNAPSHOT.jar.