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(java.lang.Iterable<? extends T> elements)
Adds all of the given elements to this set, if not already contained.(package private) BitSet<T>
addElement(int element)
java.util.Comparator<T>
comparator()
Returns the comparator which defines the order of the elements contained in this collection.boolean
contains(T t)
Shortcut forexists(e -> Objects.equals(e, element))
, tests if the givenelement
is 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(java.util.Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.<U> BitSet<T>
distinctBy(java.util.function.Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.BitSet<T>
drop(int n)
Drops the first n elements of this or all elements, if this length < n.BitSet<T>
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.BitSet<T>
dropWhile(java.util.function.Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element.boolean
equals(java.lang.Object o)
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.BitSet<T>
filter(java.util.function.Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.(package private) BitSet<T>
fromBitMaskNoCopy(long[] elements)
(package private) abstract long
getWord(int index)
(package private) abstract int
getWordsNum()
<C> Map<C,BitSet<T>>
groupBy(java.util.function.Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.int
hashCode()
Returns the hash code of this collection.BitSet<T>
init()
Dual of Traversable.tail(), returning all elements except the last.BitSet<T>
intersect(Set<? extends T> elements)
Computes the intersection between this set and another set.Iterator<T>
iterator()
An iterator by means of head() and tail().BitSet<T>
orElse(java.lang.Iterable<? extends T> other)
Returns thisBitSet
if it is nonempty, otherwiseBitSet
created from iterable, using existing bitset properties.BitSet<T>
orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Returns thisBitSet
if it is nonempty, otherwiseBitSet
created from result of evaluating supplier, using existing bitset properties.Tuple2<BitSet<T>,BitSet<T>>
partition(java.util.function.Predicate<? super T> predicate)
Creates a partition of thisTraversable
by splitting this elements in two in distinct traversables according to a predicate.BitSet<T>
reject(java.util.function.Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which do not satisfy the given predicate.BitSet<T>
remove(T t)
Removes a specific element from this set, if present.BitSet<T>
removeAll(java.lang.Iterable<? extends T> elements)
Removes all of the given elements from this set, if present.BitSet<T>
scan(T zero, java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.private void
setElement(long[] words, int element)
(package private) long[]
shrink(long[] elements)
Iterator<BitSet<T>>
slideBy(java.util.function.Function<? super T,?> classifier)
Slides a non-overlapping window of a variable size over thisTraversable
.Iterator<BitSet<T>>
sliding(int size, int step)
Slides a window of a specificsize
andstep
size over thisTraversable
.Tuple2<BitSet<T>,BitSet<T>>
span(java.util.function.Predicate<? super T> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the givenpredicate
and the second element is the remainder.BitSet<T>
take(int n)
Takes the first n elements of this or all elements, if this length < n.BitSet<T>
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.BitSet<T>
takeWhile(java.util.function.Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.java.lang.String
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 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(java.util.Comparator<? super T> comparator)
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
public <U> BitSet<T> distinctBy(java.util.function.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 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
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 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
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 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
public BitSet<T> dropWhile(java.util.function.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 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
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)
.
-
orElse
public BitSet<T> orElse(java.lang.Iterable<? extends T> other)
Returns thisBitSet
if it is nonempty, otherwiseBitSet
created from iterable, using existing bitset properties.
-
orElse
public BitSet<T> orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
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
public Iterator<BitSet<T>> slideBy(java.util.function.Function<? super T,?> classifier)
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
public Iterator<BitSet<T>> sliding(int size, int step)
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
public Tuple2<BitSet<T>,BitSet<T>> span(java.util.function.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 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
public BitSet<T> scan(T zero, java.util.function.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 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
public Tuple2<BitSet<T>,BitSet<T>> partition(java.util.function.Predicate<? super T> predicate)
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
public BitSet<T> filter(java.util.function.Predicate<? super T> predicate)
Description copied from interface:Traversable
Returns a new traversable consisting of all elements which satisfy the given predicate.
-
reject
public BitSet<T> reject(java.util.function.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()
-
groupBy
public <C> Map<C,BitSet<T>> groupBy(java.util.function.Function<? super T,? extends C> classifier)
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:
Traversable.arrangeBy(Function)
-
comparator
public java.util.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 interfaceOrdered<T>
- Returns:
- The comparator that defines the order of this collection's elements.
-
takeWhile
public BitSet<T> takeWhile(java.util.function.Predicate<? super T> predicate)
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
public BitSet<T> addAll(java.lang.Iterable<? extends T> elements)
Description copied from interface:Set
Adds all of the given elements to this set, if not already contained.
-
contains
public boolean contains(T t)
Description copied from interface:Value
Shortcut forexists(e -> Objects.equals(e, element))
, tests if the givenelement
is contained.
-
init
public BitSet<T> init()
Description copied from interface:Traversable
Dual of Traversable.tail(), returning 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.
-
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 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
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 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
public BitSet<T> remove(T t)
Description copied from interface:Set
Removes a specific element from this set, if present.
-
removeAll
public BitSet<T> removeAll(java.lang.Iterable<? extends T> elements)
Description copied from interface:Set
Removes all of the given elements from this set, if present.
-
toString
public java.lang.String toString()
Description copied from interface:Value
Clarifies that values have a proper toString() method implemented.See Object.toString().
-
equals
public boolean equals(java.lang.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)
- 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()) + ")"; } }
-
-