Ejemplo n.º 1
0
        public void Setup()
        {
            bitSet1.Set(0);
            bitSet1.Set(35);
            bitSet1.Set(79);
            bitSet1.Set(120);

            bitSet2.Set(0);
            bitSet2.Set(35);
            bitSet2.Set(79);
            bitSet2.Set(120);

            javaBitSet1 = new BitSet(256);
            javaBitSet2 = new BitSet(256);

            javaBitSet1.Set(0);
            javaBitSet1.Set(35);
            javaBitSet1.Set(79);
            javaBitSet1.Set(120);

            javaBitSet2.Set(0);
            javaBitSet2.Set(35);
            javaBitSet2.Set(79);
            javaBitSet2.Set(120);
        }
        public void IncludeReadWrite <T>() where T : IComponent
        {
            int pos = TypeHelper.Component <T> .componentIndex;

            includeMask.Set(pos);
            includeWriteMask.Set(pos);
            excludeMask.Unset(pos);
#if DEBUG
            AddToDebugList(ref includeTypes, typeof(T));
            AddToDebugList(ref includeWriteTypes, typeof(T));
#endif
        }
        public void ExcludeShared <T>() where T : ISharedComponent
        {
            int pos = TypeHelper.SharedComponent <T> .componentIndex;

            sharedExcludeMask.Set(pos);
            sharedIncludeMask.Unset(pos);
#if DEBUG
            AddToDebugList(ref sharedExcludeTypes, typeof(T));
#endif
        }
Ejemplo n.º 4
0
        public void ContainsAll()
        {
            BitSet256 left  = new BitSet256();
            BitSet256 right = new BitSet256();

            left.Set(0);
            left.Set(12);
            left.Set(70);
            left.Set(128);
            left.Set(156);
            left.Set(255);

            right.Set(0);
            right.Set(12);
            right.Set(70);
            right.Set(128);
            right.Set(255);

            Assert.True(left.ContainsAll(right));
            Assert.False(right.ContainsAll(left));
        }
Ejemplo n.º 5
0
        public void HashCode()
        {
            for (int i = 0; i < 256; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    BitSet256 left  = new BitSet256();
                    BitSet256 right = new BitSet256();

                    left.Set(i);
                    right.Set(j);

                    int leftHash  = left.GetHashCode();
                    int rightHash = right.GetHashCode();

                    if (i == j)
                    {
                        Assert.Equal(leftHash, rightHash);
                    }
                    else
                    {
                        Assert.NotEqual(leftHash, rightHash);
                    }
                }
            }


            Random r = new Random(1234);

            for (int i = 0; i < 1000; i++)
            {
                BitSet256 left  = new BitSet256();
                BitSet256 right = new BitSet256();
                for (int j = 0; j < 12; j++)
                {
                    left.Set(r.Next(0, 256));
                    right.Set(r.Next(0, 256));
                }

                int leftHash  = left.GetHashCode();
                int rightHash = right.GetHashCode();

                if (left == right)
                {
                    Assert.Equal(leftHash, rightHash);
                }
                else
                {
                    Assert.NotEqual(leftHash, rightHash);
                }
            }
        }
        private void CalculateHashAndMask()
        {
            componentMask       = new BitSet256();
            sharedComponentMask = new BitSet256();
            _hash = 0;
            foreach (var kp in components)
            {
                _hash ^= kp.Key.GetHashCode();
                componentMask.Set(ComponentMask.GetComponentIndex(kp.Key));
            }

            foreach (var kp in sharedComponents)
            {
                _hash ^= kp.Key.GetHashCode();
                _hash ^= kp.Value.GetHashCode();
                sharedComponentMask.Set(SharedComponentMask.GetSharedComponentIndex(kp.Key));
            }
        }