Package org.apache.lucene.util
Class FrequencyTrackingRingBuffer
- java.lang.Object
-
- org.apache.lucene.util.FrequencyTrackingRingBuffer
-
- All Implemented Interfaces:
Accountable
public final class FrequencyTrackingRingBuffer extends java.lang.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).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classFrequencyTrackingRingBuffer.IntBagA bag of integers.
-
Field Summary
Fields Modifier and Type Field Description private static longBASE_RAM_BYTES_USEDprivate int[]bufferprivate FrequencyTrackingRingBuffer.IntBagfrequenciesprivate intmaxSizeprivate intposition-
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE
-
-
Constructor Summary
Constructors Constructor Description FrequencyTrackingRingBuffer(int maxSize, int sentinel)Create a new ring buffer that will contain at mostmaxSizeitems.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int i)Add a new item to this ring buffer, potentially removing the oldest entry from this buffer if it is already full.(package private) java.util.Map<java.lang.Integer,java.lang.Integer>asFrequencyMap()intfrequency(int key)Returns the frequency of the provided key in the ring buffer.longramBytesUsed()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
-
Methods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
-
-
-
Field Detail
-
BASE_RAM_BYTES_USED
private static final long BASE_RAM_BYTES_USED
-
maxSize
private final int maxSize
-
buffer
private final int[] buffer
-
position
private int position
-
frequencies
private final FrequencyTrackingRingBuffer.IntBag frequencies
-
-
Method Detail
-
ramBytesUsed
public long ramBytesUsed()
Description copied from interface:AccountableReturn the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsedin interfaceAccountable
-
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.
-
asFrequencyMap
java.util.Map<java.lang.Integer,java.lang.Integer> asFrequencyMap()
-
-