Skip to content

Instantly share code, notes, and snippets.

@ken-tune
Created July 9, 2020 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ken-tune/8e248c893d3539b0201393df4bb3dbcf to your computer and use it in GitHub Desktop.
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
/**
* 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