Beispiel #1
0
        public void Operations_IdentityEqualSizes(int vectorSize)
        {
            Random rnd = new Random(1000);

            ulong[] data = new ulong[vectorSize];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (ulong)(rnd.Next() << 32 | rnd.Next());
            }

            var v1 = BitVector.Of(data);
            var v2 = BitVector.OfLength(v1.Count);

            v1.CopyTo(v2);

            var rAnd = BitVector.And(v1, v2);
            var rOr  = BitVector.Or(v1, v2);
            var rXor = BitVector.Xor(v1, v2);

            BitVector[] array = { rAnd, rOr, rXor };
            foreach (var r in array)
            {
                Assert.Equal(v1.Count, r.Count);
                Assert.Equal(v2.Count, r.Count);
            }

            for (int i = 0; i < v1.Count; i++)
            {
                Assert.Equal(rAnd[i], v1[i] && v2[i]);
                Assert.Equal(rOr[i], v1[i] || v2[i]);
                Assert.Equal(rXor[i], v1[i] ^ v2[i]);
            }
        }
Beispiel #2
0
        public void Operations_IdentityDifferentSizesInverted(int vectorSize)
        {
            ulong[] data     = GenerateRandomArray(vectorSize);
            ulong[] dataPlus = GenerateRandomArray(vectorSize + BitVector.BitsPerWord);

            var v1 = BitVector.Of(data);
            var v2 = BitVector.Of(dataPlus);

            var rAnd = BitVector.And(v2, v1);
            var rOr  = BitVector.Or(v2, v1);
            var rXor = BitVector.Xor(v2, v1);

            BitVector[] array = { rAnd, rOr, rXor };
            foreach (var r in array)
            {
                Assert.Equal(v1.Count, r.Count);
                Assert.True(v2.Count > r.Count);
            }

            for (int i = 0; i < v1.Count; i++)
            {
                Assert.Equal(rAnd[i], v1[i] && v2[i]);
                Assert.Equal(rOr[i], v1[i] || v2[i]);
                Assert.Equal(rXor[i], v1[i] ^ v2[i]);
            }
        }
Beispiel #3
0
        public void Evaluate(BitVector vector)
        {
            Allocator.AllocateToSize(ref _termVector, vector.Capacity);
            vector.All(vector.Capacity);

            foreach (IExpression term in _terms)
            {
                _termVector.None();
                term.Evaluate(_termVector);
                vector.And(_termVector);
            }
        }