Added support for ArraySegment, as well as adding support for offsets of a byte array
This commit is contained in:
parent
e86fdeb0bf
commit
7599c32151
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user