1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// Dll PosBM *******************************************************************
procedure InitSkipBuf(SStr : Pointer; LenSStr: longword); StdCall; external'PosBM';
function PosBM_KR(SStr, Str : Pointer; LSStr, LStr, Depuis :longWord): longword; stdcall; external'PosBM';
// GILBERT *********************************************************************
const MNA: array[Char] of Char
= #0#1#2#3#4#5#6#7#8#9#10#11#12#13#14#15 +
#16#17#18#19#20#21#22#23#24#25#26#27#28#29#30#31 +
' !"#$%&''()*+,-./0123456789:;<=>?' +
'@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_' +
'`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~'#127 +
''#129'
S'#141'Z'#143#144'S'#157'ZY' +
#160'¡¢£¤¥¦§¨©ª«¬*®¯°±²³´µ¶·¸¹º»¼½¾¿' +
'AAAAAAÆCEEEEIIIIDNOOOOO×OUUUUYÞß' +
'AAAAAAÆCEEEEIIIIDNOOOOO÷OUUUUYÞY';
function StrAleatoireMinus(Len: LongWord): AnsiString;
var i: longWord; R: Integer;
begin
SetLength(Result, Len);
for i := 1 to Len do begin
R := random(123 - 97); R := R + 97; Result[i] := Chr(R);
end;
end;
function StrAleatoireMajus(Len: LongWord): AnsiString;
var i: longWord; R: Integer;
begin
SetLength(Result, Len);
for i := 1 to Len do begin
R := random(91 - 65); R := R + 65; Result[i] := Chr(R);
end;
end;
// ***************************************************************************
procedure TForm1.Button1Click(Sender: TObject);
var Texte, Mot,Separ : string;
NbTours,i,j,Occ,Depuis:longword;
Gtc1,Gtc2 : Int64;
procedure Trace(S : string);
begin
Memo1.Lines.Add(S);
end;
begin
Randomize;
Mot :=StrAleatoireMajus(400);
Separ :=StrAleatoireMajus(1020);
Texte := '';
initskipBuf(@Mot[1],length(Mot));
NbTours:=100000;
for i := 1 to 10 do Texte := Mot + Separ + Texte;
Trace('Texte : '+Texte); Trace(' ');
Trace('Mot : '+Mot); Trace(' ');
Trace('Mot de '+IntToStr (length(Mot))+' Chr');
Trace('Texte de '+IntToStr(length(Texte))+' Chr');
Trace('pour '+IntToStr(NbTours)+' tours :'); trace(' ');
Gtc1 := GetTickCount;
for i:=1 to NbTours do begin
Depuis:=1; j:=0; Occ:=0;
repeat
j:=PosBM_KR(@Mot[1],@Texte[1],length(Mot),length(Texte),Depuis);
if j>0 then begin
inc(Occ); Depuis:=j+Length(Mot);
end;
until j=0;
end;
Gtc2:=GetTickCount;
Trace(IntToStr(Occ)+' occurences trouvées en '+IntToStr(Gtc2-Gtc1)+ ' ms');
Trace(' ');
end;
end. |
Partager