Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a902b43

Browse files
committedJun 5, 2024·
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 3946805 commit a902b43

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
@@ -664,17 +664,30 @@ public String toString() {
664664
StringBuilder s = new StringBuilder();
665665
s.append("{\n");
666666
s.append("Vertices:\n");
667+
668+
List<String> lines = new ArrayList<>();
667669
for (V vertex : outgoingEdges.keySet()) {
668-
s.append(" ").append(vertex).append('\n');
670+
lines.add(" " + vertex + '\n');
671+
}
672+
Collections.sort(lines);
673+
for (String line : lines) {
674+
s.append(line);
669675
}
676+
670677
s.append("Edges:\n");
678+
lines = new ArrayList<>();
671679
for (V source : outgoingEdges.keySet()) {
672680
for (V dest : outgoingEdges.get(source).keySet()) {
673681
for (E edge : outgoingEdges.get(source).get(dest)) {
674-
s.append(" ").append(source).append(" -> ").append(dest).append(" : ").append(edge).append('\n');
682+
lines.add(" " + source + " -> " + dest + " : " + edge + "\n");
675683
}
676684
}
677685
}
686+
Collections.sort(lines);
687+
for (String line : lines) {
688+
s.append(line);
689+
}
690+
678691
s.append('}');
679692
return s.toString();
680693
}

0 commit comments

Comments
 (0)
Please sign in to comment.