Реферат: Алгоритмы поиска в тексте
for i := n - lp + 1 downto 1 do
for j := 1 to lp do
if P[j] <> S[i+j-1] then Break
else if j = lp then
begin
Result := i;
Exit;
end;
end;
procedure MakeBMTable( var BMT : PBMTable; const P : String);
var
i, j, lp, MaxShift, CurShift, SufPos : Integer;
Suffix : String;
begin
lp := Length(P);
GetMem(BMT, SizeOf(TIntVect)*lp);
for i := 0 to 255 do BMT^[lp-1][i] := lp;
for i := lp downto 1 do
if BMT^[lp-1][Byte(P[i])] = lp then
BMT^[lp-1][Byte(P[i])] := lp - i;
MaxShift := lp;
for i := lp - 1 downto 1 do
begin
SetLength(Suffix, lp - i);
Move(P[i+1], Suffix[1], lp - i);
if Pos(Suffix, P) = 1 then MaxShift := i;
for j := 0 to 255 do
begin
CurShift := MaxShift;