Class BitmapContainer

java.lang.Object
org.roaringbitmap.Container
org.roaringbitmap.BitmapContainer
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Iterable<Character>, WordStorage<Container>

public final class BitmapContainer extends Container implements Cloneable
Simple bitset-like container.
See Also:
  • Field Details

  • Constructor Details

    • BitmapContainer

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

      public BitmapContainer(int firstOfRun, int lastOfRun)
      Create a bitmap container with a run of ones from firstOfRun to lastOfRun. 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)
    • BitmapContainer

      public BitmapContainer(long[] newBitmap, int newCardinality)
      Create a new container, no copy is made.
      Parameters:
      newBitmap - content
      newCardinality - desired cardinality.
    • BitmapContainer

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

    • getReverseShortIterator

      public static CharIterator getReverseShortIterator(long[] bitmap)
      Return a bitmap iterator over this array
      Parameters:
      bitmap - array to be iterated over
      Returns:
      an iterator
    • getShortIterator

      public static PeekableCharIterator getShortIterator(long[] bitmap)
      Return a bitmap iterator over this array
      Parameters:
      bitmap - array to be iterated over
      Returns:
      an iterator
    • serializedSizeInBytes

      protected static int serializedSizeInBytes(int unusedCardinality)
    • add

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

      public Container add(char i)
      Description copied from class: Container
      Add a short to the container. May generate a new container.
      Specified by:
      add in interface WordStorage<Container>
      Specified by:
      add in class Container
      Parameters:
      i - short to be added
      Returns:
      the new container
    • and

      public ArrayContainer and(ArrayContainer value2)
      Description copied from class: Container
      Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.
      Specified by:
      and in class Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • and

      public Container and(BitmapContainer value2)
      Description copied from class: Container
      Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.
      Specified by:
      and in class Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • and

      public Container and(RunContainer x)
      Description copied from class: Container
      Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.
      Specified by:
      and in class Container
      Parameters:
      x - other container
      Returns:
      aggregated container
    • andCardinality

      public int andCardinality(ArrayContainer value2)
      Specified by:
      andCardinality in class Container
    • andCardinality

      public int andCardinality(BitmapContainer value2)
      Specified by:
      andCardinality in class Container
    • andCardinality

      public int andCardinality(RunContainer x)
      Specified by:
      andCardinality in class Container
    • andNot

      public Container andNot(ArrayContainer value2)
      Description copied from class: Container
      Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.
      Specified by:
      andNot in class Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • andNot

      public Container andNot(BitmapContainer value2)
      Description copied from class: Container
      Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.
      Specified by:
      andNot in class Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • andNot

      public Container andNot(RunContainer x)
      Description copied from class: Container
      Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.
      Specified by:
      andNot in class Container
      Parameters:
      x - other container
      Returns:
      aggregated container
    • clear

      public void clear()
      Description copied from class: Container
      Empties the container
      Specified by:
      clear in class Container
    • clone

      public BitmapContainer clone()
      Specified by:
      clone in class Container
    • isEmpty

      public boolean isEmpty()
      Description copied from class: Container
      Checks whether the container is empty or not.
      Specified by:
      isEmpty in interface WordStorage<Container>
      Specified by:
      isEmpty in class Container
      Returns:
      true if the container is empty.
    • contains

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

      public boolean contains(int minimum, int supremum)
      Description copied from class: Container
      Checks whether the container contains the entire range
      Specified by:
      contains in class Container
      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
    • contains

      protected boolean contains(BitmapContainer bitmapContainer)
      Specified by:
      contains in class Container
    • contains

      protected boolean contains(RunContainer runContainer)
      Specified by:
      contains in class Container
    • contains

      protected boolean contains(ArrayContainer arrayContainer)
      Specified by:
      contains in class Container
    • deserialize

      public void deserialize(DataInput in) throws IOException
      Description copied from class: Container
      Deserialize (recover) the container.
      Specified by:
      deserialize in class Container
      Parameters:
      in - the DataInput stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • fillLeastSignificant16bits

      public void fillLeastSignificant16bits(int[] x, int i, int mask)
      Description copied from class: Container
      Fill the least significant 16 bits of the integer array, starting at index i, 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 Container
      Parameters:
      x - provided array
      i - starting index
      mask - indicates most significant bits
    • flip

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

      public int getArraySizeInBytes()
      Description copied from class: Container
      Size of the underlying array
      Specified by:
      getArraySizeInBytes in class Container
      Returns:
      size in bytes
    • getCardinality

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

      public PeekableCharIterator getReverseCharIterator()
      Description copied from class: Container
      Iterator to visit the char values in the container in descending order.
      Specified by:
      getReverseCharIterator in class Container
      Returns:
      iterator
    • getCharIterator

      public PeekableCharIterator getCharIterator()
      Description copied from class: Container
      Iterator to visit the char values in the container in ascending order.
      Specified by:
      getCharIterator in class Container
      Returns:
      iterator
    • getCharRankIterator

      public PeekableCharRankIterator getCharRankIterator()
      Description copied from class: Container
      Iterator to visit the short values in container and pre-compute ranks
      Specified by:
      getCharRankIterator in class Container
      Returns:
      iterator
    • getBatchIterator

      public ContainerBatchIterator getBatchIterator()
      Description copied from class: Container
      Gets an iterator to visit the contents of the container in batches
      Specified by:
      getBatchIterator in class Container
      Returns:
      iterator
    • getSizeInBytes

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

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

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

      public Container iand(ArrayContainer b2)
      Description copied from class: Container
      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 Container
      Parameters:
      b2 - other container
      Returns:
      aggregated container
    • iand

      public Container iand(BitmapContainer b2)
      Description copied from class: Container
      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 Container
      Parameters:
      b2 - other container
      Returns:
      aggregated container
    • iand

      public Container iand(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - other container
      Returns:
      aggregated container
    • iandNot

      public Container iandNot(ArrayContainer b2)
      Description copied from class: Container
      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 Container
      Parameters:
      b2 - other container
      Returns:
      aggregated container
    • iandNot

      public Container iandNot(BitmapContainer b2)
      Description copied from class: Container
      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 Container
      Parameters:
      b2 - other container
      Returns:
      aggregated container
    • iandNot

      public Container iandNot(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - other container
      Returns:
      aggregated container
    • inot

      public Container inot(int firstOfRange, int lastOfRange)
      Description copied from class: Container
      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 Container
      Parameters:
      firstOfRange - beginning of range (inclusive); 0 is beginning of this container.
      lastOfRange - ending of range (exclusive)
      Returns:
      (partially) complemented container
    • intersects

      public boolean intersects(ArrayContainer value2)
      Description copied from class: Container
      Returns true if the current container intersects the other container.
      Specified by:
      intersects in class Container
      Parameters:
      value2 - other container
      Returns:
      whether they intersect
    • intersects

      public boolean intersects(BitmapContainer value2)
      Description copied from class: Container
      Returns true if the current container intersects the other container.
      Specified by:
      intersects in class Container
      Parameters:
      value2 - other container
      Returns:
      whether they intersect
    • intersects

      public boolean intersects(RunContainer x)
      Description copied from class: Container
      Returns true if the current container intersects the other container.
      Specified by:
      intersects in class Container
      Parameters:
      x - other container
      Returns:
      whether they intersect
    • intersects

      public boolean intersects(int minimum, int supremum)
      Description copied from class: Container
      Checks if the container intersects with a range
      Specified by:
      intersects in class Container
      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
    • ior

      public BitmapContainer ior(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • ior

      public Container ior(BitmapContainer b2)
      Description copied from class: Container
      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 Container
      Parameters:
      b2 - other container
      Returns:
      aggregated container
    • ior

      public Container ior(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - other container
      Returns:
      aggregated container
    • iremove

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

      public Iterator<Character> iterator()
      Specified by:
      iterator in interface Iterable<Character>
    • ixor

      public Container ixor(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • ixor

      public Container ixor(BitmapContainer b2)
      Description copied from class: Container
      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 Container
      Parameters:
      b2 - other container
      Returns:
      aggregated container
    • ixor

      public Container ixor(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - other container
      Returns:
      aggregated container
    • lazyor

      protected Container lazyor(ArrayContainer value2)
    • lazyor

      protected Container lazyor(BitmapContainer x)
    • lazyor

      protected Container lazyor(RunContainer x)
    • limit

      public Container limit(int maxcardinality)
      Description copied from class: Container
      Create a new Container containing at most maxcardinality integers.
      Specified by:
      limit in class Container
      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
    • not

      public Container not(int firstOfRange, int lastOfRange)
      Description copied from class: Container
      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 Container
      Parameters:
      firstOfRange - beginning of range (inclusive); 0 is beginning of this container.
      lastOfRange - ending of range (exclusive)
      Returns:
      (partially) complemented 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
    • or

      public Container or(ArrayContainer value2)
      Description copied from class: Container
      Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.
      Specified by:
      or in class Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • isFull

      public boolean isFull()
      Description copied from class: Container
      Checks whether the container is full or not.
      Specified by:
      isFull in class Container
      Returns:
      true if the container is full.
    • or

      public Container or(BitmapContainer value2)
      Description copied from class: Container
      Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.
      Specified by:
      or in class Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • or

      public Container or(RunContainer x)
      Description copied from class: Container
      Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.
      Specified by:
      or in class Container
      Parameters:
      x - other container
      Returns:
      aggregated container
    • rank

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

      public void readExternal(ObjectInput in) throws IOException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
    • remove

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

      public Container remove(char i)
      Description copied from class: Container
      Remove the char from this container. May create a new container.
      Specified by:
      remove in class Container
      Parameters:
      i - to be removed
      Returns:
      New container
    • repairAfterLazy

      public Container repairAfterLazy()
      Description copied from class: Container
      The output of a lazyOR or lazyIOR might be an invalid container, this should be called on it.
      Specified by:
      repairAfterLazy in class Container
      Returns:
      a new valid container
    • runOptimize

      public Container runOptimize()
      Description copied from class: Container
      Convert to RunContainers, when the result is smaller. Overridden by RunContainer to possibility switch from RunContainer to a smaller alternative. Overridden by BitmapContainer with a more efficient approach.
      Specified by:
      runOptimize in interface WordStorage<Container>
      Specified by:
      runOptimize in class Container
      Returns:
      the new container
    • select

      public char select(int j)
      Description copied from class: Container
      Return the jth value
      Specified by:
      select in class Container
      Parameters:
      j - index of the value
      Returns:
      the value
    • serialize

      public void serialize(DataOutput out) throws IOException
      Description copied from class: Container
      Serialize the container.
      Specified by:
      serialize in class Container
      Parameters:
      out - the DataOutput stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • serializedSizeInBytes

      public int serializedSizeInBytes()
      Description copied from class: Container
      Report the number of bytes required to serialize this container.
      Specified by:
      serializedSizeInBytes in class Container
      Returns:
      the size in bytes
    • toLongBuffer

      public LongBuffer toLongBuffer()
      Return the content of this container as a LongBuffer. This creates a copy and might be relatively slow.
      Returns:
      the LongBuffer
    • toMappeableContainer

      public MappeableContainer toMappeableContainer()
      Description copied from class: Container
      Convert to a mappeable container.
      Specified by:
      toMappeableContainer in class Container
      Returns:
      the mappeable container
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • trim

      public void trim()
      Description copied from class: Container
      If possible, recover wasted memory.
      Specified by:
      trim in class Container
    • writeArray

      public void writeArray(DataOutput out) throws IOException
      Description copied from class: Container
      Write just the underlying array.
      Specified by:
      writeArray in class Container
      Parameters:
      out - output stream
      Throws:
      IOException - in case of failure
    • writeArray

      public void writeArray(ByteBuffer buffer)
      Description copied from class: Container
      Write just the underlying array.
      Specified by:
      writeArray in class Container
      Parameters:
      buffer - ByteBuffer to write to
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • xor

      public Container xor(ArrayContainer value2)
      Description copied from class: Container
      Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.
      Specified by:
      xor in class Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • xor

      public Container xor(BitmapContainer value2)
      Description copied from class: Container
      Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.
      Specified by:
      xor in class Container
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • xor

      public Container xor(RunContainer x)
      Description copied from class: Container
      Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.
      Specified by:
      xor in class Container
      Parameters:
      x - other container
      Returns:
      aggregated container
    • forEach

      public void forEach(char msb, IntConsumer ic)
      Description copied from class: Container
      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 Container
      Parameters:
      msb - 16 most significant bits
      ic - consumer
    • forAll

      public void forAll(int offset, RelativeRangeConsumer rrc)
      Description copied from class: Container
      Consume presence information for all values in this container.
      Specified by:
      forAll in class Container
      Parameters:
      offset - First value in this container corresponds to this relativePos in the range consumer.
      rrc - consumer
    • forAllFrom

      public void forAllFrom(char startValue, RelativeRangeConsumer rrc)
      Description copied from class: Container
      Consume presence information for all values greater or equal to startValue in this container.
      Specified by:
      forAllFrom in class Container
      Parameters:
      startValue - First value to consume. Corresponds to relativePos=0 in the range consumer.
      rrc - consumer
    • forAllUntil

      public void forAllUntil(int offset, char endValue, RelativeRangeConsumer rrc)
      Description copied from class: Container
      Consume presence information for all values smaller than endValue in this container.
      Specified by:
      forAllUntil in class Container
      Parameters:
      offset - First value in this container corresponds to this relativePos in the range consumer.
      endValue - First value greater than last value to consume.
      rrc - consumer
    • forAllInRange

      public void forAllInRange(char startValue, char endValue, RelativeRangeConsumer rrc)
      Description copied from class: Container
      Consumer presence information for all values in the range [startValue, endValue) in this container.
      Specified by:
      forAllInRange in class Container
      Parameters:
      startValue - First value to consume. Corresponds to relativePos=0 in the range consumer.
      endValue - First value greater than last value to consume.
      rrc - consumer
    • toBitmapContainer

      public BitmapContainer toBitmapContainer()
      Description copied from class: Container
      Convert the current container to a BitmapContainer, if a conversion is needed. If the container is already a bitmap, the container is returned unchanged.
      Specified by:
      toBitmapContainer in class Container
      Returns:
      a bitmap container
    • nextValue

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

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

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

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

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

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