ParallelHelperSortTKeyFrom, TKeyTo, TValueFrom, TValueTo(CastArrayTKeyFrom, TKeyTo, CastArrayTValueFrom, TValueTo, IComparerTKeyTo) Method

Sorts the elements in a pair of CastArrayTFrom, TTo instances synchronously (one contains the keys, the other contains the corresponding values), potentially using multiple threads.

Definition

Namespace: KGySoft.Threading
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.5.0
C#
public static void Sort<TKeyFrom, TKeyTo, TValueFrom, TValueTo>(
	CastArray<TKeyFrom, TKeyTo> keys,
	CastArray<TValueFrom, TValueTo> values,
	IComparer<TKeyTo>? comparer = null
)
where TKeyFrom : struct, new()
where TKeyTo : struct, new()
where TValueFrom : struct, new()
where TValueTo : struct, new()

Parameters

keys  CastArrayTKeyFrom, TKeyTo
The CastArrayTFrom, TTo that contains the keys to sort.
values  CastArrayTValueFrom, TValueTo
The CastArrayTFrom, TTo that contains the values that correspond to the keys in the keys collection. If the IsNull property of values is , then only the keys are sorted.
comparer  IComparerTKeyTo  (Optional)
The IComparerT implementation to use when comparing elements, or to use a default comparer. This parameter is optional.
Default value: .

Type Parameters

TKeyFrom
The actual element type of the underlying array in keys.
TKeyTo
The reinterpreted element type of the CastArrayTFrom, TTo instance in keys.
TValueFrom
The actual element type of the underlying array in values.
TValueTo
The reinterpreted element type of the CastArrayTFrom, TTo instance in values.

Remarks

  Note

This method adjusts the degree of parallelization automatically, blocks the caller, and does not support cancellation. Use the overloads with a ParallelConfig parameter to adjust parallelization and to set up cancellation; or the BeginSort/SortAsync (in .NET Framework 4.0 and above) methods to perform the sorting asynchronously.

Exceptions

ArgumentExceptionThe IsNull property of values is and values has fewer elements than keys.
-or-
The comparer returned inconsistent results.
InvalidOperationExceptioncomparer is , and an element does not implement the IComparableT interface.

See Also