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 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"); }
public void TestMassiveXOR() { Console.WriteLine("testing massive xor (can take a couple of minutes)"); int N = 16; var ewah = new EwahCompressedBitArray[N]; var bset = new BitArray[N]; for (int k = 0; k < ewah.Length; ++k) { ewah[k] = new EwahCompressedBitArray(); } for (int k = 0; k < bset.Length; ++k) { bset[k] = new BitArray(30000); } for (int k = 0; k < 30000; ++k) { ewah[(k + 2 * k * k) % ewah.Length].Set(k); bset[(k + 2 * k * k) % ewah.Length].Set(k, true); } EwahCompressedBitArray answer = ewah[0]; BitArray BitArrayanswer = bset[0]; for (int k = 1; k < ewah.Length; ++k) { answer = answer.Xor(ewah[k]); BitArrayanswer.Xor(bset[k]); assertEqualsPositions(BitArrayanswer, answer); } int k2 = 0; foreach (int j in answer) { if (k2 != j) { Console.WriteLine(answer.ToDebugString()); } Assert.AreEqual(k2, j); k2 += 1; } Console.WriteLine("testing massive xor:ok"); }