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

commonMain.com.seiko.imageloader.util.LruHashMap.kt Maven / Gradle / Ivy

package com.seiko.imageloader.util

/**
 * There is no equivalent to Java `LinkedHashMap(initialCapacity, loadFactor, accessOrder)`
 * in Kotlin/Native. This class provides only necessary things, so it doesn't implement the whole
 * `MutableMap` interface.
 *
 * See [KT-52183](https://youtrack.jetbrains.com/issue/KT-52183).
 */
internal expect class LruHashMap(
    initialCapacity: Int = 16,
    loadFactor: Float = 0.75F,
) {

    constructor(original: LruHashMap)

    val isEmpty: Boolean
    val entries: Set>

    operator fun get(key: K): V?

    fun put(key: K, value: V): V?

    fun remove(key: K): V?
}

internal fun  LruHashMap.getOrPut(key: K, defaultValue: () -> V): V {
    return get(key) ?: defaultValue().also {
        put(key, it)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy