Skip to content

Commit c463f96

Browse files
committed
Sort the lines of the graph when printing it for debug purposes, so that random hash ordering doesn't cause the graph to have a different output
1 parent 20062f4 commit c463f96

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/edu/stanford/nlp/graph/DirectedMultiGraph.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -666,17 +666,30 @@ public String toString() {
666666
StringBuilder s = new StringBuilder();
667667
s.append("{\n");
668668
s.append("Vertices:\n");
669+
670+
List<String> lines = new ArrayList<>();
669671
for (V vertex : outgoingEdges.keySet()) {
670-
s.append(" ").append(vertex).append('\n');
672+
lines.add(" " + vertex + '\n');
673+
}
674+
Collections.sort(lines);
675+
for (String line : lines) {
676+
s.append(line);
671677
}
678+
672679
s.append("Edges:\n");
680+
lines = new ArrayList<>();
673681
for (V source : outgoingEdges.keySet()) {
674682
for (V dest : outgoingEdges.get(source).keySet()) {
675683
for (E edge : outgoingEdges.get(source).get(dest)) {
676-
s.append(" ").append(source).append(" -> ").append(dest).append(" : ").append(edge).append('\n');
684+
lines.add(" " + source + " -> " + dest + " : " + edge + "\n");
677685
}
678686
}
679687
}
688+
Collections.sort(lines);
689+
for (String line : lines) {
690+
s.append(line);
691+
}
692+
680693
s.append('}');
681694
return s.toString();
682695
}

0 commit comments

Comments
 (0)