Added support for ArraySegment, as well as adding support for offsets of a byte array

This commit is contained in:
K Smith 2019-12-13 20:34:30 +01:00 committed by ksmith3036
parent e86fdeb0bf
commit 7599c32151
2 changed files with 66 additions and 0 deletions

View File

@ -22,5 +22,39 @@
return UnsafeComputeHash(pData, length, seed); return UnsafeComputeHash(pData, length, seed);
} }
} }
/// <summary>
/// Compute xxHash for the data byte array
/// </summary>
/// <param name="data">The source of data</param>
/// <param name="offset">The offset of the data for hashing</param>
/// <param name="length">The length of the data for hashing</param>
/// <param name="seed">The seed number</param>
/// <returns>hash</returns>
public static unsafe uint ComputeHash(byte[] data, int offset, int length, uint seed = 0)
{
Debug.Assert(data != null);
Debug.Assert(length >= 0);
Debug.Assert(offset < data.Length);
Debug.Assert(length <= data.Length - offset);
fixed (byte* pData = &data[0 + offset])
{
return UnsafeComputeHash(pData, length, seed);
}
}
/// <summary>
/// Compute xxHash for the data byte array
/// </summary>
/// <param name="data">The source of data</param>
/// <param name="seed">The seed number</param>
/// <returns>hash</returns>
public static unsafe ulong ComputeHash(System.ArraySegment<byte> data, uint seed = 0)
{
Debug.Assert(data != null);
return ComputeHash(data.Array, data.Offset, data.Count, seed);
}
} }
} }

View File

@ -22,5 +22,37 @@
return UnsafeComputeHash(pData, length, seed); return UnsafeComputeHash(pData, length, seed);
} }
} }
/// <summary>
/// Compute xxHash for the data byte array
/// </summary>
/// <param name="data">The source of data</param>
/// <param name="length">The length of the data for hashing</param>
/// <param name="seed">The seed number</param>
/// <returns>hash</returns>
public static unsafe ulong ComputeHash(byte[] data, int offset, int length, ulong seed = 0)
{
Debug.Assert(data != null);
Debug.Assert(length >= 0);
Debug.Assert(offset < data.Length);
Debug.Assert(length <= data.Length - offset);
fixed (byte* pData = &data[0 + offset])
{
return UnsafeComputeHash(pData, length, seed);
}
}
/// <summary>
/// Compute xxHash for the data byte array
/// </summary>
/// <param name="data">The source of data</param>
/// <param name="seed">The seed number</param>
/// <returns>hash</returns>
public static unsafe ulong ComputeHash(System.ArraySegment<byte> data, ulong seed = 0)
{
Debug.Assert(data != null);
return ComputeHash(data.Array, data.Offset, data.Count, seed);
}
} }
} }