public class SnapshotStateMap<K, V> : StateObject, MutableMap<K, V>
An implementation of MutableMap that can be observed and snapshot. This is the result type created by androidx.compose.runtime.mutableStateMapOf.
This class closely implements the same semantics as HashMap.
Properties
firstStateRecord
override var firstStateRecord: StateRecord =
persistentHashMapOf<K, V>().let { map ->
val snapshot = currentSnapshot()
StateMapStateRecord(snapshot.snapshotId, map).also {
if (snapshot !is GlobalSnapshot) {
it.next =
StateMapStateRecord(Snapshot.PreexistingSnapshotId.toSnapshotId(), map)
}
}
}
size
override val size: Int
entries
override val entries: MutableSet<MutableMap.MutableEntry<K, V>> = SnapshotMapEntrySet(this)
keys
override val keys: MutableSet<K> = SnapshotMapKeySet(this)
values
override val values: MutableCollection<V> = SnapshotMapValueSet(this)
Functions
prependStateRecord
override fun prependStateRecord(value: StateRecord)
toMap
public fun toMap(): Map<K, V>
Returns an immutable map containing all key-value pairs from the original map.
The content of the map returned will not change even if the content of the map is changed in the same snapshot. It also will be the same instance until the content is changed. It is not, however, guaranteed to be the same instance for the same content as adding and removing the same item from the this map might produce a different instance with the same content.
This operation is O(1) and does not involve a physically copying the map. It instead returns the underlying immutable map used internally to store the content of the map.
It is recommended to use toMap when using returning the value of this map from androidx.compose.runtime.snapshotFlow.
containsKey
override fun containsKey(key: K): Boolean
containsValue
override fun containsValue(value: V): Boolean
get
override fun get(key: K): V?
isEmpty
override fun isEmpty(): Boolean
toString
override fun toString(): String
clear
override fun clear(): Unit
put
override fun put(key: K, value: V): V?
putAll
override fun putAll(from: Map<out K, V>): Unit
remove
override fun remove(key: K): V?