Class GorgonArray<T>
A special array type that is used to monitor and track changes to itself.
Inheritance
Inherited Members
Namespace: Gorgon.Collections
Assembly: Gorgon.Core.dll
Syntax
public class GorgonArray<T> : IList<T>, ICollection<T>, IGorgonReadOnlyArray<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IEquatable<IReadOnlyList<T>> where T : IEquatable<T>
Type Parameters
Name | Description |
---|---|
T | The type of data in the array. |
Constructors
| Edit this page View SourceGorgonArray(int)
Initializes a new instance of the GorgonArray<T> class.
Declaration
public GorgonArray(int maxSize)
Parameters
Type | Name | Description |
---|---|---|
int | maxSize | The maximum size. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
Properties
| Edit this page View SourceBackingArray
Property to return the backing store to objects that need it.
Declaration
protected T[] BackingArray { get; }
Property Value
Type | Description |
---|---|
T[] |
IsDirty
Property to return whether or not the list is dirty.
Declaration
public bool IsDirty { get; }
Property Value
Type | Description |
---|---|
bool |
this[int]
Gets or sets the element at the specified index.
Declaration
public T this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index |
Property Value
Type | Description |
---|---|
T | The element at the specified index. |
Length
Property to return the length of the array.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceAsMemory()
Function to return read only memory for a slice of the array.
Declaration
public ReadOnlyMemory<T> AsMemory()
Returns
Type | Description |
---|---|
ReadOnlyMemory<T> | The read only memory for the array slice. |
AsMemory(int, int)
Function to return read only memory for a slice of the array.
Declaration
public ReadOnlyMemory<T> AsMemory(int start, int count)
Parameters
Type | Name | Description |
---|---|---|
int | start | The starting index for the array. |
int | count | The number of items to slice. |
Returns
Type | Description |
---|---|
ReadOnlyMemory<T> | The read only memory for the array slice. |
AsSpan()
Function to return a read only span for the array.
Declaration
public ReadOnlySpan<T> AsSpan()
Returns
Type | Description |
---|---|
ReadOnlySpan<T> | The read only span for the array. |
AsSpan(int, int)
Function to return a read only span for a slice of the array.
Declaration
public ReadOnlySpan<T> AsSpan(int start, int count)
Parameters
Type | Name | Description |
---|---|---|
int | start | The starting index for the array. |
int | count | The number of items to slice. |
Returns
Type | Description |
---|---|
ReadOnlySpan<T> | The read only span for the array slice. |
Clear()
Removes all items from the ICollection<T>.
Declaration
public void Clear()
Exceptions
Type | Condition |
---|---|
NotSupportedException | The ICollection<T> is read-only. |
Contains(T)
Determines whether the ICollection<T> contains a specific value.
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate in the ICollection<T>. |
Returns
Type | Description |
---|---|
bool | true if |
CopyDirty(GorgonArray<T>)
Function to copy the dirty entries for this array into the specified array.
Declaration
public void CopyDirty(GorgonArray<T> array)
Parameters
Type | Name | Description |
---|---|---|
GorgonArray<T> | array | The array that will receive the dirty entries. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
CopyTo(GorgonArray<T>, int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
Declaration
public void CopyTo(GorgonArray<T> array, int destIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
GorgonArray<T> | array | The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing. |
int | destIndex | [Optional] The destination index in this array to start writing into. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
CopyTo(T[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing. |
int | arrayIndex | The zero-based index in |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ArgumentException | The number of elements in the source ICollection<T> is greater than the available space from |
DirtyEquals(IGorgonReadOnlyArray<T>, int)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool DirtyEquals(IGorgonReadOnlyArray<T> other, int offset = 0)
Parameters
Type | Name | Description |
---|---|---|
IGorgonReadOnlyArray<T> | other | An object to compare with this object. |
int | offset | [Optional] The offset in this array to start comparing from. |
Returns
Type | Description |
---|---|
bool | true if the current object is equal to the |
Equals(IReadOnlyList<T>)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(IReadOnlyList<T> other)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
bool | true if the current object is equal to the |
GetDirtyItems(bool)
Function to retrieve the dirty items in this list.
Declaration
public ref readonly (int Start, int Count) GetDirtyItems(bool peek = false)
Parameters
Type | Name | Description |
---|---|---|
bool | peek | [Optional] true if the dirty state should not be modified by calling this method, or false if it should be. |
Returns
Type | Description |
---|---|
(int Start, int Count) | A tuple containing the starting index and the number of items. |
Remarks
This will return a tuple that contains the start index, and count of the items that have been changed in this collection.
If the peek
parameter is set to true, then the state of this collection is not changed when retrieving the modified objects. Otherwise, the state will be reset and a
subsequent call to this method will result in a tuple that does not contain any changed values (i.e. the start and count will be 0) until the collection is modified again.
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<T> | An enumerator that can be used to iterate through the collection. |
IndexOf(T)
Determines the index of a specific item in the IList<T>.
Declaration
public int IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate in the IList<T>. |
Returns
Type | Description |
---|---|
int | The index of |
MarkDirty(Range)
Function to mark the specified range of indices as dirty.
Declaration
public void MarkDirty(Range range)
Parameters
Type | Name | Description |
---|---|---|
Range | range | The range to mark dirty. |
OnAssignDirtyItem(int, T)
Function called when a dirty item is assigned.
Declaration
protected virtual void OnAssignDirtyItem(int dirtyIndex, T value)
Parameters
Type | Name | Description |
---|---|---|
int | dirtyIndex | The index that is considered dirty. |
T | value | The dirty value. |
OnClear()
Function called when the array is cleared.
Declaration
protected virtual void OnClear()
OnItemReset(int, T)
Function called when an item is reset at an index.
Declaration
protected virtual void OnItemReset(int index, T oldItem)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the item that was assigned. |
T | oldItem | The previous item in the slot. |
OnValidate()
Function to validate an item being assigned to a slot.
Declaration
protected virtual void OnValidate()
ResetAt(int)
Function to reset the value at the specified index, and remove it from the dirty range.
Declaration
public void ResetAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the item to reset. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|