@@ -18,13 +18,14 @@ local function diff_u(fn1,fn2)
1818 f :seek (" set" ,o )local g = f :read (l )f :close ()return g end
1919 local b1 ,e ,b2 = line (fn1 ,o1 ,l1 )if not b1 then error (e )end b2 ,e = line (fn2 ,o2 ,l2 )if not b2 then error (e )end
2020 return b1 == b2 end
21- local h ,w =# f1 // ps ,# f2 // ps
22- local function print_table ()
23- -- TODO: store and reverse lookup this table to find the least amount of changes
24- for i = 1 ,h do
25- local row = {}for j = 1 ,w do table.insert (row ,cmp (i ,j )and " 1" or " 0" )end
26- print (table.concat (row ," " ))end end
27- print_table ()end
21+ local h ,w ,m =# f1 // ps ,# f2 // ps ,{}for i = 1 ,h do for j = 1 ,w do if cmp (i ,j )then table.insert (m ,j + (h * (i - 1 )))end end end
22+ local function score (x ,y )local i ,j = y + h * (x - 1 ),1
23+ repeat if m [j ]<= i then j = j + 1 else break end until (j ># m )return j - 1 end
24+ local x ,y ,path = h ,w ,{}
25+ while x > 0 and y > 0 do
26+ local s = score (x , y )if score (x - 1 ,y - 1 )== s - 1 then table.insert (path , 1 , {x = x , y = y })x ,y = x - 1 ,y - 1
27+ elseif score (x - 1 , y ) == s then x = x - 1 else y = y - 1 end end
28+ end
2829if # arg < 2 or# arg % 2 ~= 0 then print (arg [- 1 ].. " " .. arg [0 ].. [[ old new...
2930
3031Compare differences between files, print them as unified context.
0 commit comments