Skip to content

Commit

Permalink
fix: remove vertex in adjacency list
Browse files Browse the repository at this point in the history
Fix bug in Python 3.9, 'set has changed size during iteration'
  • Loading branch information
rubenperezm committed Oct 7, 2024
1 parent c8ebb17 commit dbed54b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pystrukts/graph/adjacency_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def remove_vertex(self, x: int) -> None:
self.num_vertices -= 1

for u in range(self.num_vertices):
for v in self.vertex_list[u]:
if v >= x:
self.vertex_list[u].discard(x)
for v in range(x + 1, self.num_vertices + 1):
if v in self.vertex_list[u]:
self.vertex_list[u].discard(v)
if v > x:
self.vertex_list[u].add(v - 1)
self.vertex_list[u].add(v - 1)

0 comments on commit dbed54b

Please sign in to comment.