Class Binner
java.lang.Object
uk.ac.starlink.ttools.plot2.layer.Binner
Accumulates counts in an array of bins.
An earlier implementation started off with a byte[] array
and dynamically adjusted the storage as the maximum bin count increased
to a short[] and then an int[] array,
to save on memory.
The current implementation just uses an int[] array,
on the untested assumption that
the extra cleverness is more trouble than it's worth;
the array size is not going to be of unlimited size
(expected use is to map a pixel grid, so it will usually be not much
more than a million).
- Since:
- 15 Feb 2013
- Author:
- Mark Taylor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the contents of another binner to this one.intgetCount(int index) Returns the count in a given bin.intReturns the number of bins.longgetTotal()Returns the total number of increments made to this binner.voidincrement(int index) Increments the count in a given bin by 1.
-
Constructor Details
-
Binner
public Binner(int n) Constructor.- Parameters:
n- number of bins
-
-
Method Details
-
getLength
public int getLength()Returns the number of bins.- Returns:
- bin count
-
increment
public void increment(int index) Increments the count in a given bin by 1.- Parameters:
index- bin index
-
getCount
public int getCount(int index) Returns the count in a given bin.- Parameters:
index- bin index- Returns:
- current total for given bin, or Integer.MAX_VALUE in case of overflow
-
getTotal
public long getTotal()Returns the total number of increments made to this binner.- Returns:
- sum of all bins
-
add
Adds the contents of another binner to this one. The effect is as if all the increments made to the other bin were made to this one as well.- Parameters:
other- other binner, expected to be the same size as this
-