@Override public IntIterator iterator() { iterator.reset(); return iterator; }
public IntHashSet(final int capacity, final int missingValue) { checkTrue(capacity <= MAX_CAPACITY, "Maximum capacity is 2^29"); this.capacity = capacity; size = 0; this.missingValue = missingValue; final int arraySize = nextPowerOfTwo(2 * capacity); mask = arraySize - 1; values = new int[arraySize]; Arrays.fill(values, missingValue); // NB: references values in the constructor, so must be assigned after values iterator = new IntIterator(missingValue, values); }
/** * Strongly typed alternative of {@link Iterator#next()} to avoid boxing. * * @return the next int value. */ public int nextValue() { if (!hasNext()) { throw new NoSuchElementException(); } final int value = values[position]; position++; return value; }
public Integer next() { return nextValue(); }
public IntHashSet(final int capacity, final int missingValue) { checkTrue(capacity <= MAX_CAPACITY, "Maximum capacity is 2^29"); this.capacity = capacity; size = 0; this.missingValue = missingValue; final int arraySize = nextPowerOfTwo(2 * capacity); mask = arraySize - 1; values = new int[arraySize]; Arrays.fill(values, missingValue); // NB: references values in the constructor, so must be assigned after values iterator = new IntIterator(missingValue, values); }
/** * Strongly typed alternative of {@link Iterator#next()} to avoid boxing. * * @return the next int value. */ public int nextValue() { if (!hasNext()) { throw new NoSuchElementException(); } final int value = values[position]; position++; return value; }
public Integer next() { return nextValue(); }
@Override public IntIterator iterator() { iterator.reset(); return iterator; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }