| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | |
| | | 5 | | namespace NanoCLang.Entities { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Provides a class for comparing two heap objects, or rather collections of location bindings. |
| | | 8 | | /// </summary> |
| | | 9 | | public class HeapComparer : IEqualityComparer<IDictionary<Location, BlockType[]>> { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Provides the default instance of a heap comparer. |
| | | 12 | | /// </summary> |
| | 70 | 13 | | public static HeapComparer Default { get; } = new HeapComparer(); |
| | | 14 | | /// <inheritdoc cref="IEqualityComparer{T}.Equals(T, T)"/> |
| | 142 | 15 | | public bool Equals(IDictionary<Location, BlockType[]> x, IDictionary<Location, BlockType[]> y) => x.Count == y.C |
| | | 16 | | /// <inheritdoc cref="IEqualityComparer{T}.GetHashCode(T)"/> |
| | 0 | 17 | | public int GetHashCode(IDictionary<Location, BlockType[]> obj) { |
| | 0 | 18 | | var hash = new HashCode(); |
| | 0 | 19 | | foreach (var item in obj) { |
| | 0 | 20 | | hash.Add(item.Key); |
| | 0 | 21 | | foreach (var block in item.Value) hash.Add(block); |
| | 0 | 22 | | } |
| | 0 | 23 | | return hash.ToHashCode(); |
| | 0 | 24 | | } |
| | | 25 | | } |
| | | 26 | | } |