From 274ea3bf9ad0c2e4fe9f8954dbd63c7638fa09a3 Mon Sep 17 00:00:00 2001 From: Damian Rouson Date: Wed, 22 Sep 2021 11:40:53 -0700 Subject: [PATCH] refac(topological_sort): rm unneeded variables --- src/dag_s.f90 | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/dag_s.f90 b/src/dag_s.f90 index fa1f503..1abdb72 100644 --- a/src/dag_s.f90 +++ b/src/dag_s.f90 @@ -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 @@ -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