Class ExponentialHistogram


  • public class ExponentialHistogram
    extends Object
    An implementation of the Exponential Histogram sketch as outlined by Datar et al.

    This class is *not thread-safe*, safe consumption in a multi-threaded environment will require some form of external locking.

    See Also:
    Maintaining Stream Statistics over Sliding Windows
    • Constructor Detail

      • ExponentialHistogram

        public ExponentialHistogram​(double epsilon,
                                    long window)
        Creates an exponential histogram maintaining a count over window to within @{epsilon} fractional accuracy.
        Parameters:
        epsilon - fractional accuracy
        window - sliding window size
    • Method Detail

      • merge

        public void merge​(ExponentialHistogram b)
        Merge the supplied ExponentialHistogram in to this one.
        Parameters:
        b - histogram to merge
        Throws:
        IllegalArgumentException - if the two merge-thresholds are not equals
      • insert

        public void insert​(long time)
        Insert a single event at time
        Parameters:
        time - event timestamp
      • expire

        public long expire​(long time)
        Expire old events.
        Parameters:
        time - current timestamp
        Returns:
        the count following expiry
      • count

        public long count()
        Returns the approximate current count.
        Returns:
        the approximate count
      • split

        public ExponentialHistogram split​(double fraction)
        Split an exponential histogram off this one.

        The returned histogram will contain {code fraction} of the events in this one.

        Parameters:
        fraction - splitting fraction
        Returns:
        the new histogram
      • epsilon

        public double epsilon()
        Return the fractional accuracy of this exponential histogram
        Returns:
        fractional accuracy