Table of Contents

Class SlotMap<T>

Namespace
Misaki.HighPerformance.Collections
Assembly
Misaki.HighPerformance.dll

A slot-based collection that stores values in reusable positions and validates access by generation.

public class SlotMap<T> : IEnumerable<T>, IEnumerable

Type Parameters

T

Represents a type that can be stored in the slot map.

Inheritance
SlotMap<T>
Implements
Inherited Members

Constructors

SlotMap(int)

Initializes a new instance of SlotMap<T> with the specified initial capacity.

public SlotMap(int initialCapacity = 16)

Parameters

initialCapacity int

The initial number of slots to allocate.

Properties

Capacity

public int Capacity { get; }

Property Value

int

Count

public int Count { get; }

Property Value

int

Methods

Add(T, out int)

Adds an item to the slot map and returns the slot index used to store it.

public int Add(T item, out int generation)

Parameters

item T

The item to add.

generation int

Outputs the generation value associated with the stored item.

Returns

int

The slot index assigned to the item.

AsSpan()

Returns a span over the occupied portion of the underlying storage.

public Span<T> AsSpan()

Returns

Span<T>

A span containing the active items.

Clear()

Removes all items from the collection.

public void Clear()

Contains(int, int)

Determines whether the specified slot index and generation refer to a valid item.

public bool Contains(int slotIndex, int generation)

Parameters

slotIndex int

The slot index to check.

generation int

The generation to validate.

Returns

bool

True if the slot contains a valid item; otherwise, false.

GetElementAt(int, int)

Gets the item at the specified slot index and generation.

public T GetElementAt(int slotIndex, int generation)

Parameters

slotIndex int

The slot index to retrieve.

generation int

The generation to validate.

Returns

T

The item stored at the slot.

Exceptions

InvalidOperationException

Thrown when the slot is not occupied or the generation does not match.

GetElementReferenceAt(int, int, out bool)

Gets a reference to the item at the specified slot index and generation.

public ref T GetElementReferenceAt(int slotIndex, int generation, out bool exist)

Parameters

slotIndex int

The slot index to retrieve.

generation int

The generation to validate.

exist bool

When this method returns, indicates whether the slot was found.

Returns

T

A reference to the stored item when found; otherwise, a null reference.

GetEnumerator()

Gets an enumerator that iterates over the occupied slots in the collection.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

An enumerator for the collection.

Remove(int, int)

Removes the item at the specified slot index when the generation matches.

public bool Remove(int slotIndex, int generation)

Parameters

slotIndex int

The slot index to remove.

generation int

The generation to validate.

Returns

bool

True if the item was removed; otherwise, false.

TryGetElement(int, int, out T)

Tries to get the item at the specified slot index and generation.

public bool TryGetElement(int slotIndex, int generation, out T value)

Parameters

slotIndex int

The slot index to retrieve.

generation int

The generation to validate.

value T

When this method returns, contains the stored item if found.

Returns

bool

True if the item was found; otherwise, false.

UpdateElement(int, int, T)

Updates the item at the specified slot index when the generation matches.

public bool UpdateElement(int slotIndex, int generation, T newValue)

Parameters

slotIndex int

The slot index to update.

generation int

The generation to validate.

newValue T

The replacement value.

Returns

bool

True if the item was updated; otherwise, false.