Package mondrian.util

Class PrimeFinder


  • final class PrimeFinder
    extends java.lang.Object
    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

      Fields 
      Modifier and Type Field Description
      static int largestPrime
      The largest prime this class can generate; currently equal to Integer.MAX_VALUE.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void main​(java.lang.String[] args)
      Tests correctness.
      static int nextPrime​(int desiredCapacity)
      Returns a prime number which is >= desiredCapacity and very close to desiredCapacity (within 11% if desiredCapacity >= 1000).
      protected static void statistics​(int from, int to, java.io.PrintWriter pw)
      Tests correctness.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • largestPrime

        public static final int largestPrime
        The largest prime this class can generate; currently equal to Integer.MAX_VALUE. yes, it is prime.
        See Also:
        Constant Field Values
    • Method Detail

      • nextPrime

        public static int nextPrime​(int desiredCapacity)
        Returns a prime number which is >= desiredCapacity and very close to desiredCapacity (within 11% if desiredCapacity >= 1000).
        Parameters:
        desiredCapacity - the capacity desired by the user.
        Returns:
        the capacity which should be used for a hashtable.
      • main

        protected static void main​(java.lang.String[] args)
        Tests correctness. Try from=1000, to=10000 from=200, to=1000 from=16, to=1000 from=1000, to=Integer.MAX_VALUE
      • statistics

        protected static void statistics​(int from,
                                         int to,
                                         java.io.PrintWriter pw)
        Tests correctness.