DotNext.Threading by .NET Foundation and Contributors

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

 IndexPool

Represents a pool of integer values.
public struct Enumerator

Represents an enumerator over available indicies 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 indicies.

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 indicies in the pool.

public void Return(int value)

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

public void Return(ReadOnlySpan<int> indicies)

Returns multiple indicies, atomically.

public int Take()

Returns the available index from the pool.

public int Take(Span<int> indicies)

Takes all available indicies, 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.