Show / Hide Table of Contents

Struct IndexPool

Represents a pool of integer values.

Implements
ISupplier<int>
IFunctional<Func<int>>
IConsumer<int>
IFunctional<Action<int>>
IReadOnlyCollection<int>
IEnumerable<int>
IEnumerable
IResettable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: DotNext.Collections.Concurrent
Assembly: DotNext.Threading.dll
Syntax
public struct IndexPool : ISupplier<int>, IFunctional<Func<int>>, IConsumer<int>, IFunctional<Action<int>>, IReadOnlyCollection<int>, IEnumerable<int>, IEnumerable, IResettable
Remarks

This type is thread-safe.

Constructors

| Edit this page View Source

IndexPool()

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

Declaration
public IndexPool()
| Edit this page View Source

IndexPool(int)

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

Declaration
public IndexPool(int maxValue)
Parameters
Type Name Description
int maxValue

The maximum possible value to return, inclusive.

Exceptions
Type Condition
ArgumentOutOfRangeException

maxValue is less than zero; or greater than MaxValue.

Properties

| Edit this page View Source

Capacity

Gets the maximum capacity of the pool.

Declaration
public static int Capacity { get; }
Property Value
Type Description
int
| Edit this page View Source

Count

Gets the number of available indices.

Declaration
public readonly int Count { get; }
Property Value
Type Description
int
| Edit this page View Source

IsEmpty

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

Declaration
public bool IsEmpty { readonly get; init; }
Property Value
Type Description
bool
| Edit this page View Source

MaxValue

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

Declaration
public static int MaxValue { get; }
Property Value
Type Description
int

Always returns 63.

Methods

| Edit this page View Source

Contains(int)

Determines whether the specified index is available for rent.

Declaration
public readonly bool Contains(int value)
Parameters
Type Name Description
int value

The value to check.

Returns
Type Description
bool

true if value is available for rent; otherwise, false.

| Edit this page View Source

GetEnumerator()

Gets an enumerator over available indices in the pool.

Declaration
public readonly IndexPool.Enumerator GetEnumerator()
Returns
Type Description
IndexPool.Enumerator

The enumerator over available indices in this pool.

| Edit this page View Source

Reset()

Returns all values to the pool.

Declaration
public void Reset()
| Edit this page View Source

Return(int)

Returns an index previously obtained using TryTake(out int) back to the pool.

Declaration
public void Return(int value)
Parameters
Type Name Description
int value
Exceptions
Type Condition
ArgumentOutOfRangeException

value is less than zero or greater than the maximum value specified for this pool.

| Edit this page View Source

Return(ReadOnlySpan<int>)

Returns multiple indices, atomically.

Declaration
public void Return(ReadOnlySpan<int> indices)
Parameters
Type Name Description
ReadOnlySpan<int> indices

The buffer of indices to return back to the pool.

| Edit this page View Source

Take()

Returns the available index from the pool.

Declaration
public int Take()
Returns
Type Description
int

The index which is greater than or equal to zero.

Exceptions
Type Condition
OverflowException

There is no available index to return.

See Also
Return(int)
| Edit this page View Source

Take(Span<int>)

Takes all available indices, atomically.

Declaration
public int Take(Span<int> indices)
Parameters
Type Name Description
Span<int> indices

The buffer to be modified with the indices taken from the pool. The size of the buffer should not be less than Capacity.

Returns
Type Description
int

The number of indices written to the buffer.

Exceptions
Type Condition
ArgumentOutOfRangeException

indices is too small to place indices.

See Also
Return(ReadOnlySpan<int>)
| Edit this page View Source

TryPeek(out int)

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

Declaration
public readonly bool TryPeek(out int result)
Parameters
Type Name Description
int result

The index which is greater than or equal to zero.

Returns
Type Description
bool

true if the index is available for rent; otherwise, false.

| Edit this page View Source

TryTake(out int)

Returns the available index from the pool.

Declaration
public bool TryTake(out int result)
Parameters
Type Name Description
int result

The index which is greater than or equal to zero.

Returns
Type Description
bool

true if the index is successfully rented from the pool; otherwise, false.

See Also
Return(int)

Implements

ISupplier<TResult>
IFunctional<TDelegate>
IConsumer<T>
IFunctional<TDelegate>
IReadOnlyCollection<T>
IEnumerable<T>
IEnumerable
IResettable

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)
Collection.Append<T>(IEnumerable<T>, params T[])
Collection.Copy<T>(IEnumerable<T>, int, MemoryAllocator<T>?)
Collection.ElementAt<T>(IEnumerable<T>, int, out T)
Collection.FirstOrNone<T>(IEnumerable<T>)
Collection.ForEachAsync<T>(IEnumerable<T>, Func<T, CancellationToken, ValueTask>, CancellationToken)
Collection.ForEach<T>(IEnumerable<T>, Action<T>)
Collection.LastOrNone<T>(IEnumerable<T>)
Collection.Prepend<T>(IEnumerable<T>, params T[])
Collection.SequenceHashCode<T>(IEnumerable<T>, bool)
Collection.ToAsyncEnumerable<T>(IEnumerable<T>)
Collection.ToString<T>(IEnumerable<T>, string, string)
Enumerator.GetAsyncEnumerator<T>(IEnumerable<T>, CancellationToken)
Collection.Convert<TInput, TOutput>(IReadOnlyCollection<TInput>, Converter<TInput, TOutput>)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾