Class Binner
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.layer.Binner
-
public class Binner extends java.lang.Object
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 ashort[]
and then anint[]
array, to save on memory. The current implementation just uses anint[]
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 Constructor Description Binner(int n)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Binner other)
Adds the contents of another binner to this one.int
getCount(int index)
Returns the count in a given bin.int
getLength()
Returns the number of bins.long
getTotal()
Returns the total number of increments made to this binner.void
increment(int index)
Increments the count in a given bin by 1.
-
-
-
Method Detail
-
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
public void add(Binner other)
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
-
-