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

darwinMain.com.adeo.kviewmodel.odyssey.ConcurrentHashMap.kt Maven / Gradle / Ivy

There is a newer version: 0.18
Show newest version
package com.adeo.kviewmodel.odyssey

import kotlinx.atomicfu.locks.SynchronizedObject
import kotlinx.atomicfu.locks.synchronized

actual class ConcurrentHashMap(
    private val delegate: HashMap = HashMap()
) : MutableMap by delegate {

    actual constructor() : this(HashMap())

    private val sync = SynchronizedObject()

    override val size: Int
        get() = synchronized(sync) { delegate.size }

    override fun get(key: K): V? = synchronized(sync) { delegate.get(key) }

    override fun put(key: K, value: V): V? = synchronized(sync) { delegate.put(key, value) }

    override fun remove(key: K): V? = synchronized(sync) { delegate.remove(key) }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy