@Override public boolean test(E x) { return add(x); } };
@Override public boolean addAll(final Collection<? extends Integer> coll) { return addAllCapture(coll); }
private <E extends Integer> boolean addAllCapture(final Collection<E> coll) { final Predicate<E> p = new Predicate<E>() { @Override public boolean test(E x) { return add(x); } }; return conjunction(coll, p); }
public boolean equals(final Object other) { if (other == this) { return true; } if (other instanceof IntHashSet) { final IntHashSet otherSet = (IntHashSet) other; return otherSet.missingValue == missingValue && otherSet.size() == size() && containsAll(otherSet); } return false; }
/** * Fast Path set difference for comparison with another IntHashSet. * <p/> * NB: garbage free in the identical case, allocates otherwise. * * @param collection the other set to subtract * @return null if identical, otherwise the set of differences */ public IntHashSet difference(final IntHashSet collection) { checkNotNull(collection, "Collection must not be null"); IntHashSet difference = null; final IntIterator it = iterator(); while (it.hasNext()) { final int value = it.nextValue(); if (!collection.contains(value)) { if (difference == null) { difference = new IntHashSet(size, missingValue); } difference.add(value); } } return difference; }
/** * IntHashSet specialised variant of {this#containsAll(Collection)}. * * @param other the int hashset to compare against. * @return true if every element in other is in this. */ public boolean containsAll(final IntHashSet other) { final IntIterator iterator = other.iterator(); while (iterator.hasNext()) { if (!contains(iterator.nextValue())) { return false; } } return true; }
/** * An int specialised version of {this#remove(Object)}. * * @param value the value to remove * @return true if the value was present, false otherwise */ public boolean remove(final int value) { int index = intHash(value, mask); while (values[index] != missingValue) { if (values[index] == value) { values[index] = missingValue; compactChain(index); return true; } index = next(index); } return false; }
public boolean contains(final int value) { int index = intHash(value, mask); while (values[index] != missingValue) { if (values[index] == value) { return true; } index = next(index); } return false; }
@Override public boolean test(E value) { return contains(value); } });
public int hashCode() { final IntIterator iterator = iterator(); int total = 0; while (iterator.hasNext()) { // Cast exists for substitutions total += (int) iterator.nextValue(); } return total; }
@Override public boolean containsAll(final Collection<?> coll) { return containsAllCapture(coll); }
/** * Fast Path set difference for comparison with another IntHashSet. * <p/> * NB: garbage free in the identical case, allocates otherwise. * * @param collection the other set to subtract * @return null if identical, otherwise the set of differences */ public IntHashSet difference(final IntHashSet collection) { checkNotNull(collection, "Collection must not be null"); IntHashSet difference = null; final IntIterator it = iterator(); while (it.hasNext()) { final int value = it.nextValue(); if (!collection.contains(value)) { if (difference == null) { difference = new IntHashSet(size, missingValue); } difference.add(value); } } return difference; }
public boolean equals(final Object other) { if (other == this) { return true; } if (other instanceof IntHashSet) { final IntHashSet otherSet = (IntHashSet) other; return otherSet.missingValue == missingValue && otherSet.size() == size() && containsAll(otherSet); } return false; }
/** * IntHashSet specialised variant of {this#containsAll(Collection)}. * * @param other the int hashset to compare against. * @return true if every element in other is in this. */ public boolean containsAll(final IntHashSet other) { final IntIterator iterator = other.iterator(); while (iterator.hasNext()) { if (!contains(iterator.nextValue())) { return false; } } return true; }
/** * An int specialised version of {this#remove(Object)}. * * @param value the value to remove * @return true if the value was present, false otherwise */ public boolean remove(final int value) { int index = intHash(value, mask); while (values[index] != missingValue) { if (values[index] == value) { values[index] = missingValue; compactChain(index); return true; } index = next(index); } return false; }
public boolean contains(final int value) { int index = intHash(value, mask); while (values[index] != missingValue) { if (values[index] == value) { return true; } index = next(index); } return false; }
@Override public boolean test(E value) { return contains(value); } });
public int hashCode() { final IntIterator iterator = iterator(); int total = 0; while (iterator.hasNext()) { // Cast exists for substitutions total += (int) iterator.nextValue(); } return total; }
@Override public boolean containsAll(final Collection<?> coll) { return containsAllCapture(coll); }
private void compactChain(int deleteIndex) { final int[] values = this.values; int index = deleteIndex; while (true) { index = next(index); if (values[index] == missingValue) { return; } final int hash = intHash(values[index], mask); if ((index < hash && (hash <= deleteIndex || deleteIndex <= index)) || (hash <= deleteIndex && deleteIndex <= index) ) { values[deleteIndex] = values[index]; values[index] = missingValue; deleteIndex = index; } } }