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
TRepresents a type that can be stored in the slot map.
- Inheritance
-
SlotMap<T>
- Implements
-
IEnumerable<T>
- Inherited Members
Constructors
SlotMap(int)
Initializes a new instance of SlotMap<T> with the specified initial capacity.
public SlotMap(int initialCapacity = 16)
Parameters
initialCapacityintThe initial number of slots to allocate.
Properties
Capacity
public int Capacity { get; }
Property Value
Count
public int Count { get; }
Property Value
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
itemTThe item to add.
generationintOutputs 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
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
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
slotIndexintThe slot index to retrieve.
generationintThe generation to validate.
existboolWhen 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
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
slotIndexintThe slot index to retrieve.
generationintThe generation to validate.
valueTWhen 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
slotIndexintThe slot index to update.
generationintThe generation to validate.
newValueTThe replacement value.
Returns
- bool
True if the item was updated; otherwise, false.