/* Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; using System.Diagnostics; using SCG = System.Collections.Generic; namespace C5 { #region char comparer and equality comparer class CharComparer : SCG.IComparer { public int Compare(char item1, char item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type char, also known as System.Char. /// public class CharEqualityComparer : SCG.IEqualityComparer { static CharEqualityComparer cached = new CharEqualityComparer(); CharEqualityComparer() { } /// /// /// /// public static CharEqualityComparer Default { get { return cached ?? (cached = new CharEqualityComparer()); } } /// /// Get the hash code of this char /// /// The char /// The same public int GetHashCode(char item) { return item.GetHashCode(); } /// /// Check if two chars are equal /// /// first char /// second char /// True if equal public bool Equals(char item1, char item2) { return item1 == item2; } } #endregion #region sbyte comparer and equality comparer [Serializable] class SByteComparer : SCG.IComparer { [Tested] public int Compare(sbyte item1, sbyte item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type sbyte, also known as System.SByte. /// This class is a singleton and the instance can be accessed /// via the static property /// [Serializable] public class SByteEqualityComparer : SCG.IEqualityComparer { static SByteEqualityComparer cached; SByteEqualityComparer() { } /// /// /// /// [Tested] public static SByteEqualityComparer Default { get { return cached ?? (cached = new SByteEqualityComparer()); } } /// /// Get the hash code of this sbyte, that is, itself /// /// The sbyte /// The same [Tested] public int GetHashCode(sbyte item) { return item.GetHashCode(); } /// /// Determine whether two sbytes are equal /// /// first sbyte /// second sbyte /// True if equal [Tested] public bool Equals(sbyte item1, sbyte item2) { return item1 == item2; } } #endregion #region byte comparer and equality comparer class ByteComparer : SCG.IComparer { public int Compare(byte item1, byte item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type byte, also known as System.Byte. /// This class is a singleton and the instance can be accessed /// via the property /// public class ByteEqualityComparer : SCG.IEqualityComparer { static ByteEqualityComparer cached = new ByteEqualityComparer(); ByteEqualityComparer() { } /// /// /// /// public static ByteEqualityComparer Default { get { return cached ?? (cached = new ByteEqualityComparer()); } } /// /// Get the hash code of this byte, i.e. itself /// /// The byte /// The same public int GetHashCode(byte item) { return item.GetHashCode(); } /// /// Check if two bytes are equal /// /// first byte /// second byte /// True if equal public bool Equals(byte item1, byte item2) { return item1 == item2; } } #endregion #region short comparer and equality comparer [Serializable] class ShortComparer : SCG.IComparer { [Tested] public int Compare(short item1, short item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type short, also known as System.Int16. /// This class is a singleton and the instance can be accessed /// via the static property /// [Serializable] public class ShortEqualityComparer : SCG.IEqualityComparer { static ShortEqualityComparer cached; ShortEqualityComparer() { } /// /// /// /// [Tested] public static ShortEqualityComparer Default { get { return cached ?? (cached = new ShortEqualityComparer()); } } /// /// Get the hash code of this short, that is, itself /// /// The short /// The same [Tested] public int GetHashCode(short item) { return item.GetHashCode(); } /// /// Determine whether two shorts are equal /// /// first short /// second short /// True if equal [Tested] public bool Equals(short item1, short item2) { return item1 == item2; } } #endregion #region ushort comparer and equality comparer [Serializable] class UShortComparer : SCG.IComparer { [Tested] public int Compare(ushort item1, ushort item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type ushort, also known as System.UInt16. /// This class is a singleton and the instance can be accessed /// via the static property /// [Serializable] public class UShortEqualityComparer : SCG.IEqualityComparer { static UShortEqualityComparer cached; UShortEqualityComparer() { } /// /// /// /// [Tested] public static UShortEqualityComparer Default { get { return cached ?? (cached = new UShortEqualityComparer()); } } /// /// Get the hash code of this ushort, that is, itself /// /// The ushort /// The same [Tested] public int GetHashCode(ushort item) { return item.GetHashCode(); } /// /// Determine whether two ushorts are equal /// /// first ushort /// second ushort /// True if equal [Tested] public bool Equals(ushort item1, ushort item2) { return item1 == item2; } } #endregion #region int comparer and equality comparer [Serializable] class IntComparer : SCG.IComparer { [Tested] public int Compare(int item1, int item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type int, also known as System.Int32. /// This class is a singleton and the instance can be accessed /// via the static property /// [Serializable] public class IntEqualityComparer : SCG.IEqualityComparer { static IntEqualityComparer cached; IntEqualityComparer() { } /// /// /// /// [Tested] public static IntEqualityComparer Default { get { return cached ?? (cached = new IntEqualityComparer()); } } /// /// Get the hash code of this integer, that is, itself /// /// The integer /// The same [Tested] public int GetHashCode(int item) { return item; } /// /// Determine whether two integers are equal /// /// first integer /// second integer /// True if equal [Tested] public bool Equals(int item1, int item2) { return item1 == item2; } } #endregion #region uint comparer and equality comparer [Serializable] class UIntComparer : SCG.IComparer { [Tested] public int Compare(uint item1, uint item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type uint, also known as System.UInt32. /// This class is a singleton and the instance can be accessed /// via the static property /// [Serializable] public class UIntEqualityComparer : SCG.IEqualityComparer { static UIntEqualityComparer cached; UIntEqualityComparer() { } /// /// /// /// [Tested] public static UIntEqualityComparer Default { get { return cached ?? (cached = new UIntEqualityComparer()); } } /// /// Get the hash code of this unsigned integer /// /// The integer /// The same bit pattern as a signed integer [Tested] public int GetHashCode(uint item) { return item.GetHashCode(); } /// /// Determine whether two unsigned integers are equal /// /// first unsigned integer /// second unsigned integer /// True if equal [Tested] public bool Equals(uint item1, uint item2) { return item1 == item2; } } #endregion #region long comparer and equality comparer [Serializable] class LongComparer : SCG.IComparer { [Tested] public int Compare(long item1, long item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type long, also known as System.Int64. /// This class is a singleton and the instance can be accessed /// via the static property /// [Serializable] public class LongEqualityComparer : SCG.IEqualityComparer { static LongEqualityComparer cached; LongEqualityComparer() { } /// /// /// /// [Tested] public static LongEqualityComparer Default { get { return cached ?? (cached = new LongEqualityComparer()); } } /// /// Get the hash code of this long integer /// /// The long integer /// The hash code [Tested] public int GetHashCode(long item) { return item.GetHashCode(); } /// /// Determine whether two long integers are equal /// /// first long integer /// second long integer /// True if equal [Tested] public bool Equals(long item1, long item2) { return item1 == item2; } } #endregion #region ulong comparer and equality comparer [Serializable] class ULongComparer : SCG.IComparer { [Tested] public int Compare(ulong item1, ulong item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type uint, also known as System.UInt64. /// This class is a singleton and the instance can be accessed /// via the static property /// [Serializable] public class ULongEqualityComparer : SCG.IEqualityComparer { static ULongEqualityComparer cached; ULongEqualityComparer() { } /// /// /// /// [Tested] public static ULongEqualityComparer Default { get { return cached ?? (cached = new ULongEqualityComparer()); } } /// /// Get the hash code of this unsigned long integer /// /// The unsigned long integer /// The hash code [Tested] public int GetHashCode(ulong item) { return item.GetHashCode(); } /// /// Determine whether two unsigned long integers are equal /// /// first unsigned long integer /// second unsigned long integer /// True if equal [Tested] public bool Equals(ulong item1, ulong item2) { return item1 == item2; } } #endregion #region float comparer and equality comparer class FloatComparer : SCG.IComparer { public int Compare(float item1, float item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type float, also known as System.Single. /// This class is a singleton and the instance can be accessed /// via the static property /// public class FloatEqualityComparer : SCG.IEqualityComparer { static FloatEqualityComparer cached; FloatEqualityComparer() { } /// /// /// /// [Tested] public static FloatEqualityComparer Default { get { return cached ?? (cached = new FloatEqualityComparer()); } } /// /// Get the hash code of this float /// /// The float /// The same [Tested] public int GetHashCode(float item) { return item.GetHashCode(); } /// /// Check if two floats are equal /// /// first float /// second float /// True if equal [Tested] public bool Equals(float item1, float item2) { return item1 == item2; } } #endregion #region double comparer and equality comparer class DoubleComparer : SCG.IComparer { public int Compare(double item1, double item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type double, also known as System.Double. /// This class is a singleton and the instance can be accessed /// via the static property /// public class DoubleEqualityComparer : SCG.IEqualityComparer { static DoubleEqualityComparer cached; DoubleEqualityComparer() { } /// /// /// /// [Tested] public static DoubleEqualityComparer Default { get { return cached ?? (cached = new DoubleEqualityComparer()); } } /// /// Get the hash code of this double /// /// The double /// The same [Tested] public int GetHashCode(double item) { return item.GetHashCode(); } /// /// Check if two doubles are equal /// /// first double /// second double /// True if equal [Tested] public bool Equals(double item1, double item2) { return item1 == item2; } } #endregion #region decimal comparer and equality comparer [Serializable] class DecimalComparer : SCG.IComparer { [Tested] public int Compare(decimal item1, decimal item2) { return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; } } /// /// An equality comparer for type decimal, also known as System.Decimal. /// This class is a singleton and the instance can be accessed /// via the static property /// [Serializable] public class DecimalEqualityComparer : SCG.IEqualityComparer { static DecimalEqualityComparer cached; DecimalEqualityComparer() { } /// /// /// /// [Tested] public static DecimalEqualityComparer Default { get { return cached ?? (cached = new DecimalEqualityComparer()); } } /// /// Get the hash code of this decimal. /// /// The decimal /// The hash code [Tested] public int GetHashCode(decimal item) { return item.GetHashCode(); } /// /// Determine whether two decimals are equal /// /// first decimal /// second decimal /// True if equal [Tested] public bool Equals(decimal item1, decimal item2) { return item1 == item2; } } #endregion }