private CharKeyOpenHashMap(
     CharHashFunction keyhash,
     int capacity,
     int growthPolicy,
     double growthFactor,
     int growthChunk,
     double loadFactor) {
   if (keyhash == null) Exceptions.nullArgument("hash function");
   if (capacity < 0) Exceptions.negativeArgument("capacity", String.valueOf(capacity));
   if (growthFactor <= 0.0)
     Exceptions.negativeOrZeroArgument("growthFactor", String.valueOf(growthFactor));
   if (growthChunk <= 0)
     Exceptions.negativeOrZeroArgument("growthChunk", String.valueOf(growthChunk));
   if (loadFactor <= 0.0)
     Exceptions.negativeOrZeroArgument("loadFactor", String.valueOf(loadFactor));
   this.keyhash = keyhash;
   capacity = Primes.nextPrime(capacity);
   keys = new char[capacity];
   values = (Object[]) new Object[capacity];
   this.states = new byte[capacity];
   size = 0;
   expandAt = (int) Math.round(loadFactor * capacity);
   this.used = 0;
   this.growthPolicy = growthPolicy;
   this.growthFactor = growthFactor;
   this.growthChunk = growthChunk;
   this.loadFactor = loadFactor;
 }
 /**
  * Returns a clone of this hash map.
  *
  * @return a clone of this hash map.
  * @since 1.1
  */
 public Object clone() {
   try {
     CharKeyOpenHashMap c = (CharKeyOpenHashMap) super.clone();
     c.keys = new char[keys.length];
     System.arraycopy(keys, 0, c.keys, 0, keys.length);
     c.values = (Object[]) new Object[values.length];
     System.arraycopy(values, 0, c.values, 0, values.length);
     c.states = new byte[states.length];
     System.arraycopy(states, 0, c.states, 0, states.length);
     //  The views should not refer to this map's views
     c.cvalues = null;
     c.ckeys = null;
     return c;
   } catch (CloneNotSupportedException e) {
     Exceptions.cloning();
     return null;
   }
 }
Пример #3
0
 /**
  * Returns from a static prime table the least prime that is greater than or equal to a specified
  * value.
  *
  * <p>On average, the returned prime will about 1/64 of 2<sup>(r+1)</sup> - 2<sup>r</sup> greater
  * than n, where r is the order of n (the number of bits required for representing it).
  *
  * @return the least prime in the table that is greater than or equal to the specified value.
  */
 public static int nextPrime(int n) {
   if (n <= 0) Exceptions.negativeArgument("lower bound", String.valueOf(n));
   int idx = java.util.Arrays.binarySearch(primes, n);
   if (idx < 0) return primes[-idx - 1];
   return primes[idx];
 }