seqcomp
-- if you build something with this, -- or derive something from this, -- i'd like a credit. Kat -- I built this from inspiration and code provided by DCuny. -- -- entry is global function diff_seqs() include machine.e include sort.e with trace --**************************************************************************************************************************************** function diff3sort3(sequence result) integer bplace1, bplace2 sequence origresult, newresult -- sort the result by the number of "x" in "[,]xx[,]" if sequence(result[1]) then origresult = result for loop = 1 to length(result) do bplace1 = find('[',result[loop]) while ( bplace1 != 0 ) do result[loop] = result[loop][1..bplace1-1] & result[loop][find(']',result[loop])+1..length(result[loop])] bplace1 = find('[',result[loop]) end while origresult[loop] = length(result[loop]) & " " & origresult[loop] end for origresult = sort(origresult) newresult = "" -- reverse the sort for loop = length(origresult) to 1 by -1 do newresult = append(newresult,origresult[loop]) end for else newresult = result end if return newresult end function -- diff3sort3(sequence result) --****************************************************************************************** procedure putseq(sequence data) for loop = 1 to length(data) do puts(1,data[loop] & " ") end for -- puts(1,"\n") end procedure -- putseq(sequence data) --****************************************************************************************** sequence hugeresult global function diff_seqs( sequence s1_orig, sequence s2_orig, integer MinG, integer MaxG, integer recursing, sequence middleresult ) sequence result, compared, tempresult, syncs, s1, s2 integer min1, min2 sequence syncs1, syncs2 puts(1,"recursing = "&sprintf("%d",recursing)&"\n") --trace(1) --if recursing = 1 then trace(1) end if if length(s1_orig) and not length(s2_orig) then return {{"["} & s1_orig & {"|"} & {"]"}} end if if not length(s1_orig) and length(s2_orig) then return {{"["} & {"|"} & s2_orig & {"]"}} end if if not length(s1_orig) and not length(s2_orig) then return "" end if if equal(s1_orig,s2_orig) then return {{s1_orig}} end if s1 = s1_orig s2 = s2_orig if recursing = 0 then hugeresult = {} end if result = {} tempresult = {} syncs1 = {{0,0}} -- haveto preload to avoid Eu crashes later syncs2 = {{0,0}} syncs = {} min1 = 0 min2 = 0 --trace(1) for loop = 1 to length(s1) do if find(s1[loop],s2) then if length(syncs1) then min1 = syncs1[length(syncs1)][1] min2 = syncs1[length(syncs1)][2] end if if (min1+1 = loop) and (min2+1 = find(s1[loop],s2)) then syncs1[length(syncs1)] = {loop,find(s1[loop],s2)} else syncs1 = syncs1 & {{loop,find(s1[loop],s2)}} if length(syncs1) > 1 then if equal(syncs1[1],{0,0}) then syncs1 = {syncs1[2]} end if end if syncs1 = {syncs1[1]} exit end if -- else -- exit end if end for for loop = 1 to length(s2) do if find(s2[loop],s1) then if length(syncs1) then min1 = syncs2[length(syncs2)][1] min2 = syncs2[length(syncs2)][2] end if if (min1+1 = loop) and (min2+1 = find(s1[loop],s2)) then syncs2[length(syncs2)] = {loop,find(s1[loop],s2)} else syncs2 = syncs2 & {{loop,find(s1[loop],s2)}} if length(syncs2) > 1 then if equal(syncs2[1],{0,0}) then syncs2 = {syncs2[2]} end if syncs2 = {syncs2[1]} end if exit end if --else -- exit end if end for syncs = syncs1 for syncloop = 1 to length(syncs2) do if not find(syncs2[syncloop],syncs) then -- check for the reverse too min1 = syncs2[syncloop][1] min2 = syncs2[syncloop][2] syncs1 = {min2,min1} if not find(syncs1,syncs) then syncs = syncs & {syncs2[syncloop]} end if end if end for --trace(1) --if recursing = 1 then trace(1) end if if equal(syncs,{{0,0}}) then return({"["} & s1 & {"|"} & s2 & {"]"}) end if for loop = 1 to length(syncs) do s1 = s1_orig s2 = s2_orig puts(1,"syncs[loop] = {"&sprintf("%d",syncs[loop][1])&","&sprintf("%d",syncs[loop][2])&"}\n") --trace(1) if (syncs[loop][1]=1) and (syncs[loop][2]=1) then result = {s1[1]} -- so result[1] = s1[1] elsif (syncs[loop][1]>1) and (syncs[loop][2]>1) then if equal(s1[1..syncs[loop][1]],s2[1..syncs[loop][2]]) then result = s1[1..syncs[loop][1]] else result = {"["} & s1[1..syncs[loop][1]-1] & {"|"} & s2[1..syncs[loop][2]-1] & {"]"} & {s1[syncs[loop][1]]} end if elsif (syncs[loop][1]=1) and (syncs[loop][2]>1) then result = {"["}&{"|"} & s2[1..syncs[loop][2]-1] & {"]"} & {s1[1]} elsif (syncs[loop][1]>1) and (syncs[loop][2]=1) then result = {"["} & s1[1..syncs[loop][1]-1] & {"|"} & {"]"} & {s2[1]} end if --if length(middleresult) -- then -- for addloop = 1 to length(middleresult) do -- middleresult[addloop] &= result -- end for -- else -- middleresult = result --end if s1 = s1[syncs[loop][1]+1..length(s1)] s2 = s2[syncs[loop][2]+1..length(s2)] -- recurse here compared = diff_seqs(s1,s2,MinG,MaxG,recursing+1,result) trace(1) if not length(hugeresult) then hugeresult &= "" end if for hugeloop = 1 to length(hugeresult) do hugeresult[hugeloop] &= {middleresult & result & compared} end for middleresult = "" end for -- loop = 1 to length(syncs) do if recursing = 0 then return(hugeresult) else return(middleresult) end if end function
Not Categorized, Please Help
|