diff --git a/dir.go b/dir.go index a9ce535..1c140c7 100644 --- a/dir.go +++ b/dir.go @@ -641,12 +641,14 @@ func (nc *negCyc) step5(F LabeledPath, fEnd NI) (ok bool) { // new end node. make recursive call, then restore saved // inbound arcs for the node. F.Path[last] = h - nc.a[fEnd][0] = h - save := nc.cutTo(h.To) - ok = nc.all_nc(F) - nc.restore(save) - if !ok { - break + if len(nc.a[fEnd]) > 0 { + nc.a[fEnd][0] = h + save := nc.cutTo(h.To) + ok = nc.all_nc(F) + nc.restore(save) + if !ok { + break + } } } // after loop, restore saved outgoing arcs in g. @@ -685,9 +687,14 @@ func (nc *negCyc) restore(c []arc) { r := c[i] toList := nc.a[r.n] last := len(toList) - toList = toList[:last+1] - toList[r.x], toList[last] = toList[last], toList[r.x] - nc.a[r.n] = toList + if last > 0 { + toList = toList[:last+1] + if r.x <= last { + toList[r.x], toList[last] = toList[last], toList[r.x] + nc.a[r.n] = toList + } + + } } } diff --git a/go.mod b/go.mod index 67bf8e0..3da6891 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module "github.com/soniakeys/graph" +module "github.com/badasr/graph" require "github.com/soniakeys/bits" v1.0.0