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(@NonNull Comparator<? super T> comparator)
      Description copied from interface: Traversable
      Returns a new Traversable containing the elements of this instance without duplicates, as determined by 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 used to determine equality of elements
      Returns:
      a new Traversable with duplicates removed
    • distinctBy

      public <U> BitSet<T> distinctBy(@NonNull Function<? super T,? extends U> keyExtractor)
      Description copied from interface: Traversable
      Returns a new Traversable containing the elements of this instance without duplicates, based on keys extracted from elements using keyExtractor.

      The first occurrence of each key is retained in the resulting sequence.

      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 - the type of key
      Parameters:
      keyExtractor - a function to extract keys for determining uniqueness
      Returns:
      a new Traversable with duplicates removed based on keys
    • drop

      public BitSet<T> drop(int n)
      Description copied from interface: Traversable
      Returns a new Traversable without the first n elements, or an empty instance if this contains fewer than n elements.
      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 excluding the first n elements
    • dropRight

      public BitSet<T> dropRight(int n)
      Description copied from interface: Traversable
      Returns a new Traversable without the last n elements, or an empty instance if this contains fewer than n elements.
      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 from the end
      Returns:
      a new instance excluding the last n elements
    • dropWhile

      public BitSet<T> dropWhile(@NonNull Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Returns a new Traversable starting from the first element that does not satisfy the given predicate, dropping all preceding elements.

      This is equivalent to dropUntil(predicate.negate()), which is useful for method references that 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 on each element
      Returns:
      a new instance starting from the first element not matching the predicate
    • intersect

      public BitSet<T> intersect(@NonNull Set<? extends T> elements)
      Description copied from interface: Set
      Returns a new set containing only the elements present in both this set and the given set.
      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 with elements common to both sets
    • orElse

      public BitSet<T> orElse(@NonNull 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(@NonNull 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(@NonNull Function<? super T,?> classifier)
      Description copied from interface: Traversable
      Partitions this Traversable into consecutive non-overlapping windows according to a classification function.

      Each window contains elements with the same class, as determined by classifier. Two consecutive elements belong to the same window only if classifier returns equal values for both. Otherwise, the current window ends and a new window begins with the next element.

      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 classifying elements into groups
      Returns:
      An Iterator of windows (grouped elements)
    • sliding

      public Iterator<BitSet<T>> sliding(int size, int step)
      Description copied from interface: Traversable
      Slides a window of a specific size with a given step 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:
      an Iterator of windows with the given size and step
    • span

      public Tuple2<BitSet<T>,BitSet<T>> span(@NonNull Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Splits this Traversable into a prefix and remainder according to the given predicate.

      The first element of the returned Tuple is the longest prefix of elements satisfying predicate, and the second element is the remaining elements.

      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 used to determine the prefix
      Returns:
      a Tuple containing the prefix and remainder
    • scan

      public BitSet<T> scan(T zero, @NonNull BiFunction<? super T,? super T,? extends T> operation)
      Description copied from interface: Traversable
      Computes a prefix scan of the elements of this Traversable.

      The neutral element zero 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 - the neutral element for the operator
      operation - an associative binary operator
      Returns:
      a new Traversable containing the prefix scan of the elements
    • partition

      public Tuple2<BitSet<T>,BitSet<T>> partition(@NonNull Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Splits this Traversable into two partitions according to a predicate.

      The first partition contains all elements that satisfy the predicate, and the second contains all elements that do not. The original iteration order is preserved.

      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 used to classify elements
      Returns:
      a Tuple2 containing the two resulting Traversable instances
    • filter

      public BitSet<T> filter(@NonNull Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Returns a new traversable containing only the elements that 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 - the condition to test elements
      Returns:
      a traversable with elements matching the predicate
    • reject

      public BitSet<T> reject(@NonNull Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Returns a new traversable containing only the elements that do not satisfy the given predicate.

      This 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 - the condition to test elements
      Returns:
      a traversable with elements not matching the predicate
    • groupBy

      public <C> Map<C,BitSet<T>> groupBy(@NonNull Function<? super T,? extends C> classifier)
      Description copied from interface: Traversable
      Groups elements of this Traversable based on a classifier function.
      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 - The type of the group keys
      Parameters:
      classifier - A function that assigns each element to a group
      Returns:
      A map where each key corresponds to a group of elements
      See Also:
    • comparator

      public Comparator<T> comparator()
      Description copied from interface: Ordered
      Returns the comparator that governs the ordering of elements in this collection. The returned comparator must be consistent with the collection's iteration order.
      Specified by:
      comparator in interface Ordered<T>
      Returns:
      the comparator defining the element order
    • takeWhile

      public BitSet<T> takeWhile(@NonNull Predicate<? super T> predicate)
      Description copied from interface: Traversable
      Takes elements from this Traversable while the given predicate holds.
      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 sequentially on the elements
      Returns:
      a new Traversable containing all elements up to (but not including) the first one that does not satisfy the predicate
    • addAll

      public BitSet<T> addAll(@NonNull Iterable<? extends T> elements)
      Description copied from interface: Set
      Returns a new set containing all elements of this set plus the given elements, excluding duplicates.
      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 add
      Returns:
      a new set including the additional elements
    • 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
      Returns all elements of this Traversable except the last one.

      This is the dual of Traversable.tail().

      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 @NonNull Iterator<T> iterator()
      Description copied from interface: Traversable
      Returns an iterator over the elements of this Traversable, implemented via Traversable.head() and Traversable.tail(). Subclasses may override for a more efficient implementation.
      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 over the elements of this Traversable
    • take

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

      Equivalent to sublist(0, max(0, min(length(), n))), but safe for n < 0 or n > length().

      If n < 0, an empty instance is returned. If n > length(), the full instance 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 Traversable containing the first n elements
    • takeRight

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

      Equivalent to sublist(max(0, length() - n), length()), but safe for n < 0 or n > length().

      If n < 0, an empty instance is returned. If n > length(), the full instance 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 from the end
      Returns:
      a new Traversable containing the last n elements
    • remove

      public BitSet<T> remove(T t)
      Description copied from interface: Set
      Returns a new set with the given element removed, if it was 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 remove
      Returns:
      a new set without the specified element
    • removeAll

      public BitSet<T> removeAll(@NonNull Iterable<? extends T> elements)
      Description copied from interface: Set
      Returns a new set with all given elements removed, 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 remove
      Returns:
      a new set without the specified 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
      Determines whether this collection is equal to the given object.

      In Vavr, there are four basic collection types:

      • Seq – sequential elements
      • Set – distinct elements
      • Map – key-value pairs
      • Multimap – keys mapped to multiple values
      Two collections are considered equal if and only if:
      • They are of the same collection type (Seq, Set, Map, Multimap)
      • They contain the same elements
      • For Seq, the element order is the same

      For Map and Multimap, two entries (key1, value1) and (key2, value2) are equal if both their keys and values are equal.

      Additional notes:

      • No collection equals null (e.g., Queue(1) != null)
      • Null elements are allowed and treated as expected (e.g., List(null, 1) == Stream(null, 1), HashMap((null,1)) == LinkedHashMap((null,1)))
      • Element order matters only for Seq
      • Other collection classes are equal if their types and elements (in iteration order) are equal
      • Iterators are compared by reference only
      Specified by:
      equals in interface Traversable<T>
      Specified by:
      equals in interface Value<T>
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare with, may be null
      Returns:
      true if the collections are equal according to the rules above, false otherwise
    • hashCode

      public int hashCode()
      Description copied from interface: Traversable
      Returns the hash code of this collection.

      Vavr distinguishes between collections with predictable iteration order (like Seq) and collections with arbitrary iteration order (like Set, Map, and Multimap). In all cases, the hash of an empty collection is defined as 1.

      For collections with predictable iteration order, the hash is computed as:

      
       int hash = 1;
       for (T t : this) {
           hash = hash * 31 + Objects.hashCode(t);
       }
       

      For collections with arbitrary iteration order, the hash is computed to be independent of element order:

      
       int hash = 1;
       for (T t : this) {
           hash += Objects.hashCode(t);
       }
       

      Note that these algorithms may change in future Vavr versions. Hash codes are generally not cached, unlike size/length, because caching would increase memory usage due to persistent tree-based structures. Computing the hash code is linear in time, O(n). For frequently re-used collections (e.g., as HashMap keys), caching can be done externally using a wrapper, for example:

      
       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; }
      
           @Override
           public boolean equals(Object o) {
               if (o == key) return true;
               if (key != null && o instanceof Hashed) return key.equals(((Hashed<?>) o).key);
               return false;
           }
      
           @Override
           public int hashCode() { return hashCode.get(); }
      
           @Override
           public String toString() { return "Hashed(" + key + ")"; }
       }
       
      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