linearPathsIn returns the linear paths in g created from p. If g contains any cycles linearPaths will panic.
(g graph)
| 607 | // linearPathsIn returns the linear paths in g created from p. |
| 608 | // If g contains any cycles linearPaths will panic. |
| 609 | func (p path) linearPathsIn(g graph) []path { |
| 610 | var pa []path |
| 611 | |
| 612 | var u int |
| 613 | for u < len(g) { |
| 614 | for ; u < len(g) && len(g[u]) == 0; u++ { |
| 615 | } |
| 616 | if u == len(g) { |
| 617 | return pa |
| 618 | } |
| 619 | var curr path |
| 620 | for { |
| 621 | if len(g[u]) == 0 { |
| 622 | curr = append(curr, p[u]) |
| 623 | pa = append(pa, curr) |
| 624 | if u == len(g)-1 { |
| 625 | return pa |
| 626 | } |
| 627 | break |
| 628 | } |
| 629 | if len(g[u]) > 1 { |
| 630 | panic("contour: not a linear path") |
| 631 | } |
| 632 | for v := range g[u] { |
| 633 | curr = append(curr, p[u]) |
| 634 | u = v |
| 635 | break |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | return pa |
| 641 | } |
| 642 | |
| 643 | // exciseQuick is a heuristic approach to loop excision. It does not |
| 644 | // correctly identify loops in all cases, but those cases are likely |