Package dev.nm.misc.algorithm
Class Bins<T>
- java.lang.Object
-
- dev.nm.misc.algorithm.Bins<T>
-
- Type Parameters:
T
- object type
public class Bins<T> extends Object
This class divides the items based on their keys into a number of bins. Information can be extracted from each bin.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(double key, T item)
Add a valued item to the bin.double[]
getBinKeyValues(RealScalarFunction f)
Applies a function to the key of each bin.double[]
getBinObjectValues(Function<List<T>,Double> f)
Applies a function to the items of each bin.List<TreeMap<Double,T>>
getBins()
Divides the items inton
bins.int
maxBinSize()
Gets the maximal size of the bins.
-
-
-
Method Detail
-
add
public void add(double key, T item)
Add a valued item to the bin.- Parameters:
key
- the valueitem
- the item
-
getBins
public List<TreeMap<Double,T>> getBins()
Divides the items inton
bins. If the total cannot be evenly divided, the last bin may be not fully filled. If the n-th bin is empty, only n - 1 bins are returned.- Returns:
- the bins
-
getBinKeyValues
public double[] getBinKeyValues(RealScalarFunction f)
Applies a function to the key of each bin.- Parameters:
f
- a function to be applied on the keys- Returns:
- the functional values of the keys
-
getBinObjectValues
public double[] getBinObjectValues(Function<List<T>,Double> f)
Applies a function to the items of each bin.- Parameters:
f
- a function to be applied on the items- Returns:
- the functional values of the items
-
maxBinSize
public int maxBinSize()
Gets the maximal size of the bins.- Returns:
- the maximal size of the bins
-
-