# SnapshotStateMap

Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/snapshots/SnapshotStateMap.kt+class:androidx.compose.runtime.snapshots.SnapshotStateMap) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0) Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  class SnapshotStateMap<K : Any?, V : Any?> : StateObject, MutableMap<K, V>
  ```

*** ** * ** ***

An implementation of `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html` that can be observed and snapshot. This is the result type created by `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#mutableStateMapOf()`.

This class closely implements the same semantics as `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-hash-map/index.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#mutableStateMapOf()` |   |

## Summary

| ### Public constructors |
|---|---|
| `<K : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, V : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#SnapshotStateMap()()` | Cmn |

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#clear()()` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#containsKey(kotlin.Any)(key: K)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#containsValue(kotlin.Any)(value: V)` | Cmn |
| `open operator V?` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#get(kotlin.Any)(key: K)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#isEmpty()()` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#prependStateRecord(androidx.compose.runtime.snapshots.StateRecord)(value: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord)` Add a new state record to the beginning of a list. | Cmn |
| `open V?` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#put(kotlin.Any,kotlin.Any)(key: K, value: V)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#putAll(kotlin.collections.Map)(from: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<K, V>)` | Cmn |
| `open V?` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#remove(kotlin.Any)(key: K)` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<K, V>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#toMap()()` Returns an immutable map containing all key-value pairs from the original map. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/-mutable-entry/index.html<K, V>>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#entries()` | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#firstStateRecord()` The first state record in a linked list of state records. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html<K>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#keys()` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#size()` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html<V>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#values()` | Cmn |

### Inherited functions

From [androidx.compose.runtime.snapshots.StateObject](https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject) `open https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord?` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject#mergeRecords(androidx.compose.runtime.snapshots.StateRecord,androidx.compose.runtime.snapshots.StateRecord,androidx.compose.runtime.snapshots.StateRecord)(
previous: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord,
current: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord,
applied: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord
)`

Produce a merged state based on the conflicting state changes.
Cmn

## Public constructors

### SnapshotStateMap

Cmn

```
<K : Any?, V : Any?> SnapshotStateMap()
```

## Public functions

### clear

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open fun clear(): Unit
```

### containsKey

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open fun containsKey(key: K): Boolean
```

### containsValue

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open fun containsValue(value: V): Boolean
```

### get

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.10.0)

```
open operator fun get(key: K): V?
```

### isEmpty

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open fun isEmpty(): Boolean
```

### prependStateRecord

Cmn

```
open fun prependStateRecord(value: StateRecord): Unit
```

Add a new state record to the beginning of a list. After this call `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject#firstStateRecord()` should be `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject#prependStateRecord(androidx.compose.runtime.snapshots.StateRecord)`.

### put

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open fun put(key: K, value: V): V?
```

### putAll

Cmn

```
open fun putAll(from: Map<K, V>): Unit
```

### remove

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.10.0)

```
open fun remove(key: K): V?
```

### toMap

Cmn Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.4.0)

```
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 `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotStateMap#toMap()` when using returning the value of this map from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#snapshotFlow(kotlin.Function0)`.

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### entries

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open val entries: MutableSet<MutableMap.MutableEntry<K, V>>
```

### firstStateRecord

Cmn

```
open val firstStateRecord: StateRecord
```

The first state record in a linked list of state records.

### keys

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open val keys: MutableSet<K>
```

### size

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open val size: Int
```

### values

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
open val values: MutableCollection<V>
```