Exemple #1
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);
  }
Exemple #2
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));
 }