Class 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
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.vavr.collection.BitSet
BitSet.Builder<T> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a new set containing all elements of this set plus the given elements, excluding duplicates.addElement(int element) Returns the comparator that governs the ordering of elements in this collection.booleanShortcut forexists(e -> Objects.equals(e, element)), tests if the givenelementis contained.(package private) abstract long[]copyExpand(int wordsNum) createFromAll(Iterable<? extends T> values) distinctBy(@NonNull Comparator<? super T> comparator) Returns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.distinctBy(@NonNull Function<? super T, ? extends U> keyExtractor) Returns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.drop(int n) Returns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.dropRight(int n) Returns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.Returns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.booleanDetermines whether this collection is equal to the given object.Returns a new traversable containing only the elements that satisfy the given predicate.fromBitMaskNoCopy(long[] elements) (package private) abstract longgetWord(int index) (package private) abstract intGroups elements of thisTraversablebased on a classifier function.inthashCode()Returns the hash code of this collection.init()Returns all elements of this Traversable except the last one.Returns a new set containing only the elements present in both this set and the given set.iterator()Returns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail().Returns thisBitSetif it is nonempty, otherwiseBitSetcreated from iterable, using existing bitset properties.Returns thisBitSetif it is nonempty, otherwiseBitSetcreated from result of evaluating supplier, using existing bitset properties.Splits thisTraversableinto two partitions according to a predicate.Returns a new traversable containing only the elements that do not satisfy the given predicate.Returns a new set with the given element removed, if it was present.Returns a new set with all given elements removed, if present.Computes a prefix scan of the elements of this Traversable.private voidsetElement(long[] words, int element) (package private) long[]shrink(long[] elements) Partitions thisTraversableinto consecutive non-overlapping windows according to a classification function.sliding(int size, int step) Slides a window of a specificsizewith a givenstepover thisTraversable.Splits thisTraversableinto a prefix and remainder according to the givenpredicate.take(int n) Returns the firstnelements of thisTraversable, or all elements ifnexceeds the length.takeRight(int n) Returns the lastnelements of thisTraversable, or all elements ifnexceeds the length.Takes elements from thisTraversablewhile the given predicate holds.toString()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, waitMethods 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, zipWithIndexMethods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOptionMethods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, curried, isMemoized, memoized, partial, reversed, tupledMethods inherited from interface io.vavr.collection.Set
apply, isDistinct, lengthMethods 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, sumMethods 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 Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
fromInt
-
toInt
-
-
Constructor Details
-
AbstractBitSet
-
-
Method Details
-
getWordsNum
abstract int getWordsNum() -
copyExpand
abstract long[] copyExpand(int wordsNum) -
getWord
abstract long getWord(int index) -
createEmpty
-
createFromAll
-
fromBitMaskNoCopy
-
setElement
private void setElement(long[] words, int element) -
unsetElement
private void unsetElement(long[] words, int element) -
shrink
long[] shrink(long[] elements) -
addElement
-
distinctBy
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
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
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements. -
dropRight
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
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
Description copied from interface:SetReturns a new set containing only the elements present in both this set and the given set. -
orElse
Returns thisBitSetif it is nonempty, otherwiseBitSetcreated from iterable, using existing bitset properties. -
orElse
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
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
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
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
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
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
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate. -
reject
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
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:
-
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
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
Description copied from interface:SetReturns a new set containing all elements of this set plus the given elements, excluding duplicates. -
contains
Description copied from interface:ValueShortcut forexists(e -> Objects.equals(e, element)), tests if the givenelementis contained. -
init
Description copied from interface:TraversableReturns all elements of this Traversable except the last one.This is the dual of
Traversable.tail(). -
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
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
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
Description copied from interface:SetReturns a new set with the given element removed, if it was present. -
removeAll
Description copied from interface:SetReturns a new set with all given elements removed, if present. -
toString
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
equals
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: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 + ")"; } }
-