Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MergeSort.cs « Sorting « Common « tools « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7faf01aeafb5b885bb2f76fde408bf7f41c00ff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using ILCompiler.Sorting.Implementation;

namespace ILCompiler
{
    public static class MergeSortApi
    {
        // Parallel sorting api which will sort in parallel when appropriate
        public static void MergeSort<T>(this List<T> listToSort, Comparison<T> comparison)
        {
            MergeSortCore<T, List<T>, ListAccessor<T>, ComparisonWrapper<T>, RequireTotalOrderAssert>.ParallelSortApi(listToSort, new ComparisonWrapper<T>(comparison));
        }

        // Parallel sorting api which will sort in parallel when appropriate
        public static void MergeSortAllowDuplicates<T>(this List<T> listToSort, Comparison<T> comparison)
        {
            MergeSortCore<T, List<T>, ListAccessor<T>, ComparisonWrapper<T>, AllowDuplicates>.ParallelSortApi(listToSort, new ComparisonWrapper<T>(comparison));
        }

        // Parallel sorting api which will sort in parallel when appropriate
        public static void MergeSort<T>(this List<T> listToSort, IComparer<T> comparer)
        {
            MergeSortCore<T, List<T>, ListAccessor<T>, IComparer<T>, RequireTotalOrderAssert>.ParallelSortApi(listToSort, comparer);
        }

        // Parallel sorting api which will sort in parallel when appropriate
        public static void MergeSortAllowDuplicates<T>(this List<T> listToSort, IComparer<T> comparer)
        {
            MergeSortCore<T, List<T>, ListAccessor<T>, IComparer<T>, AllowDuplicates>.ParallelSortApi(listToSort, comparer);
        }

        // Parallel sorting api which will sort in parallel when appropriate
        public static void MergeSort<T>(this T[] arrayToSort, Comparison<T> comparison)
        {
            MergeSortCore<T, T[], ArrayAccessor<T>, ComparisonWrapper<T>, RequireTotalOrderAssert>.ParallelSortApi(arrayToSort, new ComparisonWrapper<T>(comparison));
        }

        // Parallel sorting api which will sort in parallel when appropriate
        public static void MergeSortAllowDuplicates<T>(this T[] arrayToSort, Comparison<T> comparison)
        {
            MergeSortCore<T, T[], ArrayAccessor<T>, ComparisonWrapper<T>, AllowDuplicates>.ParallelSortApi(arrayToSort, new ComparisonWrapper<T>(comparison));
        }

        // Parallel sorting api which will sort in parallel when appropriate
        public static void MergeSort<T>(this T[] arrayToSort, IComparer<T> comparer)
        {
            MergeSortCore<T, T[], ArrayAccessor<T>, IComparer<T>, RequireTotalOrderAssert>.ParallelSortApi(arrayToSort, comparer);
        }

        // Parallel sorting api which will sort in parallel when appropriate
        public static void MergeSortAllowDuplicates<T>(this T[] arrayToSort, IComparer<T> comparer)
        {
            MergeSortCore<T, T[], ArrayAccessor<T>, IComparer<T>, AllowDuplicates>.ParallelSortApi(arrayToSort, comparer);
        }


        // Internal helper struct used to enable use of Comparison<T> delegates instead of IComparer<T> instances
        private struct ComparisonWrapper<T> : IComparer<T>
        {
            private Comparison<T> _comparison;
            public ComparisonWrapper(Comparison<T> comparison)
            {
                _comparison = comparison;
            }
            int IComparer<T>.Compare(T x, T y)
            {
                return _comparison(x, y);
            }
        }
    }
}