# Class HashBinList

java.lang.Object
uk.ac.starlink.ttools.plot2.layer.HashBinList

All Implemented Interfaces:
  `BinList`

public class HashBinList extends Object implements BinList
BinList implementation based on a hash. Good for sparse bin lists.

Since:
  5 Oct 2015
Author:
  Mark Taylor

## Nested Class Summary

### Nested classes/interfaces inherited from interface BinList

`BinList.Result`

## Constructor Summary

Constructors
Constructor
Description
`HashBinList(long size, Combiner combiner)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`addBins(BinList other)`
Accumulates all the data from another BinList into this one.
`static BinList.Result`
`createHashResult(Map<Long,Double> map)`
Returns a new Result instance based on a Map.
`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.
`Map<Long, Combiner.Container>`
`getMap()`
Returns the hash used to store this bin list's state.
`BinList.Result`
`getResult()`
Returns an object containing the result values accumulated into the bins so far.
`long`
`getSize()`
Returns the maximum number of bins.
`void`
`submitToBin(long index, double value)`
Adds a given numeric value to the bin at the given index.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### HashBinList

public HashBinList(long size, Combiner combiner)
Constructor.

Parameters:
  `size` - number of bins
  `combiner` - combiner

## Method Details

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

### getCombiner

public Combiner getCombiner()
Description copied from interface: `BinList`
Returns the combination method used for bins.

Specified by:
  `getCombiner` in interface `BinList`
Returns:
  combiner

### submitToBin

public void submitToBin(long index, double value)
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
  `value` - 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

### addBins

public void addBins(BinList other)
Accumulates all the data from another BinList into this one. The effect is the same as if all the data submitted to `other` had been submitted to this.

The other list must be of the same type (have the same combiner) as this one.

Parameters:
  `other` - second BinList compatible with this one
Throws:
  `ClassCastException` - if `other`'s type does not match this one

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

### getMap

public Map<Long, Combiner.Container> getMap()
Returns the hash used to store this bin list's state.

Returns:
  index->container map

### createHashResult

public static BinList.Result createHashResult(Map<Long,Double> map)
Returns a new Result instance based on a Map.

Parameters:
  `map` - map of values
Returns:
  result based on `map`