public abstract class SummingHistogram extends Histogram
Summing histogram: an extension of Histogram
class, allowing quick calculation of sums
of all elements of the sorted source array A[k] with indexes, lying in some range
This class is an inheritor of Histogram
class, so any summing histogram is also a usual histogram:
an array of nonnegative integer numbers b[v], 0≤v<M,
where every element b[v] represents the number of occurrence of the value v
in some source array A, consisting of integer elements in 0..M−1 range.
As in Histogram
class, the integer values v in the source array are 31bit:
0≤M<2^{31}, the bars of the histogram b[v] and their sum N
are 63bit: 0≤N<2^{63}, and
the source array A is always supposed to be sorted in increasing order:
The difference from usual histograms is that this class implement several additional methods,
which allow efficient solving two additional tasks.
Namely, in addition to (1) finding the percentile Histogram
class), this class provide efficient solution of the following tasks:
Obviously, it allows to find the sum of all elements lying in a range of indexes in the sorted
source array
Like Histogram
, this class does not store and does not try to sort the source array A,
it stores only the histogram b and solves all tasks on the base of it.
The price of the additional features is less performance: the methods of this class
work little slower than the methods of more simple Histogram
class.
Like Histogram
, this class generalizes the concept of sum of elements to the
floatingpoint case. Below is the formal definition of the real S and
s functions, calculated by this class.
Definition of floatingpoint summing functions S(r) and s(v) Let b[0..M−1] be an array of nonnegative integer numbers, called the histogram (and stored by this class), and let N be the sum of all these elements (the length of the supposed, but not stored source sorted array A). Let v(r),
0.0≤r≤N , and r(v),0.0≤v≤M , are the percentile and the rank real functions, formally defined in the comments toHistogram
class.This class allow to calculate two additional real functions:
S(r) , where r is a real number in range0.0≤r≤N , ands(v) , where v is a real number in range0.0≤v≤M . Likev(r) andr(v) , theS(r) ands(v) functions are different in different histogram models: simple and precise (see comments toHistogram
class). Namely, these functions are defined via the following definite integrals:
 Simple histogram model
Generalization of Z(r), which is an sum of elements
A[r] with integer indexes, to the real functionS(r) is very simple: we use a definite integral of the functionv(r) with a real argument. After this, we just define s(v) asS(r(v)) .
 S(r) = ∫_{0≤x≤r} v(x) dx;
 s(v) = S(r(v)) = ∫_{0≤x≤r(v)} v(x) dx.
Note: according this definition,s(v)=S(0)=0 when v<v(0) ands(v)=S(N) when v>v(N).In the simple histogram model, there is a simple relation between s(v) function and the more simple concept of z(v) sum, defined above in integer terms. Namely, if v_{0} is integer, then
s(v_{0}) = Σ _{0≤j<v0}(j+0.5)*b[j] = z(v_{0}) + r(v_{0})/2 Precise histogram model
In this case, the behaviour of
v(r) andr(v) is more complicated and calculating the integral is little more difficult. To allow this class optimization of algorithms, we little change the definition ofS(r) ands(v) . Namely, in the precise histogram model, these functions also depend on some constant C, the value of which is undocumented and can be chosen by this class to provide the maximal performance:
 S(r) = C + ∫_{0≤x≤r} v(x) dx, where C is some constant, the value of which is undocumented;
 s(v) = S(r(v)) = C + ∫_{0≤x≤r(v)} v(x) dx.
Note: according this definition,s(v)=S(0)=C when v<v(0) ands(v)=S(N) when v>v(N).Though this definition includes some unknown constant C, is is not important if you need to calculate the difference
S(r_{2})−S(r_{1}) ors(v_{2})−s(v_{1}) : such differences do not contain C constant. If you really need to calculate the integral from the right sides of the formulas above, you can calculate it asS(r)−S(0) ors(v)−s(0) .The value of the constant C depends on the histogram bars b[k]: in this class, for example, it can vary when you add or remove elements by
include
/exclude
methods.
Like Histogram
, this class is optimized for the case, when we already know some corresponding
pair r (rank) and v (percentile), and we need to slightly change the situation:
add or remove several A elements, increase or decrease the known rank r or
the value v. But in addition to the current value v,
current simple rank r^{S} and current precise rank r^{P},
this class supports two new parameters:
currentIntegral()
method;currentPreciseIntegral()
method.Unlike v, r^{S} and r^{P}, which can be set and read, the S^{S} and S^{P} parameters are readonly: they can be only read according the current values of v, r^{S} and r^{P}.
If you want to get the simple sum of elements of the source A array in integer terms,
you also can use currentSum()
method, which just returns
currentIValue()
You can create an instance of this class by the following methods:
newSummingLongHistogram(int histogramLength, int... bitLevelsOfPyramid)
;newSummingLongHistogram(int histogramLength, boolean optimizeSimpleIntegral, int... bitLevelsOfPyramid)
;newSummingLongHistogram(long[] histogram, int... bitLevelsOfPyramid)
;newSummingLongHistogram(long[] histogram, boolean optimizeSimpleIntegral, int... bitLevelsOfPyramid)
;newSummingIntHistogram(int histogramLength, int... bitLevelsOfPyramid)
;newSummingIntHistogram(int histogramLength, boolean optimizeSimpleIntegral, int... bitLevelsOfPyramid)
;newSummingIntHistogram(int[] histogram, int... bitLevelsOfPyramid)
;newSummingIntHistogram(int[] histogram, boolean optimizeSimpleIntegral, int... bitLevelsOfPyramid)
.This class is often used for calculating differences
share
the histogram between two instances of this object
and set the 1nd necessary rank r_{1} (or value v_{1}) in the 1st instance
and the 2nd necessary rank r_{2} (or value v_{2}) in the 2nd instance.
The difference between currentIntegral()
or currentPreciseIntegral()
, calculated in two
instances, will contain the necessary result. Because this situation is often enough, there are
special methods currentIntegralBetweenSharing()
and currentPreciseIntegralBetweenSharing()
for this task.
This class also provides static methods for calculating
integralBetweenRanks(long[], double, double)
/
integralBetweenRanks(int[], double, double)
and
integralBetweenValues(long[], double, double, CountOfValues)
/
integralBetweenValues(int[], double, double, CountOfValues)
for the simple histogram model,
preciseIntegralBetweenRanks(long[], double, double)
/
preciseIntegralBetweenRanks(int[], double, double)
and
preciseIntegralBetweenValues(long[], double, double, CountOfValues)
/
preciseIntegralBetweenValues(int[], double, double, CountOfValues)
for the precise histogram model.
These methods can be useful if you need to process the given histogram only once.
The floatingpoint calculations in this class are performed not in strictfp, but in the usual mode. So, there is no guarantee that the results are absolutely identical on all platforms. Moreover, there is no guarantee that the same results, got by different ways (for example, by static methods and by creating an instance of this class and using its methods) are absolutely identical: little mismatches in the last digits after the decimal point are possible.
This class does not implement own equals and hashCode methods. So, this class does not provide a mechanism for comparing different histograms.
This class is not threadsafe, but is threadcompatible and can be synchronized manually, if multithread access is necessary.
AlgART Laboratory 2007–2014
Modifier and Type  Class and Description 

static class 
SummingHistogram.CountOfValues
The helper class for static methods of
SummingHistogram class,
calculating the integrals of 
Modifier and Type  Method and Description 

double 
currentIntegral()
Returns the current simple integral

double 
currentIntegralBetweenSharing()
Equivalent to
nextSharing() .currentIntegral()
 thisInstance.currentIntegral() , but probably works little faster. 
abstract int 
currentNumberOfDifferentValues()
Returns the number of nonzero bars b[k] with indexes
currentIValue() 
double 
currentPreciseIntegral()
Returns the current precise integral

double 
currentPreciseIntegralBetweenSharing()
Equivalent to
nextSharing() .currentPreciseIntegral()
 thisInstance.currentPreciseIntegral() , but probably works little faster. 
abstract double 
currentSum()
Returns the sum of all elements of the source array A, less than
currentIValue() 
static double 
integralBetweenRanks(int[] histogram,
double fromRank,
double toRank)
Precise equivalent of
integralBetweenRanks(long[], double, double) for a case
of int[] type of the histogram. 
static double 
integralBetweenRanks(long[] histogram,
double fromRank,
double toRank)
Returns the difference S(toRank)−S(fromRank),
where

static double 
integralBetweenValues(int[] histogram,
double minValue,
double maxValue,
SummingHistogram.CountOfValues countOfValues)
Precise equivalent of
integralBetweenValues(long[], double, double, CountOfValues) for a case
of int[] type of the histogram. 
static double 
integralBetweenValues(long[] histogram,
double minValue,
double maxValue,
SummingHistogram.CountOfValues countOfValues)
Returns the difference s(maxValue)−s(minValue),
where

abstract SummingHistogram 
moveToIRank(long rank)
Sets the current simple rank r^{S} and
precise rank r^{P}
to be equal of the rank argument.

abstract SummingHistogram 
moveToIValue(int value)
Sets the current value v
to be equal of the value argument.

SummingHistogram 
moveToPreciseRank(double rank)
Sets the current precise rank r^{P}
to be equal of the rank argument.

SummingHistogram 
moveToValue(double value)
Sets the current value v
to be equal of the value argument.

static SummingHistogram 
newSummingIntHistogram(int[] histogram,
boolean optimizeSimpleIntegral,
int... bitLevelsOfPyramid)
Creates new histogram, consisting of M=histogram.length bars, equal to elements
of the given array.

static SummingHistogram 
newSummingIntHistogram(int[] histogram,
int... bitLevelsOfPyramid)
Equivalent to
newSummingIntHistogram(histogram, false, bitLevelsOfPyramid) . 
static SummingHistogram 
newSummingIntHistogram(int histogramLength,
boolean optimizeSimpleIntegral,
int... bitLevelsOfPyramid)
Creates new histogram, consisting of M=histogramLength empty bars.

static SummingHistogram 
newSummingIntHistogram(int histogramLength,
int... bitLevelsOfPyramid)

static SummingHistogram 
newSummingLongHistogram(int histogramLength,
boolean optimizeSimpleIntegral,
int... bitLevelsOfPyramid)
Creates new histogram, consisting of M=histogramLength empty bars.

static SummingHistogram 
newSummingLongHistogram(int histogramLength,
int... bitLevelsOfPyramid)

static SummingHistogram 
newSummingLongHistogram(long[] histogram,
boolean optimizeSimpleIntegral,
int... bitLevelsOfPyramid)
Creates new histogram, consisting of M=histogram.length bars, equal to elements
of the given array.

static SummingHistogram 
newSummingLongHistogram(long[] histogram,
int... bitLevelsOfPyramid)

abstract SummingHistogram 
nextSharing()
Returns the next instance of this class, sharing the histogram array b[k] with this instance.

static double 
preciseIntegralBetweenRanks(int[] histogram,
double fromRank,
double toRank)
Precise equivalent of
preciseIntegralBetweenRanks(long[], double, double) for a case
of int[] type of the histogram. 
static double 
preciseIntegralBetweenRanks(long[] histogram,
double fromRank,
double toRank)
Returns the difference S(toRank)−S(fromRank),
where

static double 
preciseIntegralBetweenValues(int[] histogram,
double minValue,
double maxValue,
SummingHistogram.CountOfValues countOfValues)
Precise equivalent of
preciseIntegralBetweenValues(long[], double, double, CountOfValues) for a case
of int[] type of the histogram. 
static double 
preciseIntegralBetweenValues(long[] histogram,
double minValue,
double maxValue,
SummingHistogram.CountOfValues countOfValues)
Returns the difference s(maxValue)−s(minValue),
where

abstract SummingHistogram 
share()
Creates new instance of this class, which uses the same arrays of bars b[k].

bar, bars, clear, currentIRank, currentIValue, currentPreciseRank, currentRank, currentValue, exclude, exclude, include, include, iPreciseValue, iPreciseValue, iValue, iValue, leftFromNonZeroPart, leftFromOrAtBoundOfNonZeroPart, length, moveToRank, newIntHistogram, newIntHistogram, newLongHistogram, newLongHistogram, outsideNonZeroPart, percentile, percentile, preciseValue, preciseValue, rightFromNonZeroPart, rightFromOrAtBoundOfNonZeroPart, shareCount, sumOf, sumOf, total, value, value
public static SummingHistogram newSummingLongHistogram(int histogramLength, int... bitLevelsOfPyramid)
histogramLength
 the number M of bars of the new histogram.bitLevelsOfPyramid
 the bit levels: binary logarithms of widths of bars in the subhistograms
in the "histogram pyramid"; can be empty, then will be ignored
(the histogram pyramid will not be used).java.lang.NullPointerException
 if bitLevelsOfPyramid argument is null.java.lang.IllegalArgumentException
 if histogramLength<0,
or if bitLevelsOfPyramid.length>30,
or if some of elements bitLevelsOfPyramid is not in 1..31 range,
or if public static SummingHistogram newSummingLongHistogram(int histogramLength, boolean optimizeSimpleIntegral, int... bitLevelsOfPyramid)
Histogram.newLongHistogram(int, int...)
method; the only difference
is that this method creates an instance of SummingHistogram
class.
The optimizeSimpleIntegral argument allows to provide maximal performance
if you are going to use the created instance for calculating only the simple current
integral S^{S} and do not need to calculate the precise integral S^{P}
(see the comments to this class
). Namely, if this argument is false,
this class provides good performance for calculating both integrals:
all methods of this class usually require include
, exclude
and all moveTo... methods will work rather more quickly, because they will not recalculate
some internal invariants necessary for calculating the current precise integral S^{P}.
But, as a result, the methods currentPreciseIntegral()
and currentPreciseIntegralBetweenSharing()
, calculating S^{P},
and also currentNumberOfDifferentValues()
method
will work more slowly. Namely, they can require Histogram.newLongHistogram(int, int...)
method).
histogramLength
 the number M of bars of the new histogram.optimizeSimpleIntegral
 whether the created instance should be optimized for calculating
the current simple integral S^{S}.bitLevelsOfPyramid
 the bit levels: binary logarithms of widths of bars in the subhistograms
in the "histogram pyramid"; can be empty, then will be ignored
(the histogram pyramid will not be used).java.lang.NullPointerException
 if bitLevelsOfPyramid argument is null.java.lang.IllegalArgumentException
 if histogramLength<0,
or if bitLevelsOfPyramid.length>30,
or if some of elements bitLevelsOfPyramid is not in 1..31 range,
or if public static SummingHistogram newSummingLongHistogram(long[] histogram, int... bitLevelsOfPyramid)
histogram
 initial values of the bars b[k] of the histogram.bitLevelsOfPyramid
 the bit levels: binary logarithms of widths of bars in the subhistograms
in the "histogram pyramid"; can be empty, then will be ignored
(the histogram pyramid will not be used).java.lang.NullPointerException
 if histogram or bitLevelsOfPyramid argument is null.java.lang.IllegalArgumentException
 if some of histogram elements are negative (<0),
or if sum of all bars (elements of histogram array) is greater
than Long.MAX_VALUE,
or if bitLevelsOfPyramid.length>30,
or if some of elements bitLevelsOfPyramid is not in 1..31 range,
or if public static SummingHistogram newSummingLongHistogram(long[] histogram, boolean optimizeSimpleIntegral, int... bitLevelsOfPyramid)
Histogram.newLongHistogram(long[], int...)
method; the only difference
is that this method creates an instance of SummingHistogram
class.
The optimizeSimpleIntegral argument allows to provide maximal performance
if you are going to use the created instance for calculating only the simple current
integral S^{S} and do not need to calculate the precise integral S^{P}
(see the comments to this class
). Namely, if this argument is false,
this class provides good performance for calculating both integrals:
all methods of this class usually require include
, exclude
and all moveTo... methods will work rather more quickly, because they will not recalculate
some internal invariants necessary for calculating the current precise integral S^{P}.
But, as a result, the methods currentPreciseIntegral()
and currentPreciseIntegralBetweenSharing()
, calculating S^{P},
and also currentNumberOfDifferentValues()
method
will work more slowly. Namely, they can require Histogram.newLongHistogram(long[], int...)
method).
histogram
 initial values of the bars b[k] of the histogram.optimizeSimpleIntegral
 whether the created instance should be optimized for calculating
the current simple integral S^{S}.bitLevelsOfPyramid
 the bit levels: binary logarithms of widths of bars in the subhistograms
in the "histogram pyramid"; can be empty, then will be ignored
(the histogram pyramid will not be used).java.lang.NullPointerException
 if histogram or bitLevelsOfPyramid argument is null.java.lang.IllegalArgumentException
 if some of histogram elements are negative (<0),
or if sum of all bars (elements of histogram array) is greater
than Long.MAX_VALUE,
or if bitLevelsOfPyramid.length>30,
or if some of elements bitLevelsOfPyramid is not in 1..31 range,
or if public static SummingHistogram newSummingIntHistogram(int histogramLength, int... bitLevelsOfPyramid)
histogramLength
 the number M of bars of the new histogram.bitLevelsOfPyramid
 the bit levels: binary logarithms of widths of bars in the subhistograms
in the "histogram pyramid"; can be empty, then will be ignored
(the histogram pyramid will not be used).java.lang.NullPointerException
 if bitLevelsOfPyramid argument is null.java.lang.IllegalArgumentException
 if histogramLength<0,
or if bitLevelsOfPyramid.length>30,
or if some of elements bitLevelsOfPyramid is not in 1..31 range,
or if public static SummingHistogram newSummingIntHistogram(int histogramLength, boolean optimizeSimpleIntegral, int... bitLevelsOfPyramid)
Histogram.newIntHistogram(int, int...)
method; the only difference
is that this method creates an instance of SummingHistogram
class.
The optimizeSimpleIntegral argument allows to provide maximal performance
if you are going to use the created instance for calculating only the simple current
integral S^{S} and do not need to calculate the precise integral S^{P}
(see the comments to this class
). Namely, if this argument is false,
this class provides good performance for calculating both integrals:
all methods of this class usually require include
, exclude
and all moveTo... methods will work rather more quickly, because they will not recalculate
some internal invariants necessary for calculating the current precise integral S^{P}.
But, as a result, the methods currentPreciseIntegral()
and currentPreciseIntegralBetweenSharing()
, calculating S^{P},
and also currentNumberOfDifferentValues()
method
will work more slowly. Namely, they can require Histogram.newIntHistogram(int, int...)
method).
histogramLength
 the number M of bars of the new histogram.optimizeSimpleIntegral
 whether the created instance should be optimized for calculating
the current simple integral S^{S}.bitLevelsOfPyramid
 the bit levels: binary logarithms of widths of bars in the subhistograms
in the "histogram pyramid"; can be empty, then will be ignored
(the histogram pyramid will not be used).java.lang.NullPointerException
 if bitLevelsOfPyramid argument is null.java.lang.IllegalArgumentException
 if histogramLength<0,
or if bitLevelsOfPyramid.length>30,
or if some of elements bitLevelsOfPyramid is not in 1..31 range,
or if public static SummingHistogram newSummingIntHistogram(int[] histogram, int... bitLevelsOfPyramid)
newSummingIntHistogram(histogram, false, bitLevelsOfPyramid)
.histogram
 initial values of the bars b[k] of the histogram.bitLevelsOfPyramid
 the bit levels: binary logarithms of widths of bars in the subhistograms
in the "histogram pyramid"; can be empty, then will be ignored
(the histogram pyramid will not be used).java.lang.NullPointerException
 if histogram or bitLevelsOfPyramid argument is null.java.lang.IllegalArgumentException
 if some of histogram elements are negative (<0),
or if sum of all bars (elements of histogram array) is greater
than Integer.MAX_VALUE,
or if bitLevelsOfPyramid.length>30,
or if some of elements bitLevelsOfPyramid is not in 1..31 range,
or if public static SummingHistogram newSummingIntHistogram(int[] histogram, boolean optimizeSimpleIntegral, int... bitLevelsOfPyramid)
Histogram.newIntHistogram(int[], int...)
method; the only difference
is that this method creates an instance of SummingHistogram
class.
The optimizeSimpleIntegral argument allows to provide maximal performance
if you are going to use the created instance for calculating only the simple current
integral S^{S} and do not need to calculate the precise integral S^{P}
(see the comments to this class
). Namely, if this argument is false,
this class provides good performance for calculating both integrals:
all methods of this class usually require include
, exclude
and all moveTo... methods will work rather more quickly, because they will not recalculate
some internal invariants necessary for calculating the current precise integral S^{P}.
But, as a result, the methods currentPreciseIntegral()
and currentPreciseIntegralBetweenSharing()
, calculating S^{P},
and also currentNumberOfDifferentValues()
method
will work more slowly. Namely, they can require Histogram.newIntHistogram(int[], int...)
method).
histogram
 initial values of the bars b[k] of the histogram.optimizeSimpleIntegral
 whether the created instance should be optimized for calculating
the current simple integral S^{S}.bitLevelsOfPyramid
 the bit levels: binary logarithms of widths of bars in the subhistograms
in the "histogram pyramid"; can be empty, then will be ignored
(the histogram pyramid will not be used).java.lang.NullPointerException
 if histogram or bitLevelsOfPyramid argument is null.java.lang.IllegalArgumentException
 if some of histogram elements are negative (<0),
or if sum of all bars (elements of histogram array) is greater
than Integer.MAX_VALUE,
or if bitLevelsOfPyramid.length>30,
or if some of elements bitLevelsOfPyramid is not in 1..31 range,
or if public abstract SummingHistogram nextSharing()
Histogram
All instances, created by Histogram.share()
method, are connected into a circular list, and this method
returns the next element in this list. For example, if the instance h1 was created by
Histogram.newLongHistogram(int, int...)
method and, after this, the instance h2 was created as
Histogram.share()
You can get all instances, sharing the same array b[k] with the given histogram hist, by the following loop:
Histogram h = hist.nextSharing(); do { // some processing h instance h = h.nextSharing(); } while (h != hist);
See comments to Histogram class
for more details.
nextSharing
in class Histogram
Histogram.share()
method.Histogram.shareCount()
public abstract SummingHistogram share()
Histogram
include
/ exclude
methods
will be immediately reflected in all shared instances. However, the created sharing instance
has an independent set of current value
, current simple rank
and current precise rank
, and they are initially set to 0.
The returned instance has the absolutely same behaviour as this one: it uses the same set of
bit levels (see comments to Histogram.newLongHistogram(int, int...)
method),
it is 32bit
if and only if this instance is 32bit,
it is a SummingHistogram
if and only if this instance is a SummingHistogram
, etc.
See comments to Histogram class
for more details.
share
in class Histogram
Histogram.nextSharing()
,
Histogram.shareCount()
public abstract int currentNumberOfDifferentValues()
currentIValue()
currentIValue()
.
This method works quickly (it just returns an internal variable, supported by all methods of this class)
only if this class was not created by
newSummingLongHistogram(int, boolean, int...)
,
newSummingLongHistogram(long[], boolean, int...)
,
newSummingIntHistogram(int, boolean, int...)
,
newSummingIntHistogram(int[], boolean, int...)
methods
with the argument optimizeSimpleIntegral=true.
In this case, the internal value, returned by this method, is also used for calculating
the current precise integral S^{P}.
If this class was created with the flag optimizeSimpleIntegral=true,
this method just performs a simple loop on all currentIValue()
−1
currentIValue()
currentPreciseIntegral()
public abstract double currentSum()
currentIValue()
comments to this class
for more details.
Note: if the current value is integer, for example, after
moveToIValue
(v_{0})currentIntegral()
currentRank()
:
S^{S} = s(v_{0}) = Σ _{0≤j<v0}(j+0.5)*b[j] = z(v_{0}) + 0.5 * Σ _{0≤j<v0}b[j] = z(v_{0}) + r(v_{0})/2
currentIValue()
.currentSum()
,
currentIntegral()
,
currentPreciseIntegral()
public final double currentIntegral()
comments to this class
for more details.currentSum()
,
currentPreciseIntegral()
,
currentIntegralBetweenSharing()
public final double currentPreciseIntegral()
comments to this class
for more details.currentSum()
,
currentIntegral()
,
currentPreciseIntegralBetweenSharing()
public final double currentIntegralBetweenSharing()
nextSharing()
.currentIntegral()
 thisInstance.currentIntegral()
, but probably works little faster.public final double currentPreciseIntegralBetweenSharing()
nextSharing()
.currentPreciseIntegral()
 thisInstance.currentPreciseIntegral()
, but probably works little faster.public abstract SummingHistogram moveToIRank(long rank)
Histogram
Histogram.total()
current value
v automatically changes
in accordance to the new rank.
See comments to Histogram class
for more details.
In the special case N=0 (all bars of the histograms are zero),
both simple and precise ranks are always zero, not depending on calls of this method:
This method works little faster than equivalent calls
moveToRank(rank)
and
moveToPreciseRank(rank)
.
moveToIRank
in class Histogram
rank
 new rank r^{S}=r^{P}.Histogram.moveToRank(double)
,
Histogram.moveToPreciseRank(double)
public abstract SummingHistogram moveToIValue(int value)
Histogram
Histogram.length()
current simple rank
r^{S}
and the current precise rank
r^{P}
automatically change in accordance to the new value.
See comments to Histogram class
for more details.
This methods works little faster than the equivalent call
moveToValue(value)
.
moveToIValue
in class Histogram
value
 new current value (percentile).Histogram.moveToValue(double)
public SummingHistogram moveToPreciseRank(double rank)
Histogram
Histogram.total()
current simple rank
r^{S}
and the current value
v automatically change
in accordance to the new precise rank.
See comments to Histogram class
for more details.
In the special case N=0 (all bars of the histograms are zero),
both simple and precise ranks are always zero, not depending on calls of this method:
moveToPreciseRank
in class Histogram
rank
 new precise rank r^{P}.Histogram.moveToRank(double)
,
Histogram.moveToIRank(long)
public SummingHistogram moveToValue(double value)
Histogram
Histogram.length()
current simple rank
r^{S}
and the current precise rank
r^{P}
automatically change in accordance to the new value.
See comments to Histogram class
for more details.moveToValue
in class Histogram
value
 new current value (percentile).Histogram.moveToIValue(int)
public static double integralBetweenRanks(long[] histogram, double fromRank, double toRank)
Returns the difference S(toRank)−S(fromRank),
where comments to this class
for more details.
If fromRank<=toRank, the result of this method is equal to the result of the following operators:
SummingHistogram
hist =SummingHistogram
.newSummingLongHistogram
(histogram); double fromIntegral = hist.moveToRank
(fromRank).currentIntegral()
; double toIntegral = hist.moveToRank
(toRank).currentIntegral()
; double result = toIntegral  fromIntegral;
but this method works little faster.
histogram
 histogram[k]=b[k] is the number of elements in the source array
that are equal to k.
All histogram[k] must be nonnegative; in other case,
IllegalArgumentException can be thrown (but also can be not thrown).fromRank
 the start rank.toRank
 the end rank.java.lang.NullPointerException
 if histogram argument is null.java.lang.IllegalArgumentException
 if Double.isNaN(fromRank) or Double.isNaN(toRank).public static double integralBetweenRanks(int[] histogram, double fromRank, double toRank)
integralBetweenRanks(long[], double, double)
for a case
of int[] type of the histogram.histogram
 histogram[k]=b[k] is the number of elements in the source array
that are equal to k.
All histogram[k] must be nonnegative; in other case,
IllegalArgumentException can be thrown (but also can be not thrown).fromRank
 the start rank.toRank
 the end rank.java.lang.NullPointerException
 if histogram argument is null.java.lang.IllegalArgumentException
 if Double.isNaN(fromRank) or Double.isNaN(toRank).public static double preciseIntegralBetweenRanks(long[] histogram, double fromRank, double toRank)
Returns the difference S(toRank)−S(fromRank),
where comments to this class
for more details.
If fromRank<=toRank, the result of this method is equal to the result of the following operators:
SummingHistogram
hist =SummingHistogram
.newSummingLongHistogram
(histogram); double fromIntegral = hist.moveToPreciseRank
(fromRank).currentPreciseIntegral()
; double toIntegral = hist.moveToPreciseRank
(toRank).currentPreciseIntegral()
; double result = toIntegral  fromIntegral;
but this method works little faster.
histogram
 histogram[k]=b[k] is the number of elements in the source array
that are equal to k.
All histogram[k] must be nonnegative; in other case,
IllegalArgumentException can be thrown (but also can be not thrown).fromRank
 the start rank.toRank
 the end rank.java.lang.NullPointerException
 if histogram argument is null.java.lang.IllegalArgumentException
 if Double.isNaN(fromRank) or Double.isNaN(toRank).public static double preciseIntegralBetweenRanks(int[] histogram, double fromRank, double toRank)
preciseIntegralBetweenRanks(long[], double, double)
for a case
of int[] type of the histogram.histogram
 histogram[k]=b[k] is the number of elements in the source array
that are equal to k.
All histogram[k] must be nonnegative; in other case,
IllegalArgumentException can be thrown (but also can be not thrown).fromRank
 the start rank.toRank
 the end rank.java.lang.NullPointerException
 if histogram argument is null.java.lang.IllegalArgumentException
 if Double.isNaN(fromRank) or Double.isNaN(toRank).public static double integralBetweenValues(long[] histogram, double minValue, double maxValue, SummingHistogram.CountOfValues countOfValues)
Returns the difference s(maxValue)−s(minValue),
where comments to this class
for more details.
If minValue<=maxValue, the result of this method is equal to the result of the following operators:
SummingHistogram
hist =SummingHistogram
.newSummingLongHistogram
(histogram); hist.moveToValue
(minValue); double fromRank = hist.currentRank()
; double fromIntegral = hist.currentIntegral()
; hist.moveToValue
(maxValue); double toRank = hist.currentRank()
; double toIntegral = hist.currentIntegral()
; double result = toIntegral  fromIntegral;
but this method works little faster.
The countOfValue argument, if it is not null, is filled by this method by some additional information. Namely:
count()
will be equal to the difference
comments to Histogram class
);
in the code example, listed above, it will be equal to
isLeftBound()
will be true if minValue<maxValue and
leftFromNonZeroPart()
method after
hist.moveToValue
(maxValue) call;isRightBound()
will be true if minValue<maxValue and
rightFromNonZeroPart()
method after
hist.moveToValue
(minValue) call.Note: in the special case N=0 (all bars b[k] are zero),
the countOfValue.isLeftBound()
and
countOfValue.isRightBound()
values can be any: they are not specified.
It is the only exception from the rules specified above.
This information, for example, allows to calculate the mean of all elements
of the source array A[k], lying in range minValue..maxValue,
with generalization to the floatingpoint case: it is
count()
histogram
 histogram[k]=b[k] is the number of elements
in the source array that are equal to k.
All histogram[k] must be nonnegative; in other case,
IllegalArgumentException can be thrown (but also can be not thrown).minValue
 the minimal value.maxValue
 the maximal value.countOfValues
 some additional information filled by this method;
may be null, then will be ignored.java.lang.NullPointerException
 if histogram argument is null.java.lang.IllegalArgumentException
 if Double.isNaN(minValue) or Double.isNaN(maxValue).public static double integralBetweenValues(int[] histogram, double minValue, double maxValue, SummingHistogram.CountOfValues countOfValues)
integralBetweenValues(long[], double, double, CountOfValues)
for a case
of int[] type of the histogram.histogram
 histogram[k]=b[k] is the number of elements
in the source array that are equal to k.
All histogram[k] must be nonnegative; in other case,
IllegalArgumentException can be thrown (but also can be not thrown).minValue
 the minimal value.maxValue
 the maximal value.countOfValues
 some additional information filled by this method;
may be null, then will be ignored.java.lang.NullPointerException
 if histogram argument is null.java.lang.IllegalArgumentException
 if Double.isNaN(minValue) or Double.isNaN(maxValue).public static double preciseIntegralBetweenValues(long[] histogram, double minValue, double maxValue, SummingHistogram.CountOfValues countOfValues)
Returns the difference s(maxValue)−s(minValue),
where comments to this class
for more details.
If minValue<=maxValue, the result of this method is equal to the result of the following operators:
SummingHistogram
hist =SummingHistogram
.newSummingLongHistogram
(histogram); hist.moveToValue
(minValue); double fromRank = hist.currentPreciseRank()
; double fromIntegral = hist.currentPreciseIntegral()
; hist.moveToValue
(maxValue); double toRank = hist.currentPreciseRank()
; double toIntegral = hist.currentPreciseIntegral()
; double result = toIntegral  fromIntegral;
but this method works little faster.
The countOfValue argument, if it is not null, is filled by this method by some additional information. Namely:
count()
will be equal to the difference
comments to Histogram class
);
in the code example, listed above, it will be equal to
isLeftBound()
will be true if minValue<maxValue and
leftFromNonZeroPart()
method after
hist.moveToValue
(maxValue) call;isRightBound()
will be true if minValue<maxValue and
rightFromNonZeroPart()
method after
hist.moveToValue
(minValue) call.Note: in the special case N=0 (all bars b[k] are zero),
the countOfValue.isLeftBound()
and
countOfValue.isRightBound()
values can be any: they are not specified.
It is the only exception from the rules specified above.
This information, for example, allows to calculate the mean of all elements
of the source array A[k], lying in range minValue..maxValue,
with generalization to the floatingpoint case: it is
count()
histogram
 histogram[k]=b[k] is the number of elements
in the source array that are equal to k.
All histogram[k] must be nonnegative; in other case,
IllegalArgumentException can be thrown (but also can be not thrown).minValue
 the minimal value.maxValue
 the maximal value.countOfValues
 some additional information filled by this method;
may be null, then will be ignored.java.lang.NullPointerException
 if histogram argument is null.java.lang.IllegalArgumentException
 if Double.isNaN(minValue) or Double.isNaN(maxValue).public static double preciseIntegralBetweenValues(int[] histogram, double minValue, double maxValue, SummingHistogram.CountOfValues countOfValues)
preciseIntegralBetweenValues(long[], double, double, CountOfValues)
for a case
of int[] type of the histogram.histogram
 histogram[k]=b[k] is the number of elements
in the source array that are equal to k.
All histogram[k] must be nonnegative; in other case,
IllegalArgumentException can be thrown (but also can be not thrown).minValue
 the minimal value.maxValue
 the maximal value.countOfValues
 some additional information filled by this method;
may be null, then will be ignored.java.lang.NullPointerException
 if histogram argument is null.java.lang.IllegalArgumentException
 if Double.isNaN(minValue) or Double.isNaN(maxValue).