Skip to content

Commit

Permalink
Update dfs.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Jun 3, 2024
1 parent fbebdc3 commit 7e5f2a8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/iterators/dfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ Iterator to visit vertices in a graph using depth-first search.
"""
function Base.iterate(t::DFSIterator, state::DFSVertexIteratorState)
graph, visited, queue = t.graph, state.visited, state.queue
while !isempty(queue)
@inbounds while !isempty(queue)
# we take the last node in the queue
node_start = last(queue)
curr_node = last(queue)
# we first return it
if !visited[node_start]
visited[node_start] = true
return (node_start, state)
if !visited[curr_node]
visited[curr_node] = true
return (curr_node, state)
end
# and then we visit a neighbor and push it at the
# end of the queue
for node in outneighbors(graph, node_start)
if !visited[node]
push!(queue, node)
visited[node] = true
return (node, state)
for adj_node in outneighbors(graph, curr_node)
if !visited[adj_node]
push!(queue, adj_node)
visited[adj_node] = true
return (adj_node, state)
end
end
# we pop the last node in the queue
Expand Down

0 comments on commit 7e5f2a8

Please sign in to comment.