示例#1
0
		private void  DoTestGetSetVectorOfSize(int n)
		{
			BitVector bv = new BitVector(n);
			for (int i = 0; i < bv.Size(); i++)
			{
				// ensure a set bit can be git'
				Assert.IsFalse(bv.Get(i));
				bv.Set(i);
				Assert.IsTrue(bv.Get(i));
			}
		}
 private BigSegmentedArray GetCollapsedCounts()
 {
     if (_collapsedCounts == null)
     {
         _collapsedCounts = new LazyBigIntArray(_bucketValues.Count);
         FacetDataCache dataCache = _subCollector.DataCache;
         ITermValueList subList = dataCache.ValArray;
         BigSegmentedArray subcounts = _subCollector.Count;
         BitVector indexSet = new BitVector(subcounts.Size());
         int c = 0;
         int i = 0;
         foreach (string val in _bucketValues)
         {
             if (val.Length > 0)
             {
                 string[] subVals = _predefinedBuckets.Get(val);
                 int count = 0;
                 foreach (string subVal in subVals)
                 {
                     int index = subList.IndexOf(subVal);
                     if (index > 0)
                     {
                         int subcount = subcounts.Get(index);
                         count += subcount;
                         if (!indexSet.Get(index))
                         {
                             indexSet.Set(index);
                             c += dataCache.Freqs[index];
                         }
                     }
                 }
                 _collapsedCounts.Add(i, count);
             }
             i++;
         }
         _collapsedCounts.Add(0, (_numdocs - c));
     }
     return _collapsedCounts;
 }
示例#3
0
		private void  DoTestClearVectorOfSize(int n)
		{
			BitVector bv = new BitVector(n);
			for (int i = 0; i < bv.Size(); i++)
			{
				// ensure a set bit is cleared
				Assert.IsFalse(bv.Get(i));
				bv.Set(i);
				Assert.IsTrue(bv.Get(i));
				bv.Clear(i);
				Assert.IsFalse(bv.Get(i));
			}
		}
示例#4
0
		private BitVector CreateSubsetTestVector()
		{
			BitVector bv = new BitVector(subsetPattern.Length);
			for (int i = 0; i < subsetPattern.Length; i++)
			{
				if (subsetPattern[i] == 1)
				{
					bv.Set(i);
				}
			}
			return bv;
		}
示例#5
0
		private void  DoTestDgaps(int size, int count1, int count2)
		{
			Directory d = new RAMDirectory();
			BitVector bv = new BitVector(size);
			for (int i = 0; i < count1; i++)
			{
				bv.Set(i);
				Assert.AreEqual(i + 1, bv.Count());
			}
			bv.Write(d, "TESTBV");
			// gradually increase number of set bits
			for (int i = count1; i < count2; i++)
			{
				BitVector bv2 = new BitVector(d, "TESTBV");
				Assert.IsTrue(DoCompare(bv, bv2));
				bv = bv2;
				bv.Set(i);
				Assert.AreEqual(i + 1, bv.Count());
				bv.Write(d, "TESTBV");
			}
			// now start decreasing number of set bits
			for (int i = count2 - 1; i >= count1; i--)
			{
				BitVector bv2 = new BitVector(d, "TESTBV");
				Assert.IsTrue(DoCompare(bv, bv2));
				bv = bv2;
				bv.Clear(i);
				Assert.AreEqual(i, bv.Count());
				bv.Write(d, "TESTBV");
			}
		}
示例#6
0
		private void  DoTestWriteRead(int n)
		{
			Directory d = new RAMDirectory();
			
			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");
				BitVector compare = new BitVector(d, "TESTBV");
				// compare bit vectors with bits set incrementally
				Assert.IsTrue(DoCompare(bv, compare));
			}
		}
示例#7
0
		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());
			}
		}