binary_search Function

public recursive function binary_search(Ain, value) result(bsresult)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: Ain(:)
integer, intent(in) :: value

Return Value integer


Calls

proc~~binary_search~~CallsGraph proc~binary_search binary_search proc~binary_search->proc~binary_search proc~sort_array sort_array proc~binary_search->proc~sort_array

Called by

proc~~binary_search~~CalledByGraph proc~binary_search binary_search proc~binary_search->proc~binary_search none~insert sparse_dmatrix_csr%insert none~insert->proc~binary_search none~insert~2 sparse_zmatrix_csr%insert none~insert~2->proc~binary_search none~insert~3 sparse_dmatrix_csc%insert none~insert~3->proc~binary_search none~insert~4 sparse_zmatrix_csc%insert none~insert~4->proc~binary_search proc~dmatmul_csc_csc dmatmul_csc_csc proc~dmatmul_csc_csc->none~insert~3 proc~dmatmul_csc_csr_2csc dmatmul_csc_csr_2csc proc~dmatmul_csc_csr_2csc->none~insert~3 proc~dmatmul_csc_csr_2csr dmatmul_csc_csr_2csr proc~dmatmul_csc_csr_2csr->none~insert proc~dmatmul_csr_csr dmatmul_csr_csr proc~dmatmul_csr_csr->none~insert proc~zmatmul_csc_csc zmatmul_csc_csc proc~zmatmul_csc_csc->none~insert~4 proc~zmatmul_csc_csr_2csc zmatmul_csc_csr_2csc proc~zmatmul_csc_csr_2csc->none~insert~4 proc~zmatmul_csc_csr_2csr zmatmul_csc_csr_2csr proc~zmatmul_csc_csr_2csr->none~insert~2 proc~zmatmul_csr_csr zmatmul_csr_csr proc~zmatmul_csr_csr->none~insert~2 interface~matmul~2 matmul interface~matmul~2->proc~dmatmul_csc_csc interface~matmul~2->proc~dmatmul_csc_csr_2csc interface~matmul~2->proc~dmatmul_csc_csr_2csr interface~matmul~2->proc~dmatmul_csr_csr interface~matmul~2->proc~zmatmul_csc_csc interface~matmul~2->proc~zmatmul_csc_csr_2csc interface~matmul~2->proc~zmatmul_csc_csr_2csr interface~matmul~2->proc~zmatmul_csr_csr

Source Code

  recursive function binary_search(Ain,value) result(bsresult)
    integer,intent(in)           :: Ain(:), value
    integer                      :: bsresult, mid
    integer,dimension(size(Ain)) :: A,Order
    !
    a = ain
    call sort_array(a,Order)
    !
    mid = size(a)/2 + 1
    if (size(a) == 0) then
       bsresult = 0        ! not found
       !stop "binary_search error: value not found"
    else if (a(mid) > value) then
       bsresult= binary_search(a(:mid-1), value)
    else if (a(mid) < value) then
       bsresult = binary_search(a(mid+1:size(a)), value)
       if (bsresult /= 0) then
          bsresult = mid + bsresult
       end if
    else
       bsresult = mid      ! SUCCESS !
    end if
    !
    bsresult = Order(bsresult)
    !
  end function binary_search