graph/encoding/dot: factor out repeated forward keys

This commit is contained in:
Dan Kortschak
2020-12-01 21:30:08 +10:30
parent e2a07cfc01
commit ca24245762

View File

@@ -210,16 +210,17 @@ func (p *simpleGraphPrinter) print(g graph.Graph, name string, needsIndent, isSu
sort.Sort(ordered.ByID(to)) sort.Sort(ordered.ByID(to))
for _, t := range to { for _, t := range to {
tid := t.ID() tid := t.ID()
f := edge{inGraph: name, from: nid, to: tid}
if isDirected { if isDirected {
if p.visited[edge{inGraph: name, from: nid, to: tid}] { if p.visited[f] {
continue continue
} }
p.visited[edge{inGraph: name, from: nid, to: tid}] = true p.visited[f] = true
} else { } else {
if p.visited[edge{inGraph: name, from: nid, to: tid}] { if p.visited[f] {
continue continue
} }
p.visited[edge{inGraph: name, from: nid, to: tid}] = true p.visited[f] = true
p.visited[edge{inGraph: name, from: tid, to: nid}] = true p.visited[edge{inGraph: name, from: tid, to: nid}] = true
} }
@@ -512,16 +513,17 @@ func (p *multiGraphPrinter) print(g graph.Multigraph, name string, needsIndent,
for _, l := range lines { for _, l := range lines {
lid := l.ID() lid := l.ID()
f := line{inGraph: name, from: nid, to: tid, id: lid}
if isDirected { if isDirected {
if p.visited[line{inGraph: name, from: nid, to: tid, id: lid}] { if p.visited[f] {
continue continue
} }
p.visited[line{inGraph: name, from: nid, to: tid, id: lid}] = true p.visited[f] = true
} else { } else {
if p.visited[line{inGraph: name, from: nid, to: tid, id: lid}] { if p.visited[f] {
continue continue
} }
p.visited[line{inGraph: name, from: nid, to: tid, id: lid}] = true p.visited[f] = true
p.visited[line{inGraph: name, from: tid, to: nid, id: lid}] = true p.visited[line{inGraph: name, from: tid, to: nid, id: lid}] = true
} }