Google is committed to advancing racial equity for Black communities. See how.

SlotWriter

class SlotWriter
kotlin.Any
   ↳ androidx.compose.runtime.SlotWriter

The writer for a slot table. See SlotTable for details.

Summary

Public methods
Unit
advanceBy(amount: Int)

Advance currentGroup by amount.

Anchor
anchor(index: Int = currentGroup)

Allocate an anchor to the current group or index.

Int

Return the current anchor location while changing the slot table.

Unit

Begin inserting at the current location.

Unit

Close the writer

Int

End the current group.

Unit

Ends inserting.

Unit

If the start of a group was skipped using skip, calling ensureStarted puts the writer into the same state as if startGroup or startNode was called on the group starting at index.

Unit

Any?
groupAux(index: Int)

Return the aux of the group at index.

Int
groupKey(index: Int)

Return the key for the group at index.

Any?

Return the object key for the group at index, if it has one, or null if not.

Int
groupSize(index: Int)

Return the size of the group at index.

Iterator<Any?>

Returns an iterator for all the slots of group and all the children of the group.

String

A debugging aid that emits groups as a string.

List<Anchor>
moveFrom(table: SlotTable, index: Int)

Move (insert and then delete) the group at index from slots.

Unit
moveGroup(offset: Int)

Move the group at offset groups after currentGroup to be in front of currentGroup.

Any?
node(index: Int)

Return the node at index if index is a node group or null.

Int
parent(index: Int)

Return the index of the parent for the group at index.

Int
parent(anchor: Anchor)

Return the index of the parent for the group referenced by anchor.

Boolean

Remove the current group.

Unit
seek(anchor: Anchor)

Seek the current location to anchor.

Unit
set(value: Any?)

Set the value at the groups current data slot

Any?
set(index: Int, value: Any?)

Set the group's slot at index to value.

Any?

Skip the current slot without updating.

Int

Skip the current group.

Unit

Skip to the end of the current group.

Unit
startData(key: Int, objectKey: Any?, aux: Any?)

Start a data group.

Unit
startData(key: Int, aux: Any?)

Start a data group.

Unit

Enter the group at current without changing it.

Unit

Start a group with a integer key

Unit
startGroup(key: Int, dataKey: Any?)

Start a group with a data key

Unit
startNode(key: Any?)

Start a node.

Unit
startNode(key: Any?, node: Any?)

Start a node

String

Any?
update(value: Any?)

Set the value of the next slot.

Unit
updateAux(value: Any?)

Updates the data for the current data group.

Unit
updateNode(value: Any?)

Updates the node for the current node group.

Unit

Updates the node of the parent group.

Properties
Boolean

True if the writer has been closed

Int

The current group that will be started by startGroup or skipped by skipGroup

Boolean

True if at the end of a group and an endGroup is expected.

Boolean

Return true if the current slot starts a node.

Int

Return the index of the nearest group that contains currentGroup.

Public methods

advanceBy

fun advanceBy(amount: Int): Unit

Advance currentGroup by amount. The currentGroup group cannot be advanced outside the currently started parent.

anchor

fun anchor(index: Int = currentGroup): Anchor

Allocate an anchor to the current group or index.

anchorIndex

fun anchorIndex(anchor: Anchor): Int

Return the current anchor location while changing the slot table.

beginInsert

fun beginInsert(): Unit

Begin inserting at the current location. beginInsert() can be nested and must be called with a balanced number of endInsert()

close

fun close(): Unit

Close the writer

endGroup

fun endGroup(): Int

End the current group. Must be called after the corresponding startGroup().

endInsert

fun endInsert(): Unit

Ends inserting.

ensureStarted

fun ensureStarted(index: Int): Unit

If the start of a group was skipped using skip, calling ensureStarted puts the writer into the same state as if startGroup or startNode was called on the group starting at index. If, after starting, the group, currentGroup is not a the end of the group or currentGroup is not at the start of a group for which index is not location the parent group, an exception is thrown.

Calling ensureStarted implies that an endGroup should be called once the end of the group is reached.

ensureStarted

fun ensureStarted(anchor: Anchor): Unit

groupAux

fun groupAux(index: Int): Any?

Return the aux of the group at index.

groupKey

fun groupKey(index: Int): Int

Return the key for the group at index.

groupObjectKey

fun groupObjectKey(index: Int): Any?

Return the object key for the group at index, if it has one, or null if not.

groupSize

fun groupSize(index: Int): Int

Return the size of the group at index.

groupSlots

fun groupSlots(): Iterator<Any?>

Returns an iterator for all the slots of group and all the children of the group.

groupsAsString

fun groupsAsString(): String

A debugging aid that emits groups as a string.

moveFrom

fun moveFrom(
    table: SlotTable,
    index: Int
): List<Anchor>

Move (insert and then delete) the group at index from slots. All anchors in the range (including index) are moved to the slot table for which this is a reader.

It is required that the writer be inserting.

Return
a list of the anchors that were moved

moveGroup

fun moveGroup(offset: Int): Unit

Move the group at offset groups after currentGroup to be in front of currentGroup. After this completes, the moved group will be the current group. offset must less than the number of groups after the currentGroup left in the parent group.

node

fun node(index: Int): Any?

Return the node at index if index is a node group or null.

parent

fun parent(index: Int): Int

Return the index of the parent for the group at index.

parent

fun parent(anchor: Anchor): Int

Return the index of the parent for the group referenced by anchor. If the anchor is not valid it returns -1.

removeGroup

fun removeGroup(): Boolean

Remove the current group. Returns if any anchors were in the group removed.

seek

fun seek(anchor: Anchor): Unit

Seek the current location to anchor. The anchor must be an anchor to a possibly indirect child of parent.

set

fun set(value: Any?): Unit

Set the value at the groups current data slot

set

fun set(
    index: Int,
    value: Any?
): Any?

Set the group's slot at index to value. Returns the previous value.

skip

fun skip(): Any?

Skip the current slot without updating. If the slot table is inserting then and EMPTY slot is added and skip return EMPTY.

skipGroup

fun skipGroup(): Int

Skip the current group. Returns the number of nodes skipped by skipping the group.

skipToGroupEnd

fun skipToGroupEnd(): Unit

Skip to the end of the current group.

startData

fun startData(
    key: Int,
    objectKey: Any?,
    aux: Any?
): Unit

Start a data group.

startData

fun startData(
    key: Int,
    aux: Any?
): Unit

Start a data group.

startGroup

fun startGroup(): Unit

Enter the group at current without changing it. Requires not currently inserting.

startGroup

fun startGroup(key: Int): Unit

Start a group with a integer key

startGroup

fun startGroup(
    key: Int,
    dataKey: Any?
): Unit

Start a group with a data key

startNode

fun startNode(key: Any?): Unit

Start a node.

startNode

fun startNode(
    key: Any?,
    node: Any?
): Unit

Start a node

toString

fun toString(): String

update

fun update(value: Any?): Any?

Set the value of the next slot. Returns the previous value of the slot or EMPTY is being inserted.

updateAux

fun updateAux(value: Any?): Unit

Updates the data for the current data group.

updateNode

fun updateNode(value: Any?): Unit

Updates the node for the current node group.

updateParentNode

fun updateParentNode(value: Any?): Unit

Updates the node of the parent group.

Properties

closed

var closed: Boolean

True if the writer has been closed

currentGroup

var currentGroup: Int

The current group that will be started by startGroup or skipped by skipGroup

isGroupEnd

val isGroupEnd: Boolean

True if at the end of a group and an endGroup is expected.

isNode

val isNode: Boolean

Return true if the current slot starts a node. A node is a kind of group so this will return true for isGroup as well.

parent

var parent: Int

Return the index of the nearest group that contains currentGroup.