Table of Contents

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

list ResizeableArray<T>
item T
timesToAdd int

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

list ResizeableArray<T>

The list to add the elements to.

newITems IEnumerable<T>

The collection whose elements should be added to the end of the list.

Type Parameters

T

The type of elements in the list.

AsList<T>(IEnumerable<T>)

public static IRandomAccessList<T> AsList<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

IRandomAccessList<T>

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

list IEnumerable<T>

The input sequence from which sliding windows are generated.

Returns

IEnumerable<IEnumerable<T>>

Type Parameters

T

The 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

list IEnumerable<T>

The input sequence from which circular sliding windows are generated.

windowSize int

The 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

T

The 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

list IRandomAccessList<T>
start int
count int
valueGenerator Func<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

list IRandomAccessList<T>
start int
count int
value T

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

list IList<T>
start int
count int
valueGenerator Func<int, T>

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

list IList<T>
start int
count int
valueGenerator Func<T>

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

list IList<T>
start int
count int
value T

Type Parameters

T

Fill<T>(IRandomAccessList<T>, Func<T>)

public static void Fill<T>(this IRandomAccessList<T> list, Func<T> valueGenerator)

Parameters

list IRandomAccessList<T>
valueGenerator Func<T>

Type Parameters

T

Fill<T>(IRandomAccessList<T>, T)

public static void Fill<T>(this IRandomAccessList<T> list, T value)

Parameters

list IRandomAccessList<T>
value T

Type Parameters

T

Fill<T>(IList<T>, Func<int, T>)

public static void Fill<T>(this IList<T> list, Func<int, T> valueGenerator)

Parameters

list IList<T>
valueGenerator Func<int, T>

Type Parameters

T

Fill<T>(IList<T>, Func<T>)

public static void Fill<T>(this IList<T> list, Func<T> valueGenerator)

Parameters

list IList<T>
valueGenerator Func<T>

Type Parameters

T

Fill<T>(IList<T>, T)

public static void Fill<T>(this IList<T> list, T value)

Parameters

list IList<T>
value T

Type Parameters

T

Range(int, int)

public static IRandomAccessList<int> Range(int start, int count)

Parameters

start int
count int

Returns

IRandomAccessList<int>

RemoveLast<T>(LinkedList<T>)

[ExerciseReference(1, 3, 19)]
public static void RemoveLast<T>(this LinkedList<T> list)

Parameters

list LinkedList<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

list IEnumerable<T>

The input sequence from which sliding windows are generated.

Returns

IEnumerable<(T item1, T item2)>

Type Parameters

T

The 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

list IEnumerable<T>

The input sequence from which sliding windows are generated.

windowSize int

The 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

T

The 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

list IRandomAccessList<T>
count int

Returns

IRandomAccessList<T>

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

list IEnumerable<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

list IList<T>

Returns

IRandomAccessList<T>

Type Parameters

T