Class BitEncodedSet<T>

    • Field Detail

      • set

        protected final BitMask set
        The underlying bitmask on the range of the encoding that indicates set membership of the corresponding domain items.
    • Method Detail

      • getBitMask

        public BitMask getBitMask()
      • containsIndex

        public boolean containsIndex​(int index)
      • kMaxRangeMask

        public BitMask kMaxRangeMask​(int k)
        Computes a bitmask of the unset indices between the k-th largest and the k-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 the k-th smallest set index, aka the smallest item in this subset when the encoding is interpreted as an ordering. Returns -1 for k<1 and maxSize() for k exceeding the cardinality of the underlying bitmask set.
        Parameters:
        k -
        Returns:
        See Also:
        maxSize(), set
      • kMaxIndex

        public int kMaxIndex​(int k)
        Computes the k-th largest set index, aka the largest item in this subset when the encoding is interpreted as an ordering. Returns maxSize() for k<1 and -1 for k exceeding the cardinality of the underlying bitmask set.
        Parameters:
        k -
        Returns:
        See Also:
        maxSize(), set
      • 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 the k-th and k-1-th largest set indices in the underlying set. With the encoding read as an ordering, this is the number of currently not contained items between the contained k-th largest item and its largest contained predecessor. The sum of all ranges over 0 to maxIndex() is exactly the number of unset indices in the underlying bitset, 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:
      • 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 if index is 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:
        remove in interface SlightlyMutableSet<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 if index is 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
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface ProperlyHashable
        Overrides:
        hashCode in class java.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.
        Specified by:
        copy in interface Copyable<T>
        Returns:
        a copy of this subset
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.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 IntStream of all set indices in the underlying bitmask.
        See Also:
        set
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • clearMask

        public void clearMask​(BitMask bitMask)
      • retainMask

        public void retainMask​(BitMask bitMask)
      • addMask

        public void addMask​(BitMask bitMask)