Alice0725 Expert Cheater
Reputation: 11
Joined: 24 Jul 2012 Posts: 145
|
Posted: Wed Nov 28, 2012 6:16 am Post subject: Quick Search Algorithm:simplification of the Boyer-Moore alg |
|
|
It's really a very quick search algorithm for simple aobscan.
Anyone know an other better quick search algorithm ?
http://www-igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
| Code: | {
Quick Search Algorithm:
1.See QSA in http://www-igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
2.Add wildcards support.wildcard=$0100;.
}
function PreQsBc(aob:PWord;aobSize:integer):TIntegers;
const
ASIZE=256; //yes,a byte.
var
shift:TIntegers;
i,wcshift:integer;
wildcard:boolean=false;
begin
setlength(shift,ASIZE);
for i:=0 to ASIZE-1 do
shift[i]:= aobSize+1;
for i:=0 to aobSize-1 do
begin
if (aob[i] <> $0100) then
begin
Shift[aob[i]]:=aobSize-i;
end else
begin
wildcard:=true;
wcshift:=aobsize-i;
end;
end;
if(wildcard=true)then
for i:=0 to ASIZE-1 do
if Shift[i]>wcshift then
Shift[i]:=wcshift;
Exit(shift);
end;
function QS(aob:PWord;aobSize:integer;buffer:PByte;bufferSize:integer;Shift:PInteger):integer;
var
i:integer = 0;
j:integer = 0;
begin
result := -1;
while j <= bufferSize-aobSize do
begin
for i:=0 to (aobSize-1) do
begin
if(aob[i]=$0100)or(aob[i]=buffer[i+j])
then continue
else break;
end;
if i+1=aobSize then
begin
result := j;
exit;
end else
begin
j:= j+shift[Buffer[j+aobSize]];
end;
end; //end of while
end; |
|
|