mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Make graph.toString return dot representation of graph
This commit is contained in:
parent
6d68010416
commit
4f9110f7b1
|
@ -99,11 +99,11 @@ public class GraphBuilder {
|
||||||
return builtGraph;
|
return builtGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class GraphImpl implements Graph {
|
private static final class GraphImpl implements Graph {
|
||||||
private final int[][] incomingEdgeList;
|
private final int[][] incomingEdgeList;
|
||||||
private final int[][] outgoingEdgeList;
|
private final int[][] outgoingEdgeList;
|
||||||
|
|
||||||
public GraphImpl(int[][] incomingEdgeList, int[][] outgoingEdgeList) {
|
GraphImpl(int[][] incomingEdgeList, int[][] outgoingEdgeList) {
|
||||||
this.incomingEdgeList = incomingEdgeList;
|
this.incomingEdgeList = incomingEdgeList;
|
||||||
this.outgoingEdgeList = outgoingEdgeList;
|
this.outgoingEdgeList = outgoingEdgeList;
|
||||||
}
|
}
|
||||||
|
@ -148,5 +148,27 @@ public class GraphBuilder {
|
||||||
public int outgoingEdgesCount(int node) {
|
public int outgoingEdgesCount(int node) {
|
||||||
return outgoingEdgeList[node].length;
|
return outgoingEdgeList[node].length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("digraph {\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < size(); ++i) {
|
||||||
|
if (outgoingEdgesCount(i) > 0) {
|
||||||
|
sb.append(" ").append(i).append(" -> { ");
|
||||||
|
int[] outgoingEdges = outgoingEdges(i);
|
||||||
|
sb.append(outgoingEdges[0]);
|
||||||
|
for (int j = 1; j < outgoingEdges.length; ++j) {
|
||||||
|
sb.append(", ").append(outgoingEdges[j]);
|
||||||
|
}
|
||||||
|
sb.append(" }\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("}");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user