Class AdaptiveBinList
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.layer.AdaptiveBinList
-
- All Implemented Interfaces:
BinList
public class AdaptiveBinList extends java.lang.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface uk.ac.starlink.ttools.plot2.layer.BinList
BinList.Result
-
-
Constructor Summary
Constructors Constructor Description AdaptiveBinList(int size, Combiner combiner, int factThresh)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BinList
getBaseBinList()
Returns the bin list to which this one is currently delegating its operations.Combiner.Container
getBinContainer(long index)
Returns a container representing the current contents of a given bin.Combiner
getCombiner()
Returns the combination method used for bins.BinList.Result
getResult()
Returns an object containing the result values accumulated into the bins so far.long
getSize()
Returns the maximum number of bins.boolean
isHash()
Indicates which underlying BinList implementation is currently in use.void
submitToBin(long index, double datum)
Adds a given numeric value to the bin at the given index.
-
-
-
Constructor Detail
-
AdaptiveBinList
public AdaptiveBinList(int size, Combiner combiner, int factThresh)
Constructor. ThefactThresh
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 binscombiner
- combinerfactThresh
- thershold factor - once size/factThresh bins are occupied, an array will be used instead
-
-
Method Detail
-
getCombiner
public Combiner getCombiner()
Description copied from interface:BinList
Returns the combination method used for bins.- Specified by:
getCombiner
in interfaceBinList
- 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.
-
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 interfaceBinList
- Parameters:
index
- bin indexdatum
- 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 interfaceBinList
- 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.
-
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
-
-