Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.lutris.util
Class BMByteSearch  view BMByteSearch download BMByteSearch.java

java.lang.Object
  extended bycom.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.


Field Summary
private  int[] charJump
          Table of jump distances for each mismatched character in the alphabet for a given search pattern.
private  int m
          The length of the search pattern.
private  int[] matchJump
          Table of partial suffix match jump distances for a given pattern.
private  byte[] P
          Byte array, beginning at index 1 (for algorithmic convenience), that contains the intended search pattern data.
 
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
private  void computeJumps()
          Initializes the per-character jump table charJump as specified by the Boyer-Moore algorithm.
private  void computeMatchJumps()
          Computes a partial-match jump table that skips over partially matching suffixes.
private  void genPatternFromByteArray(byte[] bytes, int off, int length)
          Generates the pattern byte string P from a portion of another byte string.
private  void genPatternFromCharArray(char[] chars)
          Generates the pattern byte string P from a character array.
 int getPatternLength()
          Returns the length of the pattern for this searcher.
private static int max(int i1, int i2)
          Compares two integers and returns the greater value.
private static int min(int i1, int i2)
          Compares two integers and returns the lesser value.
 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
 

Field Detail

P

private byte[] P
Byte array, beginning at index 1 (for algorithmic convenience), that contains the intended search pattern data.


m

private int m
The length of the search pattern.


charJump

private int[] charJump
Table of jump distances for each mismatched character in the alphabet for a given search pattern. Must be recomputed for each new pattern.


matchJump

private int[] matchJump
Table of partial suffix match jump distances for a given pattern. Must be recomputed for each new pattern.

Constructor Detail

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.


BMByteSearch

public BMByteSearch(byte[] pattern)
Creates a precomputed Boyer-Moore byte string search object from the given pattern.


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.

Method Detail

min

private static final int min(int i1,
                             int i2)
Compares two integers and returns the lesser value.


max

private static final int max(int i1,
                             int i2)
Compares two integers and returns the greater value.


genPatternFromByteArray

private final void genPatternFromByteArray(byte[] bytes,
                                           int off,
                                           int length)
Generates the pattern byte string P from a portion of another byte string.


genPatternFromCharArray

private final void genPatternFromCharArray(char[] chars)
Generates the pattern byte string P from a character array. The signed unicode characters are truncated to 8 bits, and converted into signed byte values. Characters between 128 and 255 are converted to their signed negative counterpart in twos-complement fashion by subtracting 256.


computeJumps

private final void computeJumps()
Initializes the per-character jump table charJump as specified by the Boyer-Moore algorithm.


computeMatchJumps

private void computeMatchJumps()
Computes a partial-match jump table that skips over partially matching suffixes.


getPatternLength

public int getPatternLength()
Returns the length of the pattern for this searcher.


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.


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.