/** * Inserts a value into the set. * * @param obj an <code>Object</code> value * @return true if the set was modified by the add operation */ @Override public boolean add(E obj) { int index = insertKey(obj); if (index < 0) { return false; // already present in set, nothing to add } if (!order.add(index)) throw new IllegalStateException("Order not changed after insert"); postInsertHook(consumeFreeSlot); return true; // yes, we added something }
/** * Expands the set to accommodate new values. * * @param newCapacity an <code>int</code> value */ @Override protected void rehash(int newCapacity) { TIntLinkedList oldOrder = new TIntLinkedList(order); int oldSize = size(); Object oldSet[] = _set; order.clear(); _set = new Object[newCapacity]; Arrays.fill(_set, FREE); for (TIntIterator iterator = oldOrder.iterator(); iterator.hasNext();) { int i = iterator.next(); E o = (E) oldSet[i]; if (o == FREE || o == REMOVED) { throw new IllegalStateException("Iterating over empty location while rehashing"); } if (o != FREE && o != REMOVED) { int index = insertKey(o); if (index < 0) { // everyone pays for this because some people can't RTFM throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); } if (!order.add(index)) throw new IllegalStateException("Order not changed after insert"); } } }
/** * Inserts a value into the set. * * @param obj an <code>Object</code> value * @return true if the set was modified by the add operation */ @Override public boolean add(E obj) { int index = insertKey(obj); if (index < 0) { return false; // already present in set, nothing to add } if (!order.add(index)) throw new IllegalStateException("Order not changed after insert"); postInsertHook(consumeFreeSlot); return true; // yes, we added something }
/** * Inserts a value into the set. * * @param obj an <code>Object</code> value * @return true if the set was modified by the add operation */ @Override public boolean add(E obj) { int index = insertKey(obj); if (index < 0) { return false; // already present in set, nothing to add } if (!order.add(index)) throw new IllegalStateException("Order not changed after insert"); postInsertHook(consumeFreeSlot); return true; // yes, we added something }
/** * Expands the set to accommodate new values. * * @param newCapacity an <code>int</code> value */ @Override protected void rehash(int newCapacity) { TIntLinkedList oldOrder = new TIntLinkedList(order); int oldSize = size(); Object oldSet[] = _set; order.clear(); _set = new Object[newCapacity]; Arrays.fill(_set, FREE); for (TIntIterator iterator = oldOrder.iterator(); iterator.hasNext();) { int i = iterator.next(); E o = (E) oldSet[i]; if (o == FREE || o == REMOVED) { throw new IllegalStateException("Iterating over empty location while rehashing"); } if (o != FREE && o != REMOVED) { int index = insertKey(o); if (index < 0) { // everyone pays for this because some people can't RTFM throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); } if (!order.add(index)) throw new IllegalStateException("Order not changed after insert"); } } }
/** * Expands the set to accommodate new values. * * @param newCapacity an <code>int</code> value */ @Override @SuppressWarnings("unchecked") protected void rehash(int newCapacity) { TIntLinkedList oldOrder = new TIntLinkedList(order); int oldSize = size(); Object oldSet[] = _set; order.clear(); _set = new Object[newCapacity]; Arrays.fill(_set, FREE); for (TIntIterator iterator = oldOrder.iterator(); iterator.hasNext();) { int i = iterator.next(); E o = (E) oldSet[i]; if (o == FREE || o == REMOVED) { throw new IllegalStateException("Iterating over empty location while rehashing"); } if (o != FREE && o != REMOVED) { int index = insertKey(o); if (index < 0) { // everyone pays for this because some people can't RTFM throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); } if (!order.add(index)) throw new IllegalStateException("Order not changed after insert"); } } }