Skip to content

Commit 2868be8

Browse files
committed
Refactor loop so that first count is correct.
1 parent 210ad14 commit 2868be8

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

xtra/DIFF.LUA

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ local function diff_u(fn1,fn2)
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
1717
h,w,m=#f1//ps,#f2//ps,{}
18-
local function inList(l,v)for _,p in ipairs(l)do if v==p then return true end end return false end
1918
for x=1,h do
20-
for y=1,w do
21-
if cmp(x,y)then
22-
if #m>0 and m[#m].x==x then
23-
table.insert(m[#m].y,y)
24-
elseif #m>0 and m[#m].x==x-1 and inList(m[#m].y,y-1)then
25-
m[#m].l=m[#m].l+1
26-
else
27-
table.insert(m,{y={y},x=x,l=1})
28-
end
19+
local b={}
20+
for y=1,w do if cmp(x,y)then table.insert(b,y)end end
21+
if #m>0 and m[#m].x+m[#m].l==x then
22+
local function inList(v)for k,p in ipairs(b)do if v==p then return k end end end
23+
if inList(m[#m].y+m[#m].l) then
24+
m[#m].l=m[#m].l+1
25+
else
26+
--TODO: Know where to run the next block
2927
end
28+
else
29+
table.insert(m,{y=b[1],x=x,l=1})
3030
end
3131
end
3232
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
@@ -38,9 +38,10 @@ local function diff_u(fn1,fn2)
3838
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}}
3939
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
4040
--TODO: Select correct y grid on each compare table
41+
print("x","y","l")
4142
for _,p in ipairs(m)do
4243
-- Temporary debug code
43-
print(p.x, p.l, table.concat(p.y,","))--[[
44+
print(p.x, p.y, p.l)--[[
4445
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
4546
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
4647
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

0 commit comments

Comments
 (0)