public void TestMassiveAnd() { Console.WriteLine("testing massive logical and"); var ewah = new EwahCompressedBitArray[1024]; for (int k = 0; k < ewah.Length; ++k) { ewah[k] = new EwahCompressedBitArray(); } for (int k = 0; k < 30000; ++k) { ewah[(k + 2 * k * k) % ewah.Length].Set(k); } EwahCompressedBitArray answer = ewah[0]; for (int k = 1; k < ewah.Length; ++k) { answer = answer.And(ewah[k]); } // result should be empty if (answer.GetPositions().Count != 0) { Console.WriteLine(answer.ToDebugString()); } Assert.IsTrue(answer.GetPositions().Count == 0); Console.WriteLine("testing massive logical and:ok"); }
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 SsiYanKaiTest() { Console.WriteLine("testing SsiYanKaiTest"); EwahCompressedBitArray a = EwahCompressedBitArray.BitmapOf(39935, 39936, 39937, 39938, 39939, 39940, 39941, 39942, 39943, 39944, 39945, 39946, 39947, 39948, 39949, 39950, 39951, 39952, 39953, 39954, 39955, 39956, 39957, 39958, 39959, 39960, 39961, 39962, 39963, 39964, 39965, 39966, 39967, 39968, 39969, 39970, 39971, 39972, 39973, 39974, 39975, 39976, 39977, 39978, 39979, 39980, 39981, 39982, 39983, 39984, 39985, 39986, 39987, 39988, 39989, 39990, 39991, 39992, 39993, 39994, 39995, 39996, 39997, 39998, 39999, 40000, 40001, 40002, 40003, 40004, 40005, 40006, 40007, 40008, 40009, 40010, 40011, 40012, 40013, 40014, 40015, 40016, 40017, 40018, 40019, 40020, 40021, 40022, 40023, 40024, 40025, 40026, 40027, 40028, 40029, 40030, 40031, 40032, 40033, 40034, 40035, 40036, 40037, 40038, 40039, 40040, 40041, 40042, 40043, 40044, 40045, 40046, 40047, 40048, 40049, 40050, 40051, 40052, 40053, 40054, 40055, 40056, 40057, 40058, 40059, 40060, 40061, 40062, 40063, 40064, 40065, 40066, 40067, 40068, 40069, 40070, 40071, 40072, 40073, 40074, 40075, 40076, 40077, 40078, 40079, 40080, 40081, 40082, 40083, 40084, 40085, 40086, 40087, 40088, 40089, 40090, 40091, 40092, 40093, 40094, 40095, 40096, 40097, 40098, 40099, 40100); EwahCompressedBitArray b = EwahCompressedBitArray.BitmapOf(39935, 39936, 39937, 39938, 39939, 39940, 39941, 39942, 39943, 39944, 39945, 39946, 39947, 39948, 39949, 39950, 39951, 39952, 39953, 39954, 39955, 39956, 39957, 39958, 39959, 39960, 39961, 39962, 39963, 39964, 39965, 39966, 39967, 39968, 39969, 39970, 39971, 39972, 39973, 39974, 39975, 39976, 39977, 39978, 39979, 39980, 39981, 39982, 39983, 39984, 39985, 39986, 39987, 39988, 39989, 39990, 39991, 39992, 39993, 39994, 39995, 39996, 39997, 39998, 39999, 270000); HashSet <int> aPositions = new HashSet <int>(a.GetPositions()); int intersection = 0; EwahCompressedBitArray inter = new EwahCompressedBitArray(); HashSet <int> bPositions = new HashSet <int>(b.GetPositions()); foreach (int integer in bPositions) { if (aPositions.Contains(integer)) { inter.Set(integer); ++intersection; } } EwahCompressedBitArray and2 = a.And(b); List <int> l1 = inter.GetPositions(); List <int> l2 = and2.GetPositions(); var ok = true; if (l1.Count != l2.Count) { Console.WriteLine("cardinality differs = " + l1.Count + " " + l2.Count); ok = false; } for (int k = 0; k < l1.Count; ++k) { if (l1[k] != l2[k]) { Console.WriteLine("differ at " + k + " = " + l1[k] + " " + l2[k]); ok = false; } } Assert.IsTrue(ok); Assert.AreEqual(true, and2.Equals(inter)); Assert.AreEqual(inter.GetHashCode(), and2.GetHashCode()); Assert.AreEqual(intersection, and2.GetCardinality()); }
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 TestMassiveAndNot() { Console.WriteLine("testing massive and not"); int N = 1024; var ewah = new EwahCompressedBitArray[N]; for (int k = 0; k < ewah.Length; ++k) { ewah[k] = new EwahCompressedBitArray(); } for (int k = 0; k < 30000; ++k) { ewah[(k + 2 * k * k) % ewah.Length].Set(k); } EwahCompressedBitArray answer = ewah[0]; EwahCompressedBitArray answer2 = ewah[0]; ; for (int k = 1; k < ewah.Length; ++k) { answer = answer.AndNot(ewah[k]); EwahCompressedBitArray copy = null; try { copy = (EwahCompressedBitArray)ewah[k].Clone(); copy.Not(); answer2.And(copy); assertEqualsPositions(answer.GetPositions(), answer2.GetPositions()); } catch (InvalidOperationException e) { Console.Error.WriteLine(e.StackTrace); } } Console.WriteLine("testing massive and not: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); } } }
private static bool Overlaps(this EwahCompressedBitArray PurportedOverlappingSet, EwahCompressedBitArray Set) { return(Set.And(PurportedOverlappingSet).GetCardinality() > 1); }