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

commonMain.internal.MapImplementation.kt Maven / Gradle / Ivy

There is a newer version: 0.3.8
Show newest version
/*
 * Copyright 2016-2021 JetBrains s.r.o.
 * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
 */

package kotlinx.collections.immutable.internal

/**
 * This should not be needed after KT-30016 and KT-45673 are fixed
 */
internal object MapImplementation {
    internal fun  containsEntry(map: Map, element: Map.Entry): Boolean {
        @Suppress("USELESS_CAST")
        if ((element as Any?) !is Map.Entry<*, *>) return false
        return map[element.key]?.let { candidate -> candidate == element.value }
                ?: (element.value == null && map.containsKey(element.key))
    }

    internal fun  equals(thisMap: Map, otherMap: Map<*, *>): Boolean {
        require(thisMap.size == otherMap.size)
        @Suppress("UNCHECKED_CAST")
        return (otherMap as Map).all { entry -> containsEntry(thisMap, entry) }
    }

    internal fun  hashCode(map: Map): Int = map.entries.hashCode()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy