#if NET_2_0 /* 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 int stuff [Serializable] class IntComparer : SCG.IComparer { [Tested] public int Compare(int a, int b) { return a > b ? 1 : a < b ? -1 : 0; } } /// /// An equalityComparer for System.Int32 integers. /// 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 int1, int int2) { return int1 == int2; } } #endregion #region double stuff class DoubleComparer : SCG.IComparer { public int Compare(double a, double b) { return a > b ? 1 : a < b ? -1 : 0; } } /// /// An equalityComparer for 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 byte stuff class ByteComparer : SCG.IComparer { public int Compare(byte a, byte b) { return a > b ? 1 : a < b ? -1 : 0; } } /// /// An equalityComparer for 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; } /// /// 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 char stuff class CharComparer : SCG.IComparer { public int Compare(char a, char b) { return a > b ? 1 : a < b ? -1 : 0; } } /// /// An equalityComparer for 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 } #endif