We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
has_path
popfirst!
push!
1 parent 24539fd commit 6954605Copy full SHA for 6954605
src/traversals/bfs.jl
@@ -182,15 +182,18 @@ function has_path(
182
end
183
(seen[u] || seen[v]) && return false
184
u == v && return true # cannot be separated
185
- next = Vector{T}()
186
- push!(next, u)
+ next = Vector{T}(undef, nv(g))
+ front = back = 1
187
+ next[front] = u
188
seen[u] = true
- while !isempty(next)
189
- src = popfirst!(next) # get new element from queue
+ while front <= back
190
+ src = next[front]
191
+ front += 1 # dequeue; pop from queue
192
for vertex in outneighbors(g, src)
193
vertex == v && return true
194
if !seen[vertex]
- push!(next, vertex) # push onto queue
195
+ back += 1
196
+ next[back] = vertex # enqueue; push onto queue
197
seen[vertex] = true
198
199
0 commit comments