Recent

Author Topic: Boyer Moore Horspool string search algorithm  (Read 4703 times)

teminian

  • Newbie
  • Posts: 2
Boyer Moore Horspool string search algorithm
« on: November 06, 2012, 09:56:36 am »
Dear community:

http://teminian.tumblr.com/post/35031097964

I humbly introduce PosBMH unit, my personal implementation of Boyer-Moore-Horspool string search algorithm, which is de facto standard for string search. Most of the Pascal implementations I found on the Internet were broken themselves so I made it myself.

To use, create a TPosBMH object, call PosBMH() for doing initial search, and PosBMHNext() for next occurrence. It'll return nil if there's no occurrence. For substring and parameter the function accepts string, but internal operation and return values are always PChar for further operation or manipulation.

Because currently I use only Tumblr myself, I posted the full source code to the posting itself. Just copy and paste the source code to new pas file and use at your convenience.

Basically, the license is the same as LCL(=modified LGPL) so you don't have to worry about licensing issues, but please let me know or write in your introduction of the application you have used "PosBMH from Robert Teminian" and I'll be happy sharing my humble codes.

Hope you like it. Happy coding!

Robert Teminian, a.k.a. T.Robin
http://teminian.tumblr.com

Update:
I didn't recognize I can attach a file in the posting here. For your convenience, I've attached unit file in this posting so feel free to get the source in either way.
Of course, stopping by and saying hello in my Tumblr page is always welcome.
Also, there was some trivial grammar error in the source code that howardpc pointed out. The error is fixed in both my Tumblr posting and the attachment here.
« Last Edit: November 06, 2012, 01:04:33 pm by teminian »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Boyer Moore Horspool string search algorithm
« Reply #1 on: November 06, 2012, 12:07:40 pm »
Thanks for this offering.
At your web page there is a redundant "string;" at the beginning of the declaration of the method
Code: [Select]
function PosBMH(String; Needle: ...  )
both in the class declaration and the implementation.
If these are removed your code performs well.
I've adapted it to provide an integer NeedlePos property since I dislike dealing with PChars :)

teminian

  • Newbie
  • Posts: 2
Re: Boyer Moore Horspool string search algorithm
« Reply #2 on: November 06, 2012, 12:51:48 pm »
@howardpc: thanks for pointing out. I thought I already removed that.
Now I fixed that error too in my posting in Tumblr so others will not encounter the same error.

And it's good to hear that you like it. :)
« Last Edit: November 06, 2012, 12:54:36 pm by teminian »

 

TinyPortal © 2005-2018