routing: pop heap at the end of the loop

This prepares for routing to self.
This commit is contained in:
Joost Jager 2019-11-18 10:00:16 +01:00
parent 683282fa24
commit 81b7798c03
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -530,25 +530,14 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
// TODO(roasbeef): also add path caching // TODO(roasbeef): also add path caching
// * similar to route caching, but doesn't factor in the amount // * similar to route caching, but doesn't factor in the amount
// To start, our target node will the sole item within our distance // The partial path that we start out with is a path that consists of
// heap. // just the target node.
heap.Push(&nodeHeap, distance[target]) partialPath := distance[target]
for { for {
nodesVisited++ nodesVisited++
// Fetch the node within the smallest distance from our source
// from the heap.
partialPath := heap.Pop(&nodeHeap).(*nodeWithDist)
pivot := partialPath.node pivot := partialPath.node
// If we've reached our source (or we don't have any incoming
// edges), then we're done here and can exit the graph
// traversal early.
if pivot == source {
break
}
// Create unified policies for all incoming connections. // Create unified policies for all incoming connections.
u := newUnifiedPolicies(source, pivot, r.OutgoingChannelID) u := newUnifiedPolicies(source, pivot, r.OutgoingChannelID)
@ -589,6 +578,17 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
if nodeHeap.Len() == 0 { if nodeHeap.Len() == 0 {
break break
} }
// Fetch the node within the smallest distance from our source
// from the heap.
partialPath = heap.Pop(&nodeHeap).(*nodeWithDist)
// If we've reached our source (or we don't have any incoming
// edges), then we're done here and can exit the graph
// traversal early.
if partialPath.node == source {
break
}
} }
// Use the distance map to unravel the forward path from source to // Use the distance map to unravel the forward path from source to