/** * {@inheritDoc} */ public LongIterator iterator() { iterator.reset(); return iterator; }
public LongHashSet(final int capacity, final long 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 long[arraySize]; Arrays.fill(values, missingValue); // NB: references values in the constructor, so must be assigned after values iterator = new LongIterator(missingValue, values); }
public Long next() { return nextValue(); }
public LongHashSet(final int capacity, final long 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 long[arraySize]; Arrays.fill(values, missingValue); // NB: references values in the constructor, so must be assigned after values iterator = new LongIterator(missingValue, values); }
public Long next() { return nextValue(); }
/** * {@inheritDoc} */ public LongIterator iterator() { iterator.reset(); return iterator; }
/** * LongHashSet specialised variant of {this#containsAll(Collection)}. * * @param other the long hashset to compare against. * @return true if every element in other is in this. */ public boolean containsAll(final LongHashSet other) { final LongIterator iterator = other.iterator(); while (iterator.hasNext()) { if (!contains(iterator.nextValue())) { return false; } } return true; }
/** * LongHashSet specialised variant of {this#containsAll(Collection)}. * * @param other the long hashset to compare against. * @return true if every element in other is in this. */ public boolean containsAll(final LongHashSet other) { final LongIterator iterator = other.iterator(); while (iterator.hasNext()) { if (!contains(iterator.nextValue())) { return false; } } return true; }
/** * Fast Path set difference for comparison with another LongHashSet. * <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 LongHashSet difference(final LongHashSet collection) { checkNotNull(collection); LongHashSet difference = null; final LongIterator it = iterator(); while (it.hasNext()) { final long value = it.nextValue(); if (!collection.contains(value)) { if (difference == null) { difference = new LongHashSet(size, missingValue); } difference.add(value); } } return difference; }
/** * Fast Path set difference for comparison with another LongHashSet. * <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 LongHashSet difference(final LongHashSet collection) { checkNotNull(collection); LongHashSet difference = null; final LongIterator it = iterator(); while (it.hasNext()) { final long value = it.nextValue(); if (!collection.contains(value)) { if (difference == null) { difference = new LongHashSet(size, missingValue); } difference.add(value); } } return difference; }