Vixen
02b45cc4
csharp
public sealed class FreeList<T>

A dense array whose removed slots are recycled, addressed by plain Int32 index.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The difference from HandlePool`1 is who owns the identity. Use a free list where the index never leaves the structure that holds it — the nodes of a tree, the entries of a graph, a scheduler's task table — so a stale index is impossible by construction. Use a handle pool wherever the reference is handed to somebody else, where staleness is not only possible but expected and needs detecting.

There is no generation counter, so an index kept past its release will silently read whatever landed there next. What is caught is releasing the same index twice, which would otherwise put one slot on the free list twice and hand it to two callers — a corruption that shows up arbitrarily far from its cause.

Fields and properties (3)

  • public int SlotCount

    How many slots have ever been used, live and free together.

  • public int Count

    How many slots hold a live item.

  • public ref T? this[int index]

    The item at .

Methods (6)

  • public FreeList(int capacity = 16)

    Creates a list with room for items before it grows.

  • public bool IsLive(int index)

    Whether a slot currently holds an item.

  • public int Add(T item)

    Stores an item in the first available slot.

  • public void Release(int index)

    Releases a slot for reuse.

  • public void Clear()

    Empties the list, keeping the buffers.

  • public FreeList<T>.Enumerator GetEnumerator()

    Enumerates the live slots and their items, in index order.

Used by (2)

  • CollectionTestsVixen.Core.Collections.Tests
  • EnumeratorVixen.Core.Collections