@MinDoc(copyright="Copyright 2010 A. Weinert", author="Albrecht Weinert", version="V.39", lastModified="17.04.2021", usage="make for substrings to search for and use multiply", purpose="Rabin Karp substring search implementation") public class RK extends CleverSSS
RK
object holdsRK
String
and consorts, are
of type O(n*m).RK
object. The other hash is
"sliding" over the longer character sequence to search in. The
hash function used here is a polynomial with the character values acting
as coefficients.super class
.CleverSSS.Simple
Modifier and Type | Field and Description |
---|---|
int |
iFac
The hash factor to remove the actual first character from
a sliding hash.
|
char |
subLast
The sub sequence's last character.
|
algName, ignoreCase, ignoreWS, len, mskMod, optimisticOK, primF, subC
Modifier | Constructor and Description |
---|---|
protected |
RK(char[] subC,
char subLast,
int subHash,
int iFac,
boolean ignoreCase,
boolean ignoreWS,
boolean optimisticOK)
Constructor (for factory methods only, no checks).
|
Modifier and Type | Method and Description |
---|---|
static int |
extHash(int oldHash,
char charIn)
Extend a RK hash by one character (helper function).
|
protected long |
implAlgWhere(CharSequence sequ,
int lk,
int sI,
int mxSi)
The basic implementation of the RK search algorithm
using this object's settings.
|
static CleverSSS |
make(CharSequence sub,
boolean ignoreCase)
Make a RK for a subsequence to be searched for.
|
static CleverSSS |
make(CharSequence sub,
boolean ignoreCase,
boolean ignoreWS)
Make a RK for a subsequence to be searched for (later).
|
int |
slideHash(int oldHash,
char charOut,
char charIn)
Slide a hash for this RK hash by one character (helper function).
|
allWhere, asPair, asPairs, charAt, commonState, compareTo, endIndexOf, endIndexOf, equals, hashCode, implAlgWhere, indexOf, indexOf, lastIndexOf, lastIndexOf, lastWhereImpl, length, make, make, makeSimple, pair2long, state, subSequence, toCharA, toString, where, where, whereImpl
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
chars, codePoints
public final char subLast
CleverSSS.length()
.CleverSSS.ignoreCase
this character is lower case.CleverSSS.ignoreWS
this character is guaranteed to be
> blank.public final int iFac
protected RK(char[] subC, char subLast, int subHash, int iFac, boolean ignoreCase, boolean ignoreWS, boolean optimisticOK)
public static CleverSSS make(CharSequence sub, boolean ignoreCase)
RK
object for the
sub
sequence supplied. That object is suitable for subsequent
multiple and multi-thread indexOf
type
searches for that sub
sequence. If (all) that searches are to
ignore case, this has to has to be (finally) set here.sub
null (no RK
object) is returned,
as this case requires no search at all.public static CleverSSS make(CharSequence sub, boolean ignoreCase, boolean ignoreWS)
make(CharSequence, boolean)
with the
extra option to make the subsequence search totally white space ignoring
if the the third parameter ignoreWS
is supplied as true.sub
's non blank characters would be transferred
to the RK
object to be made."al L"
in
" H a l l o "
both ignoring white space and case would
yield 3 as the first matching index (and 8 as the first non matching index
after the fitting sub sequence pattern).public static int extHash(int oldHash, char charIn)
charIn
. Ignoring case and or white space has to be done by the
caller.oldHash
- the old hash value; supply 0 for new startcharIn
- the character to put as new last character to the hashpublic final int slideHash(int oldHash, char charOut, char charIn)
charIn
and charOut
. Ignoring case
and
or white space
has to be done by the caller.oldHash
- the old hash value; supply 0 for new startcharIn
- the character to put as new last character to the hashcharOut
- the character to remove as old first character from the
the sliding hash; supply 0 for new start or use
extHash(1, charIn)
to startprotected final long implAlgWhere(CharSequence sequ, int lk, int sI, int mxSi)
CleverSSS.whereImpl(CharSequence, int, int)
for
all non trivial cases and with checked / correct parameters.implAlgWhere
in class CleverSSS
sequ
- the sequence to search inlk
- its correct or shortened) lengthsI
- the starting index for the searchmxSi
- the maximum possible value of the match indexCleverSSS.implAlgWhere()