public final class FrequencyTrackingRingBuffer extends java.lang.Object implements Accountable
Modifier and Type | Class and Description |
---|---|
private static class |
FrequencyTrackingRingBuffer.IntBag
A bag of integers.
|
Modifier and Type | Field and Description |
---|---|
private static long |
BASE_RAM_BYTES_USED |
private int[] |
buffer |
private FrequencyTrackingRingBuffer.IntBag |
frequencies |
private int |
maxSize |
private int |
position |
Constructor and Description |
---|
FrequencyTrackingRingBuffer(int maxSize,
int sentinel)
Create a new ring buffer that will contain at most
maxSize items. |
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.
|
(package private) java.util.Map<java.lang.Integer,java.lang.Integer> |
asFrequencyMap() |
int |
frequency(int key)
Returns the frequency of the provided key in the ring buffer.
|
long |
ramBytesUsed()
Return the memory usage of this object in bytes.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getChildResources
private static final long BASE_RAM_BYTES_USED
private final int maxSize
private final int[] buffer
private int position
private final FrequencyTrackingRingBuffer.IntBag frequencies
public FrequencyTrackingRingBuffer(int maxSize, int sentinel)
maxSize
items.
This buffer will initially contain maxSize
times the
sentinel
value.public long ramBytesUsed()
Accountable
ramBytesUsed
in interface Accountable
public void add(int i)
public int frequency(int key)
java.util.Map<java.lang.Integer,java.lang.Integer> asFrequencyMap()