Top Description Fields Constructors Methods
com.github.benmanes.caffeine.cache

pack-priv final Class FrequencySketch<E>

extends Object
Class Inheritance
Static Imports
com.github.benmanes.caffeine.cache.Caffeine.requireArgument

A probabilistic multiset for estimating the popularity of an element within a time window. The maximum frequency of an element is limited to 15 (4-bits) and an aging process periodically halves the popularity of all elements.
Author
[email protected] (Ben Manes)

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv static final long
pack-priv static final long
pack-priv int
pack-priv int
pack-priv long[]

Constructor Summary

AccessConstructor and Description
public
FrequencySketch()

Creates a lazily initialized frequency sketch, requiring ensureCapacity be called when the maximum size of the cache has been determined.

Method Summary

Modifier and TypeMethod and Description
public void
ensureCapacity(@NonNegative long
the maximum size of the cache
maximumSize
)

Initializes and increases the capacity of this FrequencySketch instance, if necessary, to ensure that it can accurately estimate the popularity of elements given the maximum size of the cache.

public @NonNegative int

Returns:

the estimated number of occurrences of the element; possibly zero but never negative
frequency
(E
the element to count occurrences of
e
)

Returns the estimated number of occurrences of an element, up to the maximum (15).

public void
increment(E
the element to add
e
)

Increments the popularity of the element if it does not exceed the maximum (15).

pack-priv boolean

Returns:

if incremented
incrementAt
(int
the table index (16 counters)
i
,
int
the counter to increment
j
)

Increments the specified counter by 1 if it is not already at the maximum value (15).

public boolean
isNotInitialized()

Returns if the sketch has not yet been initialized, requiring that ensureCapacity is called before it begins to track frequencies.

pack-priv static int
rehash(int x)

Applies another round of hashing for additional randomization.

pack-priv void
reset()

Reduces every counter by half of its original value.

pack-priv static int
spread(int x)

Applies a supplemental hash functions to defends against poor quality hash.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockMaskback to summary
pack-priv int blockMask
ONE_MASKback to summary
pack-priv static final long ONE_MASK
RESET_MASKback to summary
pack-priv static final long RESET_MASK
sampleSizeback to summary
pack-priv int sampleSize
sizeback to summary
pack-priv int size
tableback to summary
pack-priv long[] table

Constructor Detail

FrequencySketchback to summary
public FrequencySketch()

Creates a lazily initialized frequency sketch, requiring ensureCapacity be called when the maximum size of the cache has been determined.

Annotations
@SuppressWarnings:NullAway.Init

Method Detail

ensureCapacityback to summary
public void ensureCapacity(@NonNegative long maximumSize)

Initializes and increases the capacity of this FrequencySketch instance, if necessary, to ensure that it can accurately estimate the popularity of elements given the maximum size of the cache. This operation forgets all previous counts when resizing.

Parameters
maximumSize:@NonNegative long

the maximum size of the cache

frequencyback to summary
public @NonNegative int frequency(E e)

Returns the estimated number of occurrences of an element, up to the maximum (15).

Parameters
e:E

the element to count occurrences of

Returns:@NonNegative int

the estimated number of occurrences of the element; possibly zero but never negative

incrementback to summary
public void increment(E e)

Increments the popularity of the element if it does not exceed the maximum (15). The popularity of all elements will be periodically down sampled when the observed events exceed a threshold. This process provides a frequency aging to allow expired long term entries to fade away.

Parameters
e:E

the element to add

Annotations
@SuppressWarnings:ShortCircuitBoolean
incrementAtback to summary
pack-priv boolean incrementAt(int i, int j)

Increments the specified counter by 1 if it is not already at the maximum value (15).

Parameters
i:int

the table index (16 counters)

j:int

the counter to increment

Returns:boolean

if incremented

isNotInitializedback to summary
public boolean isNotInitialized()

Returns if the sketch has not yet been initialized, requiring that ensureCapacity is called before it begins to track frequencies.

rehashback to summary
pack-priv static int rehash(int x)

Applies another round of hashing for additional randomization.

resetback to summary
pack-priv void reset()

Reduces every counter by half of its original value.

spreadback to summary
pack-priv static int spread(int x)

Applies a supplemental hash functions to defends against poor quality hash.