org.apache.lucene.util

## Class FrequencyTrackingRingBuffer

- java.lang.Object
- - org.apache.lucene.util.FrequencyTrackingRingBuffer

- All Implemented Interfaces:
    Accountable

      public final class FrequencyTrackingRingBuffer
      extends Object
      implements Accountable

  A ring buffer that tracks the frequency of the integers that it contains. This is typically useful to track the hash codes of popular recently-used items. This data-structure requires 22 bytes per entry on average (between 16 and 28).
  NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FrequencyTrackingRingBuffer(int maxSize, int sentinel)` Create a new ring buffer that will contain at most `maxSize` items.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(int i)` Add a new item to this ring buffer, potentially removing the oldest entry from this buffer if it is already full.
    `int` | `frequency(int key)` Returns the frequency of the provided key in the ring buffer.
    `Collection<Accountable>` | `getChildResources()` Returns nested resources of this class.
    `long` | `ramBytesUsed()` Return the memory usage of this object in bytes.

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

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

- - ### Constructor Detail

    - #### FrequencyTrackingRingBuffer

          public FrequencyTrackingRingBuffer(int maxSize,
                                     int sentinel)

      Create a new ring buffer that will contain at most `maxSize` items. This buffer will initially contain `maxSize` times the `sentinel` value.

  - ### Method Detail

    - #### ramBytesUsed

          public long ramBytesUsed()

      Description copied from interface: `Accountable`
      Return the memory usage of this object in bytes. Negative values are illegal.
      Specified by:
        `ramBytesUsed` in interface `Accountable`

    - #### getChildResources

          public Collection<Accountable> getChildResources()

      Description copied from interface: `Accountable`
      Returns nested resources of this class. The result should be a point-in-time snapshot (to avoid race conditions).
      Specified by:
        `getChildResources` in interface `Accountable`
      See Also:
        `Accountables`

    - #### add

          public void add(int i)

      Add a new item to this ring buffer, potentially removing the oldest entry from this buffer if it is already full.

    - #### frequency

          public int frequency(int key)

      Returns the frequency of the provided key in the ring buffer.

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.