Class MappeableBitmapContainer

    • Field Detail

      • USE_BRANCHLESS

        public static final boolean USE_BRANCHLESS
        optimization flag: whether the cardinality of the bitmaps is maintained through branchless operation
        See Also:
        Constant Field Values
    • Constructor Detail

      • MappeableBitmapContainer

        public MappeableBitmapContainer()
        Create a bitmap container with all bits set to false
      • MappeableBitmapContainer

        public MappeableBitmapContainer​(BitmapContainer bc)
        Creates a new bitmap container from a non-mappeable one. This copies the data.
        Parameters:
        bc - the original container
      • MappeableBitmapContainer

        public MappeableBitmapContainer​(int firstOfRun,
                                        int lastOfRun)
        Create a bitmap container with a run of ones from firstOfRun to lastOfRun, inclusive caller must ensure that the range isn't so small that an ArrayContainer should have been created instead
        Parameters:
        firstOfRun - first index
        lastOfRun - last index (range is exclusive)
      • MappeableBitmapContainer

        public MappeableBitmapContainer​(LongBuffer array,
                                        int initCardinality)
        Construct a new BitmapContainer backed by the provided LongBuffer.
        Parameters:
        array - LongBuffer where the data is stored
        initCardinality - cardinality (number of values stored)
    • Method Detail

      • serializedSizeInBytes

        protected static int serializedSizeInBytes​(int unusedCardinality)
      • add

        public MappeableContainer add​(int begin,
                                      int end)
        Description copied from class: MappeableContainer
        Return a new container with all shorts in [begin,end) added using an unsigned interpretation.
        Specified by:
        add in class MappeableContainer
        Parameters:
        begin - start of range (inclusive)
        end - end of range (exclusive)
        Returns:
        the new container
      • computeCardinality

        protected void computeCardinality()
        Recomputes the cardinality of the bitmap.
      • cardinalityInRange

        protected int cardinalityInRange​(int start,
                                         int end)
      • updateCardinality

        protected void updateCardinality​(int prevOnes,
                                         int newOnes)
      • contains

        public boolean contains​(short i)
        Description copied from class: MappeableContainer
        Checks whether the contain contains the provided value
        Specified by:
        contains in class MappeableContainer
        Parameters:
        i - value to check
        Returns:
        whether the value is in the container
      • bitValue

        protected long bitValue​(short i)
      • contains

        public static boolean contains​(ByteBuffer buf,
                                       int position,
                                       short i)
        Checks whether the container contains the value i.
        Parameters:
        buf - underlying buffer
        position - position of the container in the buffer
        i - index
        Returns:
        whether the container contains the value i
      • fillArray

        protected void fillArray​(short[] array)
        Fill the array with set bits
        Parameters:
        array - container (should be sufficiently large)
      • fillLeastSignificant16bits

        public void fillLeastSignificant16bits​(int[] x,
                                               int i,
                                               int mask)
        Description copied from class: MappeableContainer
        Fill the least significant 16 bits of the integer array, starting at index index, with the short values from this container. The caller is responsible to allocate enough room. The most significant 16 bits of each integer are given by the most significant bits of the provided mask.
        Specified by:
        fillLeastSignificant16bits in class MappeableContainer
        Parameters:
        x - provided array
        i - starting index
        mask - indicates most significant bits
      • flip

        public MappeableContainer flip​(short i)
        Description copied from class: MappeableContainer
        Add a short to the container if it is not present, otherwise remove it. May generate a new container.
        Specified by:
        flip in class MappeableContainer
        Parameters:
        i - short to be added
        Returns:
        the new container
      • getCardinality

        public int getCardinality()
        Description copied from class: MappeableContainer
        Computes the distinct number of short values in the container. Can be expected to run in constant time.
        Specified by:
        getCardinality in class MappeableContainer
        Returns:
        the cardinality
      • getSizeInBytes

        public int getSizeInBytes()
        Description copied from class: MappeableContainer
        Computes an estimate of the memory usage of this container. The estimate is not meant to be exact.
        Specified by:
        getSizeInBytes in class MappeableContainer
        Returns:
        estimated memory usage in bytes
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • iadd

        public MappeableContainer iadd​(int begin,
                                       int end)
        Description copied from class: MappeableContainer
        Add all shorts in [begin,end) using an unsigned interpretation. May generate a new container.
        Specified by:
        iadd in class MappeableContainer
        Parameters:
        begin - start of range (inclusive)
        end - end of range (exclusive)
        Returns:
        the new container
      • iand

        public MappeableContainer iand​(MappeableArrayContainer b2)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        iand in class MappeableContainer
        Parameters:
        b2 - other container
        Returns:
        aggregated container
      • iand

        public MappeableContainer iand​(MappeableBitmapContainer b2)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        iand in class MappeableContainer
        Parameters:
        b2 - other container
        Returns:
        aggregated container
      • iand

        public MappeableContainer iand​(MappeableRunContainer x)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        iand in class MappeableContainer
        Parameters:
        x - other container
        Returns:
        aggregated container
      • iandNot

        public MappeableContainer iandNot​(MappeableArrayContainer b2)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        iandNot in class MappeableContainer
        Parameters:
        b2 - other container
        Returns:
        aggregated container
      • iandNot

        public MappeableContainer iandNot​(MappeableBitmapContainer b2)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        iandNot in class MappeableContainer
        Parameters:
        b2 - other container
        Returns:
        aggregated container
      • iandNot

        public MappeableContainer iandNot​(MappeableRunContainer x)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        iandNot in class MappeableContainer
        Parameters:
        x - other container
        Returns:
        aggregated container
      • inot

        public MappeableContainer inot​(int firstOfRange,
                                       int lastOfRange)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise NOT of this container (complement). Only those bits within the range are affected. The current container is generally modified. May generate a new container.
        Specified by:
        inot in class MappeableContainer
        Parameters:
        firstOfRange - beginning of range (inclusive); 0 is beginning of this container.
        lastOfRange - ending of range (exclusive)
        Returns:
        (partially) completmented container
      • ior

        public MappeableBitmapContainer ior​(MappeableArrayContainer value2)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        ior in class MappeableContainer
        Parameters:
        value2 - other container
        Returns:
        aggregated container
      • ior

        public MappeableContainer ior​(MappeableBitmapContainer b2)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        ior in class MappeableContainer
        Parameters:
        b2 - other container
        Returns:
        aggregated container
      • isFull

        protected boolean isFull()
      • ior

        public MappeableContainer ior​(MappeableRunContainer x)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        ior in class MappeableContainer
        Parameters:
        x - other container
        Returns:
        aggregated container
      • iremove

        public MappeableContainer iremove​(int begin,
                                          int end)
        Description copied from class: MappeableContainer
        Remove shorts in [begin,end) using an unsigned interpretation. May generate a new container.
        Specified by:
        iremove in class MappeableContainer
        Parameters:
        begin - start of range (inclusive)
        end - end of range (exclusive)
        Returns:
        the new container
      • ixor

        public MappeableContainer ixor​(MappeableArrayContainer value2)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        ixor in class MappeableContainer
        Parameters:
        value2 - other container
        Returns:
        aggregated container
      • ixor

        public MappeableContainer ixor​(MappeableBitmapContainer b2)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        ixor in class MappeableContainer
        Parameters:
        b2 - other container
        Returns:
        aggregated container
      • ixor

        public MappeableContainer ixor​(MappeableRunContainer x)
        Description copied from class: MappeableContainer
        Computes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
        Specified by:
        ixor in class MappeableContainer
        Parameters:
        x - other container
        Returns:
        aggregated container
      • limit

        public MappeableContainer limit​(int maxcardinality)
        Description copied from class: MappeableContainer
        Create a new MappeableContainer containing at most maxcardinality integers.
        Specified by:
        limit in class MappeableContainer
        Parameters:
        maxcardinality - maximal cardinality
        Returns:
        a new bitmap with cardinality no more than maxcardinality
      • nextSetBit

        public int nextSetBit​(int i)
        Find the index of the next set bit greater or equal to i, returns -1 if none found.
        Parameters:
        i - starting index
        Returns:
        index of the next set bit
      • nextClearBit

        public int nextClearBit​(int i)
        Find the index of the next clear bit greater or equal to i.
        Parameters:
        i - starting index
        Returns:
        index of the next clear bit
      • not

        public MappeableContainer not​(int firstOfRange,
                                      int lastOfRange)
        Description copied from class: MappeableContainer
        Computes the bitwise NOT of this container (complement). Only those bits within the range are affected. The current container is left unaffected.
        Specified by:
        not in class MappeableContainer
        Parameters:
        firstOfRange - beginning of range (inclusive); 0 is beginning of this container.
        lastOfRange - ending of range (exclusive)
        Returns:
        (partially) completmented container
      • numberOfRunsAdjustment

        public int numberOfRunsAdjustment()
        Computes the number of runs
        Returns:
        the number of runs
      • numberOfRunsLowerBound

        public int numberOfRunsLowerBound​(int mustNotExceed)
        Counts how many runs there is in the bitmap, up to a maximum
        Parameters:
        mustNotExceed - maximum of runs beyond which counting is pointless
        Returns:
        estimated number of courses
      • prevSetBit

        public int prevSetBit​(int i)
        Find the index of the previous set bit less than or equal to i, returns -1 if none found.
        Parameters:
        i - starting index
        Returns:
        index of the previous set bit
      • prevClearBit

        public int prevClearBit​(int i)
        Find the index of the previous clear bit less than or equal to i.
        Parameters:
        i - starting index
        Returns:
        index of the previous clear bit
      • rank

        public int rank​(short lowbits)
        Description copied from class: MappeableContainer
        Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).
        Specified by:
        rank in class MappeableContainer
        Parameters:
        lowbits - upper limit
        Returns:
        the rank
      • remove

        public MappeableContainer remove​(int begin,
                                         int end)
        Description copied from class: MappeableContainer
        Return a new container with all shorts in [begin,end) remove using an unsigned interpretation.
        Specified by:
        remove in class MappeableContainer
        Parameters:
        begin - start of range (inclusive)
        end - end of range (exclusive)
        Returns:
        the new container
      • select

        public short select​(int j)
        Description copied from class: MappeableContainer
        Return the jth value
        Specified by:
        select in class MappeableContainer
        Parameters:
        j - index of the value
        Returns:
        the value
      • toArrayContainer

        public MappeableArrayContainer toArrayContainer()
        Copies the data to an array container
        Returns:
        the array container
      • toLongArray

        public long[] toLongArray()
        Create a copy of the content of this container as a long array. This creates a copy.
        Returns:
        copy of the content as a long array
      • forEach

        public void forEach​(short msb,
                            IntConsumer ic)
        Description copied from class: MappeableContainer
        Iterate through the values of this container and pass them along to the IntConsumer, using msb as the 16 most significant bits.
        Specified by:
        forEach in class MappeableContainer
        Parameters:
        msb - 16 most significant bits
        ic - consumer
      • first

        public int first()
        Description copied from class: MappeableContainer
        Get the first integer held in the container
        Specified by:
        first in class MappeableContainer
        Returns:
        the first integer in the container
      • last

        public int last()
        Description copied from class: MappeableContainer
        Get the last integer held in the container
        Specified by:
        last in class MappeableContainer
        Returns:
        the last integer in the container
      • nextValue

        public int nextValue​(short fromValue)
        Description copied from class: MappeableContainer
        Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.
        Specified by:
        nextValue in class MappeableContainer
        Parameters:
        fromValue - the lower bound (inclusive)
        Returns:
        the next value
      • previousValue

        public int previousValue​(short fromValue)
        Description copied from class: MappeableContainer
        Gets the last value less than or equal to the upper bound, or -1 if no such value exists.
        Specified by:
        previousValue in class MappeableContainer
        Parameters:
        fromValue - the upper bound (inclusive)
        Returns:
        the previous value
      • nextAbsentValue

        public int nextAbsentValue​(short fromValue)
        Description copied from class: MappeableContainer
        Gets the first absent value greater than or equal to the lower bound.
        Specified by:
        nextAbsentValue in class MappeableContainer
        Parameters:
        fromValue - the lower bound (inclusive)
        Returns:
        the next absent value
      • previousAbsentValue

        public int previousAbsentValue​(short fromValue)
        Description copied from class: MappeableContainer
        Gets the last value less than or equal to the upper bound.
        Specified by:
        previousAbsentValue in class MappeableContainer
        Parameters:
        fromValue - the upper bound (inclusive)
        Returns:
        the previous absent value
      • intersects

        public boolean intersects​(int minimum,
                                  int supremum)
        Description copied from class: MappeableContainer
        Checks if the container intersects with a range
        Specified by:
        intersects in class MappeableContainer
        Parameters:
        minimum - the inclusive unsigned lower bound of the range
        supremum - the exclusive unsigned upper bound of the range
        Returns:
        true if the container intersects the range
      • contains

        public boolean contains​(int minimum,
                                int supremum)
        Description copied from class: MappeableContainer
        Checks whether the container contains the entire range
        Specified by:
        contains in class MappeableContainer
        Parameters:
        minimum - the inclusive lower bound of the range
        supremum - the exclusive upper bound of the range
        Returns:
        true if the container contains the range