New Small feature

- Added: 2 Helper functions to find out how many bits are required to
store a Number.
This commit is contained in:
2021-11-30 16:20:08 +01:00
parent 53061d9f78
commit a2506b927a
2 changed files with 23 additions and 0 deletions
@@ -79,6 +79,26 @@ public class HashUtil
return x + 1L;
}
/**
* Function that finds out how many bits are required to store the number Provided
* @param value to get the required bits to store.
* @return the required bits to store that number
* @note Really useful for compression. Reducing data that is inserted into a GZIP algorithm.
*/
public static int getRequiredBits(int value) {
return Integer.bitCount(nextPowerOfTwo(value+1)-1);
}
/**
* Function that finds out how many bits are required to store the number Provided
* @param value to get the required bits to store.
* @return the required bits to store that number
* @note Really useful for compression. Reducing data that is inserted into a GZIP algorithm.
*/
public static int getRequiredBits(long value) {
return Long.bitCount(nextPowerOfTwo(value+1L)-1L);
}
/**
* Helper function that creates the ideal array size for HashMap
* @param size the original array size