get_all_pieces_above Function

recursive function get_all_pieces_above(i) result(ipieces)

reursively get a list of all pieces above piece i

Arguments

Type IntentOptional Attributes Name
integer(kind=ip), intent(in) :: i

Return Value integer(kind=ip), dimension(:), allocatable


Calls

proc~~get_all_pieces_above~~CallsGraph proc~get_all_pieces_above problem_22::get_all_pieces_above proc~get_all_pieces_above->proc~get_all_pieces_above interface~unique~2 aoc_utilities::unique proc~get_all_pieces_above->interface~unique~2 proc~get_from_cache~2 aoc_cache_module::function_cache%get_from_cache proc~get_all_pieces_above->proc~get_from_cache~2 proc~get_pieces_above problem_22::get_pieces_above proc~get_all_pieces_above->proc~get_pieces_above proc~put_in_cache~2 aoc_cache_module::function_cache%put_in_cache proc~get_all_pieces_above->proc~put_in_cache~2 proc~unique32 aoc_utilities::unique32 interface~unique~2->proc~unique32 proc~unique64 aoc_utilities::unique64 interface~unique~2->proc~unique64 proc~vector_djb_hash~2 aoc_cache_module::vector_djb_hash proc~get_from_cache~2->proc~vector_djb_hash~2 proc~get_pieces_above->interface~unique~2 interface~sort aoc_utilities::sort proc~unique32->interface~sort proc~unique64->interface~sort proc~sort_ascending aoc_utilities::sort_ascending interface~sort->proc~sort_ascending proc~sort_ascending_64 aoc_utilities::sort_ascending_64 interface~sort->proc~sort_ascending_64 interface~swap~2 aoc_utilities::swap proc~sort_ascending->interface~swap~2 proc~swap64 aoc_utilities::swap64 proc~sort_ascending_64->proc~swap64 interface~swap~2->proc~swap64 proc~swap32 aoc_utilities::swap32 interface~swap~2->proc~swap32 proc~swap_str aoc_utilities::swap_str interface~swap~2->proc~swap_str

Called by

proc~~get_all_pieces_above~~CalledByGraph proc~get_all_pieces_above problem_22::get_all_pieces_above proc~get_all_pieces_above->proc~get_all_pieces_above program~problem_22 problem_22 program~problem_22->proc~get_all_pieces_above

Source Code

    recursive function get_all_pieces_above(i) result(ipieces)
        !! reursively get a list of all pieces above piece i
        integer(ip),intent(in) :: i
        integer(ip),dimension(:),allocatable :: ipieces
        integer :: j !! counter
        logical :: found
        integer(ip) :: idx
        call above_cache%get([i],idx,ipieces,found)
        if (.not. found) then
            allocate(ipieces(0))
            associate(tmp => get_pieces_above(i))
                if (size(tmp)>0) then
                    ipieces = [ipieces, tmp] ! ones directly above
                    do j = 1, size(tmp) ! go up the tree
                        ipieces = [ipieces, get_all_pieces_above(tmp(j))]
                    end do
                    ipieces = unique(ipieces)
                end if
            end associate
           call above_cache%put(idx,[i],ipieces)
        end if
    end function get_all_pieces_above