Class ConciseSetUtils
- java.lang.Object
-
- org.apache.druid.extendedset.intset.ConciseSetUtils
-
public class ConciseSetUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static intALL_ONES_LITERALLiteral that represents all bits set to 1 (and MSB = 1)static intALL_ONES_WITHOUT_MSBAll bits set to 1 and MSB = 0static intALL_ZEROS_LITERALLiteral that represents all bits set to 0 (and MSB = 1)static intMAX_ALLOWED_INTEGERThe highest representable integer.static intMAX_LITERAL_LENGTHMaximum number of representable bits within a literalstatic intMIN_ALLOWED_SET_BITThe lowest representable integer.static intSEQUENCE_BITSequence bit
-
Constructor Summary
Constructors Constructor Description ConciseSetUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intclearBitsAfterInLastWord(int lastWord, int lastSetBit)static intflipBitAsBinaryString(int flipBit)static intgetFlippedBit(int word)Gets the position of the flipped bit within a sequence word.static intgetLiteral(int word, boolean simulateWAH)Gets the literal word that represents the first 31 bits of the given the word (i.e.static intgetLiteralBitCount(int word)Gets the number of set bits within the literal wordstatic intgetLiteralBits(int word)Gets the bits contained within the literal wordstatic intgetLiteralFromOneSeqFlipBit(int word)static intgetLiteralFromZeroSeqFlipBit(int word)static intgetSequenceCount(int word)Gets the number of blocks of 1's or 0's stored in a sequence wordstatic intgetSequenceNumWords(int word)static booleanisAllOnesLiteral(int word)static booleanisAllZerosLiteral(int word)static booleanisLiteral(int word)Checks whether a word is a literal onestatic booleanisLiteralWithSingleOneBit(int word)static booleanisLiteralWithSingleZeroBit(int word)static booleanisOneSequence(int word)Checks whether a word contains a sequence of 1'sstatic booleanisSequenceWithNoBits(int word)Checks whether a word contains a sequence of 0's with no set bit, or 1's with no unset bit.static booleanisZeroSequence(int word)Checks whether a word contains a sequence of 0'sstatic intmaxLiteralLengthDivision(int n)Calculates the division by 31static intmaxLiteralLengthModulus(int n)Calculates the modulus division by 31 in a faster way than usingn % 31static intmaxLiteralLengthMultiplication(int n)Calculates the multiplication by 31 in a faster way than usingn * 31static intonesUntil(int bit)
-
-
-
Field Detail
-
MAX_ALLOWED_INTEGER
public static final int MAX_ALLOWED_INTEGER
The highest representable integer. Its value is computed as follows. The number of bits required to represent the longest sequence of 0's or 1's is ceil(log2((Integer.MAX_VALUE- 31) / 31)) = 27. Indeed, at least one literal exists, and the other bits may all be 0's or 1's, that isInteger.MAX_VALUE- 31. If we use:- 2 bits for the sequence type;
- 5 bits to indicate which bit is set;
- See Also:
- Constant Field Values
-
MIN_ALLOWED_SET_BIT
public static final int MIN_ALLOWED_SET_BIT
The lowest representable integer.- See Also:
- Constant Field Values
-
MAX_LITERAL_LENGTH
public static final int MAX_LITERAL_LENGTH
Maximum number of representable bits within a literal- See Also:
- Constant Field Values
-
ALL_ONES_LITERAL
public static final int ALL_ONES_LITERAL
Literal that represents all bits set to 1 (and MSB = 1)- See Also:
- Constant Field Values
-
ALL_ZEROS_LITERAL
public static final int ALL_ZEROS_LITERAL
Literal that represents all bits set to 0 (and MSB = 1)- See Also:
- Constant Field Values
-
ALL_ONES_WITHOUT_MSB
public static final int ALL_ONES_WITHOUT_MSB
All bits set to 1 and MSB = 0- See Also:
- Constant Field Values
-
SEQUENCE_BIT
public static final int SEQUENCE_BIT
Sequence bit- See Also:
- Constant Field Values
-
-
Method Detail
-
maxLiteralLengthModulus
public static int maxLiteralLengthModulus(int n)
Calculates the modulus division by 31 in a faster way than usingn % 31This method of finding modulus division by an integer that is one less than a power of 2 takes at most O(lg(32)) time. The number of operations is at most 12 + 9 * ceil(lg(32)). See http://graphics.stanford.edu/~seander/bithacks.html- Parameters:
n- number to divide- Returns:
n % 31
-
maxLiteralLengthMultiplication
public static int maxLiteralLengthMultiplication(int n)
Calculates the multiplication by 31 in a faster way than usingn * 31- Parameters:
n- number to multiply- Returns:
n * 31
-
maxLiteralLengthDivision
public static int maxLiteralLengthDivision(int n)
Calculates the division by 31- Parameters:
n- number to divide- Returns:
n / 31
-
isLiteral
public static boolean isLiteral(int word)
Checks whether a word is a literal one- Parameters:
word- word to check- Returns:
trueif the given word is a literal word
-
isOneSequence
public static boolean isOneSequence(int word)
Checks whether a word contains a sequence of 1's- Parameters:
word- word to check- Returns:
trueif the given word is a sequence of 1's
-
isZeroSequence
public static boolean isZeroSequence(int word)
Checks whether a word contains a sequence of 0's- Parameters:
word- word to check- Returns:
trueif the given word is a sequence of 0's
-
isSequenceWithNoBits
public static boolean isSequenceWithNoBits(int word)
Checks whether a word contains a sequence of 0's with no set bit, or 1's with no unset bit.- Parameters:
word- word to check- Returns:
trueif the given word is a sequence of 0's or 1's but with no (un)set bit
-
getSequenceCount
public static int getSequenceCount(int word)
Gets the number of blocks of 1's or 0's stored in a sequence word- Parameters:
word- word to check- Returns:
- the number of blocks that follow the first block of 31 bits
-
getSequenceNumWords
public static int getSequenceNumWords(int word)
-
getLiteral
public static int getLiteral(int word, boolean simulateWAH)Gets the literal word that represents the first 31 bits of the given the word (i.e. the first block of a sequence word, or the bits of a literal word). If the word is a literal, it returns the unmodified word. In case of a sequence, it returns a literal that represents the first 31 bits of the given sequence word.- Parameters:
word- word to check- Returns:
- the literal contained within the given word, with the most significant bit set to 1.
-
getLiteralFromZeroSeqFlipBit
public static int getLiteralFromZeroSeqFlipBit(int word)
-
getLiteralFromOneSeqFlipBit
public static int getLiteralFromOneSeqFlipBit(int word)
-
getFlippedBit
public static int getFlippedBit(int word)
Gets the position of the flipped bit within a sequence word. If the sequence has no set/unset bit, returns -1. Note that the parameter must a sequence word, otherwise the result is meaningless.- Parameters:
word- sequence word to check- Returns:
- the position of the set bit, from 0 to 31. If the sequence has no set/unset bit, returns -1.
-
flipBitAsBinaryString
public static int flipBitAsBinaryString(int flipBit)
-
getLiteralBitCount
public static int getLiteralBitCount(int word)
Gets the number of set bits within the literal word- Parameters:
word- literal word- Returns:
- the number of set bits within the literal word
-
getLiteralBits
public static int getLiteralBits(int word)
Gets the bits contained within the literal word- Parameters:
word- literal word- Returns:
- the literal word with the most significant bit cleared
-
isAllOnesLiteral
public static boolean isAllOnesLiteral(int word)
-
isAllZerosLiteral
public static boolean isAllZerosLiteral(int word)
-
isLiteralWithSingleZeroBit
public static boolean isLiteralWithSingleZeroBit(int word)
-
isLiteralWithSingleOneBit
public static boolean isLiteralWithSingleOneBit(int word)
-
clearBitsAfterInLastWord
public static int clearBitsAfterInLastWord(int lastWord, int lastSetBit)
-
onesUntil
public static int onesUntil(int bit)
-
-