Parallel Colt 0.9.4

cern.jet.math.tlong
Class LongFunctions

java.lang.Object
  extended by cern.jet.math.tlong.LongFunctions

public class LongFunctions
extends Object

Long Function objects to be passed to generic methods. Same as DoubleFunctions except operating on longs.

For aliasing see longFunctions.

Version:
1.0, 09/24/99
Author:
wolfgang.hoschek@cern.ch

Field Summary
static LongFunction abs
          Function that returns Math.abs(a) == (a < 0) ? -a : a.
static LongLongFunction and
          Function that returns a & b.
static LongLongFunction compare
          Function that returns a < b ? -1 : a > b ? 1 : 0.
static LongFunction dec
          Function that returns a--.
static LongLongFunction div
          Function that returns a / b.
static LongLongFunction divNeg
          Function that returns -(a / b).
static LongLongFunction equals
          Function that returns a == b ? 1 : 0.
static LongFunction factorial
          Function that returns (long) Arithmetic.factorial(a).
static LongFunction identity
          Function that returns its argument.
static LongFunction inc
          Function that returns a++.
static LongLongProcedure isEqual
          Function that returns a == b.
static LongLongProcedure isGreater
          Function that returns a > b.
static LongLongProcedure isLess
          Function that returns a < b.
static LongFunctions longFunctions
          Little trick to allow for "aliasing", that is, renaming this class.
static LongLongFunction max
          Function that returns Math.max(a,b).
static LongLongFunction min
          Function that returns Math.min(a,b).
static LongLongFunction minus
          Function that returns a - b.
static LongLongFunction mod
          Function that returns a % b.
static LongLongFunction mult
          Function that returns a * b.
static LongLongFunction multNeg
          Function that returns -(a * b).
static LongLongFunction multSquare
          Function that returns a * b^2.
static LongFunction neg
          Function that returns -a.
static LongFunction not
          Function that returns ~a.
static LongLongFunction or
          Function that returns a | b.
static LongLongFunction plus
          Function that returns a + b.
static LongLongFunction plusAbs
          Function that returns Math.abs(a) + Math.abs(b).
static LongLongFunction pow
          Function that returns (long) Math.pow(a,b).
static LongLongFunction shiftLeft
          Function that returns a << b.
static LongLongFunction shiftRightSigned
          Function that returns a >> b.
static LongLongFunction shiftRightUnsigned
          Function that returns a >>> b.
static LongFunction sign
          Function that returns a < 0 ? -1 : a > 0 ? 1 : 0.
static LongFunction square
          Function that returns a * a.
static LongLongFunction xor
          Function that returns a ^ b.
 
Method Summary
static LongFunction and(long b)
          Constructs a function that returns a & b.
static LongFunction between(long from, long to)
          Constructs a function that returns (from<=a && a<=to) ? 1 : 0.
static LongFunction bindArg1(LongLongFunction function, long c)
          Constructs a unary function from a binary function with the first operand (argument) fixed to the given constant c.
static LongFunction bindArg2(LongLongFunction function, long c)
          Constructs a unary function from a binary function with the second operand (argument) fixed to the given constant c.
static LongFunction chain(LongFunction g, LongFunction h)
          Constructs the function g( h(a) ).
static LongLongFunction chain(LongFunction g, LongLongFunction h)
          Constructs the function g( h(a,b) ).
static LongLongFunction chain(LongLongFunction f, LongFunction g, LongFunction h)
          Constructs the function f( g(a), h(b) ).
static LongFunction compare(long b)
          Constructs a function that returns a < b ? -1 : a > b ? 1 : 0.
static LongFunction constant(long c)
          Constructs a function that returns the constant c.
static LongFunction div(long b)
          Constructs a function that returns a / b.
static LongFunction equals(long b)
          Constructs a function that returns a == b ? 1 : 0.
static LongProcedure isBetween(long from, long to)
          Constructs a function that returns from<=a && a<=to.
static LongProcedure isEqual(long b)
          Constructs a function that returns a == b.
static LongProcedure isGreater(long b)
          Constructs a function that returns a > b.
static LongProcedure isLess(long b)
          Constructs a function that returns a < b.
static LongFunction max(long b)
          Constructs a function that returns Math.max(a,b).
static LongFunction min(long b)
          Constructs a function that returns Math.min(a,b).
static LongFunction minus(long b)
          Constructs a function that returns a - b.
static LongLongFunction minusMult(long constant)
          Constructs a function that returns a - b*constant.
static LongFunction mod(long b)
          Constructs a function that returns a % b.
static LongFunction mult(long b)
          Constructs a function that returns a * b.
static LongLongFunction multSecond(long constant)
          Constructs a function that returns b*constant.
static LongFunction or(long b)
          Constructs a function that returns a | b.
static LongFunction plus(long b)
          Constructs a function that returns a + b.
static LongLongFunction plusMultFirst(long constant)
          Constructs a function that returns a * constant + b.
static LongLongFunction plusMultSecond(long constant)
          Constructs a function that returns a + b*constant.
static LongFunction pow(long b)
          Constructs a function that returns (long) Math.pow(a,b).
static LongFunction random()
          Constructs a function that returns a 32 bit uniformly distributed random number in the closed longerval [Long.MIN_VALUE,Long.MAX_VALUE] (including Long.MIN_VALUE and Long.MAX_VALUE).
static LongFunction shiftLeft(long b)
          Constructs a function that returns a << b.
static LongFunction shiftRightSigned(long b)
          Constructs a function that returns a >> b.
static LongFunction shiftRightUnsigned(long b)
          Constructs a function that returns a >>> b.
static LongLongFunction swapArgs(LongLongFunction function)
          Constructs a function that returns function.apply(b,a), i.e.
static LongFunction xor(long b)
          Constructs a function that returns a | b.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

longFunctions

public static final LongFunctions longFunctions
Little trick to allow for "aliasing", that is, renaming this class. Writing code like

LongFunctions.chain(LongFunctions.plus,LongFunctions.mult(3),LongFunctions.chain(LongFunctions.square,LongFunctions.div(2)));

is a bit awkward, to say the least. Using the aliasing you can instead write

LongFunctions F = LongFunctions.longFunctions;
F.chain(F.plus,F.mult(3),F.chain(F.square,F.div(2)));


abs

public static final LongFunction abs
Function that returns Math.abs(a) == (a < 0) ? -a : a.


dec

public static final LongFunction dec
Function that returns a--.


factorial

public static final LongFunction factorial
Function that returns (long) Arithmetic.factorial(a).


identity

public static final LongFunction identity
Function that returns its argument.


inc

public static final LongFunction inc
Function that returns a++.


neg

public static final LongFunction neg
Function that returns -a.


not

public static final LongFunction not
Function that returns ~a.


sign

public static final LongFunction sign
Function that returns a < 0 ? -1 : a > 0 ? 1 : 0.


square

public static final LongFunction square
Function that returns a * a.


and

public static final LongLongFunction and
Function that returns a & b.


compare

public static final LongLongFunction compare
Function that returns a < b ? -1 : a > b ? 1 : 0.


div

public static final LongLongFunction div
Function that returns a / b.


divNeg

public static final LongLongFunction divNeg
Function that returns -(a / b).


equals

public static final LongLongFunction equals
Function that returns a == b ? 1 : 0.


isEqual

public static final LongLongProcedure isEqual
Function that returns a == b.


isLess

public static final LongLongProcedure isLess
Function that returns a < b.


isGreater

public static final LongLongProcedure isGreater
Function that returns a > b.


max

public static final LongLongFunction max
Function that returns Math.max(a,b).


min

public static final LongLongFunction min
Function that returns Math.min(a,b).


minus

public static final LongLongFunction minus
Function that returns a - b.


mod

public static final LongLongFunction mod
Function that returns a % b.


mult

public static final LongLongFunction mult
Function that returns a * b.


multNeg

public static final LongLongFunction multNeg
Function that returns -(a * b).


multSquare

public static final LongLongFunction multSquare
Function that returns a * b^2.


or

public static final LongLongFunction or
Function that returns a | b.


plus

public static final LongLongFunction plus
Function that returns a + b.


plusAbs

public static final LongLongFunction plusAbs
Function that returns Math.abs(a) + Math.abs(b).


pow

public static final LongLongFunction pow
Function that returns (long) Math.pow(a,b).


shiftLeft

public static final LongLongFunction shiftLeft
Function that returns a << b.


shiftRightSigned

public static final LongLongFunction shiftRightSigned
Function that returns a >> b.


shiftRightUnsigned

public static final LongLongFunction shiftRightUnsigned
Function that returns a >>> b.


xor

public static final LongLongFunction xor
Function that returns a ^ b.

Method Detail

and

public static LongFunction and(long b)
Constructs a function that returns a & b. a is a variable, b is fixed.


between

public static LongFunction between(long from,
                                   long to)
Constructs a function that returns (from<=a && a<=to) ? 1 : 0. a is a variable, from and to are fixed.


bindArg1

public static LongFunction bindArg1(LongLongFunction function,
                                    long c)
Constructs a unary function from a binary function with the first operand (argument) fixed to the given constant c. The second operand is variable (free).

Parameters:
function - a binary function taking operands in the form function.apply(c,var).
Returns:
the unary function function(c,var).

bindArg2

public static LongFunction bindArg2(LongLongFunction function,
                                    long c)
Constructs a unary function from a binary function with the second operand (argument) fixed to the given constant c. The first operand is variable (free).

Parameters:
function - a binary function taking operands in the form function.apply(var,c).
Returns:
the unary function function(var,c).

chain

public static LongFunction chain(LongFunction g,
                                 LongFunction h)
Constructs the function g( h(a) ).

Parameters:
g - a unary function.
h - a unary function.
Returns:
the unary function g( h(a) ).

chain

public static LongLongFunction chain(LongFunction g,
                                     LongLongFunction h)
Constructs the function g( h(a,b) ).

Parameters:
g - a unary function.
h - a binary function.
Returns:
the unary function g( h(a,b) ).

chain

public static LongLongFunction chain(LongLongFunction f,
                                     LongFunction g,
                                     LongFunction h)
Constructs the function f( g(a), h(b) ).

Parameters:
f - a binary function.
g - a unary function.
h - a unary function.
Returns:
the binary function f( g(a), h(b) ).

compare

public static LongFunction compare(long b)
Constructs a function that returns a < b ? -1 : a > b ? 1 : 0. a is a variable, b is fixed.


constant

public static LongFunction constant(long c)
Constructs a function that returns the constant c.


div

public static LongFunction div(long b)
Constructs a function that returns a / b. a is a variable, b is fixed.


equals

public static LongFunction equals(long b)
Constructs a function that returns a == b ? 1 : 0. a is a variable, b is fixed.


isBetween

public static LongProcedure isBetween(long from,
                                      long to)
Constructs a function that returns from<=a && a<=to. a is a variable, from and to are fixed.


isEqual

public static LongProcedure isEqual(long b)
Constructs a function that returns a == b. a is a variable, b is fixed.


isGreater

public static LongProcedure isGreater(long b)
Constructs a function that returns a > b. a is a variable, b is fixed.


isLess

public static LongProcedure isLess(long b)
Constructs a function that returns a < b. a is a variable, b is fixed.


max

public static LongFunction max(long b)
Constructs a function that returns Math.max(a,b). a is a variable, b is fixed.


min

public static LongFunction min(long b)
Constructs a function that returns Math.min(a,b). a is a variable, b is fixed.


minus

public static LongFunction minus(long b)
Constructs a function that returns a - b. a is a variable, b is fixed.


minusMult

public static LongLongFunction minusMult(long constant)
Constructs a function that returns a - b*constant. a and b are variables, constant is fixed.


mod

public static LongFunction mod(long b)
Constructs a function that returns a % b. a is a variable, b is fixed.


mult

public static LongFunction mult(long b)
Constructs a function that returns a * b. a is a variable, b is fixed.


or

public static LongFunction or(long b)
Constructs a function that returns a | b. a is a variable, b is fixed.


plus

public static LongFunction plus(long b)
Constructs a function that returns a + b. a is a variable, b is fixed.


multSecond

public static LongLongFunction multSecond(long constant)
Constructs a function that returns b*constant.


pow

public static LongFunction pow(long b)
Constructs a function that returns (long) Math.pow(a,b). a is a variable, b is fixed.


plusMultSecond

public static LongLongFunction plusMultSecond(long constant)
Constructs a function that returns a + b*constant. a and b are variables, constant is fixed.


plusMultFirst

public static LongLongFunction plusMultFirst(long constant)
Constructs a function that returns a * constant + b. a and b are variables, constant is fixed.


random

public static LongFunction random()
Constructs a function that returns a 32 bit uniformly distributed random number in the closed longerval [Long.MIN_VALUE,Long.MAX_VALUE] (including Long.MIN_VALUE and Long.MAX_VALUE). Currently the engine is DoubleMersenneTwister and is seeded with the current time.

Note that any random engine derived from DoubleRandomEngine and any random distribution derived from AbstractDoubleDistribution are function objects, because they implement the proper longerfaces. Thus, if you are not happy with the default, just pass your favourite random generator to function evaluating methods.


shiftLeft

public static LongFunction shiftLeft(long b)
Constructs a function that returns a << b. a is a variable, b is fixed.


shiftRightSigned

public static LongFunction shiftRightSigned(long b)
Constructs a function that returns a >> b. a is a variable, b is fixed.


shiftRightUnsigned

public static LongFunction shiftRightUnsigned(long b)
Constructs a function that returns a >>> b. a is a variable, b is fixed.


swapArgs

public static LongLongFunction swapArgs(LongLongFunction function)
Constructs a function that returns function.apply(b,a), i.e. applies the function with the first operand as second operand and the second operand as first operand.

Parameters:
function - a function taking operands in the form function.apply(a,b).
Returns:
the binary function function(b,a).

xor

public static LongFunction xor(long b)
Constructs a function that returns a | b. a is a variable, b is fixed.


Parallel Colt 0.9.4

Jump to the Parallel Colt Homepage