Represents a single, immutable 256-bit hash value.

Constructors

Hash

#
public Hash(IReader reader)
Read this hash from an archive.
reader (IReader)

Fields

BitDepth

#
public const int BitDepth = 256
Gets the number of bits in the hash.

ByteDepth

#
public const int ByteDepth = 32
Gets the number of bytes in the hash.

Empty

#
public static readonly Hash Empty
Gets the empty hash.

Properties

IsEmpty

#
public bool IsEmpty { get; }
Gets whether this hash is empty.

Methods

CreateFromBytes

#
public static Hash CreateFromBytes(byte[] bytes)
Create a hash from a byte array.
bytes (byte[])Bytes to hash.
Hash.

CreateFromCollection

#
public static Hash CreateFromCollection(IEnumerable<byte> data)
Create a hash from a byte array.
data (IEnumerable<byte>)Array to hash.
Hash.

CreateFromCollection

#
public static Hash CreateFromCollection(IEnumerable<double> data)
Create a hash from a double array.
data (IEnumerable<double>)Array to hash.
Hash.

CreateFromCollection

#
public static Hash CreateFromCollection(IEnumerable<float> data)
Create a hash from a float array.
data (IEnumerable<float>)Array to hash.
Hash.

CreateFromCollection

#
public static Hash CreateFromCollection(IEnumerable<int> data)
Create a hash from an integer array.
data (IEnumerable<int>)Array to hash.
Hash.

CreateFromCollection

#
public static Hash CreateFromCollection(IEnumerable<long> data)
Create a hash from an integer array.
data (IEnumerable<long>)Array to hash.
Hash.

CreateFromDelegate<T>

#
public static Hash CreateFromDelegate<T>(IEnumerable<T> data, Func<T, byte[]> mapping)
Create a hash from a collection and a hasher function.
data (IEnumerable<T>)Items to include in hash.
mapping (Func<T, byte[]>)Mapping function for converting T instances into byte arrays.
Hash.

CreateFromFile

#
public static Hash CreateFromFile(string path)
Create a hash from the contents of a path.
path (string)File path.
Hash for file contents, ignoring the directory and name of the file.

CreateFromObjects

#
public static Hash CreateFromObjects(params object[] elements)
Use the GetHashCode() method on each object for a composite hash.
elements (params object[])Elements to hash, array may contain null items.
Composite hash.

CreateFromStream

#
public static Hash CreateFromStream(Stream stream)
Create a hash from the contents of a stream.
stream (Stream)Stream to hash. The stream position will not be set to zero, and will end up at the end of the stream. It is the responsibility of the caller to ensure the position in in the desired place and then properly restored afterwards.
Hash.

CreateFromString

#
public static Hash CreateFromString(string data)
Create a hash from a string.
data (string)String to hash.
Hash.

Equals

#
public override bool Equals(object obj)
Test equality between this hash and another object.
obj (object)Other hash.
Object.Equals

GetHashCode

#
public override int GetHashCode()
Standard 32-bit hash code implementation.

Store

#
public void Store(IWriter writer)
Write this hash to an archive. This is not typically advised as hashing algorithms may change at any moment. Hashes should be recomputed anew during each appdomain session.
writer (IWriter)Writer object.
Store
Explicit

IComparable<Hash>.CompareTo

#
int IComparable<Hash>.CompareTo(Hash other)
other (Hash)
Explicit

IEquatable<Hash>.Equals

#
bool IEquatable<Hash>.Equals(Hash other)
other (Hash)

ToBitArray

#
public BitArray ToBitArray()
Create a bit array from this hash.
An array of individual bits.

ToByteArray

#
public byte[] ToByteArray()
Create a byte array from this hash.
An array of ByteCount bytes.

ToByteArray

#
public static byte[] ToByteArray(params double[] values)
Convert a collection of doubles to a byte array.
values (params double[])

ToByteArray

#
public static byte[] ToByteArray(params float[] values)
Convert a collection of floats to a byte array.
values (params float[])

ToByteArray

#
public static byte[] ToByteArray(params int[] values)
Convert a collection of ints to a byte array.
values (params int[])

ToByteArray

#
public static byte[] ToByteArray(params long[] values)
Convert a collection of longs to a byte array.
values (params long[])

ToGuid

#
public Guid ToGuid()
Create a Guid from this hash.

ToString

#
public override string ToString()
Convert this hash to a string.
Object.ToString

ToString

#
public string ToString(HashFormat format)
Convert this hash to a string.
format (HashFormat)Format for encoding.
A string representing the hash.

Operators

OperationResultDescription
Hash&HashHashApply logical conjunction on two hashes.
Hash|HashHashApply logical disjunction on two hashes.
Hash==HashboolTest two hashes for equality.
Hash^HashHashApply a bitwise exclusive or to two hashes.
Hash!=HashboolTest two hashes for inequality.
~HashHashApply a bitwise complement on a hash.