Class 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 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 
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Binner

        public Binner​(int n)
        Constructor.
        Parameters:
        n - number of bins
    • 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