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 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
-
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.
-
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
-
-