Fix vertex filtering in layered topological sort
This commit is contained in:
parent
d2127acf04
commit
2305806c40
1 changed files with 5 additions and 2 deletions
|
|
@ -631,7 +631,7 @@ class Graph:
|
||||||
vertices: List[Vertex],
|
vertices: List[Vertex],
|
||||||
) -> List[List[str]]:
|
) -> List[List[str]]:
|
||||||
"""Performs a layered topological sort of the vertices in the graph."""
|
"""Performs a layered topological sort of the vertices in the graph."""
|
||||||
vertices_ids = [vertex.id for vertex in vertices]
|
vertices_ids = {vertex.id for vertex in vertices}
|
||||||
# Queue for vertices with no incoming edges
|
# Queue for vertices with no incoming edges
|
||||||
queue = deque(
|
queue = deque(
|
||||||
vertex.id for vertex in vertices if self.in_degree_map[vertex.id] == 0
|
vertex.id for vertex in vertices if self.in_degree_map[vertex.id] == 0
|
||||||
|
|
@ -646,7 +646,10 @@ class Graph:
|
||||||
vertex_id = queue.popleft()
|
vertex_id = queue.popleft()
|
||||||
layers[current_layer].append(vertex_id)
|
layers[current_layer].append(vertex_id)
|
||||||
for neighbor in self.successor_map[vertex_id]:
|
for neighbor in self.successor_map[vertex_id]:
|
||||||
# only vertices in `vertices` are considered
|
# only vertices in `vertices_ids` should be considered
|
||||||
|
# because vertices by have been filtered out
|
||||||
|
# in a previous step. All dependencies of theirs
|
||||||
|
# will be built automatically if required
|
||||||
if neighbor not in vertices_ids:
|
if neighbor not in vertices_ids:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue