func (g *Graph) putNewEdge(change Hash, ne NewEdge) error {
source := g.blockEnding(coalesceHash(ne.From.Change, change), ne.From.Pos)
if source == nil {
return fmt.Errorf("not found: block ending at %v:%d", coalesceHash(ne.From.Change, change), ne.From.Pos)
}
target := g.blockStarting(coalesceHash(ne.To.Change, change), ne.To.Start)
if target == nil {
return fmt.Errorf("not found: block starting at %v:%d", coalesceHash(ne.To.Change, change), ne.To.Start)
}
if target.End > ne.To.End {
g.splitBlock(target, ne.To.End)
}
introducedBy := coalesceHash(ne.IntroducedBy, change)
// Delete old edges from source to target.
for i, e := range source.Edges {
if e.Change == introducedBy && e.From == source && e.To == target {
source.Edges = append(source.Edges[:i], source.Edges[i+1:]...)
break
}
}
for i, e := range target.ReverseEdges {
if e.Change == introducedBy && e.From == source && e.To == target {
target.ReverseEdges = append(target.ReverseEdges[:i], target.ReverseEdges[i+1:]...)
break
}
}
makeEdge(change, ne.Flag, source, target)
return nil
}