ParallelHelperSortAsyncTKeyFrom, TKeyTo, TValueFrom, TValueTo(CastArrayTKeyFrom, TKeyTo, CastArrayTValueFrom, TValueTo, IComparerTKeyTo, TaskConfig) Method

Sorts the elements in a pair of CastArrayTFrom, TTo instances asynchronously (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 Task<bool> SortAsync<TKeyFrom, TKeyTo, TValueFrom, TValueTo>(
	CastArray<TKeyFrom, TKeyTo> keys,
	CastArray<TValueFrom, TValueTo> values,
	IComparer<TKeyTo>? comparer = null,
	TaskConfig? asyncConfig = 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: .
asyncConfig  TaskConfig  (Optional)
An optional configuration to adjust parallelization or cancellation. Reporting progress is not supported in sorting methods. 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.

Return Value

TaskBoolean
A task that represents the asynchronous operation. Its result is , if the operation completed successfully, or , if the operation has been canceled and ThrowIfCanceled in asyncConfig parameter was .

Remarks

This method is not a blocking call even if the MaxDegreeOfParallelism property of the asyncConfig parameter is 1.

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.
TaskCanceledExceptionThe operation has been canceled and ThrowIfCanceled in asyncConfig was . This exception is thrown when the result is awaited.

See Also