Class ListExtensions
- Namespace
- AlgorithmsSW.List
- Assembly
- AlgorithmsSW.dll
public static class ListExtensions
- Inheritance
-
ListExtensions
- Inherited Members
Methods
AddN<T>(ResizeableArray<T>, T, int)
public static void AddN<T>(this ResizeableArray<T> list, T item, int timesToAdd)
Parameters
listResizeableArray<T>itemTtimesToAddint
Type Parameters
T
AddRange<T>(ResizeableArray<T>, IEnumerable<T>)
Adds the elements of the specified collection to the end of the list.
public static void AddRange<T>(this ResizeableArray<T> list, IEnumerable<T> newITems)
Parameters
listResizeableArray<T>The list to add the elements to.
newITemsIEnumerable<T>The collection whose elements should be added to the end of the list.
Type Parameters
TThe type of elements in the list.
AsList<T>(IEnumerable<T>)
public static IRandomAccessList<T> AsList<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>
Returns
Type Parameters
T
CircularSlidingWindow2<T>(IEnumerable<T?>)
Provides a variant of CircularSlidingWindow<T>(IEnumerable<T>, int), optimized for a window size of 2.
public static IEnumerable<IEnumerable<T?>> CircularSlidingWindow2<T>(this IEnumerable<T?> list)
Parameters
listIEnumerable<T>The input sequence from which sliding windows are generated.
Returns
Type Parameters
TThe type of elements in the input sequence.
CircularSlidingWindow<T>(IEnumerable<T>, int)
Generates a sequence of circular sliding windows from the provided sequence. Each sliding window is of a specified size and contains a segment of the input sequence. This method wraps around the sequence to include earlier elements in the window as it reaches the end of the sequence.
public static IEnumerable<IEnumerable<T>> CircularSlidingWindow<T>(this IEnumerable<T> list, int windowSize)
Parameters
listIEnumerable<T>The input sequence from which circular sliding windows are generated.
windowSizeintThe size of each sliding window. Must be a positive integer.
Returns
- IEnumerable<IEnumerable<T>>
An IEnumerable<T> where each element is an IEnumerable<T> representing a circular sliding window of the specified size over the input sequence.
Type Parameters
TThe type of elements in the input sequence.
Examples
var numbers = new List<int> { 0, 1, 2, 3, 4, 5 };
foreach (var window in numbers.CircularSlidingWindow(3))
{
Console.WriteLine(string.Join(", ", window));
}
// Output:
// 0, 1, 2
// 1, 2, 3
// 2, 3, 4
// 3, 4, 5
// 4, 5, 0
// 5, 0, 1
Remarks
The circular sliding window wraps around the end of the sequence. If the window size is greater than the number of elements in the input sequence, it will continue to loop through the sequence until the window is filled. This method uses deferred execution and streams the windows as they are generated.
FillRange<T>(IRandomAccessList<T>, int, int, Func<T>)
public static void FillRange<T>(this IRandomAccessList<T> list, int start, int count, Func<T> valueGenerator)
Parameters
listIRandomAccessList<T>startintcountintvalueGeneratorFunc<T>
Type Parameters
T
FillRange<T>(IRandomAccessList<T>, int, int, T)
public static void FillRange<T>(this IRandomAccessList<T> list, int start, int count, T value)
Parameters
listIRandomAccessList<T>startintcountintvalueT
Type Parameters
T
FillRange<T>(IList<T>, int, int, Func<int, T>)
public static void FillRange<T>(this IList<T> list, int start, int count, Func<int, T> valueGenerator)
Parameters
Type Parameters
T
FillRange<T>(IList<T>, int, int, Func<T>)
public static void FillRange<T>(this IList<T> list, int start, int count, Func<T> valueGenerator)
Parameters
Type Parameters
T
FillRange<T>(IList<T>, int, int, T)
public static void FillRange<T>(this IList<T> list, int start, int count, T value)
Parameters
Type Parameters
T
Fill<T>(IRandomAccessList<T>, Func<T>)
public static void Fill<T>(this IRandomAccessList<T> list, Func<T> valueGenerator)
Parameters
listIRandomAccessList<T>valueGeneratorFunc<T>
Type Parameters
T
Fill<T>(IRandomAccessList<T>, T)
public static void Fill<T>(this IRandomAccessList<T> list, T value)
Parameters
listIRandomAccessList<T>valueT
Type Parameters
T
Fill<T>(IList<T>, Func<int, T>)
public static void Fill<T>(this IList<T> list, Func<int, T> valueGenerator)
Parameters
Type Parameters
T
Fill<T>(IList<T>, Func<T>)
public static void Fill<T>(this IList<T> list, Func<T> valueGenerator)
Parameters
Type Parameters
T
Fill<T>(IList<T>, T)
public static void Fill<T>(this IList<T> list, T value)
Parameters
listIList<T>valueT
Type Parameters
T
Range(int, int)
public static IRandomAccessList<int> Range(int start, int count)
Parameters
Returns
RemoveLast<T>(LinkedList<T>)
[ExerciseReference(1, 3, 19)]
public static void RemoveLast<T>(this LinkedList<T> list)
Parameters
listLinkedList<T>
Type Parameters
T
SlidingWindow2<T>(IEnumerable<T?>)
Provides a variant of SlidingWindow<T>(IEnumerable<T>, int), optimized for a window size of 2.
public static IEnumerable<(T? first, T? last)> SlidingWindow2<T>(this IEnumerable<T?> list)
Parameters
listIEnumerable<T>The input sequence from which sliding windows are generated.
Returns
- IEnumerable<(T item1, T item2)>
Type Parameters
TThe type of elements in the input sequence.
Remarks
If the list has fewer than 2 elements, the resulting sequence will be empty.
SlidingWindow<T>(IEnumerable<T>, int)
Generates a sequence of sliding windows from the provided sequence. Each sliding window is of a specified size and contains a segment of the input sequence.
public static IEnumerable<IEnumerable<T>> SlidingWindow<T>(this IEnumerable<T> list, int windowSize)
Parameters
listIEnumerable<T>The input sequence from which sliding windows are generated.
windowSizeintThe size of each sliding window. Must be a positive integer.
Returns
- IEnumerable<IEnumerable<T>>
An IEnumerable<T> where each element is an IEnumerable<T> representing a sliding window of the specified size over the input sequence.
Type Parameters
TThe type of elements in the input sequence.
Examples
var numbers = new List<int> { 0, 1, 2, 3, 4, 5 };
foreach (var window in numbers.SlidingWindow(3))
{
Console.WriteLine(string.Join(", ", window));
}
// Output:
// 0, 1, 2
// 1, 2, 3
// 2, 3, 4
// 3, 4, 5
Remarks
If the window size is greater than the number of elements in the input sequence, no windows are generated. This method uses deferred execution and streams the windows as they are generated.
Take<T>(IRandomAccessList<T>, int)
public static IRandomAccessList<T> Take<T>(this IRandomAccessList<T> list, int count)
Parameters
listIRandomAccessList<T>countint
Returns
Type Parameters
T
ToRandomAccessList<T>(IEnumerable<T>)
Creates a new read-only random access list that contains the same elements as this list.
public static IRandomAccessList<T> ToRandomAccessList<T>(this IEnumerable<T> list)
Parameters
listIEnumerable<T>
Returns
- IRandomAccessList<T>
A new read-only random access list that contains the same elements as this list.
Type Parameters
T
ToRandomAccessList<T>(IList<T>)
public static IRandomAccessList<T> ToRandomAccessList<T>(this IList<T> list)
Parameters
listIList<T>
Returns
Type Parameters
T