private void DoTestCountVectorOfSize(int n) { BitVector bv = new BitVector(n); // test count when incrementally setting bits for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size() { Assert.IsFalse(bv.Get(i)); Assert.AreEqual(i, bv.Count()); bv.Set(i); Assert.IsTrue(bv.Get(i)); Assert.AreEqual(i + 1, bv.Count()); } bv = new BitVector(n); // test count when setting then clearing bits for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size() { Assert.IsFalse(bv.Get(i)); Assert.AreEqual(0, bv.Count()); bv.Set(i); Assert.IsTrue(bv.Get(i)); Assert.AreEqual(1, bv.Count()); bv.Clear(i); Assert.IsFalse(bv.Get(i)); Assert.AreEqual(0, bv.Count()); } }
private void DoTestDgaps(int size, int count1, int count2) { MockDirectoryWrapper d = new MockDirectoryWrapper(Random, new RAMDirectory()); d.PreventDoubleWrite = false; BitVector bv = new BitVector(size); bv.InvertAll(); for (int i = 0; i < count1; i++) { bv.Clear(i); Assert.AreEqual(i + 1, size - bv.Count()); } bv.Write(d, "TESTBV", NewIOContext(Random)); // gradually increase number of set bits for (int i = count1; i < count2; i++) { BitVector bv2 = new BitVector(d, "TESTBV", NewIOContext(Random)); Assert.IsTrue(DoCompare(bv, bv2)); bv = bv2; bv.Clear(i); Assert.AreEqual(i + 1, size - bv.Count()); bv.Write(d, "TESTBV", NewIOContext(Random)); } // now start decreasing number of set bits for (int i = count2 - 1; i >= count1; i--) { BitVector bv2 = new BitVector(d, "TESTBV", NewIOContext(Random)); Assert.IsTrue(DoCompare(bv, bv2)); bv = bv2; bv.Set(i); Assert.AreEqual(i, size - bv.Count()); bv.Write(d, "TESTBV", NewIOContext(Random)); } }
public virtual void TestMostlySet() { Directory d = NewDirectory(); int numBits = TestUtil.NextInt32(Random, 30, 1000); for (int numClear = 0; numClear < 20; numClear++) { BitVector bv = new BitVector(numBits); bv.InvertAll(); int count = 0; while (count < numClear) { int bit = Random.Next(numBits); // Don't use getAndClear, so that count is recomputed if (bv.Get(bit)) { bv.Clear(bit); count++; Assert.AreEqual(numBits - count, bv.Count()); } } } d.Dispose(); }
public override void WriteLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) { string filename = IndexFileNames.FileNameFromGeneration(info.Info.Name, DELETES_EXTENSION, info.NextDelGen); BitVector liveDocs = (BitVector)bits; Debug.Assert(liveDocs.Count() == info.Info.DocCount - info.DelCount - newDelCount); Debug.Assert(liveDocs.Length() == info.Info.DocCount); liveDocs.Write(dir, filename, context); }
public override Bits ReadLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) { string filename = IndexFileNames.FileNameFromGeneration(info.Info.Name, DELETES_EXTENSION, info.DelGen); BitVector liveDocs = new BitVector(dir, filename, context); Debug.Assert(liveDocs.Count() == info.Info.DocCount - info.DelCount, "liveDocs.count()=" + liveDocs.Count() + " info.docCount=" + info.Info.DocCount + " info.getDelCount()=" + info.DelCount); Debug.Assert(liveDocs.Length() == info.Info.DocCount); return(liveDocs); }
public virtual void TestClearedBitNearEnd() { Directory d = NewDirectory(); int numBits = TestUtil.NextInt(Random(), 7, 1000); BitVector bv = new BitVector(numBits); bv.InvertAll(); bv.Clear(numBits - TestUtil.NextInt(Random(), 1, 7)); bv.Write(d, "test", NewIOContext(Random())); Assert.AreEqual(numBits - 1, bv.Count()); d.Dispose(); }
public override IBits ReadLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) { string filename = IndexFileNames.FileNameFromGeneration(info.Info.Name, DELETES_EXTENSION, info.DelGen); BitVector liveDocs = new BitVector(dir, filename, context); if (Debugging.AssertsEnabled) { Debugging.Assert(liveDocs.Count() == info.Info.DocCount - info.DelCount, "liveDocs.Count()={0} info.DocCount={1} info.DelCount={2}", liveDocs.Count(), info.Info.DocCount, info.DelCount); Debugging.Assert(liveDocs.Length == info.Info.DocCount); } return(liveDocs); }
public virtual void TestClearedBitNearEnd() { Directory d = NewDirectory(); int numBits = TestUtil.NextInt32(Random, 7, 1000); BitVector bv = new BitVector(numBits); bv.InvertAll(); bv.Clear(numBits - TestUtil.NextInt32(Random, 1, 7)); bv.Write(d, "test", NewIOContext(Random)); Assert.AreEqual(numBits - 1, bv.Count()); d.Dispose(); }
private void DoTestWriteRead(int n) { MockDirectoryWrapper d = new MockDirectoryWrapper(Random, new RAMDirectory()); d.PreventDoubleWrite = false; BitVector bv = new BitVector(n); // test count when incrementally setting bits for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size() { Assert.IsFalse(bv.Get(i)); Assert.AreEqual(i, bv.Count()); bv.Set(i); Assert.IsTrue(bv.Get(i)); Assert.AreEqual(i + 1, bv.Count()); bv.Write(d, "TESTBV", NewIOContext(Random)); BitVector compare = new BitVector(d, "TESTBV", NewIOContext(Random)); // compare bit vectors with bits set incrementally Assert.IsTrue(DoCompare(bv, compare)); } }
/// <summary> /// Compare two BitVectors. /// this should really be an equals method on the BitVector itself. </summary> /// <param name="bv"> One bit vector </param> /// <param name="compare"> The second to compare </param> private bool DoCompare(BitVector bv, BitVector compare) { bool equal = true; for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size() { // bits must be equal if (bv.Get(i) != compare.Get(i)) { equal = false; break; } } Assert.AreEqual(bv.Count(), compare.Count()); return(equal); }
/// <summary> /// Compare two BitVectors. /// this should really be an equals method on the BitVector itself. </summary> /// <param name="bv"> One bit vector </param> /// <param name="compare"> The second to compare </param> private bool DoCompare(BitVector bv, BitVector compare) { bool equal = true; for (int i = 0; i < bv.Size(); i++) { // bits must be equal if (bv.Get(i) != compare.Get(i)) { equal = false; break; } } Assert.AreEqual(bv.Count(), compare.Count()); return(equal); }
private void DoTestWriteRead(int n) { MockDirectoryWrapper d = new MockDirectoryWrapper(Random(), new RAMDirectory()); d.PreventDoubleWrite = false; BitVector bv = new BitVector(n); // test count when incrementally setting bits for (int i = 0; i < bv.Size(); i++) { Assert.IsFalse(bv.Get(i)); Assert.AreEqual(i, bv.Count()); bv.Set(i); Assert.IsTrue(bv.Get(i)); Assert.AreEqual(i + 1, bv.Count()); bv.Write(d, "TESTBV", NewIOContext(Random())); BitVector compare = new BitVector(d, "TESTBV", NewIOContext(Random())); // compare bit vectors with bits set incrementally Assert.IsTrue(DoCompare(bv, compare)); } }
private void DoTestDgaps(int size, int count1, int count2) { MockDirectoryWrapper d = new MockDirectoryWrapper(Random(), new RAMDirectory()); d.PreventDoubleWrite = false; BitVector bv = new BitVector(size); bv.InvertAll(); for (int i = 0; i < count1; i++) { bv.Clear(i); Assert.AreEqual(i + 1, size - bv.Count()); } bv.Write(d, "TESTBV", NewIOContext(Random())); // gradually increase number of set bits for (int i = count1; i < count2; i++) { BitVector bv2 = new BitVector(d, "TESTBV", NewIOContext(Random())); Assert.IsTrue(DoCompare(bv, bv2)); bv = bv2; bv.Clear(i); Assert.AreEqual(i + 1, size - bv.Count()); bv.Write(d, "TESTBV", NewIOContext(Random())); } // now start decreasing number of set bits for (int i = count2 - 1; i >= count1; i--) { BitVector bv2 = new BitVector(d, "TESTBV", NewIOContext(Random())); Assert.IsTrue(DoCompare(bv, bv2)); bv = bv2; bv.Set(i); Assert.AreEqual(i, size - bv.Count()); bv.Write(d, "TESTBV", NewIOContext(Random())); } }
private void DoTestCountVectorOfSize(int n) { BitVector bv = new BitVector(n); // test count when incrementally setting bits for (int i = 0; i < bv.Size(); i++) { Assert.IsFalse(bv.Get(i)); Assert.AreEqual(i, bv.Count()); bv.Set(i); Assert.IsTrue(bv.Get(i)); Assert.AreEqual(i + 1, bv.Count()); } bv = new BitVector(n); // test count when setting then clearing bits for (int i = 0; i < bv.Size(); i++) { Assert.IsFalse(bv.Get(i)); Assert.AreEqual(0, bv.Count()); bv.Set(i); Assert.IsTrue(bv.Get(i)); Assert.AreEqual(1, bv.Count()); bv.Clear(i); Assert.IsFalse(bv.Get(i)); Assert.AreEqual(0, bv.Count()); } }
/// <summary> /// Compare two BitVectors. /// this should really be an equals method on the BitVector itself. </summary> /// <param name="bv"> One bit vector </param> /// <param name="compare"> The second to compare </param> private bool DoCompare(BitVector bv, BitVector compare) { bool equal = true; for (int i = 0; i < bv.Size(); i++) { // bits must be equal if (bv.Get(i) != compare.Get(i)) { equal = false; break; } } Assert.AreEqual(bv.Count(), compare.Count()); return equal; }
public virtual void TestMostlySet() { Directory d = NewDirectory(); int numBits = TestUtil.NextInt(Random(), 30, 1000); for (int numClear = 0; numClear < 20; numClear++) { BitVector bv = new BitVector(numBits); bv.InvertAll(); int count = 0; while (count < numClear) { int bit = Random().Next(numBits); // Don't use getAndClear, so that count is recomputed if (bv.Get(bit)) { bv.Clear(bit); count++; Assert.AreEqual(numBits - count, bv.Count()); } } } d.Dispose(); }
public override Bits ReadLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) { string filename = IndexFileNames.FileNameFromGeneration(info.Info.Name, DELETES_EXTENSION, info.DelGen); BitVector liveDocs = new BitVector(dir, filename, context); Debug.Assert(liveDocs.Count() == info.Info.DocCount - info.DelCount, "liveDocs.count()=" + liveDocs.Count() + " info.docCount=" + info.Info.DocCount + " info.getDelCount()=" + info.DelCount); Debug.Assert(liveDocs.Length() == info.Info.DocCount); return liveDocs; }