/** * Create a hash table that can comfortably hold the specified number of entries. The actual table * created to be is the smallest prime greater than size * 2. */ public Int2LongHash(int size, float loadFactor) { assert (size > 0) : size; int bucketSize = Primes.findLeastPrimeNumber(size * 2); this._buckets = new BucketEntry[bucketSize]; this._loadFactor = loadFactor; this._threshold = (int) (size * loadFactor); }
protected void ensureCapacity(int newCapacity) { if (_used < _threshold) { throw new IllegalStateException("used: " + _used + ", threshold: " + _threshold); } int prime = Primes.findLeastPrimeNumber(newCapacity); rehash(prime); this._threshold = Math.round(prime * _loadFactor); }
@SuppressWarnings("unchecked") public Object2LongOpenHash(int size, float loadFactor, float growFactor) { if (size < 1) { throw new IllegalArgumentException(); } this._loadFactor = loadFactor; this._growFactor = growFactor; int actualSize = Primes.findLeastPrimeNumber(size); this._keys = (K[]) new Object[actualSize]; this._values = new long[actualSize]; this._states = new byte[actualSize]; this._threshold = Math.round(actualSize * _loadFactor); }