function edit_distance_bit(str1,str2:string):integer;
var
Peq:array[0..255] of Uint64;
Pv, Eq, Xv, Xh, Ph, Mh, Mv, ONE:Uint64;
i,j,m,n,Score:integer;
p1,p2:pbyte;
s:string;
begin
if (length(str1) < length(str2)) then
begin
p1:=@str2[1];
p2:=@str1[1];
m := length(str2);
n := length(str1);
end
else
begin
p1:=@str1[1];
p2:=@str2[1];
m := length(str1);
n := length(str2);
end;
ONE := 1;
fillbyte(Peq,0,sizeof(Peq));
Mv := 0;
Score := m;
for i := 0 to m do
begin
Peq[p1[i]] :=Peq[p1[i]] or ONE shl i;
Pv :=Pv or (ONE shl i);
end;
for j := 0 to n do
begin
Eq := Peq[p2[j]];
Xv := Eq or Mv;
Xh := (((Eq and Pv) + Pv) xor Pv) or Eq;
Ph := Mv or (not (Xh or Pv));
Mh := Pv and Xh;
if (Ph and (ONE shl (m - 1)))<>0 then
inc(Score)
else
if (Mh and (ONE shl (m - 1)))<>0 then
dec(Score);
Ph :=Ph shl ONE;
Pv := (Mh shl ONE) or (not (Xv or Ph));
Mv := Ph and Xv;
end;
result := Score;
end;