Package org.roaringbitmap.buffer
Class BufferUtil
- java.lang.Object
-
- org.roaringbitmap.buffer.BufferUtil
-
public final class BufferUtil extends java.lang.Object
Various useful methods for roaring bitmaps. This class is similar to org.roaringbitmap.Util but meant to be used with memory mapping.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MappeableContainer[]
addOffset(MappeableContainer source, char offsets)
Add value "offset" to all values in the container, producing two new containers.protected static int
advanceUntil(java.nio.CharBuffer array, int pos, int length, char min)
Find the smallest integer larger than pos such that array[pos]>= min.protected static void
arraycopy(java.nio.CharBuffer src, int srcPos, java.nio.CharBuffer dest, int destPos, int length)
protected static int
branchyUnsignedBinarySearch(java.nio.ByteBuffer array, int position, int begin, int end, char k)
protected static int
branchyUnsignedBinarySearch(java.nio.CharBuffer array, int begin, int end, char k)
static int
cardinalityInBitmapRange(java.nio.LongBuffer bitmap, int start, int end)
Hamming weight of the bitset in the range start, start+1,..., end-1protected static void
fillArrayAND(char[] container, java.nio.LongBuffer bitmap1, java.nio.LongBuffer bitmap2)
protected static void
fillArrayANDNOT(char[] container, java.nio.LongBuffer bitmap1, java.nio.LongBuffer bitmap2)
protected static void
fillArrayXOR(char[] container, java.nio.LongBuffer bitmap1, java.nio.LongBuffer bitmap2)
static void
flipBitmapRange(java.nio.LongBuffer bitmap, int start, int end)
flip bits at start, start+1,..., end-1static int
flipBitmapRangeAndCardinalityChange(java.nio.LongBuffer bitmap, int start, int end)
Deprecated.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.protected static char
highbits(int x)
protected static char
highbits(long x)
static int
intersectArrayIntoBitmap(long[] bitmap, java.nio.CharBuffer array, int length)
Intersects the bitmap with the array, returning the cardinality of the resultstatic int
intersectArrayIntoBitmap(java.nio.LongBuffer bitmap, java.nio.CharBuffer array, int length)
Intersects the bitmap with the array, returning the cardinality of the resultprotected static boolean
isBackedBySimpleArray(java.nio.Buffer b)
Checks whether the Buffer is backed by a simple array.static int
iterateUntil(java.nio.CharBuffer array, int pos, int length, int min)
Find the smallest integer larger than pos such that array[pos]>= min.protected static char
lowbits(int x)
protected static char
lowbits(long x)
protected static int
lowbitsAsInteger(long x)
protected static char
maxLowBit()
protected static int
maxLowBitAsInteger()
static void
resetBitmapRange(java.nio.LongBuffer bitmap, int start, int end)
clear bits at start, start+1,..., end-1static int
resetBitmapRangeAndCardinalityChange(java.nio.LongBuffer bitmap, int start, int end)
Deprecated.static void
setBitmapRange(java.nio.LongBuffer bitmap, int start, int end)
set bits at start, start+1,..., end-1static int
setBitmapRangeAndCardinalityChange(java.nio.LongBuffer bitmap, int start, int end)
Deprecated.static int
unsignedBinarySearch(java.nio.ByteBuffer array, int position, int begin, int end, char k)
Look for value k in buffer in the range [begin,end).static int
unsignedBinarySearch(java.nio.CharBuffer array, int begin, int end, char k)
Look for value k in buffer in the range [begin,end).protected static int
unsignedDifference(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2, char[] buffer)
protected static int
unsignedExclusiveUnion2by2(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2, char[] buffer)
protected static int
unsignedIntersect2by2(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2, char[] buffer)
static boolean
unsignedIntersects(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2)
Checks if two arrays intersectprotected static int
unsignedLocalIntersect2by2(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2, char[] buffer)
protected static int
unsignedLocalIntersect2by2Cardinality(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2)
protected static int
unsignedOneSidedGallopingIntersect2by2(java.nio.CharBuffer smallSet, int smallLength, java.nio.CharBuffer largeSet, int largeLength, char[] buffer)
protected static int
unsignedUnion2by2(java.nio.CharBuffer set1, int offset1, int length1, java.nio.CharBuffer set2, int offset2, int length2, char[] buffer)
-
-
-
Method Detail
-
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 containeroffsets
- value to add to each value in the container- Returns:
- return an array made of two containers
-
advanceUntil
protected static int advanceUntil(java.nio.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 searchpos
- initial positionmin
- minimal thresholdlength
- 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(java.nio.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 withinpos
- starting position of the searchlength
- length of the array to searchmin
- 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(java.nio.CharBuffer src, int srcPos, java.nio.CharBuffer dest, int destPos, int length)
-
branchyUnsignedBinarySearch
protected static int branchyUnsignedBinarySearch(java.nio.CharBuffer array, int begin, int end, char k)
-
branchyUnsignedBinarySearch
protected static int branchyUnsignedBinarySearch(java.nio.ByteBuffer array, int position, int begin, int end, char k)
-
fillArrayAND
protected static void fillArrayAND(char[] container, java.nio.LongBuffer bitmap1, java.nio.LongBuffer bitmap2)
-
fillArrayANDNOT
protected static void fillArrayANDNOT(char[] container, java.nio.LongBuffer bitmap1, java.nio.LongBuffer bitmap2)
-
fillArrayXOR
protected static void fillArrayXOR(char[] container, java.nio.LongBuffer bitmap1, java.nio.LongBuffer bitmap2)
-
flipBitmapRange
public static void flipBitmapRange(java.nio.LongBuffer bitmap, int start, int end)
flip bits at start, start+1,..., end-1- Parameters:
bitmap
- array of words to be modifiedstart
- first index to be modified (inclusive)end
- last index to be modified (exclusive)
-
cardinalityInBitmapRange
public static int cardinalityInBitmapRange(java.nio.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 bitsetstart
- first index (inclusive)end
- last index (exclusive)- Returns:
- the hamming weight of the corresponding range
-
setBitmapRangeAndCardinalityChange
@Deprecated public static int setBitmapRangeAndCardinalityChange(java.nio.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 modifiedstart
- first index to be modified (inclusive)end
- last index to be modified (exclusive)- Returns:
- cardinality change
-
flipBitmapRangeAndCardinalityChange
@Deprecated public static int flipBitmapRangeAndCardinalityChange(java.nio.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 modifiedstart
- first index to be modified (inclusive)end
- last index to be modified (exclusive)- Returns:
- cardinality change
-
resetBitmapRangeAndCardinalityChange
@Deprecated public static int resetBitmapRangeAndCardinalityChange(java.nio.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 modifiedstart
- 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 ignorednumRuns
- number of runs if run encoded, othewise ignoredisRunEncoded
- 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(java.nio.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(java.nio.LongBuffer bitmap, int start, int end)
clear bits at start, start+1,..., end-1- Parameters:
bitmap
- array of words to be modifiedstart
- first index to be modified (inclusive)end
- last index to be modified (exclusive)
-
setBitmapRange
public static void setBitmapRange(java.nio.LongBuffer bitmap, int start, int end)
set bits at start, start+1,..., end-1- Parameters:
bitmap
- array of words to be modifiedstart
- first index to be modified (inclusive)end
- last index to be modified (exclusive)
-
unsignedBinarySearch
public static int unsignedBinarySearch(java.nio.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 searchbegin
- first index (inclusive)end
- last index (exclusive)k
- value we search for- Returns:
- count
-
unsignedBinarySearch
public static int unsignedBinarySearch(java.nio.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 searchposition
- starting position of the container in the ByteBufferbegin
- first index (inclusive)end
- last index (exclusive)k
- value we search for- Returns:
- count
-
unsignedDifference
protected static int unsignedDifference(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2, char[] buffer)
-
intersectArrayIntoBitmap
public static int intersectArrayIntoBitmap(long[] bitmap, java.nio.CharBuffer array, int length)
Intersects the bitmap with the array, returning the cardinality of the result- Parameters:
bitmap
- the bitmap, modifiedarray
- the array, not modifiedlength
- 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(java.nio.LongBuffer bitmap, java.nio.CharBuffer array, int length)
Intersects the bitmap with the array, returning the cardinality of the result- Parameters:
bitmap
- the bitmap, modifiedarray
- the array, not modifiedlength
- 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(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2, char[] buffer)
-
unsignedIntersect2by2
protected static int unsignedIntersect2by2(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2, char[] buffer)
-
unsignedIntersects
public static boolean unsignedIntersects(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2)
Checks if two arrays intersect- Parameters:
set1
- first arraylength1
- length of first arrayset2
- second arraylength2
- length of second array- Returns:
- true if they intersect
-
unsignedLocalIntersect2by2
protected static int unsignedLocalIntersect2by2(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2, char[] buffer)
-
unsignedLocalIntersect2by2Cardinality
protected static int unsignedLocalIntersect2by2Cardinality(java.nio.CharBuffer set1, int length1, java.nio.CharBuffer set2, int length2)
-
unsignedOneSidedGallopingIntersect2by2
protected static int unsignedOneSidedGallopingIntersect2by2(java.nio.CharBuffer smallSet, int smallLength, java.nio.CharBuffer largeSet, int largeLength, char[] buffer)
-
unsignedUnion2by2
protected static int unsignedUnion2by2(java.nio.CharBuffer set1, int offset1, int length1, java.nio.CharBuffer set2, int offset2, int length2, char[] buffer)
-
-