Table of Contents

Struct ComponentCollectionAccessor<T>

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

Mutable accessor for a collection-typed component field — the variable-sized element list backing a ComponentCollection<T> value. Appends and replacements reach the owning field by ref, transparently performing copy-on-write when the buffer is shared across MVCC revisions. Must be disposed; disposal commits the pending buffer writes.

public ref struct ComponentCollectionAccessor<T> : IDisposable where T : unmanaged

Type Parameters

T

Unmanaged element type of the collection.

Implements
Inherited Members

Constructors

ComponentCollectionAccessor(ChangeSet, VariableSizedBufferSegment<T, PersistentStore>, ref ComponentCollection<T>)

Binds an accessor to collection field field and its backing buffer segment, capturing a chunk accessor from changeSet.

public ComponentCollectionAccessor(ChangeSet changeSet, VariableSizedBufferSegment<T, PersistentStore> vsbs, ref ComponentCollection<T> field)

Parameters

changeSet ChangeSet

Change set the buffer mutations are threaded through (dirty tracking and commit).

vsbs VariableSizedBufferSegment<T, PersistentStore>

Backing variable-sized buffer segment that stores the collection's elements.

field ComponentCollection<T>

Reference to the collection field being accessed; Add(T) updates its buffer id in place.

Properties

ElementCount

Total number of elements currently in the collection.

public int ElementCount { get; }

Property Value

int

Methods

Add(T)

Appends value to the collection, allocating the backing buffer on first use. A buffer shared with another revision (Versioned copy-on-write) or with the committed value (a SingleVersion write staged under the Commit discipline) is cloned before mutation; a solely-owned buffer is appended in place.

public void Add(T value)

Parameters

value T

Element to append.

Clear()

Removes every element: the collection ends with no buffer. The previous buffer is released as Replace(ReadOnlySpan<T>) releases it.

public void Clear()

Dispose()

Commits the pending buffer writes and releases the underlying chunk accessor.

public void Dispose()

GetAllElements()

Allocates and returns a new array containing every element of the collection.

public T[] GetAllElements()

Returns

T[]

A newly allocated array of length ElementCount.

GetAllElements(Span<T>)

Copies every element into dest.

public int GetAllElements(Span<T> dest)

Parameters

dest Span<T>

Destination span; must be at least ElementCount elements long.

Returns

int

The number of elements copied, or 0 when dest is too small (in which case nothing is copied).

Replace(ReadOnlySpan<T>)

Replaces the collection's whole content with elements, in order; an empty span is Clear(). The previous buffer is never written, only given back one reference: one shared with an older revision or with the committed value stays theirs, so a snapshot reading it still sees the old elements; a solely-owned one is freed.

public void Replace(ReadOnlySpan<T> elements)

Parameters

elements ReadOnlySpan<T>

The new content.

Remarks

O(elements.Length): the content goes into a fresh buffer. Through an entity handle the stored component names the new buffer as soon as this returns, and the write is recorded as a Set's is. On a SingleVersion component outside the Commit discipline the previous buffer is freed at once and a rollback does not bring it back — TickFence writes are not undone.

Exceptions

InvalidOperationException

An accessor made by Transaction.CreateComponentCollectionAccessor, over a collection it did not build: that accessor cannot tell a value being built from a copy of a stored one, whose buffer the release would free under it.