public class ConciseSetUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
ALL_ONES_LITERAL
Literal that represents all bits set to 1 (and MSB = 1)
|
static int |
ALL_ONES_WITHOUT_MSB
All bits set to 1 and MSB = 0
|
static int |
ALL_ZEROS_LITERAL
Literal that represents all bits set to 0 (and MSB = 1)
|
static int |
MAX_ALLOWED_INTEGER
The highest representable integer.
|
static int |
MAX_LITERAL_LENGTH
Maximum number of representable bits within a literal
|
static int |
MIN_ALLOWED_SET_BIT
The lowest representable integer.
|
static int |
SEQUENCE_BIT
Sequence bit
|
Constructor and Description |
---|
ConciseSetUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
clearBitsAfterInLastWord(int lastWord,
int lastSetBit) |
static int |
flipBitAsBinaryString(int flipBit) |
static int |
getFlippedBit(int word)
Gets the position of the flipped bit within a sequence word.
|
static int |
getLiteral(int word,
boolean simulateWAH)
Gets the literal word that represents the first 31 bits of the given the
word (i.e.
|
static int |
getLiteralBitCount(int word)
Gets the number of set bits within the literal word
|
static int |
getLiteralBits(int word)
Gets the bits contained within the literal word
|
static int |
getLiteralFromOneSeqFlipBit(int word) |
static int |
getLiteralFromZeroSeqFlipBit(int word) |
static int |
getSequenceCount(int word)
Gets the number of blocks of 1's or 0's stored in a sequence word
|
static int |
getSequenceNumWords(int word) |
static int |
getSequenceWithNoBits(int word)
Clears the (un)set bit in a sequence
|
static boolean |
isAllOnesLiteral(int word) |
static boolean |
isAllZerosLiteral(int word) |
static boolean |
isLiteral(int word)
Checks whether a word is a literal one
|
static boolean |
isLiteralWithSingleOneBit(int word) |
static boolean |
isLiteralWithSingleZeroBit(int word) |
static boolean |
isOneSequence(int word)
Checks whether a word contains a sequence of 1's
|
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.
|
static boolean |
isZeroSequence(int word)
Checks whether a word contains a sequence of 0's
|
static int |
maxLiteralLengthDivision(int n)
Calculates the division by 31
|
static int |
maxLiteralLengthModulus(int n)
Calculates the modulus division by 31 in a faster way than using
n % 31
This method of finding modulus division by an integer that is one less
than a power of 2 takes at most O(lg(32)) time. |
static int |
maxLiteralLengthMultiplication(int n)
Calculates the multiplication by 31 in a faster way than using
n * 31 |
static int |
onesUntil(int bit) |
public static final int MAX_ALLOWED_INTEGER
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 is Integer.MAX_VALUE
- 31. If we use:
public static final int MIN_ALLOWED_SET_BIT
public static final int MAX_LITERAL_LENGTH
public static final int ALL_ONES_LITERAL
public static final int ALL_ZEROS_LITERAL
public static final int ALL_ONES_WITHOUT_MSB
public static final int SEQUENCE_BIT
public static int maxLiteralLengthModulus(int n)
n % 31
This 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.htmln
- number to dividen % 31
public static int maxLiteralLengthMultiplication(int n)
n * 31
n
- number to multiplyn * 31
public static int maxLiteralLengthDivision(int n)
n
- number to dividen / 31
public static boolean isLiteral(int word)
word
- word to checktrue
if the given word is a literal wordpublic static boolean isOneSequence(int word)
word
- word to checktrue
if the given word is a sequence of 1'spublic static boolean isZeroSequence(int word)
word
- word to checktrue
if the given word is a sequence of 0'spublic static boolean isSequenceWithNoBits(int word)
#simulateWAH
is true
, it is
equivalent to (and as fast as) !
isLiteral(int)
word
- word to checktrue
if the given word is a sequence of 0's or 1's
but with no (un)set bitpublic static int getSequenceCount(int word)
word
- word to checkpublic static int getSequenceNumWords(int word)
public static int getSequenceWithNoBits(int word)
word
- word to checkpublic static int getLiteral(int word, boolean simulateWAH)
word
- word to checkpublic static int getLiteralFromZeroSeqFlipBit(int word)
public static int getLiteralFromOneSeqFlipBit(int word)
public static int getFlippedBit(int word)
word
- sequence word to checkpublic static int flipBitAsBinaryString(int flipBit)
public static int getLiteralBitCount(int word)
word
- literal wordpublic static int getLiteralBits(int word)
word
- literal wordpublic static boolean isAllOnesLiteral(int word)
public static boolean isAllZerosLiteral(int word)
public static boolean isLiteralWithSingleZeroBit(int word)
public static boolean isLiteralWithSingleOneBit(int word)
public static int clearBitsAfterInLastWord(int lastWord, int lastSetBit)
public static int onesUntil(int bit)
Copyright © 2011–2017. All rights reserved.