@Override public boolean add(int val) { return set.add(val); }
/** * Tests the set to determine if all of the elements in <tt>array</tt> are present. * * @param array an <code>array</code> of int primitives. * @return true if all elements were present in the set. */ public boolean containsAll(int[] array) { for (int i = array.length; i-- > 0; ) { if (!contains(array[i])) { return false; } } return true; }
@Override public int size() { return set.size(); }
/** * 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 }
/** * Compares this set with another set for equality of their stored entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean equals(Object other) { if (!(other instanceof TIntHashSet)) { return false; } final TIntHashSet that = (TIntHashSet) other; if (that.size() != this.size()) { return false; } return forEach(new TIntProcedure() { public final boolean execute(int value) { return that.contains(value); } }); }
/** * Creates a new <code>TIntHashSet</code> instance containing the elements of <tt>array</tt>. * * @param array an array of <code>int</code> primitives * @param strategy used to compute hash codes and to compare keys. */ public TIntHashSet(int[] array, TIntHashingStrategy strategy) { this(array.length, strategy); addAll(array); }
public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // NUMBER OF ENTRIES out.writeInt(_size); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure(out); if (!forEach(writeProcedure)) { throw writeProcedure.exception; } }
public TroveIntegerSet() { this.set = new TIntHashSet(); }
@Override public boolean isEmpty() { return set.isEmpty(); }
/** * 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; } } }
/** * Creates a new <code>TIntHashSet</code> instance containing the elements of <tt>array</tt>. * * @param array an array of <code>int</code> primitives */ public TIntHashSet(int[] array) { this(array.length); addAll(array); }
public int hashCode() { HashProcedure p = new HashProcedure(); forEach(p); return p.getHashCode(); }
public TroveIntegerSet(int initialCapacity) { this.set = new TIntHashSet(initialCapacity); }
public final boolean execute(int value) { return that.contains(value); } });
/** * Returns a new array containing the values in the set. * * @return an <code>int[]</code> value */ public int[] toArray() { int[] result = new int[size()]; int[] set = _set; byte[] states = _states; for (int i = states.length, j = 0; i-- > 0; ) { if (states[i] == FULL) { result[j++] = set[i]; } } return result; }
/** * Adds all of the elements in <tt>array</tt> to the set. * * @param array an <code>array</code> of int primitives. * @return true if the set was modified by the add all operation. */ public boolean addAll(int[] array) { boolean changed = false; for (int i = array.length; i-- > 0; ) { if (add(array[i])) { changed = true; } } return changed; }
@Override public boolean contains(int val) { return set.contains(val); }