/** * initializes the hashtable to a prime capacity which is at least <tt>initialCapacity + * 1</tt>. * * @param initialCapacity an <code>int</code> value * @return the actual capacity chosen */ protected int setUp(int initialCapacity) { int capacity; capacity = PrimeFinder.nextPrime(initialCapacity); computeMaxSize(capacity); computeNextAutoCompactionAmount(initialCapacity); return capacity; }
/** * Compresses the hashtable to the minimum prime size (as defined by PrimeFinder) that will hold * all of the elements currently in the table. If you have done a lot of <tt>remove</tt> * operations and plan to do a lot of queries or insertions or iteration, it is a good idea to * invoke this method. Doing so will accomplish two things: * * <ol> <li> You'll free memory allocated to the table but no longer needed because of the * remove()s.</li> * * <li> You'll get better query/insert/iterator performance because there won't be any * <tt>REMOVED</tt> slots to skip over when probing for indices in the table.</li> </ol> */ public void compact() { // need at least one free spot for open addressing rehash(PrimeFinder.nextPrime((int) Math.ceil(size() / _loadFactor) + 1)); computeMaxSize(capacity()); // If auto-compaction is enabled, re-determine the compaction interval if (_autoCompactionFactor != 0) { computeNextAutoCompactionAmount(size()); } }