Generated by DocFX

Class Sort

Extension methods for sorting operations.

Inheritance
System.Object
Sort
Namespace: ISynergy.Framework.Mathematics.Common
Assembly: ISynergy.Framework.Mathematics.dll
Syntax
public static class Sort : object

Methods

View Source

Insertion<T>(T[], Func<T, T, Int32>, Boolean)

Insertion sort.

Declaration
public static int Insertion<T>(T[] keys, Func<T, T, int> comparer, bool asc = true)
Parameters
Type Name Description
T[] keys
Func<T, T, System.Int32> comparer
System.Boolean asc
Returns
Type Description
System.Int32
Type Parameters
Name Description
T
View Source

Insertion<T>(T[], Boolean)

Insertion sort.

Declaration
public static int Insertion<T>(T[] keys, bool asc = true)
    where T : IComparable<T>
Parameters
Type Name Description
T[] keys
System.Boolean asc
Returns
Type Description
System.Int32
Type Parameters
Name Description
T
View Source

Insertion<T>(T[], Int32, Int32, Func<T, T, Int32>, Boolean)

Insertion sort.

Declaration
public static int Insertion<T>(T[] keys, int first, int last, Func<T, T, int> comparer, bool asc = true)
Parameters
Type Name Description
T[] keys
System.Int32 first
System.Int32 last
Func<T, T, System.Int32> comparer
System.Boolean asc
Returns
Type Description
System.Int32
Type Parameters
Name Description
T
View Source

Insertion<T>(T[], Int32, Int32, Boolean)

Insertion sort.

Declaration
public static int Insertion<T>(T[] keys, int first, int last, bool asc = true)
    where T : IComparable<T>
Parameters
Type Name Description
T[] keys
System.Int32 first
System.Int32 last
System.Boolean asc
Returns
Type Description
System.Int32
Type Parameters
Name Description
T
View Source

Insertion<TKey, TValue>(TKey[], TValue[], Func<TKey, TKey, Int32>, Boolean)

Insertion sort.

Declaration
public static int Insertion<TKey, TValue>(TKey[] keys, TValue[] items, Func<TKey, TKey, int> comparer, bool asc = true)
Parameters
Type Name Description
TKey[] keys
TValue[] items
Func<TKey, TKey, System.Int32> comparer
System.Boolean asc
Returns
Type Description
System.Int32
Type Parameters
Name Description
TKey
TValue
View Source

Insertion<T, U>(T[], U[], Boolean)

Insertion sort.

Declaration
public static int Insertion<T, U>(T[] keys, U[] items, bool asc = true)
    where T : IComparable<T>
Parameters
Type Name Description
T[] keys
U[] items
System.Boolean asc
Returns
Type Description
System.Int32
Type Parameters
Name Description
T
U
View Source

Insertion<TKeys, TValue>(TKeys[], TValue[], Int32, Int32, Func<TKeys, TKeys, Int32>, Boolean)

Insertion sort.

Declaration
public static int Insertion<TKeys, TValue>(TKeys[] keys, TValue[] items, int first, int last, Func<TKeys, TKeys, int> comparer, bool asc = true)
Parameters
Type Name Description
TKeys[] keys
TValue[] items
System.Int32 first
System.Int32 last
Func<TKeys, TKeys, System.Int32> comparer
System.Boolean asc
Returns
Type Description
System.Int32
Type Parameters
Name Description
TKeys
TValue
View Source

Insertion<TKey, TValue>(TKey[], TValue[], Int32, Int32, Boolean)

Insertion sort.

Declaration
public static int Insertion<TKey, TValue>(TKey[] keys, TValue[] items, int first, int last, bool asc = true)
    where TKey : IComparable<TKey>
Parameters
Type Name Description
TKey[] keys
TValue[] items
System.Int32 first
System.Int32 last
System.Boolean asc
Returns
Type Description
System.Int32
Type Parameters
Name Description
TKey
TValue
View Source

NthElement<T>(T[], Int32, Boolean)

Retrieves the n-th smallest element in an array. See remarks for more info.

Declaration
public static T NthElement<T>(this T[] items, int n, bool asc = true)
    where T : IComparable<T>
Parameters
Type Name Description
T[] items

The array of elements from which the n-th element should be extracted.

System.Int32 n

The position to look for (0 returns the smallest element, 1 the second smallest, and so on).

System.Boolean asc

Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.

Returns
Type Description
T

If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.

Type Parameters
Name Description
T

The type for the items in the array.

Remarks

As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

View Source

NthElement<T>(T[], Int32, Int32, Int32, Func<T, T, Int32>, Boolean)

Retrieves the n-th smallest element in an array. See remarks for more info.

Declaration
public static T NthElement<T>(this T[] items, int first, int last, int n, Func<T, T, int> compare, bool asc = true)
Parameters
Type Name Description
T[] items

The array of elements from which the n-th element should be extracted.

System.Int32 first

The beginning of the search interval.

System.Int32 last

The end of the search interval.

System.Int32 n

The position to look for (0 returns the smallest element, 1 the second smallest, and so on).

Func<T, T, System.Int32> compare

The comparison function to be used to sort elements.

System.Boolean asc

Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.

Returns
Type Description
T

If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.

Type Parameters
Name Description
T

The type for the items in the array.

Remarks

As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

View Source

NthElement<T>(T[], Int32, Int32, Int32, Boolean)

Retrieves the n-th smallest element in an array. See remarks for more info.

Declaration
public static T NthElement<T>(this T[] items, int first, int last, int n, bool asc = true)
    where T : IComparable<T>
Parameters
Type Name Description
T[] items

The array of elements from which the n-th element should be extracted.

System.Int32 first

The beginning of the search interval.

System.Int32 last

The end of the search interval.

System.Int32 n

The position to look for (0 returns the smallest element, 1 the second smallest, and so on).

System.Boolean asc

Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.

Returns
Type Description
T

If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.

Type Parameters
Name Description
T

The type for the items in the array.

Remarks

As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

View Source

NthElement<TKey, TValue>(TKey[], TValue[], Int32, Boolean)

Retrieves the n-th smallest element in an array. See remarks for more info.

Declaration
public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int n, bool asc = true)
    where TKey : IComparable<TKey>
Parameters
Type Name Description
TKey[] keys

The keys that will be used to determine the order of elements in items.

TValue[] items

The array of elements from which the n-th element should be extracted.

System.Int32 n

The position to look for (0 returns the smallest element, 1 the second smallest, and so on).

System.Boolean asc

Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.

Returns
Type Description
TKey

If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.

Type Parameters
Name Description
TKey

The type for the keys associated with each value in the items array.

TValue

The type for the items in the array.

Remarks

As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

View Source

NthElement<TKey, TValue>(TKey[], TValue[], Int32, Int32, Int32, Func<TKey, TKey, Int32>, Boolean)

Retrieves the n-th smallest element in an array. See remarks for more info.

Declaration
public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, int n, Func<TKey, TKey, int> compare, bool asc = true)
Parameters
Type Name Description
TKey[] keys

The keys that will be used to determine the order of elements in items.

TValue[] items

The array of elements from which the n-th element should be extracted.

System.Int32 first

The beginning of the search interval.

System.Int32 last

The end of the search interval.

System.Int32 n

The position to look for (0 returns the smallest element, 1 the second smallest, and so on).

Func<TKey, TKey, System.Int32> compare

The comparison function to be used to sort elements.

System.Boolean asc

Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.

Returns
Type Description
TKey

If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.

Type Parameters
Name Description
TKey

The type for the keys associated with each value in the items array.

TValue

The type for the items in the array.

Remarks

As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

View Source

NthElement<TKey, TValue>(TKey[], TValue[], Int32, Int32, Int32, Boolean)

Retrieves the n-th smallest element in an array. See remarks for more info.

Declaration
public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, int n, bool asc = true)
    where TKey : IComparable<TKey>
Parameters
Type Name Description
TKey[] keys

The keys that will be used to determine the order of elements in items.

TValue[] items

The array of elements from which the n-th element should be extracted.

System.Int32 first

The beginning of the search interval.

System.Int32 last

The end of the search interval.

System.Int32 n

The position to look for (0 returns the smallest element, 1 the second smallest, and so on).

System.Boolean asc

Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.

Returns
Type Description
TKey

If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.

Type Parameters
Name Description
TKey

The type for the keys associated with each value in the items array.

TValue

The type for the items in the array.

Remarks

As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

View Source

Partial<T>(T[], Int32, Boolean)

Partially orders a collection, making sure every element smaller than the n-th smaller element are in the beginning of the array.

Declaration
public static void Partial<T>(T[] items, int n, bool asc = true)
    where T : IComparable<T>
Parameters
Type Name Description
T[] items

The array of elements from which the n-th element should be extracted.

System.Int32 n

The position to look for (0 returns the smallest element, 1 the second smallest, and so on).

System.Boolean asc

Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements in the beginning of the array.

Type Parameters
Name Description
T

The type for the items in the array.

View Source

Partial<TKey, TValue>(TKey[], TValue[], Int32, Boolean)

Partially orders a collection, making sure every element smaller than the n-th smaller element are in the beginning of the array.

Declaration
public static void Partial<TKey, TValue>(TKey[] keys, TValue[] items, int n, bool asc = true)
    where TKey : IComparable<TKey>
Parameters
Type Name Description
TKey[] keys

The keys that will be used to determine the order of elements in items.

TValue[] items

The array of elements from which the n-th element should be extracted.

System.Int32 n

The position to look for (0 returns the smallest element, 1 the second smallest, and so on).

System.Boolean asc

Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements in the beginning of the array.

Type Parameters
Name Description
TKey

The type for the keys associated with each value in the items array.

TValue

The type for the items in the array.

View Source

Partition<T>(T[], Int32, Int32, Func<T, T, Int32>, Boolean)

Reorders the elements in the range [left, right) in such a way that all elements for which the function compare returns true precede the elements for which compare returns false. Relative order of the elements is not preserved. This function should be equivalent to C++'s std::partition.

Declaration
public static int Partition<T>(this T[] items, int first, int last, Func<T, T, int> compare, bool asc = true)
Parameters
Type Name Description
T[] items

The list to be reordered.

System.Int32 first

The beginning of the range to be reordered.

System.Int32 last

The end of the range to be reordered.

Func<T, T, System.Int32> compare

Function to use in the comparison.

System.Boolean asc

Whether to sort in ascending or descending order.

Returns
Type Description
System.Int32

The index of the new pivot.

Type Parameters
Name Description
T
View Source

Partition<T>(T[], Int32, Int32, Boolean)

Reorders the elements in the range [left, right) in such a way that all elements that are smaller than the pivot precede those that are greater than the pivot. Relative order of the elements is not preserved. This function should be equivalent to C++'s std::partition.

Declaration
public static int Partition<T>(this T[] keys, int first, int last, bool asc = true)
    where T : IComparable<T>
Parameters
Type Name Description
T[] keys

The list to be reordered.

System.Int32 first

The beginning of the range to be reordered.

System.Int32 last

The end of the range to be reordered.

System.Boolean asc

Whether to sort in ascending or descending order.

Returns
Type Description
System.Int32

The index of the new pivot.

Type Parameters
Name Description
T
View Source

Partition<TKey, TValue>(TKey[], TValue[], Int32, Int32, Func<TKey, TKey, Int32>, Boolean)

Reorders the elements in the range [left, right) in such a way that all elements for which the function compare returns true precede the elements for which compare returns false. Relative order of the elements is not preserved. This function should be equivalent to C++'s std::partition.

Declaration
public static int Partition<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, Func<TKey, TKey, int> compare, bool asc = true)
Parameters
Type Name Description
TKey[] keys

The list to be reordered.

TValue[] items

An array of keys associated with each element in the list.

System.Int32 first

The beginning of the range to be reordered.

System.Int32 last

The end of the range to be reordered.

Func<TKey, TKey, System.Int32> compare

Function to use in the comparison.

System.Boolean asc

Whether to sort in ascending or descending order.

Returns
Type Description
System.Int32

The index of the new pivot.

Type Parameters
Name Description
TKey
TValue
View Source

Partition<TKey, TValue>(TKey[], TValue[], Int32, Int32, Boolean)

Reorders the elements in the range [left, right) in such a way that all elements that are smaller than the pivot precede those that are greater than the pivot. Relative order of the elements is not preserved. This function should be equivalent to C++'s std::partition.

Declaration
public static int Partition<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, bool asc = true)
    where TKey : IComparable<TKey>
Parameters
Type Name Description
TKey[] keys

The list to be reordered.

TValue[] items

An array of keys associated with each element in the list.

System.Int32 first

The beginning of the range to be reordered.

System.Int32 last

The end of the range to be reordered.

System.Boolean asc

Whether to sort in ascending or descending order.

Returns
Type Description
System.Int32

The index of the new pivot.

Type Parameters
Name Description
TKey
TValue