Interface ExternalSet<T>
-
- Type Parameters:
T- the type of elements inside this set
- All Superinterfaces:
java.util.Collection<T>,java.lang.Iterable<T>,java.util.Set<T>
- All Known Implementing Classes:
BitExternalSet,UniversalExternalSet
public interface ExternalSet<T> extends java.util.Set<T>A set of elements that are stored externally from this set. Elements are stored inside anExternalSetCacheinstance that is shared among all the sets created from that instance. This avoid the duplication of the references to the elements, enabling this class' instances to store the indexes of the elements inside the cache instead of the full memory address.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidaddAll(ExternalSet<T> other)Adds to this set all elements contained intoother.default booleanallMatch(java.util.function.Predicate<T> predicate)Yieldstrueiff all the elements contained in this set satisfy the given predicate.default booleananyMatch(java.util.function.Predicate<T> predicate)Yieldstrueiff at least one element contained in this set satisfies the given predicate.default java.util.Collection<T>collect()Yields a concrete list containing all the elements corresponding to the bits in this set.default booleancontains(ExternalSet<T> other)Determines if this set contains all elements of another if they share the same cache.ExternalSet<T>copy()Yields a fresh copy of this set, defined over the same cache and containing the same elements.default ExternalSet<T>difference(ExternalSet<T> other)Yields a new set obtained from this by removing the given elements.default ExternalSet<T>filter(java.util.function.Predicate<T> predicate)Yields a new external set containing only the elements of this set that satisfy the given predicate.default Tfirst()Yields the first element inside this set.ExternalSetCache<T>getCache()Yields the cache that this set is connected to.default ExternalSet<T>intersection(ExternalSet<T> other)Yields the intersection of this set and another.default booleanintersects(ExternalSet<T> other)Determines if this set has at least an element in common with another if they share the same cache.default ExternalSet<T>multiTransform(java.util.function.Function<T,java.util.Collection<T>> transformer)Transforms this set into another set where each element is obtained by transforming elements of this set.default booleannoneMatch(java.util.function.Predicate<T> predicate)Yieldstrueiff none of the elements contained in this set satisfy the given predicate.default Treduce(T base, java.util.function.BinaryOperator<T> reducer)Reduces this set to a single element.default ExternalSet<T>transform(java.util.function.UnaryOperator<T> transformer)Transforms this set into another set where each element is obtained by transforming elements of this set.default ExternalSet<T>union(ExternalSet<T> other)Yields the union of this set and another.
-
-
-
Method Detail
-
getCache
ExternalSetCache<T> getCache()
Yields the cache that this set is connected to.- Returns:
- the cache
-
addAll
default void addAll(ExternalSet<T> other)
Adds to this set all elements contained intoother. This method is faster thanSet.addAll(Collection)since it directly operates on the underlying bit set.- Parameters:
other- the other set
-
collect
default java.util.Collection<T> collect()
Yields a concrete list containing all the elements corresponding to the bits in this set.- Returns:
- the collected elements
-
copy
ExternalSet<T> copy()
Yields a fresh copy of this set, defined over the same cache and containing the same elements.- Returns:
- the fresh copy
-
contains
default boolean contains(ExternalSet<T> other)
Determines if this set contains all elements of another if they share the same cache. This method is faster thanSet.containsAll(Collection)since it directly operates on the underlying bit set.- Parameters:
other- the other set- Returns:
trueif and only ifotheris included into this set
-
intersects
default boolean intersects(ExternalSet<T> other)
Determines if this set has at least an element in common with another if they share the same cache.- Parameters:
other- the other set- Returns:
- true if and only if this set intersects the other
-
intersection
default ExternalSet<T> intersection(ExternalSet<T> other)
Yields the intersection of this set and another. Neither of them gets modified. Ifotherisnull, or if the two sets are not defined over the same cache, this set is returned.- Parameters:
other- the other set- Returns:
- the intersection of the two sets
-
difference
default ExternalSet<T> difference(ExternalSet<T> other)
Yields a new set obtained from this by removing the given elements. Ifotherisnull, or if the two sets are not defined over the same cache, this set is returned.- Parameters:
other- the elements to remove- Returns:
- a set obtained from this by removing the elements in
other
-
union
default ExternalSet<T> union(ExternalSet<T> other)
Yields the union of this set and another. Neither of them gets modified. Ifotherisnull, or if the two sets are not defined over the same cache, this set is returned.- Parameters:
other- the other set- Returns:
- the union of this set and
other
-
anyMatch
default boolean anyMatch(java.util.function.Predicate<T> predicate)
Yieldstrueiff at least one element contained in this set satisfies the given predicate.- Parameters:
predicate- the predicate to be used for testing the elements- Returns:
trueiff that condition holds,falseotherwise
-
noneMatch
default boolean noneMatch(java.util.function.Predicate<T> predicate)
Yieldstrueiff none of the elements contained in this set satisfy the given predicate.- Parameters:
predicate- the predicate to be used for testing the elements- Returns:
trueiff that condition holds,falseotherwise
-
allMatch
default boolean allMatch(java.util.function.Predicate<T> predicate)
Yieldstrueiff all the elements contained in this set satisfy the given predicate.- Parameters:
predicate- the predicate to be used for testing the elements- Returns:
trueiff that condition holds,falseotherwise
-
filter
default ExternalSet<T> filter(java.util.function.Predicate<T> predicate)
Yields a new external set containing only the elements of this set that satisfy the given predicate.- Parameters:
predicate- the predicate to be used for testing the elements- Returns:
- a new external set filtered by
predicate
-
transform
default ExternalSet<T> transform(java.util.function.UnaryOperator<T> transformer)
Transforms this set into another set where each element is obtained by transforming elements of this set.- Parameters:
transformer- the function that transforms single elements of this set- Returns:
- the transformed set
-
multiTransform
default ExternalSet<T> multiTransform(java.util.function.Function<T,java.util.Collection<T>> transformer)
Transforms this set into another set where each element is obtained by transforming elements of this set. Note that each element of this set can be transformed into multiple elements.- Parameters:
transformer- the function that transforms single elements of this set- Returns:
- the transformed set
-
reduce
default T reduce(T base, java.util.function.BinaryOperator<T> reducer)
Reduces this set to a single element. The result starts atbase, and it is transformed by invokingreduceron the current result and each element inside this set.- Parameters:
base- the initial value for building the resultreducer- the function that combines two elements into a new result- Returns:
- the reduced element
-
first
default T first()
Yields the first element inside this set.- Returns:
- the first element
- Throws:
java.util.NoSuchElementException- if this set is empty
-
-