1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
|
/*
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<char>
{
public int Compare(char item1, char item2) {
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type char, also known as System.Char.
/// </summary>
public class CharEqualityComparer : SCG.IEqualityComparer<char>
{
static CharEqualityComparer cached = new CharEqualityComparer();
CharEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
public static CharEqualityComparer Default { get { return cached ?? (cached = new CharEqualityComparer()); } }
/// <summary>
/// Get the hash code of this char
/// </summary>
/// <param name="item">The char</param>
/// <returns>The same</returns>
public int GetHashCode(char item) { return item.GetHashCode(); }
/// <summary>
/// Check if two chars are equal
/// </summary>
/// <param name="item1">first char</param>
/// <param name="item2">second char</param>
/// <returns>True if equal</returns>
public bool Equals(char item1, char item2) { return item1 == item2; }
}
#endregion
#region sbyte comparer and equality comparer
[Serializable]
class SByteComparer : SCG.IComparer<sbyte>
{
[Tested]
public int Compare(sbyte item1, sbyte item2) {
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type sbyte, also known as System.SByte.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.SByteEqualityComparer.Default"/> property</para>
/// </summary>
[Serializable]
public class SByteEqualityComparer : SCG.IEqualityComparer<sbyte>
{
static SByteEqualityComparer cached;
SByteEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static SByteEqualityComparer Default { get { return cached ?? (cached = new SByteEqualityComparer()); } }
/// <summary>
/// Get the hash code of this sbyte, that is, itself
/// </summary>
/// <param name="item">The sbyte</param>
/// <returns>The same</returns>
[Tested]
public int GetHashCode(sbyte item) { return item.GetHashCode(); }
/// <summary>
/// Determine whether two sbytes are equal
/// </summary>
/// <param name="item1">first sbyte</param>
/// <param name="item2">second sbyte</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(sbyte item1, sbyte item2) { return item1 == item2; }
}
#endregion
#region byte comparer and equality comparer
class ByteComparer : SCG.IComparer<byte>
{
public int Compare(byte item1, byte item2) {
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type byte, also known as System.Byte.
/// <para>This class is a singleton and the instance can be accessed
/// via the <see cref="P:C5.ByteEqualityComparer.Default"/> property</para>
/// </summary>
public class ByteEqualityComparer : SCG.IEqualityComparer<byte>
{
static ByteEqualityComparer cached = new ByteEqualityComparer();
ByteEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
public static ByteEqualityComparer Default { get { return cached ?? (cached = new ByteEqualityComparer()); } }
/// <summary>
/// Get the hash code of this byte, i.e. itself
/// </summary>
/// <param name="item">The byte</param>
/// <returns>The same</returns>
public int GetHashCode(byte item) { return item.GetHashCode(); }
/// <summary>
/// Check if two bytes are equal
/// </summary>
/// <param name="item1">first byte</param>
/// <param name="item2">second byte</param>
/// <returns>True if equal</returns>
public bool Equals(byte item1, byte item2) { return item1 == item2; }
}
#endregion
#region short comparer and equality comparer
[Serializable]
class ShortComparer : SCG.IComparer<short>
{
[Tested]
public int Compare(short item1, short item2) {
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type short, also known as System.Int16.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.ShortEqualityComparer.Default"/> property</para>
/// </summary>
[Serializable]
public class ShortEqualityComparer : SCG.IEqualityComparer<short>
{
static ShortEqualityComparer cached;
ShortEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static ShortEqualityComparer Default { get { return cached ?? (cached = new ShortEqualityComparer()); } }
/// <summary>
/// Get the hash code of this short, that is, itself
/// </summary>
/// <param name="item">The short</param>
/// <returns>The same</returns>
[Tested]
public int GetHashCode(short item) { return item.GetHashCode(); }
/// <summary>
/// Determine whether two shorts are equal
/// </summary>
/// <param name="item1">first short</param>
/// <param name="item2">second short</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(short item1, short item2) { return item1 == item2; }
}
#endregion
#region ushort comparer and equality comparer
[Serializable]
class UShortComparer : SCG.IComparer<ushort>
{
[Tested]
public int Compare(ushort item1, ushort item2)
{
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type ushort, also known as System.UInt16.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.UShortEqualityComparer.Default"/> property</para>
/// </summary>
[Serializable]
public class UShortEqualityComparer : SCG.IEqualityComparer<ushort>
{
static UShortEqualityComparer cached;
UShortEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static UShortEqualityComparer Default { get { return cached ?? (cached = new UShortEqualityComparer()); } }
/// <summary>
/// Get the hash code of this ushort, that is, itself
/// </summary>
/// <param name="item">The ushort</param>
/// <returns>The same</returns>
[Tested]
public int GetHashCode(ushort item) { return item.GetHashCode(); }
/// <summary>
/// Determine whether two ushorts are equal
/// </summary>
/// <param name="item1">first ushort</param>
/// <param name="item2">second ushort</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(ushort item1, ushort item2) { return item1 == item2; }
}
#endregion
#region int comparer and equality comparer
[Serializable]
class IntComparer : SCG.IComparer<int>
{
[Tested]
public int Compare(int item1, int item2) {
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type int, also known as System.Int32.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.IntEqualityComparer.Default"/> property</para>
/// </summary>
[Serializable]
public class IntEqualityComparer : SCG.IEqualityComparer<int>
{
static IntEqualityComparer cached;
IntEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static IntEqualityComparer Default { get { return cached ?? (cached = new IntEqualityComparer()); } }
/// <summary>
/// Get the hash code of this integer, that is, itself
/// </summary>
/// <param name="item">The integer</param>
/// <returns>The same</returns>
[Tested]
public int GetHashCode(int item) { return item; }
/// <summary>
/// Determine whether two integers are equal
/// </summary>
/// <param name="item1">first integer</param>
/// <param name="item2">second integer</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(int item1, int item2) { return item1 == item2; }
}
#endregion
#region uint comparer and equality comparer
[Serializable]
class UIntComparer : SCG.IComparer<uint>
{
[Tested]
public int Compare(uint item1, uint item2)
{
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type uint, also known as System.UInt32.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.UIntEqualityComparer.Default"/> property</para>
/// </summary>
[Serializable]
public class UIntEqualityComparer : SCG.IEqualityComparer<uint>
{
static UIntEqualityComparer cached;
UIntEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static UIntEqualityComparer Default { get { return cached ?? (cached = new UIntEqualityComparer()); } }
/// <summary>
/// Get the hash code of this unsigned integer
/// </summary>
/// <param name="item">The integer</param>
/// <returns>The same bit pattern as a signed integer</returns>
[Tested]
public int GetHashCode(uint item) { return item.GetHashCode(); }
/// <summary>
/// Determine whether two unsigned integers are equal
/// </summary>
/// <param name="item1">first unsigned integer</param>
/// <param name="item2">second unsigned integer</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(uint item1, uint item2) { return item1 == item2; }
}
#endregion
#region long comparer and equality comparer
[Serializable]
class LongComparer : SCG.IComparer<long>
{
[Tested]
public int Compare(long item1, long item2)
{
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type long, also known as System.Int64.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.LongEqualityComparer.Default"/> property</para>
/// </summary>
[Serializable]
public class LongEqualityComparer : SCG.IEqualityComparer<long>
{
static LongEqualityComparer cached;
LongEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static LongEqualityComparer Default { get { return cached ?? (cached = new LongEqualityComparer()); } }
/// <summary>
/// Get the hash code of this long integer
/// </summary>
/// <param name="item">The long integer</param>
/// <returns>The hash code</returns>
[Tested]
public int GetHashCode(long item) { return item.GetHashCode(); }
/// <summary>
/// Determine whether two long integers are equal
/// </summary>
/// <param name="item1">first long integer</param>
/// <param name="item2">second long integer</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(long item1, long item2) { return item1 == item2; }
}
#endregion
#region ulong comparer and equality comparer
[Serializable]
class ULongComparer : SCG.IComparer<ulong>
{
[Tested]
public int Compare(ulong item1, ulong item2)
{
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type uint, also known as System.UInt64.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.ULongEqualityComparer.Default"/> property</para>
/// </summary>
[Serializable]
public class ULongEqualityComparer : SCG.IEqualityComparer<ulong>
{
static ULongEqualityComparer cached;
ULongEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static ULongEqualityComparer Default { get { return cached ?? (cached = new ULongEqualityComparer()); } }
/// <summary>
/// Get the hash code of this unsigned long integer
/// </summary>
/// <param name="item">The unsigned long integer</param>
/// <returns>The hash code</returns>
[Tested]
public int GetHashCode(ulong item) { return item.GetHashCode(); }
/// <summary>
/// Determine whether two unsigned long integers are equal
/// </summary>
/// <param name="item1">first unsigned long integer</param>
/// <param name="item2">second unsigned long integer</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(ulong item1, ulong item2) { return item1 == item2; }
}
#endregion
#region float comparer and equality comparer
class FloatComparer : SCG.IComparer<float>
{
public int Compare(float item1, float item2)
{
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type float, also known as System.Single.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.FloatEqualityComparer.Default"/> property</para>
/// </summary>
public class FloatEqualityComparer : SCG.IEqualityComparer<float>
{
static FloatEqualityComparer cached;
FloatEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static FloatEqualityComparer Default { get { return cached ?? (cached = new FloatEqualityComparer()); } }
/// <summary>
/// Get the hash code of this float
/// </summary>
/// <param name="item">The float</param>
/// <returns>The same</returns>
[Tested]
public int GetHashCode(float item) { return item.GetHashCode(); }
/// <summary>
/// Check if two floats are equal
/// </summary>
/// <param name="item1">first float</param>
/// <param name="item2">second float</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(float item1, float item2) { return item1 == item2; }
}
#endregion
#region double comparer and equality comparer
class DoubleComparer : SCG.IComparer<double>
{
public int Compare(double item1, double item2) {
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type double, also known as System.Double.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.DoubleEqualityComparer.Default"/> property</para>
/// </summary>
public class DoubleEqualityComparer : SCG.IEqualityComparer<double>
{
static DoubleEqualityComparer cached;
DoubleEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static DoubleEqualityComparer Default { get { return cached ?? (cached = new DoubleEqualityComparer()); } }
/// <summary>
/// Get the hash code of this double
/// </summary>
/// <param name="item">The double</param>
/// <returns>The same</returns>
[Tested]
public int GetHashCode(double item) { return item.GetHashCode(); }
/// <summary>
/// Check if two doubles are equal
/// </summary>
/// <param name="item1">first double</param>
/// <param name="item2">second double</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(double item1, double item2) { return item1 == item2; }
}
#endregion
#region decimal comparer and equality comparer
[Serializable]
class DecimalComparer : SCG.IComparer<decimal>
{
[Tested]
public int Compare(decimal item1, decimal item2)
{
return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
}
}
/// <summary>
/// An equality comparer for type decimal, also known as System.Decimal.
/// <para>This class is a singleton and the instance can be accessed
/// via the static <see cref="P:C5.DecimalEqualityComparer.Default"/> property</para>
/// </summary>
[Serializable]
public class DecimalEqualityComparer : SCG.IEqualityComparer<decimal>
{
static DecimalEqualityComparer cached;
DecimalEqualityComparer() { }
/// <summary>
///
/// </summary>
/// <value></value>
[Tested]
public static DecimalEqualityComparer Default { get { return cached ?? (cached = new DecimalEqualityComparer()); } }
/// <summary>
/// Get the hash code of this decimal.
/// </summary>
/// <param name="item">The decimal</param>
/// <returns>The hash code</returns>
[Tested]
public int GetHashCode(decimal item) { return item.GetHashCode(); }
/// <summary>
/// Determine whether two decimals are equal
/// </summary>
/// <param name="item1">first decimal</param>
/// <param name="item2">second decimal</param>
/// <returns>True if equal</returns>
[Tested]
public bool Equals(decimal item1, decimal item2) { return item1 == item2; }
}
#endregion
}
|