Class AdaptiveBinList

java.lang.Object
uk.ac.starlink.ttools.plot2.layer.AdaptiveBinList
All Implemented Interfaces:
BinList

public class AdaptiveBinList extends Object implements BinList
BinList implementation that starts off using a hash-based implementation, but switches to an array-based implementation if the hash gets full enough to make it worth while.
Since:
15 Jan 2019
Author:
Mark Taylor
  • Constructor Details

    • AdaptiveBinList

      public AdaptiveBinList(int size, Combiner combiner, int factThresh)
      Constructor. The factThresh tuning parameter should be set to a value close to the ratio of HashBinList bin size to ArrayBinList bin size (in terms of storage). Object overhead is typically 2 words (16 bytes), so if the array has one double per bin and the hash has one (Long,Combiner.Container) pair per bin, the ratio will be at least 6.
      Parameters:
      size - maximum number of bins
      combiner - combiner
      factThresh - thershold factor - once size/factThresh bins are occupied, an array will be used instead
  • Method Details

    • getCombiner

      public Combiner getCombiner()
      Description copied from interface: BinList
      Returns the combination method used for bins.
      Specified by:
      getCombiner in interface BinList
      Returns:
      combiner
    • getSize

      public long getSize()
      Description copied from interface: BinList
      Returns the maximum number of bins. All bins have an index in the range 0..size-1.
      Specified by:
      getSize in interface BinList
      Returns:
      bin count
    • submitToBin

      public void submitToBin(long index, double datum)
      Description copied from interface: BinList
      Adds a given numeric value to the bin at the given index. In general, NaN values should not be submitted.
      Specified by:
      submitToBin in interface BinList
      Parameters:
      index - bin index
      datum - finite value to submit to the bin
    • getBinContainer

      public Combiner.Container getBinContainer(long index)
      Description copied from interface: BinList
      Returns a container representing the current contents of a given bin. This is only intended for reading; the effect of submitting additional data to the returned container is not defined.

      This method is here to support conversion between different BinList implementations.

      Specified by:
      getBinContainer in interface BinList
      Parameters:
      index - bin index
      Returns:
      container instance reporting the current state of the bin; may be null if the bin is not populated
    • getResult

      public BinList.Result getResult()
      Description copied from interface: BinList
      Returns an object containing the result values accumulated into the bins so far.

      It is up to implementations to decide how to implement this method. In some cases the return value may be an adapter that extracts results as required from the data structure used for value accumulation, but in others it may return a new data structure which copies the accumulated values to a more compact form up front. Therefore this may or may not be an expensive method, and the return value may or may not be affected by subsequent BinList.submitToBin(long, double) calls.

      Specified by:
      getResult in interface BinList
      Returns:
      accumulated bin values
    • getBaseBinList

      public BinList getBaseBinList()
      Returns the bin list to which this one is currently delegating its operations.
      Returns:
      base bin list
    • isHash

      public boolean isHash()
      Indicates which underlying BinList implementation is currently in use. It starts off true at object construction time, but may turn false if enough data are submitted. It will never change back again.
      Returns:
      true if underlying bin list is hash-based, false if it's array-based