Class BitSetModule.AbstractBitSet<T>

java.lang.Object
io.vavr.collection.BitSetModule.AbstractBitSet<T>
All Implemented Interfaces:
BitSet<T>, Foldable<T>, Ordered<T>, Set<T>, SortedSet<T>, Traversable<T>, Function1<T,Boolean>, Value<T>, Serializable, Iterable<T>, Function<T,Boolean>
Direct Known Subclasses:
BitSetModule.BitSet1, BitSetModule.BitSet2, BitSetModule.BitSetN
Enclosing interface:
BitSetModule

public abstract static class BitSetModule.AbstractBitSet<T> extends Object implements BitSet<T>, Serializable
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getWordsNum

      abstract int getWordsNum()
    • copyExpand

      abstract long[] copyExpand(int wordsNum)
    • getWord

      abstract long getWord(int index)
    • createEmpty

      BitSet<T> createEmpty()
    • createFromAll

      BitSet<T> createFromAll(Iterable<? extends T> values)
    • fromBitMaskNoCopy

      BitSet<T> fromBitMaskNoCopy(long[] elements)
    • setElement

      private void setElement(long[] words, int element)
    • unsetElement

      private void unsetElement(long[] words, int element)
    • shrink

      long[] shrink(long[] elements)
    • addElement

      BitSet<T> addElement(int element)
    • distinctBy

      public BitSet<T> distinctBy(Comparator<? super T> comparator)
      Description copied from interface: Traversable
      Returns a new version of this which contains no duplicates. Elements are compared using the given comparator.
      Specified by:
      distinctBy in interface BitSet<T>
      Specified by:
      distinctBy in interface Set<T>
      Specified by:
      distinctBy in interface SortedSet<T>
      Specified by:
      distinctBy in interface Traversable<T>
      Parameters:
      comparator - A comparator
      Returns:
      a new Traversable containing this elements without duplicates
    • distinctBy

      public <U> BitSet<T> distinctBy(Function<? super T,? extends U> keyExtractor)
      Description copied from interface: Traversable
      Returns a new version of this which contains no duplicates. Elements mapped to keys which are compared using equals.

      The elements of the result are determined in the order of their occurrence - first match wins.

      Specified by:
      distinctBy in interface BitSet<T>
      Specified by:
      distinctBy in interface Set<T>
      Specified by:
      distinctBy in interface SortedSet<T>
      Specified by:
      distinctBy in interface Traversable<T>
      Type Parameters:
      U - key type
      Parameters:
      keyExtractor - A key extractor
      Returns:
      a new Traversable containing this elements without duplicates
    • drop

      public BitSet<T> drop(int n)
      Description copied from interface: Traversable
      Drops the first n elements of this or all elements, if this length < n.
      Specified by:
      drop in interface BitSet<T>
      Specified by:
      drop in interface Set<T>
      Specified by:
      drop in interface SortedSet<T>
      Specified by:
      drop in interface Traversable<T>
      Parameters:
      n - The number of elements to drop.
      Returns:
      a new instance consisting of all elements of this except the first n ones, or else the empty instance, if this has less than n elements.
    • dropRight

      public BitSet<T> dropRight(int n)
      Description copied from interface: Traversable
      Drops the last n elements of this or all elements, if this length < n.
      Specified by:
      dropRight in interface BitSet<T>
      Specified by:
      dropRight in interface Set<T>
      Specified by:
      dropRight in interface SortedSet<T>
      Specified by:
      dropRight in interface Traversable<T>
      Parameters:
      n - The number of elements to drop.
      Returns:
      a new instance consisting of all elements of this except the last n ones, or else the empty instance, if this has less than n elements.
    • dropWhile

      public BitSet<T> dropWhile(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Drops elements while the predicate holds for the current element.

      Note: This is essentially the same as dropUntil(predicate.negate()). It is intended to be used with method references, which cannot be negated directly.

      Specified by:
      dropWhile in interface BitSet<T>
      Specified by:
      dropWhile in interface Set<T>
      Specified by:
      dropWhile in interface SortedSet<T>
      Specified by:
      dropWhile in interface Traversable<T>
      Parameters:
      predicate - A condition tested subsequently for this elements.
      Returns:
      a new instance consisting of all elements starting from the first one which does not satisfy the given predicate.
    • intersect

      public BitSet<T> intersect(Set<? extends T> elements)
      Description copied from interface: Set
      Computes the intersection between this set and another set.

      See also Set.retainAll(Iterable).

      Specified by:
      intersect in interface BitSet<T>
      Specified by:
      intersect in interface Set<T>
      Specified by:
      intersect in interface SortedSet<T>
      Parameters:
      elements - the set to intersect with.
      Returns:
      A new Set consisting of all elements that are both in this set and in the given set that.
    • orElse

      public BitSet<T> orElse(Iterable<? extends T> other)
      Returns this BitSet if it is nonempty, otherwise BitSet created from iterable, using existing bitset properties.
      Specified by:
      orElse in interface Set<T>
      Specified by:
      orElse in interface SortedSet<T>
      Specified by:
      orElse in interface Traversable<T>
      Parameters:
      other - An alternative Traversable
      Returns:
      this BitSet if it is nonempty, otherwise BitSet created from iterable, using existing bitset properties.
    • orElse

      public BitSet<T> orElse(Supplier<? extends Iterable<? extends T>> supplier)
      Returns this BitSet if it is nonempty, otherwise BitSet created from result of evaluating supplier, using existing bitset properties.
      Specified by:
      orElse in interface Set<T>
      Specified by:
      orElse in interface SortedSet<T>
      Specified by:
      orElse in interface Traversable<T>
      Parameters:
      supplier - An alternative Traversable
      Returns:
      this BitSet if it is nonempty, otherwise BitSet created from result of evaluating supplier, using existing bitset properties.
    • slideBy

      public Iterator<BitSet<T>> slideBy(Function<? super T,?> classifier)
      Description copied from interface: Traversable
      Slides a non-overlapping window of a variable size over this Traversable.

      Each window contains elements with the same class, as determined by classifier. Two consecutive values in this Traversable will be in the same window only if classifier returns equal values for them. Otherwise, the values will constitute the last element of the previous window and the first element of the next window.

      Examples:

      
       [].slideBy(Function.identity()) = []
       [1,2,3,4,4,5].slideBy(Function.identity()) = [[1],[2],[3],[4,4],[5]]
       [1,2,3,10,12,5,7,20,29].slideBy(x -> x/10) = [[1,2,3],[10,12],[5,7],[20,29]]
       
      Specified by:
      slideBy in interface BitSet<T>
      Specified by:
      slideBy in interface Set<T>
      Specified by:
      slideBy in interface SortedSet<T>
      Specified by:
      slideBy in interface Traversable<T>
      Parameters:
      classifier - A function which classifies elements into classes
      Returns:
      A new Iterator of windows of the grouped elements
    • sliding

      public Iterator<BitSet<T>> sliding(int size, int step)
      Description copied from interface: Traversable
      Slides a window of a specific size and step size over this Traversable.

      Examples:

       
       [].sliding(1,1) = []
       [1,2,3,4,5].sliding(2,3) = [[1,2],[4,5]]
       [1,2,3,4,5].sliding(2,4) = [[1,2],[5]]
       [1,2,3,4,5].sliding(2,5) = [[1,2]]
       [1,2,3,4].sliding(5,3) = [[1,2,3,4],[4]]
       
       
      Specified by:
      sliding in interface BitSet<T>
      Specified by:
      sliding in interface Set<T>
      Specified by:
      sliding in interface SortedSet<T>
      Specified by:
      sliding in interface Traversable<T>
      Parameters:
      size - a positive window size
      step - a positive step size
      Returns:
      a new Iterator of windows of a specific size using a specific step size
    • span

      public Tuple2<BitSet<T>,BitSet<T>> span(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Returns a tuple where the first element is the longest prefix of elements that satisfy the given predicate and the second element is the remainder.
      Specified by:
      span in interface BitSet<T>
      Specified by:
      span in interface Set<T>
      Specified by:
      span in interface SortedSet<T>
      Specified by:
      span in interface Traversable<T>
      Parameters:
      predicate - A predicate.
      Returns:
      a Tuple containing the longest prefix of elements that satisfy p and the remainder.
    • scan

      public BitSet<T> scan(T zero, BiFunction<? super T,? super T,? extends T> operation)
      Description copied from interface: Traversable
      Computes a prefix scan of the elements of the collection. Note: The neutral element z may be applied more than once.
      Specified by:
      scan in interface BitSet<T>
      Specified by:
      scan in interface Set<T>
      Specified by:
      scan in interface SortedSet<T>
      Specified by:
      scan in interface Traversable<T>
      Parameters:
      zero - neutral element for the operator op
      operation - the associative operator for the scan
      Returns:
      a new traversable collection containing the prefix scan of the elements in this traversable collection
    • partition

      public Tuple2<BitSet<T>,BitSet<T>> partition(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Creates a partition of this Traversable by splitting this elements in two in distinct traversables according to a predicate.
      Specified by:
      partition in interface BitSet<T>
      Specified by:
      partition in interface Set<T>
      Specified by:
      partition in interface SortedSet<T>
      Specified by:
      partition in interface Traversable<T>
      Parameters:
      predicate - A predicate which classifies an element if it is in the first or the second traversable.
      Returns:
      A disjoint union of two traversables. The first Traversable contains all elements that satisfy the given predicate, the second Traversable contains all elements that don't. The original order of elements is preserved.
    • filter

      public BitSet<T> filter(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Returns a new traversable consisting of all elements which satisfy the given predicate.
      Specified by:
      filter in interface BitSet<T>
      Specified by:
      filter in interface Set<T>
      Specified by:
      filter in interface SortedSet<T>
      Specified by:
      filter in interface Traversable<T>
      Parameters:
      predicate - A predicate
      Returns:
      a new traversable
    • reject

      public BitSet<T> reject(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Returns a new traversable consisting of all elements which do not satisfy the given predicate.

      The default implementation is equivalent to

      filter(predicate.negate()
      Specified by:
      reject in interface BitSet<T>
      Specified by:
      reject in interface Set<T>
      Specified by:
      reject in interface SortedSet<T>
      Specified by:
      reject in interface Traversable<T>
      Parameters:
      predicate - A predicate
      Returns:
      a new traversable
    • groupBy

      public <C> Map<C,BitSet<T>> groupBy(Function<? super T,? extends C> classifier)
      Description copied from interface: Traversable
      Groups this elements by classifying the elements.
      Specified by:
      groupBy in interface BitSet<T>
      Specified by:
      groupBy in interface Set<T>
      Specified by:
      groupBy in interface SortedSet<T>
      Specified by:
      groupBy in interface Traversable<T>
      Type Parameters:
      C - classified class type
      Parameters:
      classifier - A function which classifies elements into classes
      Returns:
      A Map containing the grouped elements
      See Also:
    • comparator

      public Comparator<T> comparator()
      Description copied from interface: Ordered
      Returns the comparator which defines the order of the elements contained in this collection.
      Specified by:
      comparator in interface Ordered<T>
      Returns:
      The comparator that defines the order of this collection's elements.
    • takeWhile

      public BitSet<T> takeWhile(Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Takes elements while the predicate holds for the current element.
      Specified by:
      takeWhile in interface BitSet<T>
      Specified by:
      takeWhile in interface Set<T>
      Specified by:
      takeWhile in interface SortedSet<T>
      Specified by:
      takeWhile in interface Traversable<T>
      Parameters:
      predicate - A condition tested subsequently for the contained elements.
      Returns:
      a new instance consisting of all elements before the first one which does not satisfy the given predicate.
    • addAll

      public BitSet<T> addAll(Iterable<? extends T> elements)
      Description copied from interface: Set
      Adds all of the given elements to this set, if not already contained.
      Specified by:
      addAll in interface BitSet<T>
      Specified by:
      addAll in interface Set<T>
      Specified by:
      addAll in interface SortedSet<T>
      Parameters:
      elements - The elements to be added.
      Returns:
      A new set containing all elements of this set and the given elements, if not already contained.
    • contains

      public boolean contains(T t)
      Description copied from interface: Value
      Shortcut for exists(e -> Objects.equals(e, element)), tests if the given element is contained.
      Specified by:
      contains in interface Set<T>
      Specified by:
      contains in interface Value<T>
      Parameters:
      t - An Object of type A, may be null.
      Returns:
      true, if element is contained, false otherwise.
    • init

      public BitSet<T> init()
      Description copied from interface: Traversable
      Dual of Traversable.tail(), returning all elements except the last.
      Specified by:
      init in interface BitSet<T>
      Specified by:
      init in interface Set<T>
      Specified by:
      init in interface SortedSet<T>
      Specified by:
      init in interface Traversable<T>
      Returns:
      a new instance containing all elements except the last.
    • iterator

      public Iterator<T> iterator()
      Description copied from interface: Traversable
      An iterator by means of head() and tail(). Subclasses may want to override this method.
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Set<T>
      Specified by:
      iterator in interface Traversable<T>
      Specified by:
      iterator in interface Value<T>
      Returns:
      A new Iterator of this Traversable elements.
    • take

      public BitSet<T> take(int n)
      Description copied from interface: Traversable
      Takes the first n elements of this or all elements, if this length < n.

      The result is equivalent to sublist(0, max(0, min(length(), n))) but does not throw if n < 0 or n > length().

      In the case of n < 0 the empty instance is returned, in the case of n > length() this is returned.

      Specified by:
      take in interface BitSet<T>
      Specified by:
      take in interface Set<T>
      Specified by:
      take in interface SortedSet<T>
      Specified by:
      take in interface Traversable<T>
      Parameters:
      n - The number of elements to take.
      Returns:
      A new instance consisting of the first n elements of this or all elements, if this has less than n elements.
    • takeRight

      public BitSet<T> takeRight(int n)
      Description copied from interface: Traversable
      Takes the last n elements of this or all elements, if this length < n.

      The result is equivalent to sublist(max(0, min(length(), length() - n)), n), i.e. takeRight will not throw if n < 0 or n > length().

      In the case of n < 0 the empty instance is returned, in the case of n > length() this is returned.

      Specified by:
      takeRight in interface BitSet<T>
      Specified by:
      takeRight in interface Set<T>
      Specified by:
      takeRight in interface SortedSet<T>
      Specified by:
      takeRight in interface Traversable<T>
      Parameters:
      n - The number of elements to take.
      Returns:
      A new instance consisting of the last n elements of this or all elements, if this has less than n elements.
    • remove

      public BitSet<T> remove(T t)
      Description copied from interface: Set
      Removes a specific element from this set, if present.
      Specified by:
      remove in interface BitSet<T>
      Specified by:
      remove in interface Set<T>
      Specified by:
      remove in interface SortedSet<T>
      Parameters:
      t - The element to be removed from this set.
      Returns:
      A new set consisting of the elements of this set, without the given element.
    • removeAll

      public BitSet<T> removeAll(Iterable<? extends T> elements)
      Description copied from interface: Set
      Removes all of the given elements from this set, if present.
      Specified by:
      removeAll in interface BitSet<T>
      Specified by:
      removeAll in interface Set<T>
      Specified by:
      removeAll in interface SortedSet<T>
      Parameters:
      elements - The elements to be removed from this set.
      Returns:
      A new set consisting of the elements of this set, without the given elements.
    • toString

      public String toString()
      Description copied from interface: Value
      Clarifies that values have a proper toString() method implemented.

      See Object.toString().

      Specified by:
      toString in interface Value<T>
      Overrides:
      toString in class Object
      Returns:
      A String representation of this object
    • equals

      public boolean equals(Object o)
      Description copied from interface: Traversable
      In Vavr there are four basic classes of collections:
      • Seq (sequential elements)
      • Set (distinct elements)
      • Map (indexed elements)
      • Multimap (indexed collections)
      Two collection instances of these classes are equal if and only if both collections
      • belong to the same basic collection class (Seq, Set, Map or Multimap)
      • contain the same elements
      • have the same element order, if the collections are of type Seq
      Two Map/Multimap elements, resp. entries, (key1, value1) and (key2, value2) are equal, if the keys are equal and the values are equal.

      Notes:

      • No collection instance equals null, e.g. Queue(1) not equals null.
      • Nulls are allowed and handled as expected, e.g. List(null, 1) equals Stream(null, 1) and HashMap((null, 1)) equals LinkedHashMap((null, 1)).
      • The element order is taken into account for Seq only. E.g. List(null, 1) not equals Stream(1, null) and HashMap((null, 1), ("a", null)) equals LinkedHashMap(("a", null), (null, 1)). The reason is, that we do not know which implementations we compare when having two instances of type Map, Multimap or Set (see Liskov Substitution Principle).
      • Other collection classes are equal if their types are equal and their elements are equal (in iteration order).
      • Iterator equality is defined to be object reference equality.
      Specified by:
      equals in interface Traversable<T>
      Specified by:
      equals in interface Value<T>
      Overrides:
      equals in class Object
      Parameters:
      o - an object, may be null
      Returns:
      true, if this collection equals the given object according to the rules described above, false otherwise.
    • hashCode

      public int hashCode()
      Description copied from interface: Traversable
      Returns the hash code of this collection.
      We distinguish between two types of hashes, those for collections with predictable iteration order (like Seq) and those with arbitrary iteration order (like Set, Map and Multimap).
      In all cases the hash of an empty collection is defined to be 1.
      Collections with predictable iteration order are hashed as follows:
      
       int hash = 1;
       for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }
       
      Collections with arbitrary iteration order are hashed in a way such that the hash of a fixed number of elements is independent of their iteration order.
      
       int hash = 1;
       for (T t : this) { hash += Objects.hashCode(t); }
       
      Please note that the particular hashing algorithms may change in a future version of Vavr.
      Generally, hash codes of collections aren't cached in Vavr (opposed to the size/length). Storing hash codes in order to reduce the time complexity would increase the memory footprint. Persistent collections are built upon tree structures, it allows us to implement efficient memory sharing. A drawback of tree structures is that they make it necessary to store collection attributes at each tree node (read: element).
      The computation of the hash code is linear in time, i.e. O(n). If the hash code of a collection is re-calculated often, e.g. when using a List as HashMap key, we might want to cache the hash code. This can be achieved by simply using a wrapper class, which is not included in Vavr but could be implemented like this:
      public final class Hashed<K> {
      
           private final K key;
           private final Lazy<Integer> hashCode;
      
           public Hashed(K key) {
               this.key = key;
               this.hashCode = Lazy.of(() -> Objects.hashCode(key));
           }
      
           public K key() {
               return key;
           }
      
           &#64;Override
           public boolean equals(Object o) {
               if (o == key) {
                   return true;
               } else if (key != null && o instanceof Hashed) {
                   final Hashed that = (Hashed) o;
                   return key.equals(that.key);
               } else {
                   return false;
               }
           }
      
           &#64;Override
           public int hashCode() {
               return hashCode.get();
           }
      
           &#64;Override
           public String toString() {
               return "Hashed(" + (key == null ? "null" : key.toString()) + ")";
           }
       }
      Specified by:
      hashCode in interface Traversable<T>
      Specified by:
      hashCode in interface Value<T>
      Overrides:
      hashCode in class Object
      Returns:
      The hash code of this collection