protected static class BaseBytes.Finder
extends java.lang.Object
1 2 3
0123456789012345678901234567890
Text: a man, a map, a panama canal
Pattern: panama
This puts the 'p' of 'map' against the last byte 'a' of the pattern. Rather than testing the
pattern, we will look up 'p' in the skip table. There is a 'p' just 5 steps from the end of
the pattern, so we will move the pattern 5 places to the right before trying to match it.
This allows us to move in large strides through the text.| Modifier and Type | Field and Description |
|---|---|
protected int |
left |
protected PyBuffer |
pattern |
protected int |
right |
protected int[] |
skipTable
Table for looking up the skip, used like:
skip = skipTable[MASK & currentByte]. |
protected byte[] |
text |
| Constructor and Description |
|---|
Finder(PyBuffer pattern)
Construct a Finder object that may be used (repeatedly) to find matches with the pattern
in text (arrays of bytes).
|
| Modifier and Type | Method and Description |
|---|---|
protected int[] |
calculateSkipTable()
This method creates a compressed table of bad-character skips from the pattern.
|
int |
count(byte[] text)
Count the non-overlapping occurrences of the pattern in the text.
|
int |
count(byte[] text,
int start,
int size)
Count the non-overlapping occurrences of the pattern in the text, where the text is
effectively only the bytes
text[start] to text[start+size-1] inclusive. |
int |
count(byte[] text,
int start,
int size,
int maxcount)
Count the non-overlapping occurrences of the pattern in the text, where the text is
effectively only the bytes
text[start] to text[start+size-1]. |
int |
currIndex()
Return the index in the text array where the preceding pattern match ends (one beyond the
last character matched), which may also be one beyond the effective end ofthe text.
|
int |
nextIndex()
Find the next index in the text array where the pattern starts.
|
void |
setText(BaseBytes text)
Set the text to be searched in successive calls to
nextIndex(), where the text is
the entire byte array text. |
void |
setText(byte[] text)
Set the text to be searched in successive calls to
nextIndex(), where the text is
the entire array text[]. |
void |
setText(byte[] text,
int start,
int size)
Set the text to be searched in successive calls to
nextIndex(), where the text is
effectively only the bytes text[start] to text[start+size-1] inclusive. |
protected int[] skipTable
skip = skipTable[MASK & currentByte].protected final PyBuffer pattern
protected byte[] text
protected int left
protected int right
public Finder(PyBuffer pattern)
pattern - A vew that presents the pattern as an array of bytesprotected int[] calculateSkipTable()
public void setText(byte[] text)
nextIndex(), where the text is
the entire array text[].text - to searchpublic void setText(BaseBytes text)
nextIndex(), where the text is
the entire byte array text.text - to searchpublic void setText(byte[] text,
int start,
int size)
nextIndex(), where the text is
effectively only the bytes text[start] to text[start+size-1] inclusive.text - to searchstart - first position to considersize - number of bytes within which to matchpublic int currIndex()
nextIndex() return the start
position.
The following idiom may be used:
f.setText(text); int p = f.nextIndex(); int q = f.currIndex(); // The range text[p:q] is the matched segment.
public int nextIndex()
nextIndex() return the successive (non-overlapping) occurrences of the pattern in
the text.public int count(byte[] text)
text - to searchpublic int count(byte[] text,
int start,
int size)
text[start] to text[start+size-1] inclusive.text - to searchstart - first position to considersize - number of bytes within which to matchpublic int count(byte[] text,
int start,
int size,
int maxcount)
text[start] to text[start+size-1].text - to searchstart - first position to considersize - number of bytes within which to matchmaxcount - limit to number of occurrences to find