New Small feature
- Added: 2 Helper functions to find out how many bits are required to store a Number.
This commit is contained in:
parent
53061d9f78
commit
a2506b927a
|
@ -1,5 +1,8 @@
|
|||
# Changelog of versions
|
||||
|
||||
### Version 0.4.6
|
||||
- Added: 2 Helper functions to find out how many bits are required to store a Number.
|
||||
|
||||
### Version 0.4.5
|
||||
- Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection
|
||||
- Fixed: Supplier get function wasn't referencing original function.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue