Class PowerOf2Util
java.lang.Object
org.apache.activemq.artemis.utils.PowerOf2Util
Collection of bit-tricks for power of 2 cases.
-
Method Details
-
align
public static int align(int value, int pow2alignment) Fast alignment operation with power of 2alignmentandvalue >=0andvalue <Integer.MAX_VALUE.In order to be fast is up to the caller to check arguments correctness. Original algorithm is on https://en.wikipedia.org/wiki/Data_structure_alignment.
-
isPowOf2
public static boolean isPowOf2(int value) Is a value a positive power of two.- Parameters:
value- to be checked.- Returns:
- true if the number is a positive power of two otherwise false
-
isAligned
public static boolean isAligned(long value, int pow2alignment) Test if a value is pow2alignment-aligned.- Parameters:
value- to be tested.pow2alignment- boundary the address is tested against.- Returns:
- true if the address is on the aligned boundary otherwise false
- Throws:
IllegalArgumentException- if the alignment is not a power of 2
-