Class Algorithms
- Namespace
- AlgorithmsSW
- Assembly
- AlgorithmsSW.dll
Provides algorithms for various tasks, especially for operating on lists.
public static class Algorithms
- Inheritance
-
Algorithms
- Inherited Members
Methods
BinaryRank__<T>(IReadonlyRandomAccessList<T>, T, IComparer<T>)
[Obsolete]
public static int BinaryRank__<T>(this IReadonlyRandomAccessList<T> list, T key, IComparer<T> comparer)
Parameters
list
IReadonlyRandomAccessList<T>key
Tcomparer
IComparer<T>
Returns
Type Parameters
T
BinaryRank<T>(IReadonlyRandomAccessList<T>, T, IComparer<T>)
Returns the number of elements in a sorted list that are less than the given value.
public static int BinaryRank<T>(this IReadonlyRandomAccessList<T> list, T item, IComparer<T> comparer)
Parameters
list
IReadonlyRandomAccessList<T>item
Tcomparer
IComparer<T>
Returns
Type Parameters
T
BinarySearch(int[], int)
[Obsolete]
public static int BinarySearch(this int[] list, int key)
Parameters
Returns
BinarySearch<T>(IReadonlyRandomAccessList<T>, T, IComparer<T>)
[Obsolete]
public static int BinarySearch<T>(this IReadonlyRandomAccessList<T> list, T key, IComparer<T> comparer)
Parameters
list
IReadonlyRandomAccessList<T>key
Tcomparer
IComparer<T>
Returns
Type Parameters
T
Buffer2<T>(IEnumerable<T>)
Returns pairs of successive elements.
public static IEnumerable<IPair<T>> Buffer2<T>(this IEnumerable<T> list)
Parameters
list
IEnumerable<T>
Returns
- IEnumerable<IPair<T>>
Type Parameters
T
Remarks
Will not return any elements if the list has 1 or 0 elements. The buffer will always contain two elements.
FindIndexOfMax<T>(IReadonlyRandomAccessList<T>)
public static int FindIndexOfMax<T>(this IReadonlyRandomAccessList<T> list) where T : IComparable<T>
Parameters
list
IReadonlyRandomAccessList<T>
Returns
Type Parameters
T
FindIndexOfMax<T>(IReadonlyRandomAccessList<T>, int, int)
public static int FindIndexOfMax<T>(this IReadonlyRandomAccessList<T> list, int start, int end) where T : IComparable<T>
Parameters
list
IReadonlyRandomAccessList<T>start
intend
int
Returns
Type Parameters
T
FindIndexOfMax<T>(T[])
public static int FindIndexOfMax<T>(this T[] list) where T : IComparable<T>
Parameters
list
T[]
Returns
Type Parameters
T
FindIndexOfMax<T>(T[], int, int)
public static int FindIndexOfMax<T>(this T[] list, int start, int end) where T : IComparable<T>
Parameters
Returns
Type Parameters
T
FindIndexOfMax<T>(T[], int, int, IComparer<T>)
public static int FindIndexOfMax<T>(this T[] list, int start, int end, IComparer<T> comparer)
Parameters
Returns
Type Parameters
T
FindIndexOfMin<T>(IReadonlyRandomAccessList<T>)
public static int FindIndexOfMin<T>(this IReadonlyRandomAccessList<T> list) where T : IComparable<T>
Parameters
list
IReadonlyRandomAccessList<T>
Returns
Type Parameters
T
FindIndexOfMin<T>(IReadonlyRandomAccessList<T>, IComparer<T>)
public static int FindIndexOfMin<T>(this IReadonlyRandomAccessList<T> list, IComparer<T> comparer)
Parameters
list
IReadonlyRandomAccessList<T>comparer
IComparer<T>
Returns
Type Parameters
T
FindIndexOfMin<T>(IReadonlyRandomAccessList<T>, int, int)
public static int FindIndexOfMin<T>(this IReadonlyRandomAccessList<T> list, int start, int end) where T : IComparable<T>
Parameters
list
IReadonlyRandomAccessList<T>start
intend
int
Returns
Type Parameters
T
FindIndexOfMin<T>(IReadonlyRandomAccessList<T>, int, int, IComparer<T>)
public static int FindIndexOfMin<T>(this IReadonlyRandomAccessList<T> list, int start, int end, IComparer<T> comparer)
Parameters
list
IReadonlyRandomAccessList<T>start
intend
intcomparer
IComparer<T>
Returns
Type Parameters
T
FindIndexOfMin<T>(T[])
public static int FindIndexOfMin<T>(this T[] list) where T : IComparable<T>
Parameters
list
T[]
Returns
Type Parameters
T
FindIndexOfMin<T>(T[], int, int)
public static int FindIndexOfMin<T>(this T[] list, int start, int end) where T : IComparable<T>
Parameters
Returns
Type Parameters
T
FindInsertionIndex<T>(IReadonlyRandomAccessList<T>, T, IComparer<T>)
Finds the index in a sorted list at which an item can be inserted so that all the elements to the left are smaller or equal, and all the elements to the right are larger than the item.
[Obsolete]
public static int FindInsertionIndex<T>(this IReadonlyRandomAccessList<T> sortedList, T item, IComparer<T> comparer)
Parameters
sortedList
IReadonlyRandomAccessList<T>The sorted list to search for the item.
item
TThe item to find the index for.
comparer
IComparer<T>The IComparer<T> to use for comparisons.
Returns
- int
The index at which the item can be inserted while maintaining the sorted order.
Type Parameters
T
The type of the elements in the list. Must implement IComparable<T>.
Remarks
If the item is smaller than all the items in the list, the method returns 0
.
If the item is greater than all the items in the list, the method returns sortedList.Count
.
FindInsertionNodeUnsafe<T>(LinkedList<T>, T, IComparer<T>)
public static LinkedList<T>.Node FindInsertionNodeUnsafe<T>(this LinkedList<T> sortedList, T item, IComparer<T> comparer)
Parameters
sortedList
LinkedList<T>item
Tcomparer
IComparer<T>
Returns
- LinkedList<T>.Node
Type Parameters
T
FindInsertionNodeUnsafe<TKey, TValue>(LinkedList<KeyValuePair<TKey, TValue>>, TKey, IComparer<TKey>)
public static LinkedList<KeyValuePair<TKey, TValue>>.Node FindInsertionNodeUnsafe<TKey, TValue>(this LinkedList<KeyValuePair<TKey, TValue>> sortedList, TKey key, IComparer<TKey> comparer)
Parameters
sortedList
LinkedList<KeyValuePair<TKey, TValue>>key
TKeycomparer
IComparer<TKey>
Returns
- LinkedList<KeyValuePair<TKey, TValue>>.Node
Type Parameters
TKey
TValue
FindInsertionNode<T>(LinkedList<T>, T, IComparer<T>)
public static LinkedList<T>.Node FindInsertionNode<T>(this LinkedList<T> sortedList, T item, IComparer<T> comparer)
Parameters
sortedList
LinkedList<T>item
Tcomparer
IComparer<T>
Returns
- LinkedList<T>.Node
Type Parameters
T
First<T>(IReadonlyRandomAccessList<T>)
public static T First<T>(this IReadonlyRandomAccessList<T> source)
Parameters
source
IReadonlyRandomAccessList<T>
Returns
- T
Type Parameters
T
Identity<T>(T)
Returns the supplied parameter.
public static T Identity<T>(T value)
Parameters
value
TThe value to return.
Returns
- T
Type Parameters
T
The type of the value to return.
Remarks
This class is useful for cases where a function is required, but no transformation is needed.
IndexWhere<T>(IEnumerable<T>, Func<T, bool>)
Gives the indexes of elements in a list that satisfy the given predicate.
public static IEnumerable<int> IndexWhere<T>(this IEnumerable<T> list, Func<T, bool> predicate)
Parameters
list
IEnumerable<T>The enumerable list to search.
predicate
Func<T, bool>A function to test each element for a condition.
Returns
Type Parameters
T
The type of the values in the list.
InsertSorted<T>(LinkedList<T>, T)
public static void InsertSorted<T>(this LinkedList<T> list, T item) where T : IComparable<T>
Parameters
list
LinkedList<T>item
T
Type Parameters
T
InsertSorted<T>(LinkedList<T>, T, IComparer<T>)
public static void InsertSorted<T>(this LinkedList<T> list, T item, IComparer<T> comparer)
Parameters
list
LinkedList<T>item
Tcomparer
IComparer<T>
Type Parameters
T
InsertSorted<T>(ResizeableArray<T>, T)
public static void InsertSorted<T>(this ResizeableArray<T> list, T item) where T : IComparable<T>
Parameters
list
ResizeableArray<T>item
T
Type Parameters
T
InsertSorted<T>(ResizeableArray<T>, T, IComparer<T>)
public static int InsertSorted<T>(this ResizeableArray<T> list, T item, IComparer<T> comparer)
Parameters
list
ResizeableArray<T>item
Tcomparer
IComparer<T>
Returns
Type Parameters
T
InterpolationSearch(int[], int)
[Obsolete]
public static int InterpolationSearch(this int[] list, int key)
Parameters
Returns
JosephusSequence<T>(IEnumerable<T>, int)
[ExerciseReference(1, 3, 37)]
public static IEnumerable<T> JosephusSequence<T>(this IEnumerable<T> list, int m)
Parameters
list
IEnumerable<T>m
int
Returns
- IEnumerable<T>
Type Parameters
T
Last<T>(IReadonlyRandomAccessList<T>)
public static T Last<T>(this IReadonlyRandomAccessList<T> source)
Parameters
source
IReadonlyRandomAccessList<T>
Returns
- T
Type Parameters
T
Median(float[])
public static float Median(float[] list)
Parameters
list
float[]
Returns
NodesBeforeThat<T>(LinkedList<T>, Func<Node, bool>)
public static IEnumerable<LinkedList<T>.Node> NodesBeforeThat<T>(this LinkedList<T> list, Func<LinkedList<T>.Node, bool> predicate)
Parameters
list
LinkedList<T>predicate
Func<LinkedList<T>.Node, bool>
Returns
Type Parameters
T
Nth<T>(LinkedList<T>, int)
Returns the nth node in a list.
public static LinkedList<T>.Node Nth<T>(this LinkedList<T> list, int n)
Parameters
list
LinkedList<T>The list to return the element from.
n
intThe index of the element to return. 0 Will return the first element.
Returns
- LinkedList<T>.Node
Type Parameters
T
The type of items in the list.
PowerSet<T>(IEnumerable<T>)
public static ResizeableArray<ResizeableArray<T>> PowerSet<T>(IEnumerable<T> set)
Parameters
set
IEnumerable<T>
Returns
Type Parameters
T
RemoveIf<T>(LinkedList<T>, Func<Node, bool>)
Remove elements from a list that satisfy a predicate.
public static void RemoveIf<T>(this LinkedList<T> list, Func<LinkedList<T>.Node, bool> predicate)
Parameters
list
LinkedList<T>The list to process.
predicate
Func<LinkedList<T>.Node, bool>A predicate items to be removed should satisfy.
Type Parameters
T
The type of items in the list.
RemoveNth<T>(LinkedList<T>, int)
public static LinkedList<T>.Node RemoveNth<T>(this LinkedList<T> list, int n)
Parameters
list
LinkedList<T>n
int
Returns
- LinkedList<T>.Node
Type Parameters
T
SequentialRank<T>(IReadonlyRandomAccessList<T>, T, IComparer<T>)
Returns the number of elements in a sorted list that are less than the given value.
public static int SequentialRank<T>(this IReadonlyRandomAccessList<T> list, T item, IComparer<T> comparer)
Parameters
list
IReadonlyRandomAccessList<T>item
Tcomparer
IComparer<T>
Returns
Type Parameters
T
SequentialRank<T>(LinkedList<T>, T, IComparer<T>)
Returns the number of elements in a sorted list that are less than the given value.
public static int SequentialRank<T>(this LinkedList<T> list, T item, IComparer<T> comparer)
Parameters
list
LinkedList<T>item
Tcomparer
IComparer<T>
Returns
Type Parameters
T
SequentialSearch(int[], int)
[Obsolete]
public static int SequentialSearch(this int[] list, int key)
Parameters
Returns
Shuffle<T>(IRandomAccessList<T>)
Shuffles a list so that each permutation is equally likely.
public static void Shuffle<T>(this IRandomAccessList<T> list)
Parameters
list
IRandomAccessList<T>
Type Parameters
T
Shuffle<T>(IRandomAccessList<T>, int)
This is a variant of the Fisher-Yates shuffle that shuffles only the first count
elements of
the list.
public static void Shuffle<T>(this IRandomAccessList<T> list, int count)
Parameters
list
IRandomAccessList<T>count
int
Type Parameters
T
SortAndRemoveDuplicatesWithBuffer<T>(ResizeableArray<T>)
Sorts a list and removes duplicates by using a buffer.
public static void SortAndRemoveDuplicatesWithBuffer<T>(this ResizeableArray<T> list) where T : IComparable<T>
Parameters
list
ResizeableArray<T>The list to sort.
Type Parameters
T
The type of the items in the list.
SortAndRemoveDuplicates<T>(ResizeableArray<T>)
Sorts a list and removes any duplicates.
[ExerciseReference(2, 5, 4)]
public static void SortAndRemoveDuplicates<T>(this ResizeableArray<T> list) where T : IComparable<T>
Parameters
list
ResizeableArray<T>The list to sort.
Type Parameters
T
The type of items in the list.