All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.dev.kord.cache.map.Lru.kt Maven / Gradle / Ivy

The newest version!
package dev.kord.cache.map

/**
 * Creates a least recently used map using a [LinkedHashMap]. The map will start evicting entries once [maxSize] has been reached.
 */
fun  MapLikeCollection.Companion.lruLinkedHashMap(maxSize: Int): MapLikeCollection =
        from(LRULinkedHashMap(maxSize))

internal class LRULinkedHashMap(
        private val maxSize: Int
) : LinkedHashMap(maxSize, 1.0F), MutableMap {

    override fun removeEldestEntry(eldest: MutableMap.MutableEntry?): Boolean = size > maxSize

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy