Class PowerOf2Util
- java.lang.Object
-
- org.apache.activemq.artemis.utils.PowerOf2Util
-
public final class PowerOf2Util extends java.lang.ObjectCollection of bit-tricks for power of 2 cases.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intalign(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.static booleanisAligned(long value, int pow2alignment)Test if a value is pow2alignment-aligned.static booleanisPowOf2(int value)Is a value a positive power of two.
-
-
-
Method Detail
-
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:
java.lang.IllegalArgumentException- if the alignment is not a power of 2
-
-