org.jboss.gravel.data.phase
Class SimpleBoyerMoore

java.lang.Object
  extended by org.jboss.gravel.data.phase.SimpleBoyerMoore

public class SimpleBoyerMoore
extends Object

SimpleBoyerMoore is an implementation of the simplified version of the Boyer-Moore pattern search algorithm. This just means that the "good match" portion of the algorithm is removed, which improves the performance of non repeating patterns with the obvious side-effect of reducing repeating pattern performance (e.g. gaggaggaaaggaggaagagaggaga). This version of the algorithm performs incredibly well if the pattern is rare, for example a MIME boundary. This algorithm is binary safe.


Field Summary
static int PATTERN_NOT_FOUND
           
 
Constructor Summary
SimpleBoyerMoore(byte[] pattern)
          Constructs a SimpleBoyerMoore instance.
 
Method Summary
 int patternSearch(byte[] text, int offset, int length)
          Find an occurence of the search pattern within text.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN_NOT_FOUND

public static final int PATTERN_NOT_FOUND
See Also:
Constant Field Values
Constructor Detail

SimpleBoyerMoore

public SimpleBoyerMoore(byte[] pattern)
Constructs a SimpleBoyerMoore instance. This internally stores the pattern so that the same instance can be used across several searches.

Parameters:
pattern - the pattern to search for
Method Detail

patternSearch

public int patternSearch(byte[] text,
                         int offset,
                         int length)
Find an occurence of the search pattern within text.

Parameters:
text - a byte array of data to seach
offset - the index in text to start searching from
length - the maximum number of bytes to search
Returns:
if a match is found, the index of text where the patter occurs, otherwise PATTERN_NOT_FOUND