Struct RentedMemorySequence<T>
A lightweight container for an underlying MemorySequencePool<T> node.
public struct RentedMemorySequence<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IDisposable
Type Parameters
T
Element type.
- Implements
-
ICollection<T>IEnumerable<T>
- Inherited Members
- Extension Methods
Fields
Empty
An empty sequence. This instance cannot be used to create larger sequences.
public static readonly RentedMemorySequence<T> Empty
Field Value
Properties
this[int]
Gets or sets the element at the specified position in this sequence.
public T this[int index] { get; set; }
Parameters
index
intThe zero-based index of the element to get or set.
Property Value
- T
Exceptions
- ArgumentOutOfRangeException
When
index
is less than 0 or greater than or equal to Length.
Length
Number of elements in this sequence.
public readonly int Length { get; }
Property Value
Owner
MemorySequencePool<T> instance that owns this sequence.
public MemorySequencePool<T>? Owner { get; }
Property Value
Segments
Creates a new RentedMemorySequenceSegmentCollection<T> instance from this sequence.
public RentedMemorySequenceSegmentCollection<T> Segments { get; }
Property Value
Methods
Clear()
Sets all elements to the default value in this sequence.
public void Clear()
Contains(T)
Checks whether or not the provided item
exists in this sequence.
[Pure]
public bool Contains(T item)
Parameters
item
TItem to check.
Returns
- bool
true when the provided
item
exists, otherwise false.
CopyFrom(ReadOnlySpan<T>)
Copies the provided span
to this sequence.
public void CopyFrom(ReadOnlySpan<T> span)
Parameters
span
ReadOnlySpan<T>Copy source.
Remarks
Does nothing when this sequence has been returned to the pool.
Exceptions
- ArgumentOutOfRangeException
When Length is less than length of the provided
span
.
CopyTo(RentedMemorySequenceSpan<T>)
Copies this sequence to the provided span
.
public void CopyTo(RentedMemorySequenceSpan<T> span)
Parameters
span
RentedMemorySequenceSpan<T>Copy destination.
Exceptions
- ArgumentOutOfRangeException
When Length is greater than length of the provided
span
.
CopyTo(Span<T>)
Copies this sequence to the provided span
.
public void CopyTo(Span<T> span)
Parameters
span
Span<T>Copy destination.
Exceptions
- ArgumentOutOfRangeException
When Length is greater than length of the provided
span
.
CopyTo(T[], int)
Copies this sequence to the provided array
, starting from the given arrayIndex
.
public void CopyTo(T[] array, int arrayIndex)
Parameters
array
T[]Copy destination.
arrayIndex
intIndex of the destination
array
at which to start copying to.
Exceptions
- ArgumentOutOfRangeException
When
arrayIndex
is less than 0 or greater than or equal to the length of the providedarray
or Length is greater than length of the providedarray
segment.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Remarks
Frees the underlying node and returns it to the pool.
Expand(int)
Increases Length of this sequence by the provided length
.
public void Expand(int length)
Parameters
Remarks
Does nothing when this sequence has been returned to the pool or length
is less than 1.
GetEnumerator()
Creates a new RentedMemorySequence<T>.Enumerator instance for this sequence.
[Pure]
public RentedMemorySequence<T>.Enumerator GetEnumerator()
Returns
- RentedMemorySequence<T>.Enumerator
New RentedMemorySequence<T>.Enumerator instance.
GetRef(int)
Returns a reference to an element at the specified position.
[Pure]
public ref T GetRef(int index)
Parameters
index
intThe zero-based index of the element reference to get.
Returns
- T
Reference to an element at the specified position.
Exceptions
- ArgumentOutOfRangeException
When
index
is less than 0 or greater than or equal to Length.
Push(T)
Increases Length of this sequence by 1 and sets the last element.
public void Push(T item)
Parameters
item
TElement to add.
Remarks
Does nothing when this sequence has been returned to the pool.
Refresh()
Refreshes this sequence's Length.
public void Refresh()
Remarks
Some operations may cause the underlying node to be modified. This method can be used to synchronize a sequence with it's node's state.
Set(int, T)
Sets an element at the specified position.
public void Set(int index, T item)
Parameters
index
intThe zero-based index of the element to set.
item
TElement to set.
Exceptions
- ArgumentOutOfRangeException
When
index
is less than 0 or greater than or equal to Length.
Slice(int)
Creates a new RentedMemorySequenceSpan<T> instance.
[Pure]
public RentedMemorySequenceSpan<T> Slice(int startIndex)
Parameters
startIndex
intIndex of the first element that should be included in the slice.
Returns
- RentedMemorySequenceSpan<T>
New RentedMemorySequenceSpan<T> instance.
Exceptions
- ArgumentOutOfRangeException
When
startIndex
is less than 0 or is greater than or equal to Length.
Slice(int, int)
Creates a new RentedMemorySequenceSpan<T> instance.
[Pure]
public RentedMemorySequenceSpan<T> Slice(int startIndex, int length)
Parameters
startIndex
intIndex of the first element that should be included in the slice.
length
intLength of the slice.
Returns
- RentedMemorySequenceSpan<T>
New RentedMemorySequenceSpan<T> instance.
Exceptions
- ArgumentOutOfRangeException
When
startIndex
is less than 0 orlength
is less than 0 or computed index of the last element in the slice is greater than or equal to Length.
Sort(Comparer<T>?)
Sorts elements in this sequence.
public void Sort(Comparer<T>? comparer = null)
Parameters
comparer
Comparer<T>Optional comparer to use for sorting elements.
Sort(Comparison<T>)
Sorts elements in this sequence.
public void Sort(Comparison<T> comparer)
Parameters
comparer
Comparison<T>Delegate used for sorting elements.
ToArray()
Creates a new Array instance from this sequence.
[Pure]
public T[] ToArray()
Returns
- T[]
New Array instance.
ToString()
Returns a string representation of this RentedMemorySequence<T> instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
Operators
implicit operator RentedMemorySequenceSpan<T>(RentedMemorySequence<T>)
Converts a sequence to an equivalent RentedMemorySequenceSpan<T> instance.
[Pure]
public static implicit operator RentedMemorySequenceSpan<T>(RentedMemorySequence<T> s)
Parameters
s
RentedMemorySequence<T>Source sequence.
Returns
- RentedMemorySequenceSpan<T>
New RentedMemorySequenceSpan<T> instance.