LfuCache

class LfuCache<K : Any, V : Any> @JvmOverloads constructor(val capacity: Int, val onDiscard: BiConsumer<K, V> = BiConsumer { _, _ -> }) : Map<K, V>

A simple least frequency used cache. Non-thread-safe.

Constructors

Link copied to clipboard
constructor(capacity: Int, onDiscard: BiConsumer<K, V> = BiConsumer { _, _ -> })

Properties

Link copied to clipboard
@get:JvmName(name = "capacity")
val capacity: Int
Link copied to clipboard
open override val entries: ObjectSet<out Map.Entry<K, V>>
Link copied to clipboard
open override val keys: ObjectSet<K>
Link copied to clipboard
Link copied to clipboard
open override val size: Int
Link copied to clipboard
open override val values: ObjectCollection<V>

Functions

Link copied to clipboard
fun clear()

Clears the cache.

Link copied to clipboard
open override fun containsKey(key: K): Boolean
Link copied to clipboard
open override fun containsValue(value: V): Boolean
Link copied to clipboard
open operator override fun get(key: K): V?

Gets the key and corresponding value (if exists), and increases its access count.

Link copied to clipboard
inline fun getOrPut(key: K, mappingFunction: (K) -> V): V
Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
fun put(key: K, value: V): V?

Sets the key and corresponding value, and discards one of the least-used keys if full.

Link copied to clipboard
inline operator fun set(key: K, value: V)