Class EquatableArray<T>
An IEquatable<T> array with O(1) indexable lookup time
public sealed class EquatableArray<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IEquatable<EquatableArray<T>>, IEqualityOperators<EquatableArray<T>, EquatableArray<T>, bool> where T : IEquatable<T>
Type Parameters
T
The type of element that implements IEquatable<T> stored by the array.
- Inheritance
-
EquatableArray<T>
- Implements
-
IEnumerable<T>
- Inherited Members
Constructors
EquatableArray()
Initializes an empty new instance of the EquatableArray<T>.
public EquatableArray()
EquatableArray(int)
Initializes a new instance of the EquatableArray<T> class of size size
.
public EquatableArray(int size)
Parameters
size
intArray capacity
EquatableArray(T[])
An IEquatable<T> array with O(1) indexable lookup time
public EquatableArray(T[] values)
Parameters
values
T[]
Fields
Empty
Returns an empty EquatableArray<T>.
public static readonly EquatableArray<T> Empty
Field Value
Properties
IsEmpty
Returns a value that indicates whether the current EquatableArray<T> is empty.
public bool IsEmpty { get; }
Property Value
this[Index]
Returns a reference to specified element at index
of the EquatableArray<T>.
public ref T this[Index index] { get; }
Parameters
index
Indexarray index
Property Value
- T
this[int]
Returns a reference to specified element of the EquatableArray<T>.
public ref T this[int index] { get; }
Parameters
index
intarray index
Property Value
- T
this[Range]
Returns a rage slice as a copy of the current EquatableArray<T>
public EquatableArray<T> this[Range range] { get; }
Parameters
range
Range
Property Value
Length
Gets the total number of elements in all the dimensions of the EquatableArray<T>.
public int Length { get; }
Property Value
Methods
AsArray()
Returns the internal array of the current EquatableArray<T>.
public T[] AsArray()
Returns
- T[]
AsMemory()
public Memory<T> AsMemory()
Returns
- Memory<T>
AsReadOnly()
Returns a read-only IReadOnlyList<T> wrapper for the current EquatableArray<T>.
public IReadOnlyList<T> AsReadOnly()
Returns
AsSpan()
public Span<T> AsSpan()
Returns
- Span<T>
Clear()
Sets all elements in an array to the default value of each element type.
public void Clear()
Clear(int, int)
public void Clear(int index, int length)
Parameters
Clear(Range)
Sets a range of elements in an array to the default value of each element type.
public void Clear(Range range)
Parameters
range
RangeSlice to be clean
Clone()
Create new array with same values
public EquatableArray<T> Clone()
Returns
CopyTo(EquatableArray<T>)
Copies the contents of the EquatableArray<T> into another EquatableArray<T>.
public void CopyTo(EquatableArray<T> destination)
Parameters
destination
EquatableArray<T>
CopyTo(Memory<T>)
public void CopyTo(Memory<T> destination)
Parameters
destination
Memory<T>
CopyTo(Span<T>)
public void CopyTo(Span<T> destination)
Parameters
destination
Span<T>
Equals(EquatableArray<T>?)
public bool Equals(EquatableArray<T>? other)
Parameters
other
EquatableArray<T>
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
Exist(Predicate<T>)
Determines whether the specified array contains elements that match the conditions defined by the specified predicate.
public bool Exist(Predicate<T> predicate)
Parameters
predicate
Predicate<T>
Returns
Fill(Func<T>)
Assigns the given return value from delegate of type T to each element of the specified array.
public void Fill(Func<T> value)
Parameters
value
Func<T>
Fill(T)
Assigns the given value of type T to each element of the specified array.
public void Fill(T value)
Parameters
value
T
Find(Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Array.
public T? Find(Predicate<T> predicate)
Parameters
predicate
Predicate<T>
Returns
- T
FindAll(Predicate<T>)
Filters an array of values based on a predicate.
public EquatableArray<T> FindAll(Predicate<T> predicate)
Parameters
predicate
Predicate<T>
Returns
FindIndex(Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire Array.
public int FindIndex(Predicate<T> predicate)
Parameters
predicate
Predicate<T>
Returns
FindLast(Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire Array.
public T? FindLast(Predicate<T> predicate)
Parameters
predicate
Predicate<T>
Returns
- T
FindLastIndex(Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the entire Array.
public int FindLastIndex(Predicate<T> predicate)
Parameters
predicate
Predicate<T>
Returns
GetEnumerator()
public EquatableArray<T>.Enumerator GetEnumerator()
Returns
GetHashCode()
public override int GetHashCode()
Returns
Map<TOutput>(Func<T, TOutput>)
Projects each element of the array on a new array
public EquatableArray<TOutput> Map<TOutput>(Func<T, TOutput> projection) where TOutput : IEquatable<TOutput>
Parameters
projection
Func<T, TOutput>
Returns
- EquatableArray<TOutput>
Type Parameters
TOutput
Resize(int)
Changes the number of elements of a one-dimensional array to the specified new size.
public void Resize(int newSize)
Parameters
newSize
int
Reverse()
Reverses the sequence of the elements in the one-dimensional generic array.
public void Reverse()
Reverse(int, int)
Reverses the sequence of a subset of the elements in the one-dimensional generic array.
public void Reverse(int index, int length)
Parameters
Reverse(Range)
Reverses the sequence of a subset of the elements in the one-dimensional generic array.
public void Reverse(Range range)
Parameters
range
Range
Slice(int, int)
Forms a new Array for the slice out of the current span starting at a specified index for a specified length.
public EquatableArray<T> Slice(int start, int length)
Parameters
Returns
Sort(IComparer<T>?)
Sorts the elements of an array in ascending order.
public void Sort(IComparer<T>? comparer = null)
Parameters
comparer
IComparer<T>
Sort(int, int, IComparer<T>?)
Sorts the elements in a range of elements in an Array
public void Sort(int index, int length, IComparer<T>? comparer = null)
Parameters
Sort(Range, IComparer<T>?)
Sorts the elements in a range of elements in an Array
public void Sort(Range range, IComparer<T>? comparer = null)
Parameters
SortBy<TKey>(Func<T, TKey>, IComparer<TKey>?)
Sorts the elements of an array in ascending order according to a key.
public void SortBy<TKey>(Func<T, TKey> selector, IComparer<TKey>? comparer = null) where TKey : IComparable<TKey>
Parameters
Type Parameters
TKey
ToResized(int)
Crates new array with new size copying elements from source
public EquatableArray<T> ToResized(int newSize)
Parameters
newSize
int
Returns
ToSorted(IComparer<T>?)
Sorts the elements of an array in ascending order into a new array.
public EquatableArray<T> ToSorted(IComparer<T>? comparer = null)
Parameters
comparer
IComparer<T>
Returns
ToSorted(int, int, IComparer<T>?)
Sorts the elements in a range of elements in an Array into a new array
public EquatableArray<T> ToSorted(int index, int length, IComparer<T>? comparer = null)
Parameters
Returns
ToSorted(Range, IComparer<T>?)
Sorts the elements in a range of elements in an Array into a new array
public EquatableArray<T> ToSorted(Range range, IComparer<T>? comparer = null)
Parameters
Returns
ToSortedBy<TKey>(Func<T, TKey>, IComparer<TKey>?)
Sorts the elements of an array in ascending order according to a key.
public EquatableArray<T> ToSortedBy<TKey>(Func<T, TKey> selector, IComparer<TKey>? comparer = null) where TKey : IComparable<TKey>
Parameters
Returns
Type Parameters
TKey
ToString()
public override string ToString()
Returns
Operators
implicit operator Memory<T>(EquatableArray<T>)
public static implicit operator Memory<T>(EquatableArray<T> equatableArray)
Parameters
equatableArray
EquatableArray<T>
Returns
- Memory<T>
implicit operator ReadOnlySpan<T>(EquatableArray<T>)
Returns a read-only IReadOnlyList<T> wrapper for the current EquatableArray<T>.
public static implicit operator ReadOnlySpan<T>(EquatableArray<T> equatableArray)
Parameters
equatableArray
EquatableArray<T>
Returns
- ReadOnlySpan<T>
implicit operator Span<T>(EquatableArray<T>)
public static implicit operator Span<T>(EquatableArray<T> equatableArray)
Parameters
equatableArray
EquatableArray<T>
Returns
- Span<T>
implicit operator T[](EquatableArray<T>)
Returns the internal array of the current EquatableArray<T>.
public static implicit operator T[](EquatableArray<T> equatableArray)
Parameters
equatableArray
EquatableArray<T>
Returns
- T[]
Explicit Interface Implementations
operator ==(EquatableArray<T>?, EquatableArray<T>?)
static bool operator ==(EquatableArray<T>? left, EquatableArray<T>? right)
Parameters
left
EquatableArray<T>right
EquatableArray<T>
Returns
operator !=(EquatableArray<T>?, EquatableArray<T>?)
static bool operator !=(EquatableArray<T>? left, EquatableArray<T>? right)
Parameters
left
EquatableArray<T>right
EquatableArray<T>