Package org.roaringbitmap.buffer
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 Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MappeableContainer[]addOffset(MappeableContainer source, short offsets)Add value "offset" to all values in the container, producing two new containers.protected static intadvanceUntil(ShortBuffer array, int pos, int length, short min)Find the smallest integer larger than pos such that array[pos]>= min.protected static voidarraycopy(ShortBuffer src, int srcPos, ShortBuffer dest, int destPos, int length)protected static intbranchyUnsignedBinarySearch(ByteBuffer array, int position, int begin, int end, short k)protected static intbranchyUnsignedBinarySearch(ShortBuffer array, int begin, int end, short k)static intcardinalityInBitmapRange(LongBuffer bitmap, int start, int end)Hamming weight of the bitset in the range start, start+1,..., end-1static intcompareUnsigned(short a, short b)Compares the two specifiedshortvalues, treating them as unsigned values between0and2^16 - 1inclusive.protected static voidfillArrayAND(short[] container, LongBuffer bitmap1, LongBuffer bitmap2)protected static voidfillArrayANDNOT(short[] container, LongBuffer bitmap1, LongBuffer bitmap2)protected static voidfillArrayXOR(short[] container, LongBuffer bitmap1, LongBuffer bitmap2)static voidflipBitmapRange(LongBuffer bitmap, int start, int end)flip bits at start, start+1,..., end-1static intflipBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end)Deprecated.protected static intgetSizeInBytesFromCardinalityEtc(int card, int numRuns, boolean isRunEncoded)From the cardinality of a container, compute the corresponding size in bytes of the container.protected static shorthighbits(int x)protected static shorthighbits(long x)protected static booleanisBackedBySimpleArray(Buffer b)Checks whether the Buffer is backed by a simple array.static intiterateUntil(ShortBuffer array, int pos, int length, int min)Find the smallest integer larger than pos such that array[pos]>= min.protected static shortlowbits(int x)protected static shortlowbits(long x)protected static shortmaxLowBit()protected static intmaxLowBitAsInteger()static voidresetBitmapRange(LongBuffer bitmap, int start, int end)clear bits at start, start+1,..., end-1static intresetBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end)Deprecated.static voidsetBitmapRange(LongBuffer bitmap, int start, int end)set bits at start, start+1,..., end-1static intsetBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end)Deprecated.protected static inttoIntUnsigned(short x)static intunsignedBinarySearch(ByteBuffer array, int position, int begin, int end, short k)Look for value k in buffer in the range [begin,end).static intunsignedBinarySearch(ShortBuffer array, int begin, int end, short k)Look for value k in buffer in the range [begin,end).protected static intunsignedDifference(ShortBuffer set1, int length1, ShortBuffer set2, int length2, short[] buffer)protected static intunsignedExclusiveUnion2by2(ShortBuffer set1, int length1, ShortBuffer set2, int length2, short[] buffer)protected static intunsignedIntersect2by2(ShortBuffer set1, int length1, ShortBuffer set2, int length2, short[] buffer)static booleanunsignedIntersects(ShortBuffer set1, int length1, ShortBuffer set2, int length2)Checks if two arrays intersectprotected static intunsignedLocalIntersect2by2(ShortBuffer set1, int length1, ShortBuffer set2, int length2, short[] buffer)protected static intunsignedLocalIntersect2by2Cardinality(ShortBuffer set1, int length1, ShortBuffer set2, int length2)protected static intunsignedOneSidedGallopingIntersect2by2(ShortBuffer smallSet, int smallLength, ShortBuffer largeSet, int largeLength, short[] buffer)protected static intunsignedUnion2by2(ShortBuffer set1, int offset1, int length1, ShortBuffer set2, int offset2, int length2, short[] buffer)
-
-
-
Method Detail
-
addOffset
public static MappeableContainer[] addOffset(MappeableContainer source, short 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(ShortBuffer array, int pos, int length, short 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(ShortBuffer 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(ShortBuffer src, int srcPos, ShortBuffer dest, int destPos, int length)
-
branchyUnsignedBinarySearch
protected static int branchyUnsignedBinarySearch(ShortBuffer array, int begin, int end, short k)
-
branchyUnsignedBinarySearch
protected static int branchyUnsignedBinarySearch(ByteBuffer array, int position, int begin, int end, short k)
-
compareUnsigned
public static int compareUnsigned(short a, short b)Compares the two specifiedshortvalues, treating them as unsigned values between0and2^16 - 1inclusive.- Parameters:
a- the first unsignedshortto compareb- the second unsignedshortto compare- Returns:
- a negative value if
ais less thanb; a positive value ifais greater thanb; or zero if they are equal
-
fillArrayAND
protected static void fillArrayAND(short[] container, LongBuffer bitmap1, LongBuffer bitmap2)
-
fillArrayANDNOT
protected static void fillArrayANDNOT(short[] container, LongBuffer bitmap1, LongBuffer bitmap2)
-
fillArrayXOR
protected static void fillArrayXOR(short[] 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 modifiedstart- 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 bitsetstart- 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 modifiedstart- 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 modifiedstart- 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 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 short highbits(int x)
-
highbits
protected static short 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 short lowbits(int x)
-
lowbits
protected static short lowbits(long x)
-
maxLowBit
protected static short 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 modifiedstart- 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 modifiedstart- first index to be modified (inclusive)end- last index to be modified (exclusive)
-
toIntUnsigned
protected static int toIntUnsigned(short x)
-
unsignedBinarySearch
public static int unsignedBinarySearch(ShortBuffer array, int begin, int end, short 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 shorts 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(ByteBuffer array, int position, int begin, int end, short 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 shorts 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(ShortBuffer set1, int length1, ShortBuffer set2, int length2, short[] buffer)
-
unsignedExclusiveUnion2by2
protected static int unsignedExclusiveUnion2by2(ShortBuffer set1, int length1, ShortBuffer set2, int length2, short[] buffer)
-
unsignedIntersect2by2
protected static int unsignedIntersect2by2(ShortBuffer set1, int length1, ShortBuffer set2, int length2, short[] buffer)
-
unsignedIntersects
public static boolean unsignedIntersects(ShortBuffer set1, int length1, ShortBuffer 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(ShortBuffer set1, int length1, ShortBuffer set2, int length2, short[] buffer)
-
unsignedLocalIntersect2by2Cardinality
protected static int unsignedLocalIntersect2by2Cardinality(ShortBuffer set1, int length1, ShortBuffer set2, int length2)
-
unsignedOneSidedGallopingIntersect2by2
protected static int unsignedOneSidedGallopingIntersect2by2(ShortBuffer smallSet, int smallLength, ShortBuffer largeSet, int largeLength, short[] buffer)
-
unsignedUnion2by2
protected static int unsignedUnion2by2(ShortBuffer set1, int offset1, int length1, ShortBuffer set2, int offset2, int length2, short[] buffer)
-
-