commonMain.internal.MapImplementation.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-collections-immutable Show documentation
Show all versions of kotlinx-collections-immutable Show documentation
Kotlin Immutable Collections multiplatform library
/*
* 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