jal.bytes
Class Numeric

java.lang.Object
  extended byjal.bytes.Numeric

public final class Numeric
extends Object

A class that encapsulates generalized numeric algorithms on one and two arrays. All methods are static and all variables are static and final, so this class has no constructors.

Most methods operate on a range of elements. A range is described by the index of its first element and an index that is one past its last element. So, for example, [n, n+1) is a range that contains one element, [n, n) is a range that contains zero elements, and [n, n-1) is not a valid range.

Copyright © 1996 Silicon Graphics, Inc.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Silicon Graphics makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

Author:
Matthew Austern (austern@mti.sgi.com), Alexander Stepanov (stepanov@mti.sgi.com)
See Also:
Inspection, Modification, Sorting

Method Summary
static byte accumulate(byte[] array, int first, int last, byte init)
          Add all elements in a range.
static byte accumulate(byte[] array, int first, int last, byte init, BinaryOperator op)
          Generalized accumulation.
static int adjacent_difference(byte[] source, byte[] dest, int first, int last, int to)
          Computes the difference between each pair of adjacent elements in the input range and assigns them to an output range.
static int adjacent_difference(byte[] source, byte[] dest, int first, int last, int to, BinaryOperator op)
          Computes a binary operation op for each pair of adjacent elements in the input range and assigns the results to an output range.
static byte inner_product(byte[] array1, byte[] array2, int first1, int last1, int first2, byte init)
          Computes the inner product of two ranges.
static byte inner_product(byte[] array1, byte[] array2, int first1, int last1, int first2, byte init, BinaryOperator op1, BinaryOperator op2)
          Computes the generalized inner product of two ranges.
static int partial_sum(byte[] source, byte[] dest, int first, int last, int to)
          Computes the partial sums of elements in an input range and assigns them to elements in an output range.
static int partial_sum(byte[] source, byte[] dest, int first, int last, int to, BinaryOperator op)
          Computes the generalized partial sums of elements in an input range and assigns them to elements in an output range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

accumulate

public static byte accumulate(byte[] array,
                              int first,
                              int last,
                              byte init)
Add all elements in a range. The result acc is set to an initial value and, for each index i in the range, it is set to acc + array[i].

Parameters:
array - Array containing the range.
first - Beginning of the range.
last - Last element of the range.
init - Initial value of the accumulation.
Returns:
init + array[first] + ... + array[last-1].

accumulate

public static byte accumulate(byte[] array,
                              int first,
                              int last,
                              byte init,
                              BinaryOperator op)
Generalized accumulation. The result acc is set to an initial value and, for each index i in the range, it is set to op.apply(acc, array[i]).

Parameters:
array - Array containing the range.
first - Beginning of the range.
last - Last element of the range.
init - Initial value of the accumulation.
op - Binary operation.
Returns:
The result of the accumulation.

inner_product

public static byte inner_product(byte[] array1,
                                 byte[] array2,
                                 int first1,
                                 int last1,
                                 int first2,
                                 byte init)
Computes the inner product of two ranges. The result acc is set to an initial value, and, for each index i in the range [first, last), acc is set to acc + array1[i] * array2[first2 + (i - first1)].

Parameters:
array1 - Array containing the first range.
array2 - Array containing the second range.
first1 - Beginning of the first range.
last1 - One past the end of the first range.
first2 - Beginning of the second range.
init - Initial value for the result.
Returns:
The inner product.

inner_product

public static byte inner_product(byte[] array1,
                                 byte[] array2,
                                 int first1,
                                 int last1,
                                 int first2,
                                 byte init,
                                 BinaryOperator op1,
                                 BinaryOperator op2)
Computes the generalized inner product of two ranges. This is identical to the ordinary inner product, except that addition and multiplication are replaced, respectively, by binary operations op1 and op2. Specifically, the result acc is set to an initial value, and, for each index i in the range [first, last), acc is set to op1.apply(acc, op2.apply(array1[i] * array2[first2 + (i - first1)])).

Parameters:
array1 - Array containing the first range.
array2 - Array containing the second range.
first1 - Beginning of the first range.
last1 - One past the end of the first range.
first2 - Beginning of the second range.
init - Initial value for the result.
op1 - Binary operation that plays the role of addition.

partial_sum

public static int partial_sum(byte[] source,
                              byte[] dest,
                              int first,
                              int last,
                              int to)
Computes the partial sums of elements in an input range and assigns them to elements in an output range. dest[to] = source[first], dest[to+1] = source[first] + source[first+1], etc. There must be enough space in the destination array, and existing elements will be overwritten.

Parameters:
source - Array containing the input range.
dest - Array containing the output range.
first - Beginning of the input range.
last - One past the end of the input range.
to - Beginning of the output range.
Returns:
One past the end of the output range, that is, to + (last - first).

partial_sum

public static int partial_sum(byte[] source,
                              byte[] dest,
                              int first,
                              int last,
                              int to,
                              BinaryOperator op)
Computes the generalized partial sums of elements in an input range and assigns them to elements in an output range. Generalized partial sums are identical to partial sums except that addition is replaced by an arbitrary binary operation op. dest[to] = source[first], dest[to+1] = op.apply(source[first], source[first+1]), etc. There must be enough space in the destination array, and existing elements will be overwritten.

Parameters:
source - Array containing the input range.
dest - Array containing the output range.
first - Beginning of the input range.
last - One past the end of the input range.
to - Beginning of the output range.
op - Binary operation that plays the role of addition.
Returns:
One past the end of the output range, that is, to + (last - first).

adjacent_difference

public static int adjacent_difference(byte[] source,
                                      byte[] dest,
                                      int first,
                                      int last,
                                      int to)
Computes the difference between each pair of adjacent elements in the input range and assigns them to an output range. Assigns dest[to] = source[first], dest[to+1] = source[first+1] - source[first],..., dest[to + (last-first)] = source[last-1] - source[last-2]. There must be enough space in the destination array, and existing elements will be overwritten.

Parameters:
source - Array containing the input range.
dest - Array containing the output range.
first - Beginning of the input range.
last - One past the end of the input range.
to - Beginning of the output range.
Returns:
One past the end of the output range, that is, to + (last - first).

adjacent_difference

public static int adjacent_difference(byte[] source,
                                      byte[] dest,
                                      int first,
                                      int last,
                                      int to,
                                      BinaryOperator op)
Computes a binary operation op for each pair of adjacent elements in the input range and assigns the results to an output range. Assigns dest[to] = source[first], dest[to+1] = op.apply(source[first+1], source[first]),..., dest[to + (last-first)] = op.apply(source[last-1], source[last-2]). There must be enough space in the destination array, and existing elements will be overwritten.

Parameters:
source - Array containing the input range.
dest - Array containing the output range.
first - Beginning of the input range.
last - One past the end of the input range.
to - Beginning of the output range.
op - Binary operation.
Returns:
One past the end of the output range, that is, to + (last - first).