Ejemplo n.º 1
0
        /// <summary>
        /// tests different hasbits implementations and different filters to perform the same operation
        /// </summary>
        public static void TestHasBits()
        {
            var records = MockBitArrays.GenerateRandomBitArrays(1000000);
            var lastRecord = records.Last();

            List<IHasBits> hasBitsInt = new List<IHasBits>();
            List<IHasBits> hasBitsBoolArray = new List<IHasBits>();
            List<IHasBits> hasBitsBitVector = new List<IHasBits>();
            List<IHasBits> hasBitsBitArray = new List<IHasBits>();
            NaturalIntHasBits last1 = new NaturalIntHasBits(lastRecord);
            NaturalBoolArrayHasBits last2 = new NaturalBoolArrayHasBits(lastRecord);
            NaturalBitVectorHasBits last3 = new NaturalBitVectorHasBits(lastRecord);
            NaturalBitArrayHasBits last4 = new NaturalBitArrayHasBits(lastRecord);

            records.ForEach(x =>
            {
                hasBitsInt.Add(new NaturalIntHasBits(x));
                hasBitsBoolArray.Add(new NaturalBoolArrayHasBits(x));
                hasBitsBitVector.Add(new NaturalBitVectorHasBits(x));
                hasBitsBitArray.Add(new NaturalBitArrayHasBits(x));
            });

            Func<IHasBits, bool> findLastFilter_XOR = (x) =>
            {
                return x.Bits.AreEquivalent_XORCompare(lastRecord);
            };
            Func<IHasBits, bool> findLastFilter_BitByBit = (x) =>
            {
                return x.Bits.AreEquivalent_BitByBit(lastRecord);
            };
            Func<IHasBits, bool> findLastFilter_IntCompare = (x) =>
            {
                return x.Bits.AreEquivalent_IntCompare(lastRecord);
            };

            TestFilterTimes(hasBitsInt, findLastFilter_XOR, "int | XOR");
            TestFilterTimes(hasBitsBoolArray, findLastFilter_XOR, "boolarray | XOR");
            TestFilterTimes(hasBitsBitVector, findLastFilter_XOR, "bitvector | XOR");
            TestFilterTimes(hasBitsBitArray, findLastFilter_XOR, "bitarray | XOR");
            TestFilterTimes(hasBitsInt, findLastFilter_BitByBit, "int | bit by bit");
            TestFilterTimes(hasBitsBoolArray, findLastFilter_BitByBit, "boolarray | bit by bit");
            TestFilterTimes(hasBitsBitVector, findLastFilter_BitByBit, "bitvector | bit by bit");
            TestFilterTimes(hasBitsBitArray, findLastFilter_BitByBit, "bitarray | bit by bit");
            TestFilterTimes(hasBitsInt, findLastFilter_IntCompare, "int | int compare");
            TestFilterTimes(hasBitsBoolArray, findLastFilter_IntCompare, "boolarray | int compare");
            TestFilterTimes(hasBitsBitVector, findLastFilter_IntCompare, "bitvector | int compare");
            TestFilterTimes(hasBitsBitArray, findLastFilter_IntCompare, "bitarray | int compare");

            //apparently bitarray intcompare is the fastest arrangement

            //now try the AND
            //Func<IHasBits, bool> findLastFilter_AND = (x) =>
            //{
            //    var newBits = x.AND(last1);

            //    return newBits.Bits.AreEquivalent_IntCompare(lastRecord);
            //};


        }
Ejemplo n.º 2
0
        /// <summary>
        /// tests different hasbits implementations and different filters to perform the same operation
        /// </summary>
        public static void TestHasBits()
        {
            var records    = MockBitArrays.GenerateRandomBitArrays(1000000);
            var lastRecord = records.Last();

            List <IHasBits>         hasBitsInt       = new List <IHasBits>();
            List <IHasBits>         hasBitsBoolArray = new List <IHasBits>();
            List <IHasBits>         hasBitsBitVector = new List <IHasBits>();
            List <IHasBits>         hasBitsBitArray  = new List <IHasBits>();
            NaturalIntHasBits       last1            = new NaturalIntHasBits(lastRecord);
            NaturalBoolArrayHasBits last2            = new NaturalBoolArrayHasBits(lastRecord);
            NaturalBitVectorHasBits last3            = new NaturalBitVectorHasBits(lastRecord);
            NaturalBitArrayHasBits  last4            = new NaturalBitArrayHasBits(lastRecord);

            records.ForEach(x =>
            {
                hasBitsInt.Add(new NaturalIntHasBits(x));
                hasBitsBoolArray.Add(new NaturalBoolArrayHasBits(x));
                hasBitsBitVector.Add(new NaturalBitVectorHasBits(x));
                hasBitsBitArray.Add(new NaturalBitArrayHasBits(x));
            });

            Func <IHasBits, bool> findLastFilter_XOR = (x) =>
            {
                return(x.Bits.AreEquivalent_XORCompare(lastRecord));
            };
            Func <IHasBits, bool> findLastFilter_BitByBit = (x) =>
            {
                return(x.Bits.AreEquivalent_BitByBit(lastRecord));
            };
            Func <IHasBits, bool> findLastFilter_IntCompare = (x) =>
            {
                return(x.Bits.AreEquivalent_IntCompare(lastRecord));
            };

            TestFilterTimes(hasBitsInt, findLastFilter_XOR, "int | XOR");
            TestFilterTimes(hasBitsBoolArray, findLastFilter_XOR, "boolarray | XOR");
            TestFilterTimes(hasBitsBitVector, findLastFilter_XOR, "bitvector | XOR");
            TestFilterTimes(hasBitsBitArray, findLastFilter_XOR, "bitarray | XOR");
            TestFilterTimes(hasBitsInt, findLastFilter_BitByBit, "int | bit by bit");
            TestFilterTimes(hasBitsBoolArray, findLastFilter_BitByBit, "boolarray | bit by bit");
            TestFilterTimes(hasBitsBitVector, findLastFilter_BitByBit, "bitvector | bit by bit");
            TestFilterTimes(hasBitsBitArray, findLastFilter_BitByBit, "bitarray | bit by bit");
            TestFilterTimes(hasBitsInt, findLastFilter_IntCompare, "int | int compare");
            TestFilterTimes(hasBitsBoolArray, findLastFilter_IntCompare, "boolarray | int compare");
            TestFilterTimes(hasBitsBitVector, findLastFilter_IntCompare, "bitvector | int compare");
            TestFilterTimes(hasBitsBitArray, findLastFilter_IntCompare, "bitarray | int compare");

            //apparently bitarray intcompare is the fastest arrangement

            //now try the AND
            //Func<IHasBits, bool> findLastFilter_AND = (x) =>
            //{
            //    var newBits = x.AND(last1);

            //    return newBits.Bits.AreEquivalent_IntCompare(lastRecord);
            //};
        }
Ejemplo n.º 3
0
        private IHasBits _hasBits; //uses backing field to wrap
        #endregion

        #region Ctor
        /// <summary>
        ///
        /// </summary>
        /// <param name="decorated"></param>
        /// <param name="hasBits">if null will default to 32bit BitArrayHasBits instance</param>
        public HasBitsIHasIdDecoration(IHasId decorated, IHasBits hasBits = null)
            : base(decorated)
        {
            if (hasBits != null)
            {
                this._hasBits = hasBits;
            }
            else
            {
                this._hasBits = NaturalBitArrayHasBits.New(new BitArray(32));
            }
        }
Ejemplo n.º 4
0
 protected HasBitsIHasIdDecoration(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     this._hasBits = NaturalBitArrayHasBits.New(new BitArray(info.GetValue("_hasBits", typeof(bool[])) as bool[]));
 }