Package com.google.android.exoplayer2.util

## Class SlidingPercentile

- java.lang.Object
- - com.google.android.exoplayer2.util.SlidingPercentile

-     public class SlidingPercentile
      extends Object

  Calculate any percentile over a sliding window of weighted values. A maximum weight is configured. Once the total weight of the values reaches the maximum weight, the oldest value is reduced in weight until it reaches zero and is removed. This maintains a constant total weight, equal to the maximum allowed, at the steady state.

  This class can be used for bandwidth estimation based on a sliding window of past transfer rate observations. This is an alternative to sliding mean and exponential averaging which suffer from susceptibility to outliers and slow adaptation to step functions.

  See Also:
    Wiki: Moving average, Wiki: Selection algorithm

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `SlidingPercentile​(int maxWeight)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addSample​(int weight, float value)` | Adds a new weighted value.
    `float` | `getPercentile​(float percentile)` | Computes a percentile by integration.
    `void` | `reset()` | Resets the sliding percentile.

    - ### Methods inherited from class java.lang.Object

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

- - ### Constructor Detail

    - #### SlidingPercentile

          public SlidingPercentile​(int maxWeight)

      Parameters:
        `maxWeight` - The maximum weight.

  - ### Method Detail

    - #### reset

          public void reset()

      Resets the sliding percentile.

    - #### addSample

          public void addSample​(int weight,
                                float value)

      Adds a new weighted value.
      Parameters:
        `weight` - The weight of the new observation.
        `value` - The value of the new observation.

    - #### getPercentile

          public float getPercentile​(float percentile)

      Computes a percentile by integration.
      Parameters:
        `percentile` - The desired percentile, expressed as a fraction in the range (0,1].
      Returns:
        The requested percentile value or `Float.NaN` if no samples have been added.