pgraph: Use pointers for unique vertex identifiers

This will build more accurate graphs, since we could have duplicated
vertex names for distinct vertices. This now builds the correct
topology, even if the labels are duplicated.
This commit is contained in:
James Shubin
2019-04-29 13:52:54 -04:00
parent c0d329e6d8
commit 4de75373dd

View File

@@ -46,14 +46,17 @@ func (g *Graph) Graphviz() (out string) {
//out += "\tnode [shape=box];\n" //out += "\tnode [shape=box];\n"
str := "" str := ""
for i := range g.Adjacency() { // reverse paths for i := range g.Adjacency() { // reverse paths
out += fmt.Sprintf("\t%s [label=%s];\n", strconv.Quote(i.String()), strconv.Quote(i.String())) v1 := strconv.Quote(i.String()) // 1st vertex
out += fmt.Sprintf("\t\"%p\" [label=%s];\n", i, v1)
for j := range g.Adjacency()[i] { for j := range g.Adjacency()[i] {
k := g.Adjacency()[i][j] k := g.Adjacency()[i][j]
//v2 := strconv.Quote(j.String()) // 2nd vertex
e := strconv.Quote(k.String()) // edge
// use str for clearer output ordering // use str for clearer output ordering
//if fmtBoldFn(k) { // TODO: add this sort of formatting //if fmtBoldFn(k) { // TODO: add this sort of formatting
// str += fmt.Sprintf("\t\"%s\" -> \"%s\" [label=\"%s\",style=bold];\n", i, j, k) // str += fmt.Sprintf("\t\"%s\" -> \"%s\" [label=\"%s\",style=bold];\n", i, j, k)
//} else { //} else {
str += fmt.Sprintf("\t%s -> %s [label=%s];\n", strconv.Quote(i.String()), strconv.Quote(j.String()), strconv.Quote(k.String())) str += fmt.Sprintf("\t\"%p\" -> \"%p\" [label=%s];\n", i, j, e)
//} //}
} }
} }