Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

SlotTable

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

A gap buffer implementation of the composition slot space. A slot space can be thought of as a custom List<Any?> that optimizes around inserts and removes.

Slots stores slots, groups, and nodes.

Slot - A slot is the primitive base type of the slot space. It is of type Any? and can hold any value. Group - A group is a keyed group of slots. The group counts the number of slots and nodes it contains. Node - A node is a special group that is counted by the containing groups.

All groups and nodes are just grouping of slots and use slots to describe the groups. At the root of a slot space is a group. Groups count the number nodes that are in the group. A node only counts as one node in its group regardless of the number of nodes it contains.

ASIDE: The intent is that groups represent memoized function calls and nodes represent views. For example:


Column {
    Contact(contact = jim)
    Contact(contact = bob)
}

the LinearLayout here would be a node (the linear layout view). The node contains the groups for the child views of the linear layout.

If contact's composition looks like:


@Composable
fun Contact(contact: Contact) {
    Text(text = contact.name)
    Text(text = contact.email)
}

then composing contact into the linear layout would add two views to the linear layout's children. The composition of contact creates groups, one for each text view. The groups for each contact would be able to report that it produces two views (that is the group created for Contact has two nodes). Summing the nodes in the group produces the number of views (as each node corresponds to a view).

If the order of jim and bob change:


Column {
    Contact(contact = bob)
    Contact(contact = jim)
}
the previous result can be reused by moving the views generated bob's group before jim's (or visversa). A composition algorithm could use the key information for each group to determine if theycan be switched. For example, since the first contact's group has two nodes the compositionalgorithm can infer that the beginning of jim's views starts at 2 and contains 2 view. To movejim in front of bob, move the 2 views from offset 2 to offset 0. If contact is immutable, forexample, Contact would only need to be recomposed if the value of jim or bob change.

Summary

Public constructors
<init>(slots: Array<Any?> = arrayOf())

A gap buffer implementation of the composition slot space.

Public methods
List<Int>
groupPathTo(location: Int)

Return a list of locations of slot table that contain the groups that contain location.

SlotReader

Open a reader.

SlotWriter

Open a writer.

T
read(block: (reader: SlotReader) -> T)

Read the slot table in block.

Unit

Ensure a slot table is well-formed by verifying the internal structure of the slot table is consistent.

T
write(block: (writer: SlotWriter) -> T)

Write to the slot table in block.

Extension functions
From androidx.ui.tooling
Group

Return a group tree for for the slot table that represents the entire content of the slot table.

Properties
Int

The number of active slots in the slot table.

Companion properties
Any

Public constructors

<init>

SlotTable(slots: Array<Any?> = arrayOf())

A gap buffer implementation of the composition slot space. A slot space can be thought of as a custom List<Any?> that optimizes around inserts and removes.

Slots stores slots, groups, and nodes.

Slot - A slot is the primitive base type of the slot space. It is of type Any? and can hold any value. Group - A group is a keyed group of slots. The group counts the number of slots and nodes it contains. Node - A node is a special group that is counted by the containing groups.

All groups and nodes are just grouping of slots and use slots to describe the groups. At the root of a slot space is a group. Groups count the number nodes that are in the group. A node only counts as one node in its group regardless of the number of nodes it contains.

ASIDE: The intent is that groups represent memoized function calls and nodes represent views. For example:


Column {
    Contact(contact = jim)
    Contact(contact = bob)
}

the LinearLayout here would be a node (the linear layout view). The node contains the groups for the child views of the linear layout.

If contact's composition looks like:


@Composable
fun Contact(contact: Contact) {
    Text(text = contact.name)
    Text(text = contact.email)
}

then composing contact into the linear layout would add two views to the linear layout's children. The composition of contact creates groups, one for each text view. The groups for each contact would be able to report that it produces two views (that is the group created for Contact has two nodes). Summing the nodes in the group produces the number of views (as each node corresponds to a view).

If the order of jim and bob change:


Column {
    Contact(contact = bob)
    Contact(contact = jim)
}
the previous result can be reused by moving the views generated bob's group before jim's (or visversa). A composition algorithm could use the key information for each group to determine if theycan be switched. For example, since the first contact's group has two nodes the compositionalgorithm can infer that the beginning of jim's views starts at 2 and contains 2 view. To movejim in front of bob, move the 2 views from offset 2 to offset 0. If contact is immutable, forexample, Contact would only need to be recomposed if the value of jim or bob change.

Public methods

groupPathTo

fun groupPathTo(location: Int): List<Int>

Return a list of locations of slot table that contain the groups that contain location.

groupPathTo creates a reader so it cannot be called when the slot table is being written to.

openReader

fun openReader(): SlotReader

Open a reader. Any number of readers can be created but a slot table cannot be read while it is being written to.

See Also

openWriter

fun openWriter(): SlotWriter

Open a writer. Only one writer can be created for a slot table at a time and all readers must be closed an do readers can be created while the slot table is being written to.

See Also

read

inline fun <T> read(block: (reader: SlotReader) -> T): T

Read the slot table in block. Any number of readers can be created but a slot table cannot be read while it is being written to.

See Also

verifyWellFormed

@TestOnly fun verifyWellFormed(): Unit

Ensure a slot table is well-formed by verifying the internal structure of the slot table is consistent. This method will throw an exception when it detects inconsistency in the internal structure of the slot table. A slot table can be invalid (contain incorrect information about a composition) but still be well-formed but all valid slot tables are well-formed.

write

inline fun <T> write(block: (writer: SlotWriter) -> T): T

Write to the slot table in block. Only one writer can be created for a slot table at a time and all readers must be closed an do readers can be created while the slot table is being written to.

See Also

Properties

size

val size: Int

The number of active slots in the slot table. The current capacity of the slot table is at lease size.

Companion properties

EMPTY

val EMPTY: Any