| | 1 | | using System.Collections.Generic; |
| | 2 | |
|
| | 3 | | namespace Itinero.Indexes; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// An equality comparer to compare attribute sets. |
| | 7 | | /// </summary> |
| | 8 | | /// <remarks> |
| | 9 | | /// - Doesn't care about the order of attributes. |
| | 10 | | /// </remarks> |
| | 11 | | public class AttributeSetEqualityComparer : IEqualityComparer<IReadOnlyList<(string key, string value)>> |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// The default comparer. |
| | 15 | | /// </summary> |
| 1 | 16 | | public static readonly AttributeSetEqualityComparer Default = new(); |
| | 17 | |
|
| | 18 | | /// <inheritdoc/> |
| | 19 | | public bool Equals(IReadOnlyList<(string key, string value)> x, |
| | 20 | | IReadOnlyList<(string key, string value)> y) |
| 108 | 21 | | { |
| 108 | 22 | | if (x.Count != y.Count) |
| 0 | 23 | | { |
| 0 | 24 | | return false; |
| | 25 | | } |
| | 26 | |
|
| 234 | 27 | | for (var i = 0; i < x.Count; i++) |
| 9 | 28 | | { |
| 9 | 29 | | var xPair = x[i]; |
| 9 | 30 | | var yPair = y[i]; |
| | 31 | |
|
| 9 | 32 | | if (xPair != yPair) |
| 0 | 33 | | { |
| 0 | 34 | | return false; |
| | 35 | | } |
| 9 | 36 | | } |
| | 37 | |
|
| 108 | 38 | | return true; |
| 108 | 39 | | } |
| | 40 | |
|
| | 41 | | /// <inheritdoc/> |
| | 42 | | public int GetHashCode(IReadOnlyList<(string key, string value)> obj) |
| 466 | 43 | | { |
| 466 | 44 | | var hash = obj.Count.GetHashCode(); |
| | 45 | |
|
| 1504 | 46 | | foreach (var pair in obj) |
| 53 | 47 | | { |
| 53 | 48 | | hash ^= pair.GetHashCode(); |
| 53 | 49 | | } |
| | 50 | |
|
| 466 | 51 | | return hash; |
| 466 | 52 | | } |
| | 53 | | } |