Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int32), | intent(in) | :: | node | |||
class(type_node_adjacency), | intent(in) | :: | node_adj | |||
integer(kind=int32), | intent(in) | :: | degree(:) | |||
logical, | intent(inout) | :: | visited(:) | |||
integer(kind=int32), | intent(inout) | :: | Q(:) | |||
integer(kind=int32), | intent(inout) | :: | q_tail |
subroutine sort_and_enqueue_neighbors(node, node_adj, degree, visited, Q, q_tail) implicit none integer(int32), intent(in) :: node class(type_node_adjacency), intent(in) :: node_adj integer(int32), intent(in) :: degree(:) logical, intent(inout) :: visited(:) integer(int32), intent(inout) :: Q(:), q_tail integer(int32), allocatable :: neighbors(:), neighbor_degrees(:), sorted_indices(:) integer(int32) :: i, p, n_count call node_adj%get_neighbors(node, neighbors) n_count = size(neighbors) if (n_count == 0) return call allocate_array(neighbor_degrees, length=n_count) call allocate_array(sorted_indices, length=n_count) do i = 1, n_count neighbor_degrees(i) = degree(neighbors(i)) end do call sort_index(neighbor_degrees, sorted_indices) do i = 1, n_count p = neighbors(sorted_indices(i)) if (.not. visited(p)) then visited(p) = .true. q_tail = q_tail + 1 Q(q_tail) = p end if end do call deallocate_array(neighbors) call deallocate_array(neighbor_degrees) call deallocate_array(sorted_indices) end subroutine sort_and_enqueue_neighbors