tweaks
This commit is contained in:
parent
04f8399e24
commit
fb08ad1de7
1 changed files with 5 additions and 7 deletions
|
@ -380,13 +380,11 @@ func (d dag) topWalk(visit func(Drawer)) {
|
||||||
// If indegree(v) = 0, enqueue. Total: O(|V|).
|
// If indegree(v) = 0, enqueue. Total: O(|V|).
|
||||||
queue := make([]Drawer, 0, len(d))
|
queue := make([]Drawer, 0, len(d))
|
||||||
indegree := make(map[Drawer]int)
|
indegree := make(map[Drawer]int)
|
||||||
for u := range d {
|
for v, e := range d {
|
||||||
// NB: zero indegree vertices may be missing from d.in
|
if len(e.in) == 0 {
|
||||||
e := d[u].in
|
queue = append(queue, v)
|
||||||
if len(e) == 0 {
|
|
||||||
queue = append(queue, u)
|
|
||||||
} else {
|
} else {
|
||||||
indegree[u] = len(e)
|
indegree[v] = len(e.in)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +411,7 @@ func (d dag) topWalk(visit func(Drawer)) {
|
||||||
visit(u)
|
visit(u)
|
||||||
queue = queue[1:]
|
queue = queue[1:]
|
||||||
|
|
||||||
// Decrement indegree for all out edges, and enqueue target if its
|
// Decrement indegree for all out-edges, and enqueue target if its
|
||||||
// indegree is now 0.
|
// indegree is now 0.
|
||||||
for v := range d[u].out {
|
for v := range d[u].out {
|
||||||
if _, ready := indegree[v]; !ready {
|
if _, ready := indegree[v]; !ready {
|
||||||
|
|
Loading…
Reference in a new issue