daily pastebin goal
2%
SHARE
TWEET

Алгоритм БМ

EugenyB Feb 28th, 2013 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure boyer_moore(const haystack: string; const needle: string; var result: byte);
  2. var
  3.         i, j, k      : byte;
  4.         needle_len   : byte;
  5.         haystack_len : byte;
  6.         needle_table : array[char] of byte;
  7. begin
  8.  
  9. needle_len := length(needle);
  10. haystack_len := length(haystack);
  11.  
  12. if needle_len < haystack_len then
  13. begin
  14.         for i := 0 to 255 do
  15.                 needle_table[chr(i)] := needle_len;
  16.         for i := 1 to needle_len-1 do
  17.                 needle_table[needle[i]] := needle_len-i;
  18.  
  19.         i := needle_len;
  20.         j := i;
  21.         while (j > 0) and (i <= haystack_len) do
  22.         begin
  23.                 j := needle_len; k := i;
  24.                 while (j > 0) and (haystack[k] = needle[j]) do
  25.                 begin
  26.                         dec(k);
  27.                         dec(j);
  28.                 end;
  29.                 i := i + needle_table[haystack[i]];
  30.         end;
  31.  
  32.         if k > haystack_len - needle_len then
  33.                 result := 0
  34.         else
  35.                 result := k + 1;
  36.  
  37. end    
  38. else
  39.         result := 0;
  40. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top