Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up has_path by avoiding popfirst! and push! #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/traversals/bfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,18 @@ function has_path(
end
(seen[u] || seen[v]) && return false
u == v && return true # cannot be separated
next = Vector{T}()
push!(next, u)
next = Vector{T}(undef, nv(g))
front = back = 1
next[front] = u
seen[u] = true
while !isempty(next)
src = popfirst!(next) # get new element from queue
while front <= back
src = next[front]
front += 1 # dequeue; pop from queue
for vertex in outneighbors(g, src)
vertex == v && return true
if !seen[vertex]
push!(next, vertex) # push onto queue
back += 1
next[back] = vertex # enqueue; push onto queue
seen[vertex] = true
end
end
Expand Down
Loading