Class RangeBitmap

java.lang.Object
org.roaringbitmap.RangeBitmap

public final class RangeBitmap extends Object
A 2D bitmap which associates values with a row index and can perform range queries.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builder for constructing immutable RangeBitmaps
    private static final class 
     
    private final class 
     
    private final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
     
    private static final int
     
    private static final int
     
    private final ByteBuffer
     
    private final byte
     
    private final int
     
    private static final int
     
    private final long
     
    private final int
     
    private final long
     
    private static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    RangeBitmap(long mask, long max, ByteBuffer buffer, int masksOffset, int containersOffset, byte bytesPerMask)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    appender(long maxValue)
    Append values to the RangeBitmap before sealing it, defaults to on heap ByteBuffers.
    appender(long maxValue, IntFunction<ByteBuffer> bufferSupplier, Consumer<ByteBuffer> cleaner)
    Append values to the RangeBitmap before sealing it.
    between(long min, long max)
    Returns a RoaringBitmap of rows which have a value in between the thresholds.
    long
    betweenCardinality(long min, long max)
    Returns the number of rows which have a value in between the thresholds.
    long
    betweenCardinality(long min, long max, RoaringBitmap context)
    Returns the number of rows which have a value in between the thresholds.
    eq(long value)
    Returns a RoaringBitmap of rows which have a value equal to the value.
    eq(long value, RoaringBitmap context)
    Returns a RoaringBitmap of rows which have a value equal to the value.
    long
    eqCardinality(long value)
    Returns the number of rows which have a value equal to the value.
    long
    eqCardinality(long value, RoaringBitmap context)
    Returns the number of rows which have a value equal to the value, and intersect with the context bitmap, which will not be modified.
    private static long
    getContainerMask(ByteBuffer buffer, int position, long mask, int bytesPerMask)
     
    gt(long threshold)
    Returns a RoaringBitmap of rows which have a value greater than the threshold.
    gt(long threshold, RoaringBitmap context)
    Returns a RoaringBitmap of rows which have a value greater than the threshold, and intersect with the context bitmap, which will not be modified.
    long
    gtCardinality(long threshold)
    Returns the number of rows which have a value greater than the threshold.
    long
    gtCardinality(long threshold, RoaringBitmap context)
    Returns the number of rows which have a value greater than the threshold, and intersect with the context bitmap, which will not be modified.
    gte(long threshold)
    Returns a RoaringBitmap of rows which have a value greater than or equal to the threshold.
    gte(long threshold, RoaringBitmap context)
    Returns a RoaringBitmap of rows which have a value greater than or equal to the threshold, and intersect with the context bitmap, which will not be modified.
    long
    gteCardinality(long threshold)
    Returns the number of rows which have a value greater than or equal to the threshold.
    long
    gteCardinality(long threshold, RoaringBitmap context)
    Returns the number of rows which have a value greater than or equal to the threshold, and intersect with the context bitmap, which will not be modified.
    lt(long threshold)
    Returns a RoaringBitmap of rows which have a value less than the threshold.
    lt(long threshold, RoaringBitmap context)
    Returns a RoaringBitmap of rows which have a value less than the threshold, and intersect with the context bitmap, which will not be modified.
    long
    ltCardinality(long threshold)
    Returns the number of rows which have a value less than the threshold.
    long
    ltCardinality(long threshold, RoaringBitmap context)
    Returns the number of rows which have a value less than the threshold, and intersect with the context bitmap, which will not be modified.
    lte(long threshold)
    Returns a RoaringBitmap of rows which have a value less than or equal to the threshold.
    lte(long threshold, RoaringBitmap context)
    Returns a RoaringBitmap of rows which have a value less than or equal to the threshold, and intersect with the context bitmap, which will not be modified.
    long
    lteCardinality(long threshold)
    Returns the number of rows which have a value less than or equal to the threshold.
    long
    lteCardinality(long threshold, RoaringBitmap context)
    Returns the number of rows which have a value less than or equal to the threshold, and intersect with the context bitmap, which will not be modified.
    map(ByteBuffer buffer)
    Maps the RangeBitmap from the buffer with minimal allocation.
    neq(long value)
    Returns a RoaringBitmap of rows which have a value not equal to the value.
    neq(long value, RoaringBitmap context)
    Returns a RoaringBitmap of rows which have a value not equal to the value.
    long
    neqCardinality(long value)
    Returns the number of rows which have a value not equal to the value.
    long
    neqCardinality(long value, RoaringBitmap context)
    Returns the number of rows which have a value not equal to the value, and intersect with the context bitmap, which will not be modified.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BITMAP

      private static final int BITMAP
      See Also:
    • RUN

      private static final int RUN
      See Also:
    • ARRAY

      private static final int ARRAY
      See Also:
    • BITMAP_SIZE

      private static final int BITMAP_SIZE
      See Also:
    • buffer

      private final ByteBuffer buffer
    • masksOffset

      private final int masksOffset
    • containersOffset

      private final int containersOffset
    • mask

      private final long mask
    • max

      private final long max
    • bytesPerMask

      private final byte bytesPerMask
  • Constructor Details

    • RangeBitmap

      RangeBitmap(long mask, long max, ByteBuffer buffer, int masksOffset, int containersOffset, byte bytesPerMask)
  • Method Details

    • appender

      public static RangeBitmap.Appender appender(long maxValue, IntFunction<ByteBuffer> bufferSupplier, Consumer<ByteBuffer> cleaner)
      Append values to the RangeBitmap before sealing it.
      Parameters:
      maxValue - the maximum value to be appended, values larger than this value will be rejected.
      bufferSupplier - provides ByteBuffers.
      Returns:
      an appender.
    • appender

      public static RangeBitmap.Appender appender(long maxValue)
      Append values to the RangeBitmap before sealing it, defaults to on heap ByteBuffers.
      Parameters:
      maxValue - the maximum value to be appended, values larger than this value will be rejected.
      Returns:
      an appender.
    • map

      public static RangeBitmap map(ByteBuffer buffer)
      Maps the RangeBitmap from the buffer with minimal allocation. The buffer must not be reused while the mapped RangeBitmap is live.
      Parameters:
      buffer - a buffer containing a serialized RangeBitmap.
      Returns:
      a RangeBitmap backed by the buffer.
    • between

      public RoaringBitmap between(long min, long max)
      Returns a RoaringBitmap of rows which have a value in between the thresholds.
      Parameters:
      min - the inclusive minimum value.
      max - the inclusive maximum value.
      Returns:
      a bitmap of matching rows.
    • betweenCardinality

      public long betweenCardinality(long min, long max)
      Returns the number of rows which have a value in between the thresholds.
      Parameters:
      min - the inclusive minimum value.
      max - the inclusive maximum value.
      Returns:
      the number of matching rows.
    • betweenCardinality

      public long betweenCardinality(long min, long max, RoaringBitmap context)
      Returns the number of rows which have a value in between the thresholds.
      Parameters:
      min - the inclusive minimum value.
      max - the inclusive maximum value.
      context - to be intersected with.
      Returns:
      the number of matching rows.
    • lte

      public RoaringBitmap lte(long threshold)
      Returns a RoaringBitmap of rows which have a value less than or equal to the threshold.
      Parameters:
      threshold - the inclusive maximum value.
      Returns:
      a bitmap of matching rows.
    • lte

      public RoaringBitmap lte(long threshold, RoaringBitmap context)
      Returns a RoaringBitmap of rows which have a value less than or equal to the threshold, and intersect with the context bitmap, which will not be modified.
      Parameters:
      threshold - the inclusive maximum value.
      context - to be intersected with.
      Returns:
      a bitmap of matching rows.
    • lteCardinality

      public long lteCardinality(long threshold)
      Returns the number of rows which have a value less than or equal to the threshold.
      Parameters:
      threshold - the inclusive maximum value.
      Returns:
      the number of matching rows.
    • lteCardinality

      public long lteCardinality(long threshold, RoaringBitmap context)
      Returns the number of rows which have a value less than or equal to the threshold, and intersect with the context bitmap, which will not be modified.
      Parameters:
      threshold - the inclusive maximum value.
      context - to be intersected with.
      Returns:
      the number of matching rows.
    • lt

      public RoaringBitmap lt(long threshold)
      Returns a RoaringBitmap of rows which have a value less than the threshold.
      Parameters:
      threshold - the exclusive maximum value.
      Returns:
      a bitmap of matching rows.
    • lt

      public RoaringBitmap lt(long threshold, RoaringBitmap context)
      Returns a RoaringBitmap of rows which have a value less than the threshold, and intersect with the context bitmap, which will not be modified.
      Parameters:
      threshold - the exclusive maximum value.
      context - to be intersected with.
      Returns:
      a bitmap of matching rows which intersect .
    • ltCardinality

      public long ltCardinality(long threshold)
      Returns the number of rows which have a value less than the threshold.
      Parameters:
      threshold - the exclusive maximum value.
      Returns:
      the number of matching rows.
    • ltCardinality

      public long ltCardinality(long threshold, RoaringBitmap context)
      Returns the number of rows which have a value less than the threshold, and intersect with the context bitmap, which will not be modified.
      Parameters:
      threshold - the exclusive maximum value.
      context - to be intersected with.
      Returns:
      the number of matching rows which intersect .
    • gt

      public RoaringBitmap gt(long threshold)
      Returns a RoaringBitmap of rows which have a value greater than the threshold.
      Parameters:
      threshold - the exclusive minimum value.
      Returns:
      a bitmap of matching rows.
    • gt

      public RoaringBitmap gt(long threshold, RoaringBitmap context)
      Returns a RoaringBitmap of rows which have a value greater than the threshold, and intersect with the context bitmap, which will not be modified.
      Parameters:
      threshold - the exclusive minimum value.
      context - to be intersected with.
      Returns:
      a bitmap of matching rows.
    • gtCardinality

      public long gtCardinality(long threshold)
      Returns the number of rows which have a value greater than the threshold.
      Parameters:
      threshold - the exclusive minimum value.
      Returns:
      the number of matching rows.
    • gtCardinality

      public long gtCardinality(long threshold, RoaringBitmap context)
      Returns the number of rows which have a value greater than the threshold, and intersect with the context bitmap, which will not be modified.
      Parameters:
      threshold - the exclusive minimum value.
      context - to be intersected with.
      Returns:
      the number of matching rows.
    • gte

      public RoaringBitmap gte(long threshold)
      Returns a RoaringBitmap of rows which have a value greater than or equal to the threshold.
      Parameters:
      threshold - the inclusive minimum value.
      Returns:
      a bitmap of matching rows.
    • gte

      public RoaringBitmap gte(long threshold, RoaringBitmap context)
      Returns a RoaringBitmap of rows which have a value greater than or equal to the threshold, and intersect with the context bitmap, which will not be modified.
      Parameters:
      threshold - the inclusive minimum value.
      context - to be intersected with.
      Returns:
      a bitmap of matching rows.
    • gteCardinality

      public long gteCardinality(long threshold)
      Returns the number of rows which have a value greater than or equal to the threshold.
      Parameters:
      threshold - the inclusive minimum value.
      Returns:
      the number of matching rows.
    • gteCardinality

      public long gteCardinality(long threshold, RoaringBitmap context)
      Returns the number of rows which have a value greater than or equal to the threshold, and intersect with the context bitmap, which will not be modified.
      Parameters:
      threshold - the inclusive minimum value.
      context - to be intersected with.
      Returns:
      the number of matching rows.
    • eq

      public RoaringBitmap eq(long value)
      Returns a RoaringBitmap of rows which have a value equal to the value.
      Parameters:
      value - the value to filter by.
      Returns:
      a bitmap of matching rows.
    • eq

      public RoaringBitmap eq(long value, RoaringBitmap context)
      Returns a RoaringBitmap of rows which have a value equal to the value.
      Parameters:
      value - the value to filter by.
      context - to be intersected with.
      Returns:
      a bitmap of matching rows.
    • eqCardinality

      public long eqCardinality(long value)
      Returns the number of rows which have a value equal to the value.
      Parameters:
      value - the inclusive minimum value.
      Returns:
      the number of matching rows.
    • eqCardinality

      public long eqCardinality(long value, RoaringBitmap context)
      Returns the number of rows which have a value equal to the value, and intersect with the context bitmap, which will not be modified.
      Parameters:
      value - the inclusive minimum value.
      context - to be intersected with.
      Returns:
      the number of matching rows.
    • neq

      public RoaringBitmap neq(long value)
      Returns a RoaringBitmap of rows which have a value not equal to the value.
      Parameters:
      value - the value to filter by.
      Returns:
      a bitmap of matching rows.
    • neq

      public RoaringBitmap neq(long value, RoaringBitmap context)
      Returns a RoaringBitmap of rows which have a value not equal to the value.
      Parameters:
      value - the value to filter by.
      context - to be intersected with.
      Returns:
      a bitmap of matching rows.
    • neqCardinality

      public long neqCardinality(long value)
      Returns the number of rows which have a value not equal to the value.
      Parameters:
      value - the inclusive minimum value.
      Returns:
      the number of matching rows.
    • neqCardinality

      public long neqCardinality(long value, RoaringBitmap context)
      Returns the number of rows which have a value not equal to the value, and intersect with the context bitmap, which will not be modified.
      Parameters:
      value - the inclusive minimum value.
      context - to be intersected with.
      Returns:
      the number of matching rows.
    • getContainerMask

      private static long getContainerMask(ByteBuffer buffer, int position, long mask, int bytesPerMask)