commonMain.implementations.immutableMap.PersistentHashMapContentViews.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-jvm Show documentation
Show all versions of kotlinx-collections-immutable-jvm Show documentation
Kotlin Immutable Collections multiplatform library
/*
* Copyright 2016-2019 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.implementations.immutableMap
import kotlinx.collections.immutable.ImmutableCollection
import kotlinx.collections.immutable.ImmutableSet
internal class PersistentHashMapEntries(private val map: PersistentHashMap) : ImmutableSet>, AbstractSet>() {
override val size: Int get() = map.size
override fun contains(element: Map.Entry): Boolean {
// TODO: Eliminate this check after KT-30016 gets fixed.
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))
}
override fun iterator(): Iterator> {
return PersistentHashMapEntriesIterator(map.node)
}
}
internal class PersistentHashMapKeys(private val map: PersistentHashMap) : ImmutableSet, AbstractSet() {
override val size: Int
get() = map.size
override fun contains(element: K): Boolean {
return map.containsKey(element)
}
override fun iterator(): Iterator {
return PersistentHashMapKeysIterator(map.node)
}
}
internal class PersistentHashMapValues(private val map: PersistentHashMap) : ImmutableCollection, AbstractCollection() {
override val size: Int
get() = map.size
override fun contains(element: V): Boolean {
return map.containsValue(element)
}
override fun iterator(): Iterator {
return PersistentHashMapValuesIterator(map.node)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy