DotNext.Threading by .NET Foundation and Contributors

<PackageReference Include="DotNext.Threading" Version="5.5.0" />

 IndexPool

Represents a pool of integer values.
public struct Enumerator

Represents an enumerator over available indices in the pool.

public static int Capacity { get; }

Gets the maximum capacity of the pool.

public static int MaxValue { get; }

Gets the maximum number that can be returned by the pool.

public int Count { get; }

Gets the number of available indices.

public bool IsEmpty { get; set; }

Gets or sets a value indicating that the pool is empty.

public IndexPool()

Initializes a new pool that can return an integer value within the range [0.. MaxValue].

public IndexPool(int maxValue)

Initializes a new pool that can return an integer within the range [0..maxValue].

public bool Contains(int value)

Determines whether the specified index is available for rent.

Gets an enumerator over available indices in the pool.

public void Reset()

Returns all values to the pool.

public void Return(int value)

Returns an index previously obtained using TryTake back to the pool.

public void Return(ReadOnlySpan<int> indices)

Returns multiple indices, atomically.

public int Take()

Returns the available index from the pool.

public int Take(Span<int> indices)

Takes all available indices, atomically.

public bool TryPeek(out int result)

Tries to peek the next available index from the pool, without acquiring it.

public bool TryTake(out int result)

Returns the available index from the pool.