Class BufferUtil

java.lang.Object
org.roaringbitmap.buffer.BufferUtil

public final class BufferUtil extends Object
Various useful methods for roaring bitmaps. This class is similar to org.roaringbitmap.Util but meant to be used with memory mapping.
  • Method Details

    • addOffset

      public static MappeableContainer[] addOffset(MappeableContainer source, char offsets)
      Add value "offset" to all values in the container, producing two new containers. The existing container remains unchanged. The new container are not converted, so they need to be checked: e.g., we could produce two bitmap containers having low cardinality.
      Parameters:
      source - source container
      offsets - value to add to each value in the container
      Returns:
      return an array made of two containers
    • advanceUntil

      protected static int advanceUntil(CharBuffer array, int pos, int length, char min)
      Find the smallest integer larger than pos such that array[pos]>= min. If none can be found, return length. Based on code by O. Kaser.
      Parameters:
      array - container where we search
      pos - initial position
      min - minimal threshold
      length - how big should the array consider to be
      Returns:
      x greater than pos such that array[pos] is at least as large as min, pos is is equal to length if it is not possible.
    • iterateUntil

      public static int iterateUntil(CharBuffer array, int pos, int length, int min)
      Find the smallest integer larger than pos such that array[pos]>= min. If none can be found, return length.
      Parameters:
      array - array to search within
      pos - starting position of the search
      length - length of the array to search
      min - minimum value
      Returns:
      x greater than pos such that array[pos] is at least as large as min, pos is is equal to length if it is not possible.
    • arraycopy

      protected static void arraycopy(CharBuffer src, int srcPos, CharBuffer dest, int destPos, int length)
    • branchyUnsignedBinarySearch

      protected static int branchyUnsignedBinarySearch(CharBuffer array, int begin, int end, char k)
    • branchyUnsignedBinarySearch

      protected static int branchyUnsignedBinarySearch(ByteBuffer array, int position, int begin, int end, char k)
    • fillArrayAND

      protected static void fillArrayAND(char[] container, LongBuffer bitmap1, LongBuffer bitmap2)
    • fillArrayANDNOT

      protected static void fillArrayANDNOT(char[] container, LongBuffer bitmap1, LongBuffer bitmap2)
    • fillArrayXOR

      protected static void fillArrayXOR(char[] container, LongBuffer bitmap1, LongBuffer bitmap2)
    • flipBitmapRange

      public static void flipBitmapRange(LongBuffer bitmap, int start, int end)
      flip bits at start, start+1,..., end-1
      Parameters:
      bitmap - array of words to be modified
      start - first index to be modified (inclusive)
      end - last index to be modified (exclusive)
    • cardinalityInBitmapRange

      public static int cardinalityInBitmapRange(LongBuffer bitmap, int start, int end)
      Hamming weight of the bitset in the range start, start+1,..., end-1
      Parameters:
      bitmap - array of words representing a bitset
      start - first index (inclusive)
      end - last index (exclusive)
      Returns:
      the hamming weight of the corresponding range
    • setBitmapRangeAndCardinalityChange

      @Deprecated public static int setBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end)
      Deprecated.
      set bits at start, start+1,..., end-1 and report the cardinality change
      Parameters:
      bitmap - array of words to be modified
      start - first index to be modified (inclusive)
      end - last index to be modified (exclusive)
      Returns:
      cardinality change
    • flipBitmapRangeAndCardinalityChange

      @Deprecated public static int flipBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end)
      Deprecated.
      flip bits at start, start+1,..., end-1 and report the cardinality change
      Parameters:
      bitmap - array of words to be modified
      start - first index to be modified (inclusive)
      end - last index to be modified (exclusive)
      Returns:
      cardinality change
    • resetBitmapRangeAndCardinalityChange

      @Deprecated public static int resetBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end)
      Deprecated.
      reset bits at start, start+1,..., end-1 and report the cardinality change
      Parameters:
      bitmap - array of words to be modified
      start - first index to be modified (inclusive)
      end - last index to be modified (exclusive)
      Returns:
      cardinality change
    • getSizeInBytesFromCardinalityEtc

      protected static int getSizeInBytesFromCardinalityEtc(int card, int numRuns, boolean isRunEncoded)
      From the cardinality of a container, compute the corresponding size in bytes of the container. Additional information is required if the container is run encoded.
      Parameters:
      card - the cardinality if this is not run encoded, otherwise ignored
      numRuns - number of runs if run encoded, othewise ignored
      isRunEncoded - boolean
      Returns:
      the size in bytes
    • highbits

      protected static char highbits(int x)
    • highbits

      protected static char highbits(long x)
    • isBackedBySimpleArray

      protected static boolean isBackedBySimpleArray(Buffer b)
      Checks whether the Buffer is backed by a simple array. In java, a Buffer is an abstraction that can represent various data, from data on disk all the way to native Java arrays. Like all abstractions, a Buffer might carry a performance penalty. Thus, we sometimes check whether the Buffer is simply a wrapper around a Java array. In these instances, it might be best, from a performance point of view, to access the underlying array (using the array()) method.
      Parameters:
      b - the provided Buffer
      Returns:
      whether the Buffer is backed by a simple array
    • lowbits

      protected static char lowbits(int x)
    • lowbits

      protected static char lowbits(long x)
    • lowbitsAsInteger

      protected static int lowbitsAsInteger(long x)
    • maxLowBit

      protected static char maxLowBit()
    • maxLowBitAsInteger

      protected static int maxLowBitAsInteger()
    • resetBitmapRange

      public static void resetBitmapRange(LongBuffer bitmap, int start, int end)
      clear bits at start, start+1,..., end-1
      Parameters:
      bitmap - array of words to be modified
      start - first index to be modified (inclusive)
      end - last index to be modified (exclusive)
    • setBitmapRange

      public static void setBitmapRange(LongBuffer bitmap, int start, int end)
      set bits at start, start+1,..., end-1
      Parameters:
      bitmap - array of words to be modified
      start - first index to be modified (inclusive)
      end - last index to be modified (exclusive)
    • unsignedBinarySearch

      public static int unsignedBinarySearch(CharBuffer array, int begin, int end, char k)
      Look for value k in buffer in the range [begin,end). If the value is found, return its index. If not, return -(i+1) where i is the index where the value would be inserted. The buffer is assumed to contain sorted values where chars are interpreted as unsigned integers.
      Parameters:
      array - buffer where we search
      begin - first index (inclusive)
      end - last index (exclusive)
      k - value we search for
      Returns:
      count
    • unsignedBinarySearch

      public static int unsignedBinarySearch(ByteBuffer array, int position, int begin, int end, char k)
      Look for value k in buffer in the range [begin,end). If the value is found, return its index. If not, return -(i+1) where i is the index where the value would be inserted. The buffer is assumed to contain sorted values where chars are interpreted as unsigned integers.
      Parameters:
      array - buffer where we search
      position - starting position of the container in the ByteBuffer
      begin - first index (inclusive)
      end - last index (exclusive)
      k - value we search for
      Returns:
      count
    • unsignedDifference

      protected static int unsignedDifference(CharBuffer set1, int length1, CharBuffer set2, int length2, char[] buffer)
    • intersectArrayIntoBitmap

      public static int intersectArrayIntoBitmap(long[] bitmap, CharBuffer array, int length)
      Intersects the bitmap with the array, returning the cardinality of the result
      Parameters:
      bitmap - the bitmap, modified
      array - the array, not modified
      length - how much of the array to consume
      Returns:
      the size of the intersection, i.e. how many bits still set in the bitmap
    • intersectArrayIntoBitmap

      public static int intersectArrayIntoBitmap(LongBuffer bitmap, CharBuffer array, int length)
      Intersects the bitmap with the array, returning the cardinality of the result
      Parameters:
      bitmap - the bitmap, modified
      array - the array, not modified
      length - how much of the array to consume
      Returns:
      the size of the intersection, i.e. how many bits still set in the bitmap
    • unsignedExclusiveUnion2by2

      protected static int unsignedExclusiveUnion2by2(CharBuffer set1, int length1, CharBuffer set2, int length2, char[] buffer)
    • unsignedIntersect2by2

      protected static int unsignedIntersect2by2(CharBuffer set1, int length1, CharBuffer set2, int length2, char[] buffer)
    • unsignedIntersects

      public static boolean unsignedIntersects(CharBuffer set1, int length1, CharBuffer set2, int length2)
      Checks if two arrays intersect
      Parameters:
      set1 - first array
      length1 - length of first array
      set2 - second array
      length2 - length of second array
      Returns:
      true if they intersect
    • unsignedLocalIntersect2by2

      protected static int unsignedLocalIntersect2by2(CharBuffer set1, int length1, CharBuffer set2, int length2, char[] buffer)
    • unsignedLocalIntersect2by2Cardinality

      protected static int unsignedLocalIntersect2by2Cardinality(CharBuffer set1, int length1, CharBuffer set2, int length2)
    • unsignedOneSidedGallopingIntersect2by2

      protected static int unsignedOneSidedGallopingIntersect2by2(CharBuffer smallSet, int smallLength, CharBuffer largeSet, int largeLength, char[] buffer)
    • unsignedUnion2by2

      protected static int unsignedUnion2by2(CharBuffer set1, int offset1, int length1, CharBuffer set2, int offset2, int length2, char[] buffer)