Class BitEncodedSet<T>
- java.lang.Object
-
- org.processmining.specpp.datastructures.encoding.BitEncodedSet<T>
-
- Type Parameters:
T- the type of items in this set
- All Implemented Interfaces:
java.lang.Iterable<T>,EncodedSet<T,java.lang.Integer>,MutatingSetOperations<BitEncodedSet<T>>,SetQueries<BitEncodedSet<T>>,SlightlyMutableSet<T>,Copyable<BitEncodedSet<T>>,ProperlyHashable
public class BitEncodedSet<T> extends java.lang.Object implements EncodedSet<T,java.lang.Integer>, ProperlyHashable, SetQueries<BitEncodedSet<T>>, MutatingSetOperations<BitEncodedSet<T>>, Copyable<BitEncodedSet<T>>
Represents a subset of the encoding domain of anIntEncoding<T>. Supports efficient set queries and mutations with other encoded sets, as declared inSetQueriesandMutatingSetOperations. Primarily used as an ordered subset with compact encodings that essentially map the domain to ordering indices starting at zero.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.processmining.specpp.datastructures.encoding.EncodedSet
EncodedSet.InconsistentEncodingException
-
-
Field Summary
Fields Modifier and Type Field Description protected IntEncoding<T>encodingprotected BitMasksetThe underlying bitmask on the range of the encoding that indicates set membership of the corresponding domain items.
-
Constructor Summary
Constructors Modifier Constructor Description protectedBitEncodedSet(IntEncoding<T> encoding)BitEncodedSet(IntEncoding<T> encoding, BitMask set)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T item)voidaddAll(T... items)booleanaddIndex(int index)Adds the item corresponding to this index ifindexis contained in the encoding range.voidaddMask(BitMask bitMask)intcardinality()voidclear()voidclearMask(BitMask bitMask)booleancontains(T item)booleancontainsIndex(int index)BitEncodedSet<T>copy()Copies this subset.static <T> BitEncodedSet<T>empty(IntEncoding<T> enc)booleanequals(java.lang.Object o)BitMaskgetBitMask()IntEncoding<T>getEncoding()inthashCode()voidintersection(BitEncodedSet<T> other)booleanintersects(BitEncodedSet<T> other)booleanisEmpty()booleanisSubsetOf(BitEncodedSet<T> other)booleanisSupersetOf(BitEncodedSet<T> other)java.util.Iterator<T>iterator()intkMaxIndex(int k)Computes thek-th largest set index, aka the largest item in this subset when the encoding is interpreted as an ordering.TkMaxItem(int k)intkMaxRange(int k)Computes the number of empty spots (zeros) in the encoding between thek-th andk-1-th largest set indices in the underlyingset.BitMaskkMaxRangeMask(int k)Computes a bitmask of the unset indices between thek-th largest and thek-1-th largest set indices.intkMinIndex(int k)Computes thek-th smallest set index, aka the smallest item in this subset when the encoding is interpreted as an ordering.TkMinItem(int k)intkMinRange(int k)kMaxRange()in reverse.TmaximalElement()intmaximalIndex()intmaxSize()TminimalElement()intminimalIndex()BitEncodedSet<T>reencode(IntEncoding<T> newEncoding)booleanremove(T item)Removes the specified item from this subset.booleanremoveIndex(int index)Removes the item corresponding to this index ifindexis contained in the encoding range.voidretainMask(BitMask bitMask)booleansetEquality(BitEncodedSet<T> other)voidsetminus(BitEncodedSet<T> other)java.util.stream.IntStreamstreamIndices()java.util.stream.Stream<T>streamItems()java.lang.StringtoString()voidunion(BitEncodedSet<T> other)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.processmining.specpp.datastructures.encoding.SetQueries
isDisjoint, isStrictSubsetOf, isStrictSupersetOf
-
Methods inherited from interface org.processmining.specpp.datastructures.encoding.SlightlyMutableSet
size
-
-
-
-
Field Detail
-
encoding
protected final IntEncoding<T> encoding
-
set
protected final BitMask set
The underlying bitmask on the range of the encoding that indicates set membership of the corresponding domain items.
-
-
Constructor Detail
-
BitEncodedSet
public BitEncodedSet(IntEncoding<T> encoding, BitMask set)
-
BitEncodedSet
protected BitEncodedSet(IntEncoding<T> encoding)
-
-
Method Detail
-
empty
public static <T> BitEncodedSet<T> empty(IntEncoding<T> enc)
-
reencode
public BitEncodedSet<T> reencode(IntEncoding<T> newEncoding)
-
getEncoding
public IntEncoding<T> getEncoding()
- Specified by:
getEncodingin interfaceEncodedSet<T,java.lang.Integer>
-
getBitMask
public BitMask getBitMask()
-
intersection
public void intersection(BitEncodedSet<T> other)
- Specified by:
intersectionin interfaceMutatingSetOperations<T>
-
union
public void union(BitEncodedSet<T> other)
- Specified by:
unionin interfaceMutatingSetOperations<T>
-
setminus
public void setminus(BitEncodedSet<T> other)
- Specified by:
setminusin interfaceMutatingSetOperations<T>
-
containsIndex
public boolean containsIndex(int index)
-
contains
public boolean contains(T item)
- Specified by:
containsin interfaceSlightlyMutableSet<T>
-
kMaxRangeMask
public BitMask kMaxRangeMask(int k)
Computes a bitmask of the unset indices between thek-th largest and thek-1-th largest set indices.- Parameters:
k-- Returns:
- See Also:
kMaxRange(int),kMaxIndex(int)
-
minimalIndex
public int minimalIndex()
- Returns:
- the minimal set index in the underlying bitmask
- See Also:
set
-
maximalIndex
public int maximalIndex()
- Returns:
- the maximal set index in the underlying bitmask
- See Also:
set
-
minimalElement
public T minimalElement()
- Returns:
- the minimal item contained in this subset
-
maximalElement
public T maximalElement()
- Returns:
- the maximal item contained in this subset
-
kMinIndex
public int kMinIndex(int k)
Computes thek-th smallest set index, aka the smallest item in this subset when the encoding is interpreted as an ordering. Returns-1fork<1andmaxSize()forkexceeding the cardinality of the underlying bitmaskset.
-
kMaxIndex
public int kMaxIndex(int k)
Computes thek-th largest set index, aka the largest item in this subset when the encoding is interpreted as an ordering. ReturnsmaxSize()fork<1and-1forkexceeding the cardinality of the underlying bitmaskset.
-
kMinItem
public T kMinItem(int k)
- Parameters:
k-- Returns:
- the corresponding item to the
kMinIndex(k) - See Also:
kMinIndex(int)
-
kMaxItem
public T kMaxItem(int k)
- Parameters:
k-- Returns:
- the corresponding item to the
kMaxIndex(k) - See Also:
kMaxIndex(int)
-
kMinRange
public int kMinRange(int k)
kMaxRange()in reverse.- Parameters:
k-- Returns:
- See Also:
kMaxRange(int)
-
kMaxRange
public int kMaxRange(int k)
Computes the number of empty spots (zeros) in the encoding between thek-th andk-1-th largest set indices in the underlyingset. With the encoding read as an ordering, this is the number of currently not contained items between the containedk-th largest item and its largest contained predecessor. The sum of all ranges over0 to maxIndex()is exactly the number of unset indices in the underlyingbitset, i.e. the number of missing items in this subset. Refer to the following example:set = 0011001, c = |set| = 3, L = maxIndex(set) = 6 k kMaxRange 0 0 1 0 2 2 3 0 4 2 5 0 6 0 invariant: sum_k=0^L( kMaxRange(k) ) = L - c, i.e. #of zeros in bitset- Parameters:
k-- Returns:
-
add
public boolean add(T item)
- Specified by:
addin interfaceSlightlyMutableSet<T>
-
addAll
@SafeVarargs public final void addAll(T... items)
- Specified by:
addAllin interfaceSlightlyMutableSet<T>
-
clear
public void clear()
- Specified by:
clearin interfaceSlightlyMutableSet<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceSlightlyMutableSet<T>
-
maxSize
public int maxSize()
- Returns:
- the maximum size this subset may grow to, as specified by the encoding, i.e. its range size.
-
addIndex
public boolean addIndex(int index)
Adds the item corresponding to this index ifindexis contained in the encoding range.- Parameters:
index- the index to be set- Returns:
- whether the set changed as a result, i.e. whether the index was unset before
-
remove
public boolean remove(T item)
Removes the specified item from this subset.- Specified by:
removein interfaceSlightlyMutableSet<T>- Parameters:
item- the item to be removed- Returns:
- whether this set changed as a result, i.e. whether the item was contained before
-
removeIndex
public boolean removeIndex(int index)
Removes the item corresponding to this index ifindexis contained in the encoding range.- Parameters:
index- the index to be unset- Returns:
- whether the set changed as a result, i.e. whether the index was set before
-
cardinality
public int cardinality()
- Specified by:
cardinalityin interfaceSlightlyMutableSet<T>- Returns:
- the cardinality of this subset
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceProperlyHashable- Overrides:
hashCodein classjava.lang.Object
-
copy
public BitEncodedSet<T> copy()
Copies this subset. As encoding are immutable this object's encoding is referenced in the copy instead of deep copied itself.
-
iterator
public java.util.Iterator<T> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<T>
-
streamItems
public java.util.stream.Stream<T> streamItems()
- Returns:
- a stream of all items contained in this set
-
streamIndices
public java.util.stream.IntStream streamIndices()
- Returns:
- an
IntStreamof all set indices in the underlying bitmask. - See Also:
set
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
clearMask
public void clearMask(BitMask bitMask)
-
retainMask
public void retainMask(BitMask bitMask)
-
addMask
public void addMask(BitMask bitMask)
-
intersects
public boolean intersects(BitEncodedSet<T> other)
- Specified by:
intersectsin interfaceSetQueries<T>
-
setEquality
public boolean setEquality(BitEncodedSet<T> other)
- Specified by:
setEqualityin interfaceSetQueries<T>
-
isSubsetOf
public boolean isSubsetOf(BitEncodedSet<T> other)
- Specified by:
isSubsetOfin interfaceSetQueries<T>
-
isSupersetOf
public boolean isSupersetOf(BitEncodedSet<T> other)
- Specified by:
isSupersetOfin interfaceSetQueries<T>
-
-