Skip to content

Commit

Permalink
Use a deque instead of a list in graph_node_operations.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Timotshak committed Oct 24, 2023
1 parent 550028b commit 521496e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sampo/generator/utils/graph_node_operations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sampo.schemas.graph import GraphNode
from collections import deque


def count_ancestors(first_ancestors: list[GraphNode], root: GraphNode) -> int:
Expand All @@ -9,7 +10,7 @@ def count_ancestors(first_ancestors: list[GraphNode], root: GraphNode) -> int:
:param root: The root node of the graph.
:return:
"""
q = list(first_ancestors)
q = deque(first_ancestors)
count = len(first_ancestors)
used = set()
used.add(root)
Expand All @@ -19,7 +20,7 @@ def count_ancestors(first_ancestors: list[GraphNode], root: GraphNode) -> int:
if parent in used:
continue
used.add(parent)
q.insert(0, parent)
q.appendleft(parent)
count += 1

return count

0 comments on commit 521496e

Please sign in to comment.