Struct IndexPool
Represents a pool of integer values.
Implements
Inherited Members
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 SourceIndexPool()
Initializes a new pool that can return an integer value within the range [0..MaxValue].
Declaration
public IndexPool()
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 |
|
Properties
| Edit this page View SourceCapacity
Gets the maximum capacity of the pool.
Declaration
public static int Capacity { get; }
Property Value
Type | Description |
---|---|
int |
Count
Gets the number of available indices.
Declaration
public readonly int Count { get; }
Property Value
Type | Description |
---|---|
int |
IsEmpty
Gets or sets a value indicating that the pool is empty.
Declaration
public bool IsEmpty { readonly get; init; }
Property Value
Type | Description |
---|---|
bool |
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 |
Methods
| Edit this page View SourceContains(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 |
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. |
Reset()
Returns all values to the pool.
Declaration
public void Reset()
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 |
|
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. |
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
| Edit this page View SourceTake(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 |
|
See Also
| Edit this page View SourceTryPeek(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 |
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. |