Skip to content

Commit

Permalink
refac(topological_sort): rm unneeded variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rouson committed Sep 22, 2021
1 parent 0ac4083 commit 274ea3b
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/dag_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ pure module function topological_sort(dag) result(order)

block
type(searched_and_ordered_t) searched_and_ordered
integer, allocatable :: discovered(:)
integer v

allocate(discovered(0))
searched_and_ordered = searched_and_ordered_t(s = [integer::], o = [integer::])

do v = 1, size(dag%vertices)
if (.not. any(v == searched_and_ordered%s)) then
if (.not. any(v == searched_and_ordered%s)) &
searched_and_ordered = depth_first_search(v, [integer::], searched_and_ordered%o)
discovered = [discovered, searched_and_ordered%s]
searched_and_ordered%s= discovered
end if
end do
order = searched_and_ordered%o
end block
Expand All @@ -60,22 +55,21 @@ pure recursive function depth_first_search(v, d, o) result(hybrid)

call assert(.not. any(v == d), "depth_first_search: cycle detected", intrinsic_array_t([v,d]))

block
integer, allocatable :: dependencies(:)
integer w

hybrid = searched_and_ordered_t(s = [integer::], o = o)
dependencies = dag%depends_on(v)

do concurrent(w = 1:size(dependencies))
associate(w_dependencies => dependencies(w))
if (.not. any(w_dependencies == hybrid%s)) hybrid = depth_first_search(w_dependencies, [d, v], hybrid%o)
end associate
end do

if (.not. any(v == hybrid%o)) hybrid%o = [v, hybrid%o]
hybrid = searched_and_ordered_t(s = [v, hybrid%s], o = hybrid%o)
end block
hybrid = searched_and_ordered_t(s = [integer::], o = o)

associate(dependencies => dag%depends_on(v))
block
integer w
do concurrent(w = 1:size(dependencies))
associate(w_dependencies => dependencies(w))
if (.not. any(w_dependencies == hybrid%s)) hybrid = depth_first_search(w_dependencies, [d, v], hybrid%o)
end associate
end do
end block
end associate

if (.not. any(v == hybrid%o)) hybrid%o = [v, hybrid%o]
hybrid = searched_and_ordered_t(s = [v, hybrid%s], o = hybrid%o)

end function

Expand Down

0 comments on commit 274ea3b

Please sign in to comment.