net.jxta.search.util
Class KMP

java.lang.Object
  |
  +--net.jxta.search.util.KMP
All Implemented Interfaces:
StringMatcher

public class KMP
extends java.lang.Object
implements StringMatcher

Knuth-Morris-Pratt string-matching algorithm. Usage:

 StringMatcher kmp = new KMP ();
 
 StringMatcher.CompiledPattern pattern = kmp.compile (searchPhrase);
 
 int index = bm.match (text, 0, pattern);
 
 System.out.println ("First location of " + searchPhrase + " at " + index);
 
 


Inner classes inherited from class net.jxta.search.util.StringMatcher
StringMatcher.CompiledPattern
 
Constructor Summary
KMP()
           
 
Method Summary
 StringMatcher.CompiledPattern compile(java.lang.String pattern)
          Compile the pattern into some algorithm-specific data structure.
static void main(java.lang.String[] argv)
           
 int match(char[] text, int textStart, StringMatcher.CompiledPattern compiledPattern)
          Find the first instance of the pattern in the document starting at index docStart.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KMP

public KMP()
Method Detail

main

public static void main(java.lang.String[] argv)

compile

public StringMatcher.CompiledPattern compile(java.lang.String pattern)
Description copied from interface: StringMatcher
Compile the pattern into some algorithm-specific data structure.
Specified by:
compile in interface StringMatcher

match

public int match(char[] text,
                 int textStart,
                 StringMatcher.CompiledPattern compiledPattern)
Description copied from interface: StringMatcher
Find the first instance of the pattern in the document starting at index docStart.
Specified by:
match in interface StringMatcher