/**
  * Check the the buffer capacity is the correct size.
  *
  * @param capacity to be checked.
  * @throws IllegalStateException if the buffer capacity is not a power of 2.
  */
 public static void checkCapacity(final int capacity) {
   if (!BitUtil.isPowerOfTwo(capacity)) {
     final String msg =
         "Capacity must be a positive power of 2 + TRAILER_LENGTH: capacity=" + capacity;
     throw new IllegalStateException(msg);
   }
 }
Ejemplo n.º 2
0
  public IntHashSet(
      @DoNotSub final int initialCapacity, final int missingValue, final double loadFactor) {
    validateLoadFactor(loadFactor);

    this.loadFactor = loadFactor;
    size = 0;
    this.missingValue = missingValue;
    @DoNotSub final int capacity = BitUtil.findNextPositivePowerOfTwo(initialCapacity);
    resizeThreshold = (int) (capacity * loadFactor); // @DoNotSub
    values = new int[capacity];
    Arrays.fill(values, missingValue);

    // NB: references values in the constructor, so must be assigned after values
    iterator = new IntIterator(missingValue, values);
  }
Ejemplo n.º 3
0
 /**
  * Compact the backing arrays by rehashing with a capacity just larger than current size and
  * giving consideration to the load factor.
  */
 public void compact() {
   @DoNotSub final int idealCapacity = (int) Math.round(size() * (1.0d / loadFactor));
   rehash(BitUtil.findNextPositivePowerOfTwo(idealCapacity));
 }
Ejemplo n.º 4
0
 /**
  * Validate the the term buffer length is a power of two.
  *
  * @param length of the term buffer
  */
 public static void validateTermBufferLength(final int length) {
   if (!BitUtil.isPowerOfTwo(length)) {
     throw new IllegalStateException(
         "Term buffer length must be a positive power of 2: " + length);
   }
 }