Check if A is a subset of B
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int64), | intent(in) | :: | A(:) | |||
integer(kind=int64), | intent(in) | :: | B(:) |
pure function subset_integer_int64 (A, B) result(res)
integer (int64), intent(in) :: A(:), B(:)
logical :: res
character(*), parameter :: this_routine = "subset_integer_int64"
integer :: i, j
#ifdef DEBUG_
block
use util_mod, only: stop_all
if (.not. (is_sorted(A))) then
call stop_all (this_routine, "Assert fail: is_sorted(A)")
end if
end block
#endif
#ifdef DEBUG_
block
use util_mod, only: stop_all
if (.not. (is_sorted(B))) then
call stop_all (this_routine, "Assert fail: is_sorted(B)")
end if
end block
#endif
if (size(A) == 0) then
res = .true.
return
end if
res = .false.
if (size(A) > size(B)) return
if (A(1) < B(1) .or. A(size(A)) > B(size(B))) return
i = 1; j = 1
do while (i <= size(A))
if (j > size(B)) then
return
else if (i == size(A) .and. j == size(B) .and. A(i) /= B(j)) then
return
else if (A(i) < B(j)) then
i = i + 1
else if (A(i) > B(j)) then
j = j + 1
else if (A(i) == B(j)) then
i = i + 1
j = j + 1
end if
end do
res = .true.
end function subset_integer_int64