Boyer 1.5 build: 9470 released: 2007-05-21 A replacement for indexOf string search that runs twice as fast on long string searches. Copyright: (c) 2012 Canadian Mind Products. Java application. Download from: http://mindprod.com/products1.html#BOYER ===> Free <=== Full source included. You may even include the source code, modified or unmodified in free/commercial open source/proprietary programs that you write and distribute. May be used freely for any purpose but military. For more details on this restriction, see http://mindprod.com/contact/nonmil.html If you include any Canadian Mind Products code in your own applications, your app too must be labeled non-military use only. All Java jars and source code are included. ---- Prerequisites: This program runs under any OS, (e.g. Win2K/XP/Vista/W7x86/W7-64/OSX/Linux/Solaris/AIX...) so long as you have <><> Java version 1.1 <><> or later installed (32-bit or 64-bit Java). See http://mindprod.com/jgloss/installingjava.html for details. ---- Installing on a PC: Download source and compiled class files to run on your own machine as an application. First install a recent Java JDK or JVM. See http://mindprod.com/jgloss/installingjava.html. To install, extract the zip download with WinZip (or similar unzip utility) into any directory you please, often J:\ -- ticking off the "use folder names" option. To run as an application,type: java -ea -jar J:\com\mindprod\boyer\boyer.jar {put any parms here} adjusting as necessary to account for where the jar file is. ---- Installing on a MacIntosh: Use Safari to download source and compiled class files to run on your own machine as an application. Safari will automatically unpack the zip into ~/Downloads (version 10.5) [or on the Desktop (version 10.4 and earlier)]. First install a recent Java JDK or JVM. See http://mindprod.com/jgloss/installingjava.html. You may optionally move the download tree to a permanent home. I don't have a MacIntosh, just a PC, so I can't test my Java programs for Mac compatibility. In theory they should work without problems, but in practice that does not always happen. If you have problems please, let me know, preferably with screenshots and complete verbatim error messages. To run as an application, without parameters, just double click the jar file. To run as an application with parameters, in bash shell type: open Terminal.app cd ~/Desktop java -ea -jar com/mindprod/boyer/boyer.jar {put any parms here} adjusting as necessary to account for where the jar file is. ---- Rebuilding: The zip already contains the necessary class and jar files, so unless you modify the program, there is no need to recompile the source or rebuild the jar. Configure.java basedir="E:/" in rebuild.xml to the drive where your files are. Use ANT and rebuild.xml, not build.xml, to recompile and recreate the jar. ---- Use: Boyer-Moore Fast string search (indexOf) using the Boyer-Moore algorithm. Incorporate this class into your own Java programs to rapidly search strings. use: import com.mindprod.Boyer.Boyer; ... Boyer b = new Boyer("dogcatwombat"); int where = b.indexOf("cat"); or int where = Boyer.indexOf("dogcatwombat","cat"); Boyer-Moore is about twice as fast as String.indexOf when the string you are searching in is 2K or over and the pattern you are searching for is 4 characters or longer. String.indexOf is particularly slow when the pattern begins with a common letter such as "e". Boyer-Moore is fastest when the pattern is long and composed only of uncommon letters, e.g. "z" or "^". If you use a char[] instead of String for your text to be searched, it will run an additional 33% faster. Boyer automatically reverts to String.indexOf when that would be faster. Why the frog icon? Boyer works by hopping down a string, not processing each character. ---- Version History: 1.0 1999-01-08 1.1 1999-01-10 use simple String.indexOf for short patterns and texts lazy evaluation of skip[] array, to avoid work of calculating it. more comments. lenPat and lenText now local variables. more efficient code to catch the degenerate cases of null and 0-length strings. unravel main loop slightly to avoid extra charAt. now throw NullPointerExceptions on null arguments. also support searches of char arrays. 1.2 2001-08-13 by Jonathan Ellis added index argument to indexOf functions, to allow you to start search part way through the string. setPattern is no longer public; this cuts down on the number of overloaded fns I had to write for the above (why would anyone want to make n+1 fn calls instead of n, in the first place?) lenPat and lenText now instance variables again; I am anal about not duplicating code where possible 1.3 2001-08-13 by Roedy Green clean up JavaDoc set different breakEvenLenPat and breakEvenLenText based on debugging setting. removed the null constructor. rename pat to patternArray 1.4 2002-07-20 by David Gentzel fix bug in indexOfViaTextArray, was ignoring non-zero index. 1.5 2007-05-21 add pad, icon, pass IntelliJ lint, add ANT build.xml. -30-