index_in_queue Function

function index_in_queue(state) result(idx)

Arguments

Type IntentOptional Attributes Name
integer(kind=ip), intent(in), dimension(NSTATE) :: state

Return Value integer(kind=ip)

index in the queue. -1 if not present


Calls

proc~~index_in_queue~2~~CallsGraph proc~index_in_queue~2 problem_17::index_in_queue proc~get_from_cache~2 aoc_cache_module::function_cache%get_from_cache proc~index_in_queue~2->proc~get_from_cache~2 proc~put_in_cache~2 aoc_cache_module::function_cache%put_in_cache proc~index_in_queue~2->proc~put_in_cache~2 proc~vector_djb_hash~2 aoc_cache_module::vector_djb_hash proc~get_from_cache~2->proc~vector_djb_hash~2

Called by

proc~~index_in_queue~2~~CalledByGraph proc~index_in_queue~2 problem_17::index_in_queue proc~check~2 problem_17::check proc~check~2->proc~index_in_queue~2 program~problem_17~2 problem_17 program~problem_17~2->proc~check~2

Source Code

    function index_in_queue(state) result(idx)
        integer(ip),dimension(NSTATE),intent(in) :: state
        integer(ip) :: idx !! index in the queue. -1 if not present
        integer(ip) :: i
        logical :: found
        integer(ip) :: cache_idx
        integer(ip),dimension(:),allocatable :: cache_ival

        call cache%get(state,cache_idx,cache_ival,found)
        if (found) then
            idx = cache_ival(1)
        else
            idx = -1
            if (.not. allocated(queue)) error stop 'error: queue not allocated'
            do i = 1, queue_size
                if (all(state == queue(i)%state)) then
                    idx = i
                    exit
                end if
            end do
            if (idx /= -1) call cache%put(cache_idx,state,[idx])
        end if
    end function index_in_queue