TopKSampler (apache-cassandra API)
Date: 2018-02-14

org.apache.cassandra.utils

## Class TopKSampler<T>

- java.lang.Object
- - org.apache.cassandra.utils.TopKSampler<T>

-     public class TopKSampler<T>
      extends java.lang.Object

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TopKSampler.SamplerResult<S>` Represents the cardinality and the topK ranked items collected during a sample period

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TopKSampler()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addSample(T item)`
    `void` | `addSample(T item, long hash, int value)` Adds a sample to statistics collection.
    `void` | `beginSampling(int capacity)` Start to record samples
    `TopKSampler.SamplerResult<T>` | `finishSampling(int count)` Call to stop collecting samples, and gather the results

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

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

- - ### Constructor Detail

    - #### TopKSampler

          public TopKSampler()

  - ### Method Detail

    - #### beginSampling

          public void beginSampling(int capacity)

      Start to record samples
      Parameters:
        `capacity` - Number of sample items to keep in memory, the lower this is the less accurate results are. For best results use value close to cardinality, but understand the memory trade offs.

    - #### finishSampling

          public TopKSampler.SamplerResult<T> finishSampling(int count)

      Call to stop collecting samples, and gather the results
      Parameters:
        `count` - Number of most frequent items to return

    - #### addSample

          public void addSample(T item)

    - #### addSample

          public void addSample(T item,
                                long hash,
                                int value)

      Adds a sample to statistics collection. This method is non-blocking and will use the "Sampler" thread pool to record results if the sampler is enabled. If not sampling this is a NOOP

Copyright © 2018 The Apache Software Foundation