com.hazelcast.util
Class QuickMath

java.lang.Object
  extended by com.hazelcast.util.QuickMath

public final class QuickMath
extends Object

The class QuickMath contains methods to perform optimized mathematical operations. Methods are allowed to put additional constraints on the range of input values if required for efficiency. Methods are not required to perform validation of input arguments, but they have to indicate the constraints in theirs contract.


Method Summary
static int compareIntegers(int i1, int i2)
          Compares two integers
static int compareLongs(long l1, long l2)
          Compares two longs
static int divideByAndCeilToInt(double d, int k)
           
static long divideByAndCeilToLong(double d, int k)
           
static int divideByAndRoundToInt(double d, int k)
           
static long divideByAndRoundToLong(double d, int k)
           
static boolean isPowerOfTwo(long x)
          Return true if input argument is power of two.
static int log2(int value)
           
static int log2(long value)
           
static int modPowerOfTwo(int a, int b)
          Computes the remainder of the division of a by b.
static long modPowerOfTwo(long a, int b)
          Computes the remainder of the division of a by b.
static int nextPowerOfTwo(int value)
           
static long nextPowerOfTwo(long value)
           
static int normalize(int value, int factor)
           
static long normalize(long value, int factor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isPowerOfTwo

public static boolean isPowerOfTwo(long x)
Return true if input argument is power of two. Input has to be a a positive integer.

Result is undefined for zero or negative integers.

Parameters:
x -
Returns:
true if x is power of two

modPowerOfTwo

public static int modPowerOfTwo(int a,
                                int b)
Computes the remainder of the division of a by b. a has to be non-negative integer and b has to be power of two otherwise the result is undefined.

Parameters:
a -
b -
Returns:
remainder of the division of a by b.

modPowerOfTwo

public static long modPowerOfTwo(long a,
                                 int b)
Computes the remainder of the division of a by b. a has to be non-negative integer and b has to be power of two otherwise the result is undefined.

Parameters:
a -
b -
Returns:
remainder of the division of a by b.

nextPowerOfTwo

public static int nextPowerOfTwo(int value)

nextPowerOfTwo

public static long nextPowerOfTwo(long value)

log2

public static int log2(int value)

log2

public static int log2(long value)

divideByAndCeilToInt

public static int divideByAndCeilToInt(double d,
                                       int k)

divideByAndCeilToLong

public static long divideByAndCeilToLong(double d,
                                         int k)

divideByAndRoundToInt

public static int divideByAndRoundToInt(double d,
                                        int k)

divideByAndRoundToLong

public static long divideByAndRoundToLong(double d,
                                          int k)

normalize

public static int normalize(int value,
                            int factor)

normalize

public static long normalize(long value,
                             int factor)

compareIntegers

public static int compareIntegers(int i1,
                                  int i2)
Compares two integers

Parameters:
i1 - First number to compare with second one
i2 - Second number to compare with first one
Returns:
+1 if i1 > i2, -1 if i2 > i1, 0 if i1 and i2 are equals

compareLongs

public static int compareLongs(long l1,
                               long l2)
Compares two longs

Parameters:
l1 - First number to compare with second one
l2 - Second number to compare with first one
Returns:
+1 if l1 > l2, -1 if l2 > l1, 0 if l1 and l2 are equals


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.