From: CryptoManiac Date: Wed, 9 Sep 2015 08:48:04 +0000 (+0300) Subject: IEquatable, IComparable implementation. X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=de7187f5f9fe64925e083512d0ecbc341f877857 IEquatable, IComparable implementation. --- diff --git a/Novacoin/BigNum.cs b/Novacoin/BigNum.cs index e80d26d..af8ae4a 100644 --- a/Novacoin/BigNum.cs +++ b/Novacoin/BigNum.cs @@ -11,7 +11,7 @@ namespace Novacoin /// /// Wrapper for bouncycastle's Biginteger class. /// - public class BigNum + public class BigNum : IComparable, IEquatable { /// /// Internal coby of Biginteger object. @@ -110,6 +110,38 @@ namespace Novacoin } #endregion + #region Comparison operations + public static bool operator <(BigNum a, BigNum b) + { + return a.bn.CompareTo(b.bn) < 0; + } + public static bool operator <=(BigNum a, BigNum b) + { + return a.bn.CompareTo(b.bn) <= 0; + } + + public static bool operator >(BigNum a, BigNum b) + { + return a.bn.CompareTo(b.bn) > 0; + } + + public static bool operator >=(BigNum a, BigNum b) + { + return a.bn.CompareTo(b.bn) >= 0; + } + + public static bool operator ==(BigNum a, BigNum b) + { + return a.bn.CompareTo(b.bn) == 0; + } + + public static bool operator !=(BigNum a, BigNum b) + { + return a.bn.CompareTo(b.bn) != 0; + } + + #endregion + #region Cast operators public static implicit operator BigNum(BigInteger bnValue) { @@ -130,6 +162,37 @@ namespace Novacoin { return (ulong)a.bn.LongValue; } + + public int CompareTo(BigNum other) + { + return bn.CompareTo(other.bn); + } + + public bool Equals(BigNum other) + { + if (object.ReferenceEquals(other, null)) + { + return false; + } + + return this == other; + } + + public override int GetHashCode() + { + return bn.GetHashCode(); + } + + public override bool Equals(object obj) + { + if (object.ReferenceEquals(obj, null)) + { + return false; + } + + return this == (obj as BigNum); + } + #endregion } }