Class ListArray<T>
A list implemented as a growing array.
Inheritance
Implements
Namespace: Towel.DataStructures
Assembly: Towel.dll
Syntax
public class ListArray<T> : object, IList<T>, IDataStructure<T>, ISteppable<T>, System.Collections.Generic.IEnumerable<T>, DataStructure.IAddable<T>, DataStructure.ICountable, DataStructure.IClearable, ICloneable<ListArray<T>>
Type Parameters
Name | Description |
---|---|
T | The type of objects to be placed in the list. |
Constructors
| Improve this Doc View SourceListArray()
Creates an instance of a ListArray<T>.
Declaration
public ListArray()
ListArray(Int32)
Creates an instance of a ListArray, and sets it's minimum capacity.
Runtime: O(1)
Declaration
public ListArray(int expectedCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedCount | The initial and smallest array size allowed by this list. |
Properties
| Improve this Doc View SourceCount
Gets the current count of the data structure.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
CurrentCapacity
Gets the current capacity of the list.
Runtime: O(1)
Declaration
public int CurrentCapacity { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Item[Int32]
Look-up and set an indexed item in the list.
Declaration
public T this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the item to get or set. |
Property Value
Type | Description |
---|---|
T | The value at the given index. |
Methods
| Improve this Doc View SourceAdd(T, Int32)
Adds an item at a given index.
Declaration
public void Add(T addition, int index)
Parameters
Type | Name | Description |
---|---|---|
T | addition | The item to be added. |
System.Int32 | index | The index to add the item at. |
Clear()
Returns the data structure to an empty state.
Declaration
public void Clear()
Clone()
Clones a T
.
Declaration
public ListArray<T> Clone()
Returns
Type | Description |
---|---|
ListArray<T> | A clone of the |
GetEnumerator()
Gets the enumerator for the data structure.
Declaration
public System.Collections.Generic.IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> | The enumerator for the data structure. |
Remove(Int32)
Removes the item at a specific index.
Runtime: O(n), Ω(n - index), ε(n - index)
Declaration
public void Remove(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the item to be removed. |
RemoveAll<TPredicate>(TPredicate)
Removes all predicated items from the list.
Runtime: Θ(n)
Declaration
public void RemoveAll<TPredicate>(TPredicate predicate = default(TPredicate))
where TPredicate : struct, IFunc<T, bool>
Parameters
Type | Name | Description |
---|---|---|
TPredicate | predicate | The predicate to determine removals. |
Type Parameters
Name | Description |
---|---|
TPredicate | The type of predicate to determine removal. |
RemoveAllWithoutShrink<TPredicate>(TPredicate)
Removes all predicated items from the list.
Runtime: Θ(n)
Declaration
public void RemoveAllWithoutShrink<TPredicate>(TPredicate predicate = default(TPredicate))
where TPredicate : struct, IFunc<T, bool>
Parameters
Type | Name | Description |
---|---|---|
TPredicate | predicate | The predicate to determine removals. |
Type Parameters
Name | Description |
---|---|
TPredicate | The type of predicate to determine removal. |
RemoveFirst(Func<T, Boolean>)
Removes the first predicated value from the list.
Runtime: O(n), Ω(1)
Declaration
public void RemoveFirst(Func<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Func<T, System.Boolean> | predicate | The predicate to determine removals. |
RemoveFirstWithoutShrink(T, Nullable<Func<T, T, Boolean>>)
Removes the first occurence of a value from the list without causing the list to shrink.
Runtime: O(n), Ω(1)
Declaration
public void RemoveFirstWithoutShrink(T value, Func<T, T, bool>? equate = null)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to remove. |
System.Nullable<Func<T, T, System.Boolean>> | equate | The delegate providing the equality check. |
RemoveFirstWithoutShrink(Func<T, Boolean>)
Removes the first predicated value from the list wihtout shrinking the list.
Runtime: O(n), Ω(1)
Declaration
public void RemoveFirstWithoutShrink(Func<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Func<T, System.Boolean> | predicate | The predicate to determine removals. |
RemoveWithoutShrink(Int32)
Removes the item at a specific index.
Runtime: Θ(n - index)
Declaration
public void RemoveWithoutShrink(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the item to be removed. |
StepperBreak<TStep>(TStep)
Traverses values and invokes a function on every T
value.
Declaration
public StepStatus StepperBreak<TStep>(TStep step = default(TStep))
where TStep : struct, IFunc<T, StepStatus>
Parameters
Type | Name | Description |
---|---|---|
TStep | step | The function to invoke on every |
Returns
Type | Description |
---|---|
StepStatus | The status of the traversal. |
Type Parameters
Name | Description |
---|---|
TStep | The type of function to invoke on every |
ToArray()
Constructs an array with the values of this data structure.
Declaration
public T[] ToArray()
Returns
Type | Description |
---|---|
T[] | An array with the values of this data structure. |
Trim()
Resizes this allocation to the current count.
Declaration
public void Trim()
TryAdd(T)
Tries to add a value to a data structure.
Declaration
public (bool Success, Exception? Exception) TryAdd(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to add to the data structure. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>> | True if the value was added or false if not. |
TryRemoveFirst(Func<T, Boolean>, out Nullable<Exception>)
Tries to remove the first predicated value if the value exists.
Declaration
public bool TryRemoveFirst(Func<T, bool> predicate, out Exception? exception)
Parameters
Type | Name | Description |
---|---|---|
Func<T, System.Boolean> | predicate | The predicate to determine removals. |
System.Nullable<Exception> | exception | The exception that occured if the removal failed. |
Returns
Type | Description |
---|---|
System.Boolean | True if the item was found and removed. False if not. |
TryRemoveFirst<TPredicate>(out Nullable<Exception>, TPredicate)
Tries to remove the first predicated value if the value exists.
Declaration
public bool TryRemoveFirst<TPredicate>(out Exception? exception, TPredicate predicate = default(TPredicate))
where TPredicate : struct, IFunc<T, bool>
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<Exception> | exception | The exception that occurred if the remove failed. |
TPredicate | predicate | The predicate to determine removal. |
Returns
Type | Description |
---|---|
System.Boolean | True if the value was removed. False if the value did not exist. |
Type Parameters
Name | Description |
---|---|
TPredicate | The type of predicate to determine removal. |