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 TypeMethodDescriptionAdds all of the given elements to this set, if not already contained.addElement
(int element) Returns the comparator which defines the order of the elements contained in this collection.boolean
Shortcut forexists(e -> Objects.equals(e, element))
, tests if the givenelement
is contained.(package private) abstract long[]
copyExpand
(int wordsNum) createFromAll
(Iterable<? extends T> values) distinctBy
(Comparator<? super T> comparator) Returns a new version of this which contains no duplicates.distinctBy
(Function<? super T, ? extends U> keyExtractor) Returns a new version of this which contains no duplicates.drop
(int n) Drops the first n elements of this or all elements, if this length < n.dropRight
(int n) Drops the last n elements of this or all elements, if this length < n.Drops elements while the predicate holds for the current element.boolean
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.Returns a new traversable consisting of all elements which satisfy the given predicate.fromBitMaskNoCopy
(long[] elements) (package private) abstract long
getWord
(int index) (package private) abstract int
Groups this elements by classifying the elements.int
hashCode()
Returns the hash code of this collection.init()
Dual of Traversable.tail(), returning all elements except the last.Computes the intersection between this set and another set.iterator()
An iterator by means of head() and tail().Returns thisBitSet
if it is nonempty, otherwiseBitSet
created from iterable, using existing bitset properties.Returns thisBitSet
if it is nonempty, otherwiseBitSet
created from result of evaluating supplier, using existing bitset properties.Creates a partition of thisTraversable
by splitting this elements in two in distinct traversables according to a predicate.Returns a new traversable consisting of all elements which do not satisfy the given predicate.Removes a specific element from this set, if present.Removes all of the given elements from this set, if present.Computes a prefix scan of the elements of the collection.private void
setElement
(long[] words, int element) (package private) long[]
shrink
(long[] elements) Slides a non-overlapping window of a variable size over thisTraversable
.sliding
(int size, int step) Slides a window of a specificsize
andstep
size over thisTraversable
.Returns a tuple where the first element is the longest prefix of elements that satisfy the givenpredicate
and the second element is the remainder.take
(int n) Takes the first n elements of this or all elements, if this length < n.takeRight
(int n) Takes the last n elements of this or all elements, if this length < n.Takes elements while the predicate holds for the current element.toString()
Clarifies that values have a proper toString() method implemented.private void
unsetElement
(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, 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, 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 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:Traversable
Returns a new version of this which contains no duplicates. Elements are compared using the givencomparator
.- Specified by:
distinctBy
in interfaceBitSet<T>
- Specified by:
distinctBy
in interfaceSet<T>
- Specified by:
distinctBy
in interfaceSortedSet<T>
- Specified by:
distinctBy
in interfaceTraversable<T>
- Parameters:
comparator
- A comparator- Returns:
- a new
Traversable
containing this elements without duplicates
-
distinctBy
Description copied from interface:Traversable
Returns a new version of this which contains no duplicates. Elements mapped to keys which are compared usingequals
.The elements of the result are determined in the order of their occurrence - first match wins.
- Specified by:
distinctBy
in interfaceBitSet<T>
- Specified by:
distinctBy
in interfaceSet<T>
- Specified by:
distinctBy
in interfaceSortedSet<T>
- Specified by:
distinctBy
in interfaceTraversable<T>
- Type Parameters:
U
- key type- Parameters:
keyExtractor
- A key extractor- Returns:
- a new
Traversable
containing this elements without duplicates
-
drop
Description copied from interface:Traversable
Drops the first n elements of this or all elements, if this length < n.- Specified by:
drop
in interfaceBitSet<T>
- Specified by:
drop
in interfaceSet<T>
- Specified by:
drop
in interfaceSortedSet<T>
- Specified by:
drop
in interfaceTraversable<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
Description copied from interface:Traversable
Drops the last n elements of this or all elements, if this length < n.- Specified by:
dropRight
in interfaceBitSet<T>
- Specified by:
dropRight
in interfaceSet<T>
- Specified by:
dropRight
in interfaceSortedSet<T>
- Specified by:
dropRight
in interfaceTraversable<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
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 interfaceBitSet<T>
- Specified by:
dropWhile
in interfaceSet<T>
- Specified by:
dropWhile
in interfaceSortedSet<T>
- Specified by:
dropWhile
in interfaceTraversable<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
Description copied from interface:Set
Computes the intersection between this set and another set.See also
Set.retainAll(Iterable)
. -
orElse
Returns thisBitSet
if it is nonempty, otherwiseBitSet
created from iterable, using existing bitset properties. -
orElse
Returns thisBitSet
if it is nonempty, otherwiseBitSet
created from result of evaluating supplier, using existing bitset properties.- Specified by:
orElse
in interfaceSet<T>
- Specified by:
orElse
in interfaceSortedSet<T>
- Specified by:
orElse
in interfaceTraversable<T>
- Parameters:
supplier
- An alternativeTraversable
- Returns:
- this
BitSet
if it is nonempty, otherwiseBitSet
created from result of evaluating supplier, using existing bitset properties.
-
slideBy
Description copied from interface:Traversable
Slides a non-overlapping window of a variable size over thisTraversable
.Each window contains elements with the same class, as determined by
classifier
. Two consecutive values in thisTraversable
will be in the same window only ifclassifier
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 interfaceBitSet<T>
- Specified by:
slideBy
in interfaceSet<T>
- Specified by:
slideBy
in interfaceSortedSet<T>
- Specified by:
slideBy
in interfaceTraversable<T>
- Parameters:
classifier
- A function which classifies elements into classes- Returns:
- A new Iterator of windows of the grouped elements
-
sliding
Description copied from interface:Traversable
Slides a window of a specificsize
andstep
size over 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:
sliding
in interfaceBitSet<T>
- Specified by:
sliding
in interfaceSet<T>
- Specified by:
sliding
in interfaceSortedSet<T>
- Specified by:
sliding
in interfaceTraversable<T>
- Parameters:
size
- a positive window sizestep
- a positive step size- Returns:
- a new Iterator of windows of a specific size using a specific step size
-
span
Description copied from interface:Traversable
Returns a tuple where the first element is the longest prefix of elements that satisfy the givenpredicate
and the second element is the remainder.- Specified by:
span
in interfaceBitSet<T>
- Specified by:
span
in interfaceSet<T>
- Specified by:
span
in interfaceSortedSet<T>
- Specified by:
span
in interfaceTraversable<T>
- Parameters:
predicate
- A predicate.- Returns:
- a
Tuple
containing the longest prefix of elements that satisfy p and the remainder.
-
scan
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 interfaceBitSet<T>
- Specified by:
scan
in interfaceSet<T>
- Specified by:
scan
in interfaceSortedSet<T>
- Specified by:
scan
in interfaceTraversable<T>
- Parameters:
zero
- neutral element for the operator opoperation
- the associative operator for the scan- Returns:
- a new traversable collection containing the prefix scan of the elements in this traversable collection
-
partition
Description copied from interface:Traversable
Creates a partition of thisTraversable
by splitting this elements in two in distinct traversables according to a predicate.- Specified by:
partition
in interfaceBitSet<T>
- Specified by:
partition
in interfaceSet<T>
- Specified by:
partition
in interfaceSortedSet<T>
- Specified by:
partition
in interfaceTraversable<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 givenpredicate
, the secondTraversable
contains all elements that don't. The original order of elements is preserved.
-
filter
Description copied from interface:Traversable
Returns a new traversable consisting of all elements which satisfy the given predicate. -
reject
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()
-
groupBy
Description copied from interface:Traversable
Groups this elements by classifying the elements.- Specified by:
groupBy
in interfaceBitSet<T>
- Specified by:
groupBy
in interfaceSet<T>
- Specified by:
groupBy
in interfaceSortedSet<T>
- Specified by:
groupBy
in interfaceTraversable<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
Description copied from interface:Ordered
Returns the comparator which defines the order of the elements contained in this collection.- Specified by:
comparator
in interfaceOrdered<T>
- Returns:
- The comparator that defines the order of this collection's elements.
-
takeWhile
Description copied from interface:Traversable
Takes elements while the predicate holds for the current element.- Specified by:
takeWhile
in interfaceBitSet<T>
- Specified by:
takeWhile
in interfaceSet<T>
- Specified by:
takeWhile
in interfaceSortedSet<T>
- Specified by:
takeWhile
in interfaceTraversable<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
Description copied from interface:Set
Adds all of the given elements to this set, if not already contained. -
contains
Description copied from interface:Value
Shortcut forexists(e -> Objects.equals(e, element))
, tests if the givenelement
is contained. -
init
Description copied from interface:Traversable
Dual of Traversable.tail(), returning all elements except the last. -
iterator
Description copied from interface:Traversable
An iterator by means of head() and tail(). Subclasses may want to override this method. -
take
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 ifn < 0
orn > length()
.In the case of
n < 0
the empty instance is returned, in the case ofn > length()
this is returned.- Specified by:
take
in interfaceBitSet<T>
- Specified by:
take
in interfaceSet<T>
- Specified by:
take
in interfaceSortedSet<T>
- Specified by:
take
in interfaceTraversable<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
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 ifn < 0
orn > length()
.In the case of
n < 0
the empty instance is returned, in the case ofn > length()
this is returned.- Specified by:
takeRight
in interfaceBitSet<T>
- Specified by:
takeRight
in interfaceSet<T>
- Specified by:
takeRight
in interfaceSortedSet<T>
- Specified by:
takeRight
in interfaceTraversable<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
Description copied from interface:Set
Removes a specific element from this set, if present. -
removeAll
Description copied from interface:Set
Removes all of the given elements from this set, if present. -
toString
Description copied from interface:Value
Clarifies that values have a proper toString() method implemented.See Object.toString().
-
equals
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)
- 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
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.
-
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:
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 = hash * 31 + Objects.hashCode(t); }
Please note that the particular hashing algorithms may change in a future version of Vavr.int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }
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; } @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; } } @Override public int hashCode() { return hashCode.get(); } @Override public String toString() { return "Hashed(" + (key == null ? "null" : key.toString()) + ")"; } }
-