public unsafe static void ComputeHash128(void *data, ulong dataSize, Hash128 *hash) { ulong u64_ = hash->u64_0; ulong u64_2 = hash->u64_1; HashUnsafeUtilities.ComputeHash128(data, dataSize, &u64_, &u64_2); *hash = new Hash128(u64_, u64_2); }
public unsafe static void ComputeHash128 <T>(ref T value, ref Hash128 hash) where T : struct { void * data = UnsafeUtility.AddressOf <T>(ref value); ulong dataSize = (ulong)((long)UnsafeUtility.SizeOf <T>()); Hash128 *hash2 = (Hash128 *)UnsafeUtility.AddressOf <Hash128>(ref hash); HashUnsafeUtilities.ComputeHash128(data, dataSize, hash2); }
public unsafe static void ComputeHash128(byte[] value, ref Hash128 hash) { fixed(byte *ptr = &value[0]) { byte * data = ptr; ulong dataSize = (ulong)((long)value.Length); Hash128 *hash2 = (Hash128 *)UnsafeUtility.AddressOf <Hash128>(ref hash); HashUnsafeUtilities.ComputeHash128((void *)data, dataSize, hash2); } }
public static unsafe void ComputeHash128(void *data, ulong dataSize, Hash128 *hash) { // We don't have ref return in C# 6.0, and we don't want to expose an unsafe pointer // to Hash128's internal data. // Se we make a copy and then recreate the hash in the end. // It won't create GCable memory, but it introduce copy operations. var u61_0 = hash->u64_0; var u61_1 = hash->u64_1; ComputeHash128(data, dataSize, &u61_0, &u61_1); *hash = new Hash128(u61_0, u61_1); }
/// <summary>Combine all of the hashes of a collection of hashes.</summary> /// <typeparam name="TValue">Value type.</typeparam> /// <typeparam name="TGetter">Getter type.</typeparam> /// <param name="count">Number of hash to combine.</param> /// <param name="hashes">Hashes to combine.</param> /// <param name="outHash">Hash to update.</param> public static void CombineHashes <TValue, TGetter>(int count, void *hashes, Hash128 *outHash) where TValue : struct where TGetter : struct, IKeyGetter <TValue, Hash128> { var getter = new TGetter(); for (int i = 0; i < count; ++i) { var v = UnsafeUtility.ReadArrayElement <TValue>(hashes, i); var h = getter.Get(ref v); HashUtilities.AppendHash(ref h, ref *outHash); } }
public unsafe static void AppendHash(ref Hash128 inHash, ref Hash128 outHash) { fixed(Hash128 *ptr = &outHash) { Hash128 *hash = ptr; fixed(Hash128 *ptr2 = &inHash) { Hash128 *data = ptr2; HashUnsafeUtilities.ComputeHash128((void *)data, (ulong)((long)sizeof(Hash128)), hash); } } }
public unsafe static void QuantisedVectorHash(ref Vector3 value, ref Hash128 hash) { fixed(Hash128 *ptr = &hash) { Hash128 *hash2 = ptr; int * ptr2 = stackalloc int[3]; for (int i = 0; i < 3; i++) { ptr2[i] = (int)(value[i] * 1000f + 0.5f); } HashUnsafeUtilities.ComputeHash128((void *)ptr2, 12uL, hash2); } }
public unsafe static void QuantisedMatrixHash(ref Matrix4x4 value, ref Hash128 hash) { fixed(Hash128 *ptr = &hash) { Hash128 *hash2 = ptr; int * ptr2 = stackalloc int[16]; for (int i = 0; i < 16; i++) { ptr2[i] = (int)(value[i] * 1000f + 0.5f); } HashUnsafeUtilities.ComputeHash128((void *)ptr2, 64uL, hash2); } }
/// <summary> /// Compare hashes. /// </summary> /// <param name="oldHashCount">Number of hashes in <paramref name="oldHashes"/>.</param> /// <param name="oldHashes">Previous hashes to compare.</param> /// <param name="newHashCount">Number of hashes in <paramref name="newHashes"/>.</param> /// <param name="newHashes">New hashes to compare.</param> /// <param name="addIndices">Indices of element to add in <paramref name="newHashes"/> will be written here.</param> /// <param name="removeIndices">Indices of element to remove in <paramref name="oldHashes"/> will be written here.</param> /// <param name="addCount">Number of elements to add will be written here.</param> /// <param name="remCount">Number of elements to remove will be written here.</param> /// <returns>The number of operation to perform (<code><paramref name="addCount"/> + <paramref name="remCount"/></code>)</returns> public static int CompareHashes( int oldHashCount, Hash128 *oldHashes, int newHashCount, Hash128 *newHashes, // assume that the capacity of indices is >= max(oldHashCount, newHashCount) int *addIndices, int *removeIndices, out int addCount, out int remCount ) { return(CompareHashes <Hash128, DefaultKeyGetter <Hash128>, Hash128, DefaultKeyGetter <Hash128> >( oldHashCount, oldHashes, newHashCount, newHashes, addIndices, removeIndices, out addCount, out remCount )); }
/// <summary> /// Combine hashes. /// </summary> /// <param name="count">Number of hash to combine.</param> /// <param name="hashes">Hashes to combine.</param> /// <param name="outHash">Hash to update.</param> public static void CombineHashes(int count, Hash128 *hashes, Hash128 *outHash) { CombineHashes <Hash128, DefaultKeyGetter <Hash128> >(count, hashes, outHash); }