com.lutris.util
Class BMByteSearch
java.lang.Object
|
+--com.lutris.util.BMByteSearch
- public class BMByteSearch
- extends java.lang.Object
Implements the Boyer-Moore pattern matching algorithm for a given
byte pattern. This object implements searches on signed byte arrays.
The algorithm was obtained from "Computer Algorithms - Introduction to
Design and Analysis, Second Edition" by Sara Baase.
Constructor Summary |
BMByteSearch(byte[] pattern)
Creates a precomputed Boyer-Moore byte string search object
from the given pattern. |
BMByteSearch(byte[] pattern,
int offset,
int length)
Creates a precomputed Boyer-Moore byte string search object
from a portion of the given pattern array. |
BMByteSearch(java.lang.String pattern)
Creates a precomputed Boyer-Moore byte string search object
from the given pattern. |
Method Summary |
int |
getPatternLength()
Returns the length of the pattern for this searcher. |
int |
search(byte[] byteString)
Search for the previously pre-compiled pattern string in an
array of bytes. |
int |
search(byte[] byteString,
int offset,
int length)
Search for the previously pre-compiled pattern string in an
array of bytes. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
BMByteSearch
public BMByteSearch(java.lang.String pattern)
- Creates a precomputed Boyer-Moore byte string search object
from the given pattern. The unicode characters in
pattern
are truncated if greater than 255, and converted in twos-complement
fashion, to appropriate negative byte values, if necessary.
This method is provided as a convenience for searching for patterns
within 8 bit byte strings composed of character data.
- Parameters:
pattern
- The pattern create this object for.
BMByteSearch
public BMByteSearch(byte[] pattern)
- Creates a precomputed Boyer-Moore byte string search object
from the given pattern.
- Parameters:
pattern
- Binary pattern to search for.
BMByteSearch
public BMByteSearch(byte[] pattern,
int offset,
int length)
- Creates a precomputed Boyer-Moore byte string search object
from a portion of the given pattern array.
- Parameters:
pattern
- Byte array containing a pattern to search for.offset
- Offset to beginning of search pattern.length
- Length of the search pattern.
getPatternLength
public int getPatternLength()
- Returns the length of the pattern for this searcher.
- Returns:
- The search pattern length.
search
public int search(byte[] byteString)
- Search for the previously pre-compiled pattern string in an
array of bytes. This method uses the Boyer-Moore pattern
search algorithm.
- Parameters:
byteString
- Array of bytes in which to search
for the pattern.- Returns:
- The array index where the pattern
begins in the string, or
-1
if the pattern was not found.
search
public int search(byte[] byteString,
int offset,
int length)
- Search for the previously pre-compiled pattern string in an
array of bytes. This method uses the Boyer-Moore pattern
search algorithm.
- Parameters:
byteString
- Array of bytes in which to search
for the pattern.offset
- The the index in byteString
where the search is to begin.length
- The number of bytes to search in
byteString
.- Returns:
- The array index where the pattern
begins in the string, or
-1
if the pattern was not found.