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,java.lang.Boolean>,Value<T>,java.io.Serializable,java.lang.Iterable<T>,java.util.function.Function<T,java.lang.Boolean>
- Direct Known Subclasses:
BitSetModule.BitSet1,BitSetModule.BitSet2,BitSetModule.BitSetN
- Enclosing interface:
- BitSetModule
public abstract static class BitSetModule.AbstractBitSet<T> extends java.lang.Object implements BitSet<T>, java.io.Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.vavr.collection.BitSet
BitSet.Builder<T>
-
-
Constructor Summary
Constructors Constructor Description AbstractBitSet(Function1<java.lang.Integer,T> fromInt, Function1<T,java.lang.Integer> toInt)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BitSet<T>addAll(@NonNull java.lang.Iterable<? extends T> elements)Returns a new set containing all elements of this set plus the given elements, excluding duplicates.(package private) BitSet<T>addElement(int element)java.util.Comparator<T>comparator()Returns the comparator that governs the ordering of elements in this collection.booleancontains(T t)Shortcut forexists(e -> Objects.equals(e, element)), tests if the givenelementis contained.(package private) abstract long[]copyExpand(int wordsNum)(package private) BitSet<T>createEmpty()(package private) BitSet<T>createFromAll(java.lang.Iterable<? extends T> values)BitSet<T>distinctBy(@NonNull java.util.Comparator<? super T> comparator)Returns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.<U> BitSet<T>distinctBy(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)Returns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.BitSet<T>drop(int n)Returns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.BitSet<T>dropRight(int n)Returns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.BitSet<T>dropWhile(@NonNull java.util.function.Predicate<? super T> predicate)Returns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.booleanequals(java.lang.Object o)Determines whether this collection is equal to the given object.BitSet<T>filter(@NonNull java.util.function.Predicate<? super T> predicate)Returns a new traversable containing only the elements that satisfy the given predicate.(package private) BitSet<T>fromBitMaskNoCopy(long[] elements)(package private) abstract longgetWord(int index)(package private) abstract intgetWordsNum()<C> Map<C,BitSet<T>>groupBy(@NonNull java.util.function.Function<? super T,? extends C> classifier)Groups elements of thisTraversablebased on a classifier function.inthashCode()Returns the hash code of this collection.BitSet<T>init()Returns all elements of this Traversable except the last one.BitSet<T>intersect(@NonNull Set<? extends T> elements)Returns a new set containing only the elements present in both this set and the given set.@NonNull Iterator<T>iterator()Returns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail().BitSet<T>orElse(@NonNull java.lang.Iterable<? extends T> other)Returns thisBitSetif it is nonempty, otherwiseBitSetcreated from iterable, using existing bitset properties.BitSet<T>orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)Returns thisBitSetif it is nonempty, otherwiseBitSetcreated from result of evaluating supplier, using existing bitset properties.Tuple2<BitSet<T>,BitSet<T>>partition(@NonNull java.util.function.Predicate<? super T> predicate)Splits thisTraversableinto two partitions according to a predicate.BitSet<T>reject(@NonNull java.util.function.Predicate<? super T> predicate)Returns a new traversable containing only the elements that do not satisfy the given predicate.BitSet<T>remove(T t)Returns a new set with the given element removed, if it was present.BitSet<T>removeAll(@NonNull java.lang.Iterable<? extends T> elements)Returns a new set with all given elements removed, if present.BitSet<T>scan(T zero, @NonNull java.util.function.BiFunction<? super T,? super T,? extends T> operation)Computes a prefix scan of the elements of this Traversable.private voidsetElement(long[] words, int element)(package private) long[]shrink(long[] elements)Iterator<BitSet<T>>slideBy(@NonNull java.util.function.Function<? super T,?> classifier)Partitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Iterator<BitSet<T>>sliding(int size, int step)Slides a window of a specificsizewith a givenstepover thisTraversable.Tuple2<BitSet<T>,BitSet<T>>span(@NonNull java.util.function.Predicate<? super T> predicate)Splits thisTraversableinto a prefix and remainder according to the givenpredicate.BitSet<T>take(int n)Returns the firstnelements of thisTraversable, or all elements ifnexceeds the length.BitSet<T>takeRight(int n)Returns the lastnelements of thisTraversable, or all elements ifnexceeds the length.BitSet<T>takeWhile(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from thisTraversablewhile the given predicate holds.java.lang.StringtoString()Clarifies that values have a proper toString() method implemented.private voidunsetElement(long[] words, int element)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.collection.BitSet
add, collect, diff, distinct, dropUntil, flatMap, flatMap, foldRight, grouped, hasDefiniteSize, initOption, isAsync, isLazy, isTraversableAgain, last, map, map, mapTo, mapToVoid, peek, replace, replaceAll, retainAll, scanLeft, scanRight, sliding, stringPrefix, tail, tailOption, takeUntil, toJavaSet, union, unzip, unzip3, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
-
Methods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOption
-
Methods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, curried, isMemoized, memoized, partial, reversed, tupled
-
Methods inherited from interface io.vavr.collection.Set
apply, isDistinct, length
-
Methods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, head, headOption, isEmpty, isSequential, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
-
Methods inherited from interface io.vavr.Value
collect, collect, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, out, out, stderr, stdout, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getWordsNum
abstract int getWordsNum()
-
copyExpand
abstract long[] copyExpand(int wordsNum)
-
getWord
abstract long getWord(int index)
-
setElement
private void setElement(long[] words, int element)
-
unsetElement
private void unsetElement(long[] words, int element)
-
shrink
long[] shrink(long[] elements)
-
distinctBy
public BitSet<T> distinctBy(@NonNull java.util.Comparator<? super T> comparator)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.- Specified by:
distinctByin interfaceBitSet<T>- Specified by:
distinctByin interfaceSet<T>- Specified by:
distinctByin interfaceSortedSet<T>- Specified by:
distinctByin interfaceTraversable<T>- Parameters:
comparator- a comparator used to determine equality of elements- Returns:
- a new
Traversablewith duplicates removed
-
distinctBy
public <U> BitSet<T> distinctBy(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.The first occurrence of each key is retained in the resulting sequence.
- Specified by:
distinctByin interfaceBitSet<T>- Specified by:
distinctByin interfaceSet<T>- Specified by:
distinctByin interfaceSortedSet<T>- Specified by:
distinctByin interfaceTraversable<T>- Type Parameters:
U- the type of key- Parameters:
keyExtractor- a function to extract keys for determining uniqueness- Returns:
- a new
Traversablewith duplicates removed based on keys
-
drop
public BitSet<T> drop(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.
-
dropRight
public BitSet<T> dropRight(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.- Specified by:
dropRightin interfaceBitSet<T>- Specified by:
dropRightin interfaceSet<T>- Specified by:
dropRightin interfaceSortedSet<T>- Specified by:
dropRightin interfaceTraversable<T>- Parameters:
n- the number of elements to drop from the end- Returns:
- a new instance excluding the last
nelements
-
dropWhile
public BitSet<T> dropWhile(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.This is equivalent to
dropUntil(predicate.negate()), which is useful for method references that cannot be negated directly.- Specified by:
dropWhilein interfaceBitSet<T>- Specified by:
dropWhilein interfaceSet<T>- Specified by:
dropWhilein interfaceSortedSet<T>- Specified by:
dropWhilein interfaceTraversable<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:SetReturns a new set containing only the elements present in both this set and the given set.
-
orElse
public BitSet<T> orElse(@NonNull java.lang.Iterable<? extends T> other)
Returns thisBitSetif it is nonempty, otherwiseBitSetcreated from iterable, using existing bitset properties.
-
orElse
public BitSet<T> orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Returns thisBitSetif it is nonempty, otherwiseBitSetcreated from result of evaluating supplier, using existing bitset properties.- Specified by:
orElsein interfaceSet<T>- Specified by:
orElsein interfaceSortedSet<T>- Specified by:
orElsein interfaceTraversable<T>- Parameters:
supplier- An alternativeTraversable- Returns:
- this
BitSetif it is nonempty, otherwiseBitSetcreated from result of evaluating supplier, using existing bitset properties.
-
slideBy
public Iterator<BitSet<T>> slideBy(@NonNull java.util.function.Function<? super T,?> classifier)
Description copied from interface:TraversablePartitions thisTraversableinto 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 ifclassifierreturns 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:
slideByin interfaceBitSet<T>- Specified by:
slideByin interfaceSet<T>- Specified by:
slideByin interfaceSortedSet<T>- Specified by:
slideByin interfaceTraversable<T>- Parameters:
classifier- A function classifying elements into groups- Returns:
- An
Iteratorof windows (grouped elements)
-
sliding
public Iterator<BitSet<T>> sliding(int size, int step)
Description copied from interface:TraversableSlides a window of a specificsizewith a givenstepover thisTraversable.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:
slidingin interfaceBitSet<T>- Specified by:
slidingin interfaceSet<T>- Specified by:
slidingin interfaceSortedSet<T>- Specified by:
slidingin interfaceTraversable<T>- Parameters:
size- a positive window sizestep- a positive step size- Returns:
- an
Iteratorof windows with the given size and step
-
span
public Tuple2<BitSet<T>,BitSet<T>> span(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableSplits thisTraversableinto a prefix and remainder according to the givenpredicate.The first element of the returned
Tupleis the longest prefix of elements satisfyingpredicate, and the second element is the remaining elements.
-
scan
public BitSet<T> scan(T zero, @NonNull java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Description copied from interface:TraversableComputes a prefix scan of the elements of this Traversable.The neutral element
zeromay be applied more than once.- Specified by:
scanin interfaceBitSet<T>- Specified by:
scanin interfaceSet<T>- Specified by:
scanin interfaceSortedSet<T>- Specified by:
scanin interfaceTraversable<T>- Parameters:
zero- the neutral element for the operatoroperation- an associative binary operator- Returns:
- a new Traversable containing the prefix scan of the elements
-
partition
public Tuple2<BitSet<T>,BitSet<T>> partition(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableSplits thisTraversableinto 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:
partitionin interfaceBitSet<T>- Specified by:
partitionin interfaceSet<T>- Specified by:
partitionin interfaceSortedSet<T>- Specified by:
partitionin interfaceTraversable<T>- Parameters:
predicate- a predicate used to classify elements- Returns:
- a
Tuple2containing the two resultingTraversableinstances
-
filter
public BitSet<T> filter(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate.
-
reject
public BitSet<T> reject(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that do not satisfy the given predicate.This is equivalent to
filter(predicate.negate()).
-
groupBy
public <C> Map<C,BitSet<T>> groupBy(@NonNull java.util.function.Function<? super T,? extends C> classifier)
Description copied from interface:TraversableGroups elements of thisTraversablebased on a classifier function.- Specified by:
groupByin interfaceBitSet<T>- Specified by:
groupByin interfaceSet<T>- Specified by:
groupByin interfaceSortedSet<T>- Specified by:
groupByin interfaceTraversable<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:
Traversable.arrangeBy(Function)
-
comparator
public java.util.Comparator<T> comparator()
Description copied from interface:OrderedReturns 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:
comparatorin interfaceOrdered<T>- Returns:
- the comparator defining the element order
-
takeWhile
public BitSet<T> takeWhile(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableTakes elements from thisTraversablewhile the given predicate holds.- Specified by:
takeWhilein interfaceBitSet<T>- Specified by:
takeWhilein interfaceSet<T>- Specified by:
takeWhilein interfaceSortedSet<T>- Specified by:
takeWhilein interfaceTraversable<T>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements up to (but not including) the first one that does not satisfy the predicate
-
addAll
public BitSet<T> addAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:SetReturns a new set containing all elements of this set plus the given elements, excluding duplicates.
-
contains
public boolean contains(T t)
Description copied from interface:ValueShortcut forexists(e -> Objects.equals(e, element)), tests if the givenelementis contained.
-
init
public BitSet<T> init()
Description copied from interface:TraversableReturns all elements of this Traversable except the last one.This is the dual of
Traversable.tail().
-
iterator
public @NonNull Iterator<T> iterator()
Description copied from interface:TraversableReturns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail(). Subclasses may override for a more efficient implementation.
-
take
public BitSet<T> take(int n)
Description copied from interface:TraversableReturns the firstnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(0, max(0, min(length(), n))), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.
-
takeRight
public BitSet<T> takeRight(int n)
Description copied from interface:TraversableReturns the lastnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(max(0, length() - n), length()), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.- Specified by:
takeRightin interfaceBitSet<T>- Specified by:
takeRightin interfaceSet<T>- Specified by:
takeRightin interfaceSortedSet<T>- Specified by:
takeRightin interfaceTraversable<T>- Parameters:
n- the number of elements to take from the end- Returns:
- a new
Traversablecontaining the lastnelements
-
remove
public BitSet<T> remove(T t)
Description copied from interface:SetReturns a new set with the given element removed, if it was present.
-
removeAll
public BitSet<T> removeAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:SetReturns a new set with all given elements removed, if present.
-
toString
public java.lang.String toString()
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:TraversableDetermines whether this collection is equal to the given object.In Vavr, there are four basic collection types:
Seq– sequential elementsSet– distinct elementsMap– key-value pairsMultimap– keys mapped to multiple values
- 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
MapandMultimap, 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
-
hashCode
public int hashCode()
Description copied from interface:TraversableReturns the hash code of this collection.Vavr distinguishes between collections with predictable iteration order (like
Seq) and collections with arbitrary iteration order (likeSet,Map, andMultimap). In all cases, the hash of an empty collection is defined as1.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
HashMapkeys), caching can be done externally using a wrapper, for example:{@code public final class Hashed{ private final K key; private final Lazy hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; }
-
-