using System.Collections.Generic; namespace BizHawk.Client.Common { /// /// This class hold a collection /// Different memory domain can be mixed /// public sealed partial class WatchList { /// /// Netsed private class that define how to compare two /// based on their address /// private struct WatchAddressComparer : IEqualityComparer, IComparer { /// /// Compare two between them /// and determine wich one comes first. /// If they are equals, comapraison will done one the domain and next on size /// /// First /// True if are equal; otherwise, false /// public int Compare(Watch x, Watch y) { if (Equals(x, y)) { return 0; } else if (x.Address.Equals(y.Address)) { if (x.Domain.Name.Equals(y.Domain.Name)) { return x.Size.CompareTo(y.Size); } else { return x.Domain.Name.CompareTo(y.Domain.Name); } } else { return x.Address.CompareTo(y.Address); } } /// /// Determine if two are equals /// /// First /// Second /// True if are equal; otherwise, false public bool Equals(Watch x, Watch y) { if (object.ReferenceEquals(x, null)) { if (object.ReferenceEquals(y, null)) { return true; } else { return false; } } else if (object.ReferenceEquals(y, null)) { return false; } else if (object.ReferenceEquals(x, y)) { return true; } else { return x.Address.Equals(y.Address); } } /// /// Get the hash value of specified /// /// Watch to get hash /// int that can serves as a unique representation of current Watch public int GetHashCode(Watch obj) { return obj.GetHashCode(); } } } }