Beispiel #1
0
        unsafe public void GetHashCodeInt4()
        {
            var layout = FastEquality.CreateLayout(typeof(int4));

            Assert.AreEqual(-270419516, FastEquality.GetHashCode(new int4(1, 2, 3, 4), layout));
            Assert.AreEqual(-270419517, FastEquality.GetHashCode(new int4(1, 2, 3, 3), layout));
            Assert.AreEqual(1, FastEquality.GetHashCode(new int4(0, 0, 0, 1), layout));
            Assert.AreEqual(16777619, FastEquality.GetHashCode(new int4(0, 0, 1, 0), layout));
            Assert.AreEqual(0, FastEquality.GetHashCode(new int4(0, 0, 0, 0), layout));

            // Note, builtin .GetHashCode() returns different values even for all zeros...
        }
        public void FastEqualityWorksFromBurst()
        {
            TypeManager.Initialize();

            Entity a1 = new Entity()
            {
                Index = 1, Version = 2
            };
            Entity a2 = a1;
            Entity b  = new Entity()
            {
                Index = 2, Version = 1
            };
            var monoA1EqualsA2  = FastEquality.Equals(a1, a2);
            var monoA1EqualsB   = FastEquality.Equals(a1, b);
            var burstA1EqualsA2 = BurstedTestFuncCallingEquals.Invoke(ref a1, ref a2);
            var burstA1EqualsB  = BurstedTestFuncCallingEquals.Invoke(ref a1, ref b);

            Assert.IsTrue(monoA1EqualsA2);
            Assert.IsTrue(burstA1EqualsA2);
            Assert.IsFalse(monoA1EqualsB);
            Assert.IsFalse(burstA1EqualsB);

            var monoA1GetHashCode  = FastEquality.GetHashCode(a1);
            var monoA2GetHashCode  = FastEquality.GetHashCode(a2);
            var monoBGetHashCode   = FastEquality.GetHashCode(b);
            var burstA1GetHashCode = BurstedTestFuncCallingGetHashCode.Invoke(ref a1);
            var burstA2GetHashCode = BurstedTestFuncCallingGetHashCode.Invoke(ref a2);
            var burstBGetHashCode  = BurstedTestFuncCallingGetHashCode.Invoke(ref b);

            Assert.AreEqual(monoA1GetHashCode, burstA1GetHashCode);
            Assert.AreEqual(monoA2GetHashCode, burstA2GetHashCode);
            Assert.AreEqual(monoBGetHashCode, burstBGetHashCode);
            Assert.AreEqual(monoA1GetHashCode, monoA2GetHashCode);
            Assert.AreNotEqual(monoA1GetHashCode, monoBGetHashCode);
        }
Beispiel #3
0
 public override unsafe int GetHashCode() => FastEquality.GetHashCode(Unity.Collections.LowLevel.Unsafe.UnsafeUtility.AddressOf <MeshInstanceRenderer>(ref this), typeInfo);
 private static unsafe int _mono_to_burst_CallGetHashCode(ref Entity a)
 {
     return(FastEquality.GetHashCode(a));
 }