Package cern.colt.map
Class PrimeFinder
java.lang.Object
cern.colt.map.PrimeFinder
Not of interest for users; only for implementors of hashtables. Used to keep
hash table capacities prime numbers.
Choosing prime numbers as hash table capacities is a good idea to keep them working fast, particularly under hash table expansions.
However, JDK 1.2, JGL 3.1 and many other toolkits do nothing to keep capacities prime. This class provides efficient means to choose prime capacities.
Choosing a prime is O(log 300) (binary search in a list of 300
int's). Memory requirements: 1 KB static memory.
- Version:
- 1.0, 09/24/99
- Author:
- wolfgang.hoschek@cern.ch
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe largest prime this class can generate; currently equal toInteger.MAX_VALUE. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMakes this class non instantiable, but still let's others inherit from it. -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidTests correctness.static intnextPrime(int desiredCapacity) Returns a prime number which is>= desiredCapacityand very close todesiredCapacity(within 11% ifdesiredCapacity >= 1000).protected static voidstatistics(int from, int to) Tests correctness.
-
Field Details
-
largestPrime
public static final int largestPrimeThe largest prime this class can generate; currently equal toInteger.MAX_VALUE.- See Also:
-
-
Constructor Details
-
PrimeFinder
protected PrimeFinder()Makes this class non instantiable, but still let's others inherit from it.
-
-
Method Details
-
main
Tests correctness. Try from=1000, to=10000 from=200, to=1000 from=16, to=1000 from=1000, to=Integer.MAX_VALUE -
nextPrime
public static int nextPrime(int desiredCapacity) Returns a prime number which is>= desiredCapacityand very close todesiredCapacity(within 11% ifdesiredCapacity >= 1000).- Parameters:
desiredCapacity- the capacity desired by the user.- Returns:
- the capacity which should be used for a hashtable.
-
statistics
protected static void statistics(int from, int to) Tests correctness.
-