Package convex.core.util
Class Bits
java.lang.Object
convex.core.util.Bits
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final int
hash32
(long x) 32-bit salted hash function for hashtables etc.static final long
hash64
(long x) 64-bit salted hash function for hashtables etc.static int
indexForDigit
(int digit, short mask) Returns the index from the present mask for the given hex digit (0-15), or -1 if not foundstatic int
leadingOnes
(long value) static int
leadingZeros
(int x) Get the number of leading zeros in the binary representation of an intstatic int
leadingZeros
(long x) Get the number of leading zeros in the binary representation of a longstatic int
lowBitMask
(int numBits) Gets a bit mask for the specified number of low bits in an intstatic int
lowBits
(int numBits, int val) Gets the specified number of low Bits in an integer.static int
positionForDigit
(int digit, short mask) Returns the array position for a given digit given a current mask.static long
xorshift64
(long x) Compute XORShift64 PRNG for a given value
-
Constructor Details
-
Bits
public Bits()
-
-
Method Details
-
indexForDigit
public static int indexForDigit(int digit, short mask) Returns the index from the present mask for the given hex digit (0-15), or -1 if not found- Parameters:
digit
- Hex digit (0-15)mask
- Bitmask of hex digits- Returns:
- The index of the appropriate child for this digit, or -1 if not found
-
positionForDigit
public static int positionForDigit(int digit, short mask) Returns the array position for a given digit given a current mask. If not present, this is where the new array entry must be inserted.- Parameters:
digit
- Hex digit (0-15)mask
- Bitmask of hex digits- Returns:
- Array position for the given digit in the specified mask
-
leadingZeros
public static int leadingZeros(int x) Get the number of leading zeros in the binary representation of an int- Parameters:
x
- int value to check- Returns:
- Number of leading zeros (0-32)
-
leadingZeros
public static int leadingZeros(long x) Get the number of leading zeros in the binary representation of a long- Parameters:
x
- long value to check- Returns:
- Number of leading zeros (0-64)
-
lowBitMask
public static int lowBitMask(int numBits) Gets a bit mask for the specified number of low bits in an int- Parameters:
numBits
- Number of bits to set to 1- Returns:
- int containing the specified number of set low bits
-
lowBits
public static int lowBits(int numBits, int val) Gets the specified number of low Bits in an integer. Other bits are zeroed.- Parameters:
numBits
- Number of bits to getval
- Value to extract bits from- Returns:
- Masked in with the specified number of low bits
-
leadingOnes
public static int leadingOnes(long value) -
xorshift64
public static long xorshift64(long x) Compute XORShift64 PRNG for a given value- Parameters:
x
- Input value (state)- Returns:
- PRNG value for x
-
hash64
public static final long hash64(long x) 64-bit salted hash function for hashtables etc.- Returns:
- Hash value using salted hash
-
hash32
public static final int hash32(long x) 32-bit salted hash function for hashtables etc.- Returns:
- Hash value using salted hash
-