Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Core / System / Linq / Parallel / Utils / PairComparer.cs
1 // ==++==
2 //
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
7 //
8 // PairComparer.cs
9 //
10 // <OWNER>Microsoft</OWNER>
11 //
12 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
13
14 using System.Collections.Generic;
15
16 namespace System.Linq.Parallel
17 {
18     /// <summary>
19     /// PairComparer compares pairs by the first element, and breaks ties by the second
20     /// element.
21     /// </summary>
22     /// <typeparam name="T"></typeparam>
23     /// <typeparam name="U"></typeparam>
24     internal class PairComparer<T, U> : IComparer<Pair<T, U>>
25     {
26         private IComparer<T> m_comparer1;
27         private IComparer<U> m_comparer2;
28
29         public PairComparer(IComparer<T> comparer1, IComparer<U> comparer2)
30         {
31             m_comparer1 = comparer1;
32             m_comparer2 = comparer2;
33         }
34
35         public int Compare(Pair<T, U> x, Pair<T, U> y)
36         {
37             int result1 = m_comparer1.Compare(x.First, y.First);
38             if (result1 != 0) 
39             {
40                 return result1;
41             }
42
43             return m_comparer2.Compare(x.Second, y.Second);
44         }
45     }
46 }