Fast search for patterns within strings, arrays of
bytes and ByteBuffers.
Uses an implementation of the Boyer–Moore–Horspool algorithm with a 256 character alphabet.
The algorithm has an average-case complexity of O(n)
on random text and O(nm) in the worst case, where
m = pattern length and n = length of data to search.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private final byte[] | |
| private final int[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static SearchPattern | Returns: a new SearchPattern instance using the given patternbyte array containing the pattern to search pattern)Creates a |
| public static SearchPattern | |
| public int | Returns: the length of the partial pattern matched and 0 for no match.The data in which to search for. The data may be arbitrary binary data,
but the pattern will always be data, int StandardCharsets#US_ASCII encoded.The offset within the data to start the search offset, int The length of the data to search length)Search for a partial match of the pattern at the end of the data. |
| public int | Returns: how many bytes of the pattern were matched at the end of theByteBuffer,
or 0 for no matchthe buffer)ByteBuffer to search intoSearches for a partial match of the pattern at the end of the |
| public int | |
| public byte[] | |
| public int | Returns: The index within the data array at which the first instance of the pattern or -1 if not foundThe data in which to search for. The data may be arbitrary binary data,
but the pattern will always be data, int StandardCharsets#US_ASCII encoded.The offset within the data to start the search offset, int The length of the data to search length)Search for a complete match of the pattern within the data |
| public int | Returns: the number of bytes after the buffer's position at which the full pattern was found, or -1 if the full pattern was not foundthe buffer)ByteBuffer to search intoSearches for a full match of the pattern in the |
| public int | Returns: the length of the partial pattern matched and 0 for no match.The data in which to search for. The data may be arbitrary binary data,
but the pattern will always be data, int StandardCharsets#US_ASCII encoded.The offset within the data to start the search offset, int The length of the data to search length, int The length of the partial pattern already matched matched)Search for a possibly partial match of the pattern at the start of the data. |
| public int | Returns: how many bytes of the pattern were matched (including those already matched) at the beginning of theByteBuffer, or 0 for no matchthe buffer, int ByteBuffer to search intohow many bytes of the pattern were already matched matched)Searches for a partial match of the pattern at the beginning of the |
| private void | validateArgs(byte[]
The data in which to search for. The data may be arbitrary binary data,
but the pattern will always be data, int StandardCharsets#US_ASCII encoded.The offset within the data to start the search offset, int The length of the data to search length)Performs legality checks for standard arguments input into SearchPattern methods. |
| ALPHABET_SIZE | back to summary |
|---|---|
| private static final int ALPHABET_SIZE | |
| pattern | back to summary |
|---|---|
| private final byte[] pattern | |
| table | back to summary |
|---|---|
| private final int[] table | |
| SearchPattern | back to summary |
|---|---|
private SearchPattern(byte[] pattern)
| |
| compile | back to summary |
|---|---|
| public static SearchPattern compile(byte[] pattern) Creates a
| |
| compile | back to summary |
|---|---|
| public static SearchPattern compile(String pattern) Creates a The pattern string must only contain ASCII characters.
| |
| endsWith | back to summary |
|---|---|
| public int endsWith(byte[] data, int offset, int length) Search for a partial match of the pattern at the end of the data.
| |
| endsWith | back to summary |
|---|---|
| public int endsWith(ByteBuffer buffer) Searches for a partial match of the pattern at the end of the The The position and limit of the
| |
| getLength | back to summary |
|---|---|
public int getLength()
| |
| getPattern | back to summary |
|---|---|
public byte[] getPattern()
| |
| match | back to summary |
|---|---|
| public int match(byte[] data, int offset, int length) Search for a complete match of the pattern within the data
| |
| match | back to summary |
|---|---|
| public int match(ByteBuffer buffer) Searches for a full match of the pattern in the The The position and limit of the
| |
| startsWith | back to summary |
|---|---|
| public int startsWith(byte[] data, int offset, int length, int matched) Search for a possibly partial match of the pattern at the start of the data.
| |
| startsWith | back to summary |
|---|---|
| public int startsWith(ByteBuffer buffer, int matched) Searches for a partial match of the pattern at the beginning of the The The position and limit of the
| |
| validateArgs | back to summary |
|---|---|
| private void validateArgs(byte[] data, int offset, int length) Performs legality checks for standard arguments input into SearchPattern methods.
| |