| | | 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) |
| | 115 | 21 | | { |
| | 115 | 22 | | if (x.Count != y.Count) |
| | 0 | 23 | | { |
| | 0 | 24 | | return false; |
| | | 25 | | } |
| | | 26 | | |
| | 248 | 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 | | |
| | 115 | 38 | | return true; |
| | 115 | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <inheritdoc/> |
| | | 42 | | public int GetHashCode(IReadOnlyList<(string key, string value)> obj) |
| | 509 | 43 | | { |
| | 509 | 44 | | var hash = obj.Count.GetHashCode(); |
| | | 45 | | |
| | 1633 | 46 | | foreach (var pair in obj) |
| | 53 | 47 | | { |
| | 53 | 48 | | hash ^= pair.GetHashCode(); |
| | 53 | 49 | | } |
| | | 50 | | |
| | 509 | 51 | | return hash; |
| | 509 | 52 | | } |
| | | 53 | | } |