Skip to content

Commit 9fcd138

Browse files
author
Damian Rouson
committed
refac(depth_first_search): subroutine -> function
1 parent 0dad796 commit 9fcd138

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/dag_s.f90

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pure module function topological_sort(dag) result(order)
4242

4343
do v = 1, size(dag%vertices)
4444
if (.not. any(v == searched_and_ordered%s)) then
45-
call depth_first_search(v, [integer::], searched_and_ordered%o, searched_and_ordered%s)
45+
searched_and_ordered = depth_first_search(v, [integer::], searched_and_ordered%o)
4646
discovered = [discovered, searched_and_ordered%s]
4747
searched_and_ordered%s= discovered
4848
end if
@@ -52,10 +52,10 @@ pure module function topological_sort(dag) result(order)
5252

5353
contains
5454

55-
pure recursive subroutine depth_first_search(v, d, o, s)
56-
integer, intent(in) :: v, d(:)
57-
integer, intent(out), allocatable :: s(:)
58-
integer, intent(inout), allocatable :: o(:)
55+
pure recursive function depth_first_search(v, d, o) result(result_)
56+
integer, intent(in) :: v
57+
integer, intent(in), dimension(:) :: d, o
58+
type(searched_and_ordered_t) result_
5959

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

@@ -64,25 +64,24 @@ pure recursive subroutine depth_first_search(v, d, o, s)
6464
integer w
6565
type(searched_and_ordered_t) hybrid
6666

67-
hybrid%o = o
67+
hybrid = searched_and_ordered_t(s = [integer::], o = o)
6868
dependencies = dag%depends_on(v)
6969

70-
allocate(d_local(0), hybrid%s(0))
70+
allocate(d_local(0))
7171

7272
do w = 1, size(dependencies)
7373
if (.not. any(dependencies(w) == hybrid%s)) then
74-
call depth_first_search(dependencies(w), [d, v], hybrid%o, hybrid%s)
74+
hybrid = depth_first_search(dependencies(w), [d, v], hybrid%o)
7575
d_local = [d_local, hybrid%s]
7676
hybrid%s = d_local
7777
end if
7878
end do
7979

8080
if (.not. any(v == hybrid%o)) hybrid%o = [v, hybrid%o]
81-
s = [v, hybrid%s]
82-
o = hybrid%o
81+
result_ = searched_and_ordered_t(s = [v, hybrid%s], o = hybrid%o)
8382
end block
8483

85-
end subroutine
84+
end function
8685

8786
end function topological_sort
8887

0 commit comments

Comments
 (0)