return _hashBytes.SequenceEqual((byte[])item);
}
+ public override bool Equals(object o)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override int GetHashCode()
+ {
+ throw new NotSupportedException();
+ }
+
public int CompareTo(Hash item)
{
Contract.Requires<ArgumentException>(item.hashSize == hashSize, "Hashes must have the same size.");
{
Contract.Requires<ArgumentException>(a.hashSize == b.hashSize, "Hashes must have the same size.");
- for (int i = a.hashSize; i >= 0; i--)
+ for (int i = a.hashSize - 1; i >= 0; i--)
{
if (a._hashBytes[i] < b._hashBytes[i])
return true;
{
Contract.Requires<ArgumentException>(a.hashSize == b.hashSize, "Hashes must have the same size.");
- for (int i = a.hashSize; i >= 0; i--)
+ for (int i = a.hashSize - 1; i >= 0; i--)
{
if (a._hashBytes[i] < b._hashBytes[i])
return true;
{
Contract.Requires<ArgumentException>(a.hashSize == b.hashSize, "Hashes must have the same size.");
- for (int i = a.hashSize; i >= 0; i--)
+ for (int i = a.hashSize - 1; i >= 0; i--)
{
if (a._hashBytes[i] > b._hashBytes[i])
return true;
{
Contract.Requires<ArgumentException>(a.hashSize == b.hashSize, "Hashes must have the same size.");
- for (int i = a.hashSize; i >= 0; i--)
+ for (int i = a.hashSize - 1; i >= 0; i--)
{
if (a._hashBytes[i] > b._hashBytes[i])
return true;
return true;
}
+ public static bool operator ==(Hash a, Hash b)
+ {
+ Contract.Requires<ArgumentException>(a.hashSize == b.hashSize, "Hashes must have the same size.");
+
+ return a._hashBytes.SequenceEqual(b._hashBytes);
+ }
+
+ public static bool operator !=(Hash a, Hash b)
+ {
+ Contract.Requires<ArgumentException>(a.hashSize == b.hashSize, "Hashes must have the same size.");
+
+ return !a._hashBytes.SequenceEqual(b._hashBytes);
+ }
+
public override string ToString()
{
return Interop.ToHex(Interop.ReverseBytes(_hashBytes));
keyStore.ResetPool();
Console.WriteLine("Done in {0} ms.", watch.ElapsedMilliseconds);
+ Console.WriteLine("Hash comparison tests:");
+
+ ScryptHash256 hash1 = b1.header.Hash;
+ ScryptHash256 hash2 = b2.header.Hash;
+ ScryptHash256 hash3 = veryBigBlock.header.Hash;
+
+ Console.WriteLine("{0} < {1} : {2}", hash1.ToString(), hash2.ToString(), hash1 < hash2);
+ Console.WriteLine("{0} > {1} : {2}", hash1.ToString(), hash2.ToString(), hash1 > hash2);
+ Console.WriteLine("{0} <= {1} : {2}", hash1.ToString(), hash2.ToString(), hash1 <= hash2);
+ Console.WriteLine("{0} >= {1} : {2}", hash1.ToString(), hash2.ToString(), hash1 >= hash2);
+
+ Console.WriteLine("{0} != {1} : {2}", hash1.ToString(), hash2.ToString(), hash1 != hash2);
+ Console.WriteLine("{0} == {1} : {2}", hash3.ToString(), hash3.ToString(), hash3 == hash3);
+
/*
Console.WriteLine("Reading the block file...");
var bs = new CBlockStore();