public void TestMassiveOr()
        {
            Console.WriteLine("testing massive logical or (can take a couple of minutes)");
            int N = 128;

            for (int howmany = 512; howmany <= 10000; howmany *= 2)
            {
                var ewah = new EwahCompressedBitArray[N];
                var bset = new BitArray[N];
                int k;
                for (k = 0; k < ewah.Length; ++k)
                {
                    ewah[k] = new EwahCompressedBitArray();
                }
                for (k = 0; k < bset.Length; ++k)
                {
                    bset[k] = new BitArray(10000);
                }
                for (k = 0; k < N; ++k)
                {
                    assertEqualsPositions(bset[k], ewah[k]);
                }
                for (k = 0; k < howmany; ++k)
                {
                    ewah[(k + 2 * k * k) % ewah.Length].Set(k);
                    bset[(k + 2 * k * k) % ewah.Length].Set(k, true);
                }
                for (k = 0; k < N; ++k)
                {
                    assertEqualsPositions(bset[k], ewah[k]);
                }
                EwahCompressedBitArray answer = ewah[0];
                BitArray BitArrayanswer       = bset[0];
                for (k = 1; k < ewah.Length; ++k)
                {
                    EwahCompressedBitArray tmp = answer.Or(ewah[k]);
                    BitArrayanswer.Or(bset[k]);
                    answer = tmp;
                    assertEqualsPositions(BitArrayanswer, answer);
                }
                assertEqualsPositions(BitArrayanswer, answer);
                k = 0;
                foreach (int j in answer)
                {
                    if (k != j)
                    {
                        Console.WriteLine(answer.ToDebugString());
                    }
                    Assert.AreEqual(k, j);
                    k += 1;
                }
            }
            Console.WriteLine("testing massive logical or:ok");
        }
Ejemplo n.º 2
0
 public static void Main(string[] args)
 {
     var ewahBitmap1 = new EwahCompressedBitArray();
     var ewahBitmap2 = new EwahCompressedBitArray();
     ewahBitmap1.Set(0);
     ewahBitmap1.Set(2);
     ewahBitmap1.Set(64);
     ewahBitmap1.Set(1 << 30);
     Console.WriteLine("Running demo program:");
     Console.WriteLine("bitmap 1:");
     foreach (int k in ewahBitmap1)
         Console.WriteLine(k);
     ewahBitmap2.Set(1);
     ewahBitmap2.Set(3);
     ewahBitmap2.Set(64);
     ewahBitmap2.Set(1 << 30);
     Console.WriteLine("bitmap 2:");
     foreach (int k in ewahBitmap2)
         Console.WriteLine(k);
     Console.WriteLine();
     Console.WriteLine("bitmap 1 OR bitmap 2:");
     EwahCompressedBitArray orbitmap = ewahBitmap1.Or(ewahBitmap2);
     foreach (int k in orbitmap)
         Console.WriteLine(k);
     Console.WriteLine("memory usage: " + orbitmap.SizeInBytes + " bytes");
     Console.WriteLine();
     Console.WriteLine("bitmap 1 AND bitmap 2:");
     EwahCompressedBitArray andbitmap = ewahBitmap1.And(ewahBitmap2);
     foreach (int k in andbitmap)
         Console.WriteLine(k);
     Console.WriteLine("memory usage: " + andbitmap.SizeInBytes + " bytes");
     Console.WriteLine("bitmap 1 XOR bitmap 2:");
     EwahCompressedBitArray xorbitmap = ewahBitmap1.Xor(ewahBitmap2);
     foreach (int k in xorbitmap)
         Console.WriteLine(k);
     Console.WriteLine("memory usage: " + andbitmap.SizeInBytes + " bytes");
     Console.WriteLine("End of demo.");
     Console.WriteLine("");
     var tr = new EwahCompressedBitArrayTest();
     tr.TestNot();
     tr.TestCardinality();
     tr.TestEwahCompressedBitArray();
     tr.TestExternalization();
     tr.TestLargeEwahCompressedBitArray();
     tr.TestMassiveAnd();
     tr.TestMassiveAndNot();
     tr.TestMassiveOr();
     tr.TestMassiveXOR();
     tr.HabermaasTest();
     tr.VanSchaikTest();
 }
 public void TayaraTest()
 {
     Console.WriteLine("Tayara test");
     for (int offset = 64; offset < (1 << 30); offset *= 2)
     {
         EwahCompressedBitArray a = new EwahCompressedBitArray();
         EwahCompressedBitArray b = new EwahCompressedBitArray();
         for (int k = 0; k < 64; ++k)
         {
             a.Set(offset + k);
             b.Set(offset + k);
         }
         Assert.AreEqual(a.And(b).Equals(a), true);
         Assert.AreEqual(a.Or(b).Equals(a), true);
     }
 }
        public void HabermaasTest()
        {
            Console.WriteLine("testing habermaasTest");
            var bitArrayaa = new BitArray(1000131);
            var aa         = new EwahCompressedBitArray();

            int[] val = { 55400, 1000000, 1000128 };
            foreach (int t in val)
            {
                aa.Set(t);
                bitArrayaa.Set(t, true);
            }
            assertEquals(bitArrayaa, aa);
            var bitArrayab = new BitArray(1000131);
            var ab         = new EwahCompressedBitArray();

            for (int i = 4096; i < (4096 + 5); i++)
            {
                ab.Set(i);
                bitArrayab.Set(i, true);
            }
            ab.Set(99000);
            bitArrayab.Set(99000, true);
            ab.Set(1000130);
            bitArrayab.Set(1000130, true);
            assertEquals(bitArrayab, ab);
            EwahCompressedBitArray bb    = aa.Or(ab);
            EwahCompressedBitArray bbAnd = aa.And(ab);
            var bitArraybb = (BitArray)bitArrayaa.Clone();

            bitArraybb.Or(bitArrayab);
            var bitArraybbAnd = (BitArray)bitArrayaa.Clone();

            bitArraybbAnd.And(bitArrayab);
            AreEqual(bbAnd, bitArraybbAnd);
            AreEqual(bb, bitArraybb);
            Console.WriteLine("testing habermaasTest:ok");
        }
        public void TestEwahCompressedBitArray()
        {
            Console.WriteLine("testing EWAH (basic)");
            const long zero       = 0;
            const long specialval = 1L | (1L << 4) | (1L << 63);
            const long notzero    = ~zero;
            var        myarray1   = new EwahCompressedBitArray
            {
                zero, zero, zero, specialval, specialval, notzero, zero
            };

            Assert.AreEqual(myarray1.GetPositions().Count, 6 + 64);
            var myarray2 = new EwahCompressedBitArray();

            myarray2.Add(zero);
            myarray2.Add(specialval);
            myarray2.Add(specialval);
            myarray2.Add(notzero);
            myarray2.Add(zero);
            myarray2.Add(zero);
            myarray2.Add(zero);
            Assert.AreEqual(myarray2.GetPositions().Count, 6 + 64);
            List <int> data1     = myarray1.GetPositions();
            List <int> data2     = myarray2.GetPositions();
            var        logicalor = new List <int>();

            {
                var tmp = new HashSet <int>();
                tmp.AddRange(data1);
                tmp.AddRange(data2);
                logicalor.AddRange(tmp);
            }
            logicalor.Sort();
            var logicaland = new List <int>();

            logicaland.AddRange(data1);
            logicaland.Retain(data2);
            logicaland.Sort();
            EwahCompressedBitArray arrayand = myarray1.And(myarray2);

            AreEqual(arrayand.GetPositions(), logicaland);
            EwahCompressedBitArray arrayor = myarray1.Or(myarray2);

            AreEqual(arrayor.GetPositions(), logicalor);
            EwahCompressedBitArray arrayandbis = myarray2.And(myarray1);

            AreEqual(arrayandbis.GetPositions(), logicaland);
            EwahCompressedBitArray arrayorbis = myarray2.Or(myarray1);

            AreEqual(arrayorbis.GetPositions(), logicalor);
            var x = new EwahCompressedBitArray();

            foreach (int i in myarray1.GetPositions())
            {
                x.Set(i);
            }
            AreEqual(x.GetPositions(), myarray1.GetPositions());
            x = new EwahCompressedBitArray();
            foreach (int i in myarray2.GetPositions())
            {
                x.Set(i);
            }
            AreEqual(x.GetPositions(), myarray2.GetPositions());
            x = new EwahCompressedBitArray();
            foreach (int pos in myarray1)
            {
                x.Set(pos);
            }
            AreEqual(x.GetPositions(), myarray1.GetPositions());
            x = new EwahCompressedBitArray();
            foreach (int pos in myarray2)
            {
                x.Set(pos);
            }
            AreEqual(x.GetPositions(), myarray2.GetPositions());
            Console.WriteLine("testing EWAH (basic):ok");
        }
        /**
         * a non-deterministic test proposed by Marc Polizzi.
         *
         * @param maxlength the maximum uncompressed size of the bitmap
         */

        public static void PolizziTest(int maxlength)
        {
            Console.WriteLine("Polizzi test with max length = " + maxlength);
            for (int k = 0; k < 10000; k += 77)
            {
                var rnd          = new Random();
                var ewahBitmap1  = new EwahCompressedBitArray();
                var clrBitArray1 = new BitArray(10000);
                var ewahBitmap2  = new EwahCompressedBitArray();
                var clrBitArray2 = new BitArray(10000);
                int len          = rnd.Next(maxlength);
                for (int pos = 0; pos < len; pos++)
                {
                    // random *** number of bits set ***
                    if (rnd.Next(7) == 0)
                    {
                        // random *** increasing *** values
                        ewahBitmap1.Set(pos);
                        clrBitArray1.Set(pos, true);
                    }
                    if (rnd.Next(11) == 0)
                    {
                        // random *** increasing *** values
                        ewahBitmap2.Set(pos);
                        clrBitArray2.Set(pos, true);
                    }
                }
                assertEquals(clrBitArray1, ewahBitmap1);
                assertEquals(clrBitArray2, ewahBitmap2);
                // XOR
                {
                    EwahCompressedBitArray xorEwahBitmap = ewahBitmap1.Xor(ewahBitmap2);
                    var xorclrBitArray = (BitArray)clrBitArray1.Clone();
                    xorclrBitArray.Xor(clrBitArray2);
                    assertEquals(xorclrBitArray, xorEwahBitmap);
                }
                // AND
                {
                    EwahCompressedBitArray andEwahBitmap = ewahBitmap1.And(ewahBitmap2);
                    var andclrBitArray = (BitArray)clrBitArray1.Clone();
                    andclrBitArray.And(clrBitArray2);
                    assertEquals(andclrBitArray, andEwahBitmap);
                }
                // AND
                {
                    EwahCompressedBitArray andEwahBitmap = ewahBitmap2.And(ewahBitmap1);
                    var andclrBitArray = (BitArray)clrBitArray1.Clone();
                    andclrBitArray.And(clrBitArray2);
                    assertEquals(andclrBitArray, andEwahBitmap);
                }
                // AND NOT
                {
                    EwahCompressedBitArray andNotEwahBitmap = ewahBitmap1
                                                              .AndNot(ewahBitmap2);
                    var andNotclrBitArray = (BitArray)clrBitArray1.Clone();
                    andNotclrBitArray.AndNot(clrBitArray2);
                    assertEquals(andNotclrBitArray, andNotEwahBitmap);
                }
                // AND NOT
                {
                    EwahCompressedBitArray andNotEwahBitmap = ewahBitmap2
                                                              .AndNot(ewahBitmap1);
                    var andNotclrBitArray = (BitArray)clrBitArray2.Clone();
                    andNotclrBitArray.AndNot(clrBitArray1);
                    assertEquals(andNotclrBitArray, andNotEwahBitmap);
                }
                // OR
                {
                    EwahCompressedBitArray orEwahBitmap = ewahBitmap1.Or(ewahBitmap2);
                    var orclrBitArray = (BitArray)clrBitArray1.Clone();
                    orclrBitArray.Or(clrBitArray2);
                    assertEquals(orclrBitArray, orEwahBitmap);
                }
                // OR
                {
                    EwahCompressedBitArray orEwahBitmap = ewahBitmap2.Or(ewahBitmap1);
                    var orclrBitArray = (BitArray)clrBitArray1.Clone();
                    orclrBitArray.Or(clrBitArray2);
                    assertEquals(orclrBitArray, orEwahBitmap);
                }
            }
        }
Ejemplo n.º 7
0
 public IBitmap Or(IBitmap bitmap)
 {
     _bitmap = _bitmap.Or(((CompressedBitmap)bitmap)._bitmap);
     return(this);
 }
Ejemplo n.º 8
0
 private static bool IsSubsetOf(this EwahCompressedBitArray PurportedSubset, EwahCompressedBitArray Set)
 {
     return(Set.Or(PurportedSubset).Equals(Set));
 }