Exemplo n.º 1
0
        public void HashImpl_Multiply_SquaringLargest64BitValue_YieldsExpected128BitResult()
        {
            var result = Fnv1a128.Multiply(UInt64.MaxValue, UInt64.MaxValue);

            Assert.AreEqual(0x0000000000000001, result.x);
            Assert.AreEqual(0xfffffffffffffffe, result.y);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Computes the FNV-1a 128-bit hash for the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>The FNV-1a 128-bit hash of the specified data.</returns>
        // ReSharper disable once InconsistentNaming
        private static string Fnv1a128s(this string data)
        {
            using (HashAlgorithm alg = new Fnv1a128())
            {
                string value = new BigInteger(alg.ComputeHash(UTF8.GetBytes(data)).AddZero()).ToString("X32", InvariantCulture);

                return("0x" + value.Substring(value.Length - 32));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Asynchronously computes the FNV-1a 128-bit hash for the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>An asynchronous <see cref="Task{TResult}"/> containing the FNV-1a 128-bit hash of the specified data.</returns>
        // ReSharper disable once InconsistentNaming
        private static async Task <string> Fnv1a128sAsync(this string data)
        {
            using (HashAlgorithm alg = new Fnv1a128())
            {
                string value = new BigInteger(alg.ComputeHash(UTF8.GetBytes(data)).AddZero()).ToString("X32", InvariantCulture);

                return(await Task.FromResult("0x" + value.Substring(value.Length - 32)).ConfigureAwait(false));
            }
        }
Exemplo n.º 4
0
        public void HashImpl_Multiply_Multiplying64BitValue_YieldsExpected128BitResult()
        {
            ulong a = 0xaaaaaaaabcdefeff;
            ulong b = 0xeeeeeeeef01234ff;

            var result = Fnv1a128.Multiply(a, b);

            Assert.AreEqual(0xc731283e6bd9cc01, result.x);
            Assert.AreEqual(0x9f49f49f5bb47209, result.y);
        }
Exemplo n.º 5
0
 public void Execute()
 {
 #if ENABLE_UNITY_COLLECTIONS_CHECKS
     if (Result.Length != 1)
     {
         throw new ArgumentException("Result does not have the expected Length of 1");
     }
 #endif
     Result[0] = Fnv1a128.Hash(Data);
 }
Exemplo n.º 6
0
        public void HashContent_HashEmptyArray_YieldsExpectedFnv1a128Hash()
        {
            using (var array = new NativeArray <byte>(0, Allocator.TempJob))
            {
                var hash = Fnv1a128.Hash(array);

                Assert.AreEqual(0x6295c58d, hash.Value.x);
                Assert.AreEqual(0x62b82175, hash.Value.y);
                Assert.AreEqual(0x07bb0142, hash.Value.z);
                Assert.AreEqual(0x6c62272e, hash.Value.w);
            }
        }
Exemplo n.º 7
0
        public void HashContent_HashedArrayLength1ZeroMemory_YieldsExpectedFnv1a128Hash()
        {
            using (var array = new NativeArray <byte>(1, Allocator.TempJob))
            {
                var hash = Fnv1a128.Hash(array);

                Assert.AreEqual(0x4e4a147f, hash.Value.x);
                Assert.AreEqual(0x78912b70, hash.Value.y);
                Assert.AreEqual(0x101a8caf, hash.Value.z);
                Assert.AreEqual(0xd228cb69, hash.Value.w);
            }
        }
Exemplo n.º 8
0
        public void HashContent_HashedArrayLength16ZeroMemory_YieldsExpectedFnv1a128Hash()
        {
            using (var array = new NativeArray <byte>(16, Allocator.TempJob))
            {
                var hash = Fnv1a128.Hash(array);

                Assert.AreEqual(0x34145e4d, hash.Value.x);
                Assert.AreEqual(0x15171638, hash.Value.y);
                Assert.AreEqual(0xf705b5ef, hash.Value.z);
                Assert.AreEqual(0xf1f90b7b, hash.Value.w);
            }
        }
Exemplo n.º 9
0
        public void HashContent_HashedIdentityArrayLength16_YieldsExpectedFnv1a128Hash()
        {
            using (var array = DeterminismTestUtility.GenerateIdentity(16))
            {
                var hash = Fnv1a128.Hash(array);

                Assert.AreEqual(0x3cb989fd, hash.Value.x);
                Assert.AreEqual(0x8177f0c9, hash.Value.y);
                Assert.AreEqual(0x93cff23f, hash.Value.z);
                Assert.AreEqual(0x2f57eaee, hash.Value.w);
            }
        }
Exemplo n.º 10
0
        public void HashImpl_MultiplyModMax_SquaringLargest128BitValue_YieldsExcepted128BitModulusResultResult()
        {
            var uint128Max = new Fnv1a128.ulong2
            {
                x = UInt64.MaxValue,
                y = UInt64.MaxValue
            };

            var result = Fnv1a128.MultiplyMod(uint128Max, uint128Max);

            Assert.AreEqual(1, result.x);
            Assert.AreEqual(0, result.y);
        }
Exemplo n.º 11
0
 public static Hash128 HashContentNonbursted(NativeArray <byte> data) => Fnv1a128.Hash(data);