Created
July 9, 2020 17:09
-
-
Save ken-tune/8e248c893d3539b0201393df4bb3dbcf to your computer and use it in GitHub Desktop.
Bit mask required to be used when mapping logical keys into physical keys using Aerospike block storage technique
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Obtain bit mask required to ensure we have on average a specific number of logical objects in each physical object | |
* @param keySpaceSize - size of key space | |
* @param objectsPerBlock - average number of objects stored in each physical object | |
* @return bit mask as a BigInteger | |
*/ | |
public static BigInteger getBitMask(long keySpaceSize,int objectsPerBlock){ | |
// No of bits required is | |
// log(keySpaceSize/objectsPerBlock) / log(2) | |
// as reqd # of keys is keySpaceSize/objectsPerBlock | |
// round up as bit count has to be integral | |
int bitMaskSize = (int)Math.ceil((Math.log(keySpaceSize/objectsPerBlock) / Math.log(2))); | |
// Bit mask - 2^mask size - 1 to get all bits set | |
return (new BigInteger("2")).pow(bitMaskSize).subtract(new BigInteger("1")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment