public LongHashSet(long[] items, long missingValue) { this(items.length, missingValue); for (long item : items) { add(item); } }
/** * {@inheritDoc} */ public boolean addAll(final Collection<? extends Long> coll) { return addAllCapture(coll); }
private <E extends Long> 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); }
/** * {@inheritDoc} */ public boolean equals(final Object other) { if (other == this) { return true; } if (other instanceof LongHashSet) { final LongHashSet otherSet = (LongHashSet) other; return otherSet.missingValue == missingValue && otherSet.size() == size() && containsAll(otherSet); } return false; }
/** * 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; }
/** * 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; }
/** * An long 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 long value) { int index = longHash(value, mask); while (values[index] != missingValue) { if (values[index] == value) { values[index] = missingValue; compactChain(index); size--; return true; } index = next(index); } return false; }
/** * {@inheritDoc} */ public boolean contains(final long value) { int index = longHash(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); } });
/** * {@inheritDoc} */ public boolean containsAll(final Collection<?> coll) { return containsAllCapture(coll); }
/** * {@inheritDoc} */ public int hashCode() { final LongIterator iterator = iterator(); int total = 0; while (iterator.hasNext()) { // Cast exists for substitutions total += (long) iterator.nextValue(); } return total; }
/** * 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; }
/** * {@inheritDoc} */ public boolean equals(final Object other) { if (other == this) { return true; } if (other instanceof LongHashSet) { final LongHashSet otherSet = (LongHashSet) other; return otherSet.missingValue == missingValue && otherSet.size() == size() && containsAll(otherSet); } return false; }
/** * 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; }
/** * An long 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 long value) { int index = longHash(value, mask); while (values[index] != missingValue) { if (values[index] == value) { values[index] = missingValue; compactChain(index); size--; return true; } index = next(index); } return false; }
/** * {@inheritDoc} */ public boolean contains(final long value) { int index = longHash(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); } });
/** * {@inheritDoc} */ public boolean containsAll(final Collection<?> coll) { return containsAllCapture(coll); }
/** * {@inheritDoc} */ public int hashCode() { final LongIterator iterator = iterator(); int total = 0; while (iterator.hasNext()) { // Cast exists for substitutions total += (long) iterator.nextValue(); } return total; }
private <E> boolean removeAllCapture(final Collection<E> coll) { return conjunction(coll, new Predicate<E>() { @Override public boolean test(E value) { return remove(value); } }); }