Marcin Drobik

software journeyman notes

Generic Boyer-Moore implementation

Recently I encountered a problem of finding pattern in stream of bytes. Using Wikipedia article I implemented much of the Boyer-Moore algorithm and converted it to more general solution, that can be used on any Enumerable<T> (T must implement Equals and GetHashCode).

I did some simple benchmark and it looks surprising well - for small strings my implementation is slower than built-in String.IndexOf but it can be almost 10 times faster for larger strings (> 1 kB).

Boyer-Moore Benchmark

Take a look at it at GitHub:

comments powered by Disqus