How to de/reference the 3 array variables in this code instead of using mutable values?
The code below computes the Longest common subsequence (LCS) by diagonal traversing the m*n array.
The arguments are 2 char arrays like so:
So LCS method should result to length 4 as the longest common sub-sequence chars are "acbb" & "bcbb".
let private s1 = "ABCDBB".ToCharArray()
let private s2 = "CBACBAABA".ToCharArray()
let public lcs_seq_1d_diags (x:char[]) (y:char[]) =
let m = x.Length
let n = y.Length
let mutable dk2 = Array.create (1+m) 0
//printfn "\r\n0: %A" dk2
let mutable dk1 = Array.create (1+m) 0
//printfn "1: %A" dk1
let mutable dk = Array.create (1+m) 0
for k = 2 to m+n do
let low = max 1 (k-m)
let high = min (k-1) n
for j = low to high do
let i = k - j
if x.[i-1] = y.[j-1] then
dk.[i] <- dk2.[i-1] + 1
else
dk.[i] <- max dk1.[i] dk1.[i-1]
let mutable temp = dk2
dk2 <- dk1
dk1 <- dk
dk <- temp
dk1.[m]
let private res_seq_1d_rows = duration (fun () -> lcs_seq_1d_rows s1 s2)
//res_seq_1d_rows = 4