Package cern.jet.stat.quantile
Class DoubleBufferSet
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.jet.stat.quantile.BufferSet
-
- cern.jet.stat.quantile.DoubleBufferSet
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
class DoubleBufferSet extends BufferSet
A set of buffers holding double elements; internally used for computing approximate quantiles.
-
-
Field Summary
Fields Modifier and Type Field Description protected DoubleBuffer[]
buffers
private boolean
nextTriggerCalculationState
-
Fields inherited from class cern.colt.PersistentObject
serialVersionUID
-
-
Constructor Summary
Constructors Constructor Description DoubleBufferSet(int b, int k)
Constructs a buffer set with b buffers, each having k elements
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DoubleBuffer
_getFirstEmptyBuffer()
Returns an empty buffer if at least one exists.DoubleBuffer[]
_getFullOrPartialBuffers()
Returns all full or partial buffers.DoubleBuffer[]
_getFullOrPartialBuffersWithLevel(int level)
Determines all full buffers having the specified level.int
_getMinLevelOfFullOrPartialBuffers()
int
_getNumberOfEmptyBuffers()
Returns the number of empty buffers.DoubleBuffer
_getPartialBuffer()
Returns all empty buffers.int
b()
void
clear()
Removes all elements from the receiver.protected void
clear(int k)
Removes all elements from the receiver.java.lang.Object
clone()
Returns a deep copy of the receiver.DoubleBuffer
collapse(DoubleBuffer[] buffers)
Collapses the specified full buffers (must not include partial buffer).boolean
contains(double element)
Returns whether the specified element is contained in the receiver.boolean
forEach(DoubleProcedure procedure)
Applies a procedure to each element of the receiver, if any.protected double[]
getValuesAtPositions(DoubleBuffer[] buffers, long[] triggerPositions)
Determines all values of the specified buffers positioned at the specified triggerPositions within the sorted sequence and fills them into outputValues.int
k()
long
memory()
Returns the number of elements currently needed to store all contained elements.protected long
nextTriggerPosition(int j, long W)
Computes the next triggerPosition for collapsedouble
phi(double element)
Returns how many percent of the elements contained in the receiver are <= element.java.lang.String
toString()
long
totalSize()
Returns the number of elements in all buffers.
-
-
-
Field Detail
-
buffers
protected DoubleBuffer[] buffers
-
nextTriggerCalculationState
private boolean nextTriggerCalculationState
-
-
Method Detail
-
_getFirstEmptyBuffer
public DoubleBuffer _getFirstEmptyBuffer()
Returns an empty buffer if at least one exists. Preferably returns a buffer which has already been used, i.e. a buffer which has already been allocated.
-
_getFullOrPartialBuffers
public DoubleBuffer[] _getFullOrPartialBuffers()
Returns all full or partial buffers.
-
_getFullOrPartialBuffersWithLevel
public DoubleBuffer[] _getFullOrPartialBuffersWithLevel(int level)
Determines all full buffers having the specified level.- Returns:
- all full buffers having the specified level
-
_getMinLevelOfFullOrPartialBuffers
public int _getMinLevelOfFullOrPartialBuffers()
- Returns:
- The minimum level of all buffers which are full.
-
_getNumberOfEmptyBuffers
public int _getNumberOfEmptyBuffers()
Returns the number of empty buffers.
-
_getPartialBuffer
public DoubleBuffer _getPartialBuffer()
Returns all empty buffers.
-
b
public int b()
- Returns:
- the number of buffers
-
clear
public void clear()
Removes all elements from the receiver. The receiver will be empty after this call returns, and its memory requirements will be close to zero.
-
clear
protected void clear(int k)
Removes all elements from the receiver. The receiver will be empty after this call returns, and its memory requirements will be close to zero.
-
clone
public java.lang.Object clone()
Returns a deep copy of the receiver.- Overrides:
clone
in classPersistentObject
- Returns:
- a deep copy of the receiver.
-
collapse
public DoubleBuffer collapse(DoubleBuffer[] buffers)
Collapses the specified full buffers (must not include partial buffer).- Parameters:
buffers
- the buffers to be collapsed (all of them must be full or partially full)- Returns:
- a full buffer containing the collapsed values. The buffer has accumulated weight.
-
contains
public boolean contains(double element)
Returns whether the specified element is contained in the receiver.
-
forEach
public boolean forEach(DoubleProcedure procedure)
Applies a procedure to each element of the receiver, if any. Iterates over the receiver in no particular order.- Parameters:
procedure
- the procedure to be applied. Stops iteration if the procedure returns false, otherwise continues.
-
getValuesAtPositions
protected double[] getValuesAtPositions(DoubleBuffer[] buffers, long[] triggerPositions)
Determines all values of the specified buffers positioned at the specified triggerPositions within the sorted sequence and fills them into outputValues.- Parameters:
buffers
- the buffers to be searched (all must be full or partial)triggerPositions
- the positions of elements within the sorted sequence to be retrieved- Returns:
- outputValues a list filled with the values at triggerPositions
-
k
public int k()
- Returns:
- the number of elements within a buffer.
-
memory
public long memory()
Returns the number of elements currently needed to store all contained elements.
-
nextTriggerPosition
protected long nextTriggerPosition(int j, long W)
Computes the next triggerPosition for collapse- Parameters:
j
- specifies that the j-th trigger position is to be computedW
- the accumulated weights- Returns:
- the next triggerPosition for collapse
-
phi
public double phi(double element)
Returns how many percent of the elements contained in the receiver are <= element. Does linear interpolation if the element is not contained but lies in between two contained elements.- Parameters:
the
- element to search for.- Returns:
- the percentage p of elements <= element (0.0 <= p <=1.0).
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation of the receiver
-
totalSize
public long totalSize()
Returns the number of elements in all buffers.
-
-