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 an ExternalSetCache instance 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 void addAll​(ExternalSet<T> other)
      Adds to this set all elements contained into other.
      default boolean allMatch​(java.util.function.Predicate<T> predicate)
      Yields true iff all the elements contained in this set satisfy the given predicate.
      default boolean anyMatch​(java.util.function.Predicate<T> predicate)
      Yields true iff 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 boolean contains​(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 T first()
      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 boolean intersects​(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 boolean noneMatch​(java.util.function.Predicate<T> predicate)
      Yields true iff none of the elements contained in this set satisfy the given predicate.
      default T reduce​(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.
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, spliterator, toArray, toArray
    • 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 into other. This method is faster than Set.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 than Set.containsAll(Collection) since it directly operates on the underlying bit set.
        Parameters:
        other - the other set
        Returns:
        true if and only if other is 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. If other is null, 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. If other is null, 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. If other is null, 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)
        Yields true iff at least one element contained in this set satisfies the given predicate.
        Parameters:
        predicate - the predicate to be used for testing the elements
        Returns:
        true iff that condition holds, false otherwise
      • noneMatch

        default boolean noneMatch​(java.util.function.Predicate<T> predicate)
        Yields true iff none of the elements contained in this set satisfy the given predicate.
        Parameters:
        predicate - the predicate to be used for testing the elements
        Returns:
        true iff that condition holds, false otherwise
      • allMatch

        default boolean allMatch​(java.util.function.Predicate<T> predicate)
        Yields true iff all the elements contained in this set satisfy the given predicate.
        Parameters:
        predicate - the predicate to be used for testing the elements
        Returns:
        true iff that condition holds, false otherwise
      • 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 at base, and it is transformed by invoking reducer on the current result and each element inside this set.
        Parameters:
        base - the initial value for building the result
        reducer - 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