/** * Expands the set to accommodate new values. * * @param newCapacity an <code>int</code> value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; int oldSet[] = _set; byte oldStates[] = _states; _set = new int[newCapacity]; _states = new byte[newCapacity]; for (int i = oldCapacity; i-- > 0; ) { if (oldStates[i] == FULL) { int o = oldSet[i]; int index = insertionIndex(o); _set[index] = o; _states[index] = FULL; } } }
/** * Inserts a value into the set. * * @param val an <code>int</code> value * @return true if the set was modified by the add operation */ public boolean add(int val) { int index = insertionIndex(val); if (index < 0) { return false; // already present in set, nothing to add } byte previousState = _states[index]; _set[index] = val; _states[index] = FULL; postInsertHook(previousState == FREE); return true; // yes, we added something }