public void ClassLayout()
        {
            var ti = FastEquality.CreateTypeInfo(typeof(ClassInStruct));

            Assert.IsNotNull(ti.GetHashFn);
            Assert.IsNotNull(ti.EqualFn);
        }
Example #2
0
        public void EqualsPadding()
        {
            var layout = FastEquality.CreateLayout(typeof(EndPadding));

            Assert.IsTrue(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(1, 2), layout));
            Assert.IsFalse(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(1, 3), layout));
            Assert.IsFalse(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(4, 2), layout));
        }
Example #3
0
        public void EqualsPadding()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(EndPadding));

            Assert.IsTrue(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(1, 2), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(1, 3), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(4, 2), typeInfo));
        }
Example #4
0
        public void ClassLayout()
        {
            var layout = FastEquality.CreateLayout(typeof(ClassInStruct));

            Assert.AreEqual(1, layout.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = PtrAligned4Count, Aligned4 = true
            }, layout[0]);
        }
Example #5
0
        public void EqualsInt4()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(int4));

            Assert.IsTrue(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(1, 2, 3, 4), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(1, 2, 3, 5), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(0, 2, 3, 4), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(5, 6, 7, 8), typeInfo));
        }
Example #6
0
        public void EndPaddingLayout()
        {
            var layout = FastEquality.CreateLayout(typeof(EndPadding));

            Assert.AreEqual(1, layout.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 3, Aligned4 = true
            }, layout[0]);
        }
Example #7
0
        public void EqualsInt4()
        {
            var layout = FastEquality.CreateLayout(typeof(int4));

            Assert.IsTrue(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(1, 2, 3, 4), layout));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(1, 2, 3, 5), layout));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(0, 2, 3, 4), layout));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(5, 6, 7, 8), layout));
        }
Example #8
0
        public void SimpleLayout()
        {
            var res = FastEquality.CreateLayout(typeof(Simple));

            Assert.AreEqual(1, res.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 2, Aligned4 = true
            }, res[0]);
        }
Example #9
0
        public void PtrLayout()
        {
            var layout = FastEquality.CreateLayout(typeof(FloatPointer));

            Assert.AreEqual(1, layout.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = PtrAligned4Count, Aligned4 = true
            }, layout[0]);
        }
Example #10
0
        public void SimpleEmbeddedLayout()
        {
            var layout = FastEquality.CreateLayout(typeof(SimpleEmbedded));

            Assert.AreEqual(1, layout.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 5, Aligned4 = true
            }, layout[0]);
        }
Example #11
0
        public void CorrectEqualsIsUsed()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(DoubleEquals));
            var a        = new DoubleEquals {
            };
            var b        = new DoubleEquals {
            };
            bool iseq    = FastEquality.Equals <DoubleEquals>(a, b, typeInfo);

            Assert.IsTrue(iseq);
        }
Example #12
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...
        }
Example #13
0
        public void AlignSplitLayout()
        {
            var layout = FastEquality.CreateLayout(typeof(AlignSplit));

            Assert.AreEqual(2, layout.Length);

            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 3, Aligned4 = true
            }, layout[0]);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 16, count = 2, Aligned4 = true
            }, layout[1]);
        }
Example #14
0
        public void BytePaddding()
        {
            var layout = FastEquality.CreateLayout(typeof(BytePadding));

            Assert.AreEqual(2, layout.Length);

            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 2, Aligned4 = false
            }, layout[0]);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 4, count = 1, Aligned4 = true
            }, layout[1]);
        }
Example #15
0
        public void EqualsEnum()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(EnumStruct));

            var a = new EnumStruct {
                nephew = Nephew.Huey
            };
            var b = new EnumStruct {
                nephew = Nephew.Dewey
            };

            Assert.IsTrue(FastEquality.Equals(a, a, typeInfo));
            Assert.IsFalse(FastEquality.Equals(a, b, typeInfo));
        }
Example #16
0
        public void TypeHash()
        {
            int[] hashes =
            {
                FastEquality.CreateTypeInfo(typeof(Simple)).Hash,
                FastEquality.CreateTypeInfo(typeof(SimpleEmbedded)).Hash,
                FastEquality.CreateTypeInfo(typeof(BytePadding)).Hash,
                FastEquality.CreateTypeInfo(typeof(AlignSplit)).Hash,
                FastEquality.CreateTypeInfo(typeof(EndPadding)).Hash,
                FastEquality.CreateTypeInfo(typeof(FloatPointer)).Hash,
                FastEquality.CreateTypeInfo(typeof(ClassInStruct)).Hash,
                FastEquality.CreateTypeInfo(typeof(FixedArrayStruct)).Hash,
                FastEquality.CreateTypeInfo(typeof(EnumStruct)).Hash
            };

            Assert.AreEqual(hashes.Distinct().Count(), hashes.Length);
        }
        public unsafe void EqualsFixedArray()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(FixedArrayStruct));

            var a = new FixedArrayStruct();

            a.array[0] = 123;
            a.array[1] = 234;
            a.array[2] = 345;

            var b = a;

            Assert.IsTrue(FastEquality.Equals(a, b, typeInfo));

            b.array[1] = 456;

            Assert.IsFalse(FastEquality.Equals(a, b, typeInfo));
        }
Example #18
0
        static ExtraTypesProvider()
        {
            //@TODO: Only produce JobForEachExtensions.JobStruct_Process1
            //       if there is any use of that specific type in deployed code.

            PlayerBuildInterface.ExtraTypesProvider += () =>
            {
                var extraTypes = new HashSet <string>();

                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (!TypeManager.IsAssemblyReferencingEntities(assembly))
                    {
                        continue;
                    }

                    foreach (var type in assembly.GetTypes())
                    {
                        if (typeof(JobForEachExtensions.IBaseJobForEach).IsAssignableFrom(type) && !type.IsAbstract)
                        {
                            AddIJobForEach(type, extraTypes);
                        }
                    }
                }

                TypeManager.Initialize();

                foreach (var typeInfo in TypeManager.AllTypes)
                {
                    if (typeInfo.Type != null)
                    {
                        FastEquality.AddExtraAOTTypes(typeInfo.Type, extraTypes);
                    }
                }

                TypeManager.Shutdown();

                return(extraTypes);
            };
        }
        static ExtraTypesProvider()
        {
            //@TODO: Only produce JobForEachExtensions.JobStruct_Process1
            //       if there is any use of that specific type in deployed code.

            PlayerBuildInterface.ExtraTypesProvider += () =>
            {
                var extraTypes   = new HashSet <string>();
                var visitedTypes = new HashSet <Type>();

                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (!TypeManager.IsAssemblyReferencingEntities(assembly))
                    {
                        continue;
                    }

                    foreach (var type in assembly.GetTypes())
                    {
                        AddIJobForEachForTypeHierarchy(extraTypes, visitedTypes, type);
                    }
                }

                TypeManager.Initialize();

                foreach (var typeInfo in TypeManager.AllTypes)
                {
                    Type type = TypeManager.GetType(typeInfo.TypeIndex);
                    if (type != null)
                    {
                        FastEquality.AddExtraAOTTypes(type, extraTypes);
                    }
                }

                return(extraTypes);
            };
        }
        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);
        }
Example #21
0
        public void ManagedComponentGetHashCode()
        {
            {
                var typeInfo = FastEquality.CreateTypeInfo(typeof(EcsTestManagedComponent));
                var obj1     = new EcsTestManagedComponent()
                {
                    value = "SomeString"
                };
                var obj12 = new EcsTestManagedComponent()
                {
                    value = "SomeString"
                };
                var obj2 = new EcsTestManagedComponent()
                {
                    value = "SomeOtherString"
                };
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj1, typeInfo));
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj12, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj2, typeInfo));
            }

            {
                var typeInfo    = FastEquality.CreateTypeInfo(typeof(ComponentWithUnityObjectArray));
                var tex1        = new UnityEngine.Texture2D(512, 512);
                var tex2        = new UnityEngine.Texture2D(512, 512);
                var tex3        = new UnityEngine.Texture2D(512, 512);
                var stringList1 = new List <string>()
                {
                    "yo", "hi", "hej", "hello"
                };
                var stringList12 = new List <string>()
                {
                    "yo", "hi", "hej", "hello"
                };
                var stringList2 = new List <string>()
                {
                    "yo", "hi", "hey", "hello"
                };

                var obj1 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex2, tex3 }
                };
                var obj12 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex2, tex3 }
                };
                var obj13 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList12, Texture = tex1, Objects = new[] { tex2, tex3 }
                };
                var obj2 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex2, tex2 }
                };
                var obj3 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex1, null }
                };
                var obj4 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex1 }
                };
                var obj5 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList2, Texture = tex1, Objects = new[] { tex2, tex3 }
                };
                var obj6 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList2, Texture = tex2, Objects = new[] { tex3, tex1 }
                };
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj1, typeInfo));
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj12, typeInfo));
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj13, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj2, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj3, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj4, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj5, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj6, typeInfo));
            }

            {
                var typeInfo = FastEquality.CreateTypeInfo(typeof(ComponentOverridesGetHashCode));
                var obj      = new ComponentOverridesGetHashCode();
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj, typeInfo), FastEquality.ManagedGetHashCode(obj, typeInfo));
                Assert.IsTrue(obj.GetHashCodeWasCalled);
            }
        }
 private static unsafe bool _mono_to_burst_CallEquals(ref Entity a, ref Entity b)
 {
     return(FastEquality.Equals(a, b));
 }
 private static unsafe int _mono_to_burst_CallGetHashCode(ref Entity a)
 {
     return(FastEquality.GetHashCode(a));
 }
Example #24
0
        public void ForgettingGetHashCodeIsAnError()
        {
            var ex = Assert.Throws <ArgumentException>(() => FastEquality.CreateTypeInfo(typeof(TypeWithoutHashCodeOverride)));

            Assert.IsTrue(ex.Message.Contains("GetHashCode"));
        }
Example #25
0
 public override unsafe int GetHashCode() => FastEquality.GetHashCode(Unity.Collections.LowLevel.Unsafe.UnsafeUtility.AddressOf <MeshInstanceRenderer>(ref this), typeInfo);