org.apache.lucene.util
Class Prime

Object
  extended by Prime

public class Prime
extends Object

Utlity class for finding prime numbers (useful for making hash tables).

Author:
Martin Haye

Field Summary
private static int[] primeList
          A handy quick-reference table of primes 1 .. 2^31, spaced evenly in a logarithmic sense.
 
Constructor Summary
Prime()
           
 
Method Summary
static int findAfter(int n)
          Determines a prime number greater than n, but not too much greater.
private static BitSet makePrimeSet(int n)
          Makes a bit set of primes below n.
static void printPrimeList(int n, float v)
          Print a list of primes 1..n, evenly spaced at intervals v
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

primeList

private static int[] primeList
A handy quick-reference table of primes 1 .. 2^31, spaced evenly in a logarithmic sense. This was generated by calling: printPrimeList(Integer.MAX_VALUE, 1.1f)

Constructor Detail

Prime

public Prime()
Method Detail

findAfter

public static int findAfter(int n)
Determines a prime number greater than n, but not too much greater. Useful for sizing a hash table so that modulo arithmetic produces good results.


makePrimeSet

private static BitSet makePrimeSet(int n)
Makes a bit set of primes below n. The returned set will have a clear bit at each location (prime/2).


printPrimeList

public static void printPrimeList(int n,
                                  float v)
Print a list of primes 1..n, evenly spaced at intervals v