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
listIReadonlyRandomAccessList<T>keyTcomparerIComparer<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
listIReadonlyRandomAccessList<T>itemTcomparerIComparer<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
listIReadonlyRandomAccessList<T>keyTcomparerIComparer<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
listIEnumerable<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
listIReadonlyRandomAccessList<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
listIReadonlyRandomAccessList<T>startintendint
Returns
Type Parameters
T
FindIndexOfMax<T>(T[])
public static int FindIndexOfMax<T>(this T[] list) where T : IComparable<T>
Parameters
listT[]
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
listIReadonlyRandomAccessList<T>
Returns
Type Parameters
T
FindIndexOfMin<T>(IReadonlyRandomAccessList<T>, IComparer<T>)
public static int FindIndexOfMin<T>(this IReadonlyRandomAccessList<T> list, IComparer<T> comparer)
Parameters
listIReadonlyRandomAccessList<T>comparerIComparer<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
listIReadonlyRandomAccessList<T>startintendint
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
listIReadonlyRandomAccessList<T>startintendintcomparerIComparer<T>
Returns
Type Parameters
T
FindIndexOfMin<T>(T[])
public static int FindIndexOfMin<T>(this T[] list) where T : IComparable<T>
Parameters
listT[]
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
sortedListIReadonlyRandomAccessList<T>The sorted list to search for the item.
itemTThe item to find the index for.
comparerIComparer<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
TThe 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
sortedListLinkedList<T>itemTcomparerIComparer<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
sortedListLinkedList<KeyValuePair<TKey, TValue>>keyTKeycomparerIComparer<TKey>
Returns
- LinkedList<KeyValuePair<TKey, TValue>>.Node
Type Parameters
TKeyTValue
FindInsertionNode<T>(LinkedList<T>, T, IComparer<T>)
public static LinkedList<T>.Node FindInsertionNode<T>(this LinkedList<T> sortedList, T item, IComparer<T> comparer)
Parameters
sortedListLinkedList<T>itemTcomparerIComparer<T>
Returns
- LinkedList<T>.Node
Type Parameters
T
First<T>(IReadonlyRandomAccessList<T>)
public static T First<T>(this IReadonlyRandomAccessList<T> source)
Parameters
sourceIReadonlyRandomAccessList<T>
Returns
- T
Type Parameters
T
Identity<T>(T)
Returns the supplied parameter.
public static T Identity<T>(T value)
Parameters
valueTThe value to return.
Returns
- T
Type Parameters
TThe 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
listIEnumerable<T>The enumerable list to search.
predicateFunc<T, bool>A function to test each element for a condition.
Returns
Type Parameters
TThe 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
listLinkedList<T>itemT
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
listLinkedList<T>itemTcomparerIComparer<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
listResizeableArray<T>itemT
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
listResizeableArray<T>itemTcomparerIComparer<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
listIEnumerable<T>mint
Returns
- IEnumerable<T>
Type Parameters
T
Last<T>(IReadonlyRandomAccessList<T>)
public static T Last<T>(this IReadonlyRandomAccessList<T> source)
Parameters
sourceIReadonlyRandomAccessList<T>
Returns
- T
Type Parameters
T
Median(float[])
public static float Median(float[] list)
Parameters
listfloat[]
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
listLinkedList<T>predicateFunc<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
listLinkedList<T>The list to return the element from.
nintThe index of the element to return. 0 Will return the first element.
Returns
- LinkedList<T>.Node
Type Parameters
TThe type of items in the list.
PowerSet<T>(IEnumerable<T>)
public static ResizeableArray<ResizeableArray<T>> PowerSet<T>(IEnumerable<T> set)
Parameters
setIEnumerable<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
listLinkedList<T>The list to process.
predicateFunc<LinkedList<T>.Node, bool>A predicate items to be removed should satisfy.
Type Parameters
TThe 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
listLinkedList<T>nint
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
listIReadonlyRandomAccessList<T>itemTcomparerIComparer<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
listLinkedList<T>itemTcomparerIComparer<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
listIRandomAccessList<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
listIRandomAccessList<T>countint
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
listResizeableArray<T>The list to sort.
Type Parameters
TThe 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
listResizeableArray<T>The list to sort.
Type Parameters
TThe type of items in the list.