T - The type of the domain. All elements in the domain must be of type T or of any subtype
of T.public class SmallDomainBitSet<T> extends Object implements DomainBitSet<T>, Cloneable
IllegalArgumentException
instead.| Modifier and Type | Method and Description |
|---|---|
static <T> SmallDomainBitSet<T> |
allOf(List<T> domain)
Creates a set with the given domain, that contains all elements.
|
static <T> SmallDomainBitSet<T> |
allOf(T... domain)
Creates a set with the given domain, that contains all elements.
|
SmallDomainBitSet<T> |
clone()
Default implementation of a
cloning-method using
DomainBitSet.union(BigInteger). |
DomainBitSet<T> |
complement()
Creates a new set with the same domain, initially containing all the elements of the domain
that are not contained in this set.
|
boolean |
equals(Object other)
Compares the specified object with this domain bit set for equality.
|
boolean |
getBit(int bitIndex)
Returns the value of the bit with the specified index.
|
Domain<T> |
getDomain()
Returns a distinct list, containing all elements of the domain.
|
int |
hashCode()
Hash code of domain and elements.
|
DomainBitSet<T> |
intersect(BigInteger mask)
The intersection of this and a given mask.
|
DomainBitSet<T> |
intersect(BitSet s)
The intersection of this and a given bit set.
|
DomainBitSet<T> |
intersect(Iterable<T> s)
Intersection of this and the given set.
|
DomainBitSet<T> |
intersect(long mask)
Intersection of this and the given set.
|
DomainBitSet<T> |
intersectVarArgs(T... elements)
The intersection of this set and a set represented by an array (varargs).
|
boolean |
isEmpty()
Returns true if this set contains no elements.
|
Iterator<T> |
iterator()
Returns an iterator over elements of type T.
|
DomainBitSet<T> |
minus(BigInteger mask)
The relative complement of this set and a set represented by a
BigInteger. |
DomainBitSet<T> |
minus(BitSet s)
The relative complement of this set and a set represented by a
BitSet. |
DomainBitSet<T> |
minus(Iterable<T> s)
The relative complement of this set and another set.
|
DomainBitSet<T> |
minus(long mask)
The relative complement of this set and a set represented by a bit mask.
|
DomainBitSet<T> |
minusVarArgs(T... elements)
The relative complement of this set and a set represented by an array (varargs).
|
static <T> SmallDomainBitSet<T> |
noneOf(List<T> domain)
Creates a set with the given domain, that contains none of the elements.
|
static <T> SmallDomainBitSet<T> |
noneOf(T... domain)
Creates a set with the given domain, that contains none of the elements.
|
static <T> SmallDomainBitSet<T> |
of(List<T> domain,
Collection<T> set)
Creates a set with the given domain, containing all given elements.
|
static <T> SmallDomainBitSet<T> |
of(List<T> domain,
long mask)
Creates a set with the given domain, containing elements according to a given bit mask.
|
static <T> SmallDomainBitSet<T> |
of(List<T> domain,
T... set)
Creates a set with the given domain, containing all given elements.
|
boolean |
ofEqualElements(DomainBitSet<T> other)
Compares the elements, ignoring the domains.
|
Iterable<SmallDomainBitSet<T>> |
powerset()
The powerset, which is the set of all subsets.
|
void |
powerset(Consumer<DomainBitSet<T>> consumer,
boolean blocking)
Pass all subsets to a given consumer.
|
int |
size()
The number of elements in this set.
|
Spliterator<T> |
spliterator()
Creates a
Spliterator over the elements in this collection. |
BigInteger |
toBigInteger()
A representation of the elements in this set as a
BigInteger. |
BitSet |
toBitSet()
A representation of the elements in this set as a
BitSet. |
long |
toLong()
A representation of the elements in this set as a
long. |
Set<T> |
toSet()
A regular set, with no defined domain.
|
String |
toString() |
DomainBitSet<T> |
union(BigInteger mask)
The union of this set and a set represented by a
BitSet. |
DomainBitSet<T> |
union(BitSet s)
The union of this set and a set represented by a
BitSet. |
DomainBitSet<T> |
union(Iterable<T> s)
The union of this set and a set represented by an
iterable collection. |
DomainBitSet<T> |
union(long mask)
The union of this set and a set represented by a bit mask.
|
DomainBitSet<T> |
unionVarArgs(T... elements)
The union of this set and a set represented by an array (varargs).
|
Stream<Pair<Object,Integer,T>> |
zipWithPosition()
Returns a sequential stream with pairs of all elements of this set and their position in the
domain.
|
contains, containsAll, createMultiEnumBitSet, cross, cross, domainContains, getElement, map, map, ofEqualDomain, parallelStream, semijoin, streampublic static <T> SmallDomainBitSet<T> allOf(List<T> domain) throws MoreThan64ElementsException
allOf in interface DomainBitSet<T>T - The type of the set and its domain.domain - The type of the domain.MoreThan64ElementsException@SafeVarargs public static <T> SmallDomainBitSet<T> allOf(T... domain) throws MoreThan64ElementsException
allOf in interface DomainBitSet<T>T - The type of the domain.domain - The domain.MoreThan64ElementsExceptionpublic static <T> SmallDomainBitSet<T> noneOf(List<T> domain) throws MoreThan64ElementsException
noneOf in interface DomainBitSet<T>T - The type of the set and its domain.domain - The elements of the domain.MoreThan64ElementsException@SafeVarargs public static <T> SmallDomainBitSet<T> noneOf(T... domain)
noneOf in interface DomainBitSet<T>T - The type of the set and its domain.domain - The elements of the domain.public static <T> SmallDomainBitSet<T> of(List<T> domain, Collection<T> set)
T - The type of the set and its domain.domain - The elements of the domain.set - The elements.public static <T> SmallDomainBitSet<T> of(List<T> domain, long mask)
T - The type of the set and its domain.domain - The elements of the domain.mask - The elements as a bit mask.@SafeVarargs public static <T> SmallDomainBitSet<T> of(List<T> domain, T... set)
T - The type of the set and its domain.domain - The elements of the domain.set - The elements.public SmallDomainBitSet<T> clone()
DomainBitSetcloning-method using
DomainBitSet.union(BigInteger).clone in interface DomainBitSet<T>clone in class Objectthis.union(BigInteger.ZERO)public DomainBitSet<T> complement()
DomainBitSetcomplement in interface DomainBitSet<T>public boolean equals(Object other)
DomainBitSetDomainBitSet, the two sets have the same domain, and every
member of the given set is contained in this set.
Comparison of elements only:
this.ofEqualElements(other)
Which is equivalent to:
this.toSet().equals(other.toSet())
Comparison of domain only:
this.ofEqualDomain(other)
equals in interface DomainBitSet<T>equals in class ObjectDomainBitSet, with the same domain and elements.DomainBitSet.ofEqualElements(DomainBitSet)public boolean getBit(int bitIndex)
throws IndexOutOfBoundsException
DomainBitSettrue if the bit
with the index bitIndex is currently set in this BitSet; otherwise, the result
is false.
Note that not all DomainBitSets are implemented as a bit set. In that case this method emulates the behavior of an actual bit set.
getBit in interface DomainBitSet<T>bitIndex - the bit indexIndexOutOfBoundsException - if the specified index is negative or out of bounds.DomainBitSet.contains(Object),
BitSet.get(int),
BigInteger.testBit(int)public Domain<T> getDomain()
DomainBitSetAll elements are ordered as they are defined in the domain.
Note that the returned set is immutable.
getDomain in interface DomainBitSet<T>Domain of this set.public int hashCode()
DomainBitSet
hashCode in interface DomainBitSet<T>hashCode in class Objectpublic DomainBitSet<T> intersect(BigInteger mask)
DomainBitSetintersect in interface DomainBitSet<T>mask - The mask of the other set.public DomainBitSet<T> intersect(BitSet s)
DomainBitSetintersect in interface DomainBitSet<T>s - The bit set representation of the other set.public DomainBitSet<T> intersect(Iterable<T> s)
DomainBitSetintersect in interface DomainBitSet<T>s - An Iterable collection of elements from the domain.public DomainBitSet<T> intersect(long mask) throws IllegalArgumentException
DomainBitSetintersect in interface DomainBitSet<T>mask - The bit mask of another set.IllegalArgumentException - If the domain contains less than 64 elements then some long values are illegal.public DomainBitSet<T> intersectVarArgs(T... elements)
DomainBitSetintersectVarArgs in interface DomainBitSet<T>elements - A set as an array. Duplicates are ignored. Must not be nor contain null.DomainBitSet.intersect(Iterable)public boolean isEmpty()
DomainBitSetisEmpty in interface DomainBitSet<T>Collection.isEmpty()public Iterator<T> iterator()
DomainBitSet
The order is not defined as this could be backed by a set. Iteration in the same order as the
domain can be done like this:
domainBitSet.getDomain().stream().filter(domainBitSet::contains).forEach(...)
public DomainBitSet<T> minus(BigInteger mask)
DomainBitSetBigInteger.minus in interface DomainBitSet<T>mask - The other set as a bit mask.public DomainBitSet<T> minus(BitSet s)
DomainBitSetBitSet.minus in interface DomainBitSet<T>s - The other set.public DomainBitSet<T> minus(Iterable<T> s)
DomainBitSetminus in interface DomainBitSet<T>s - The other set.public DomainBitSet<T> minus(long mask) throws IllegalArgumentException
DomainBitSetminus in interface DomainBitSet<T>mask - The mask representing the other set.IllegalArgumentException - If the domain contains less than 64 elements then some long values are illegal.public DomainBitSet<T> minusVarArgs(T... elements)
DomainBitSetminusVarArgs in interface DomainBitSet<T>elements - A set as an array. Duplicates are ignored. Must not be nor contain null.DomainBitSet.minus(Iterable)public boolean ofEqualElements(DomainBitSet<T> other)
DomainBitSet
This is equal to, but could be a bit faster than this.toSet().equals(set.toSet()).
ofEqualElements in interface DomainBitSet<T>other - The other set.true if both contain the same elements.Set.equals(Object)public Iterable<SmallDomainBitSet<T>> powerset()
Note: Complexity is O(2n). This takes very long for large sets.
This is not thread safe and has to be processed sequentially.
powerset in interface DomainBitSet<T>powerset(Consumer, boolean)public void powerset(Consumer<DomainBitSet<T>> consumer, boolean blocking)
The consumer must be thread-safe. This will process all possible subsets concurrently, using an
ExecutorService. For better performance this uses SmallDomainBitSet only.
powerset in interface DomainBitSet<T>consumer - to process each subsetblocking - if true this will block until all are processedpowerset()public int size()
DomainBitSetsize in interface DomainBitSet<T>Collection.size()public Spliterator<T> spliterator()
DomainBitSetSpliterator over the elements in this collection.spliterator in interface DomainBitSet<T>spliterator in interface Iterable<T>Spliterator over the elements in this collectionCollection.spliterator()public BigInteger toBigInteger()
DomainBitSetBigInteger.toBigInteger in interface DomainBitSet<T>BigInteger.public BitSet toBitSet()
DomainBitSetBitSet.toBitSet in interface DomainBitSet<T>BitSet.public long toLong()
DomainBitSetlong.toLong in interface DomainBitSet<T>long.public Set<T> toSet()
DomainBitSetfalse for other sets without a domain.toSet in interface DomainBitSet<T>public DomainBitSet<T> union(BigInteger mask)
DomainBitSetBitSet.
Note: A fast version for BigInteger.ZERO should exist for each implementation!
union in interface DomainBitSet<T>mask - A BitSet representing another set.public DomainBitSet<T> union(BitSet s)
DomainBitSetBitSet.union in interface DomainBitSet<T>s - A BitSet representing another set.public DomainBitSet<T> union(Iterable<T> s)
DomainBitSetiterable collection.union in interface DomainBitSet<T>s - An Iterable representing another set.public DomainBitSet<T> union(long mask) throws IllegalArgumentException
DomainBitSetunion in interface DomainBitSet<T>mask - A bit mask representing another set.IllegalArgumentException - If the domain contains less than 64 elements then some long values are illegal.public DomainBitSet<T> unionVarArgs(T... elements)
DomainBitSetunionVarArgs in interface DomainBitSet<T>elements - A set as an array. Duplicates are ignored. Must not be nor contain null.DomainBitSet.union(Iterable)public Stream<Pair<Object,Integer,T>> zipWithPosition()
DomainBitSetzipWithPosition in interface DomainBitSet<T>BitSetUtilities.toTreeMap(),
DomainBitSet.getElement(int)