row(k): the length of the longest common subsequence of a and b(1:k).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | a(:) |
line numbers of the two texts |
||
| integer, | intent(in) | :: | b(:) |
line numbers of the two texts |
pure function lcs_lengths(a, b) result(row) !! `row(k)`: the length of the longest common subsequence of `a` and `b(1:k)`. integer, intent(in) :: a(:), b(:) !! line numbers of the two texts integer :: row(0:size(b)) integer :: prev(0:size(b)) integer :: i, k row = 0 do i = 1, size(a) prev = row do k = 1, size(b) if (a(i) == b(k)) then row(k) = prev(k - 1) + 1 else row(k) = max(row(k - 1), prev(k)) end if end do end do end function lcs_lengths