@@ -14,7 +14,7 @@ local function diff_u(fn1,fn2)
1414 local l1 ,c1 ,o1 ,l2 ,c2 ,o2 ,b1 ,e ,b2 ,f = string.unpack (PF ,f1 ,(x - 1 )* ps + 1 )l2 ,c2 ,o2 = string.unpack (PF ,f2 ,(y - 1 )* ps + 1 )if l1 ~= l2 or c1 ~= c2 then return false end
1515 local function li (fn ,o ,l )f ,e = io.open (fn ," rb" )if not f then return nil ,e end f :seek (S ,o )local g = f :read (l )f :close ()return g end
1616 b1 ,e ,b2 = li (fn1 ,o1 ,l1 )if not b1 then error (e )end b2 ,e = li (fn2 ,o2 ,l2 )if not b2 then error (e )end return b1 == b2 end
17- h ,w ,m =# f1 // ps ,# f2 // ps ,{}for x = 1 ,h do for y = 1 ,w do if cmp (x ,y )then table.insert (m , {y = y ,x = x })end end end
17+ h ,w ,m =# f1 // ps ,# f2 // ps ,{}for x = 1 ,h do for y = 1 ,w do if cmp (x ,y )then if # m > 0 and m [ # m ]. x == x then table.insert (m [ # m ]. y , y ) else table.insert ( m , {y = { y } ,x = x })end end end end
1818 local function get (fn ,p ,x )local l ,_ ,o ,f ,r = string.unpack (PF ,p ,(x - 1 )* ps + 1 )f = assert (io.open (fn ," rb" ))f :seek (S ,o )r = f :read (l )f :close ()return r end
1919 local function pfl (p ,s )return (p .. s :gsub (' \n $' ,' ' ):gsub (' \r $' ,' ' ))end
2020 local function flush ()if # u .l > 0 then if u .e >= 4 then table.remove (u .l )u .o .l ,u .n .l = u .o .l - 1 ,u .n .l - 1 end
@@ -23,12 +23,14 @@ local function diff_u(fn1,fn2)
2323 for _ ,v in ipairs (u .l )do print (v )end end u = nil end
2424 local function init ()if not u then local k ,l = math.max (i - 3 ,1 ),math.max (j - 3 ,1 )u = {e = 0 ,l = {},o = {s = k ,l = 0 },n = {s = l ,l = 0 }}
2525 for z = k ,i - 1 do table.insert (u .l ,pfl (" " ,get (fn1 ,f1 ,z )))u .o .l ,u .n .l = u .o .l + 1 ,u .n .l + 1 end end end
26- local k = 2 while k <=# m do if m [k ].x > m [k - 1 ].x then table.remove (m ,k - 1 )else k = k + 1 end end
27- -- TODO: convert to sequences
26+ -- TODO: Select correct y grid on each compare table
2827 for _ ,p in ipairs (m )do
28+ -- Temporary debug code
29+ print (p .x , table.concat (p .y ," ," ))--[[
2930 while i<p.x do init()table.insert(u.l,pfl("-",get(fn1,f1,i)))i,u.o.l,u.e=i+1,u.o.l+1,0 end
3031 while j<p.y do init()table.insert(u.l,pfl("+",get(fn2,f2,j)))j,u.n.l,u.e=j+1,u.n.l+1,0 end
3132 if u then if u.e<4 then table.insert(u.l,pfl(" ",get(fn1,f1,i)))u.e,u.o.l,u.n.l=u.e+1,u.o.l+1,u.n.l+1 else flush()end end i,j=i+1,j+1 end
33+ --]] end os.exit (1 )
3234 local function nlc ()if la then la = la :sub (- 1 )if la ~= ' \n ' and la ~= ' \r ' then table.insert (u .l ," \\ No newline at end of file" )end end end
3335 while i <= h do init ()la = get (fn1 ,f1 ,i ,ps )table.insert (u .l ,pfl (" -" ,la ))i ,u .o .l ,u .e = i + 1 ,u .o .l + 1 ,0 end nlc ()
3436 while j <= w do init ()la = get (fn2 ,f2 ,j ,ps )table.insert (u .l ,pfl (" +" ,la ))j ,u .n .l ,u .e = j + 1 ,u .n .l + 1 ,0 end nlc ()
0 commit comments