org.apache.mahout.math.map
public class: PrimeFinder [javadoc |

source]

java.lang.Object
**org.apache.mahout.math.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.

Field Summary |
---|

public static final int | **largestPrime** | The largest prime this class can generate; currently equal to `Integer.MAX_VALUE`. |

Method from **org.apache.mahout.math.map.PrimeFinder** Summary: |
---|

nextPrime |

Methods from **java.lang.Object**: |
---|

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |

Method from **org.apache.mahout.math.map.PrimeFinder** Detail: |

public static int **nextPrime**(int desiredCapacity) {
int i = java.util.Arrays.binarySearch(primeCapacities, desiredCapacity);
if (i < 0) {
// desired capacity not found, choose next prime greater than desired capacity
i = -i - 1; // remember the semantics of binarySearch...
}
return primeCapacities[i];
} Returns a prime number which is `>= desiredCapacity` and very close to `desiredCapacity`
(within 11% if `desiredCapacity >= 1000` ). |