Skip to content

Commit

Permalink
Sort the lines of the graph when printing it for debug purposes, so t…
Browse files Browse the repository at this point in the history
…hat random hash ordering doesn't cause the graph to have a different output
  • Loading branch information
AngledLuffa committed Jun 5, 2024
1 parent 3946805 commit a902b43
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/edu/stanford/nlp/graph/DirectedMultiGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,17 +664,30 @@ public String toString() {
StringBuilder s = new StringBuilder();
s.append("{\n");
s.append("Vertices:\n");

List<String> lines = new ArrayList<>();
for (V vertex : outgoingEdges.keySet()) {
s.append(" ").append(vertex).append('\n');
lines.add(" " + vertex + '\n');
}
Collections.sort(lines);
for (String line : lines) {
s.append(line);
}

s.append("Edges:\n");
lines = new ArrayList<>();
for (V source : outgoingEdges.keySet()) {
for (V dest : outgoingEdges.get(source).keySet()) {
for (E edge : outgoingEdges.get(source).get(dest)) {
s.append(" ").append(source).append(" -> ").append(dest).append(" : ").append(edge).append('\n');
lines.add(" " + source + " -> " + dest + " : " + edge + "\n");
}
}
}
Collections.sort(lines);
for (String line : lines) {
s.append(line);
}

s.append('}');
return s.toString();
}
Expand Down

0 comments on commit a902b43

Please sign in to comment.