Example #1
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());
            }
        }
Example #2
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));
			}
		}
Example #3
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));
            }
        }
Example #4
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));
            }
        }
Example #5
0
 public override sealed int FindValues(BitVector bitset, int docId, int maxId)
 {
     while (true)
     {
         if (bitset.Get(_array[docId >> SHIFT_SIZE][docId & MASK])) return docId;
         if (docId++ >= maxId) break;
     }
     return DocIdSetIterator.NO_MORE_DOCS;
 }
Example #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", null);
                BitVector compare = new BitVector(d, "TESTBV", null);
                // compare bit vectors with bits set incrementally
                Assert.IsTrue(DoCompare(bv, compare));
            }
        }
Example #7
0
        /// <summary> Compare a subset against the corresponding portion of the test pattern</summary>
        private void  DoTestSubset(int start, int end)
        {
            BitVector full   = CreateSubsetTestVector();
            BitVector subset = full.Subset(start, end);

            Assert.AreEqual(end - start, subset.Size());
            int count = 0;

            for (int i = start, j = 0; i < end; i++, j++)
            {
                if (subsetPattern[i] == 1)
                {
                    count++;
                    Assert.IsTrue(subset.Get(j));
                }
                else
                {
                    Assert.IsFalse(subset.Get(j));
                }
            }
            Assert.AreEqual(count, subset.Count());
        }
Example #8
0
        /// <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;
                }
            }
            return(equal);
        }
 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;
 }
Example #10
0
		/// <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;
				}
			}
			return equal;
		}
Example #11
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));
			}
		}
Example #12
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());
			}
		}
 /// <summary>
 /// (non-Javadoc)
 /// see com.browseengine.bobo.util.BigSegmentedArray#findValues(org.apache.lucene.util.BitVector, int, int)
 /// </summary>
 /// <param name="bitset"></param>
 /// <param name="id"></param>
 /// <param name="maxId"></param>
 /// <returns></returns>
 public override int FindValues(BitVector bitset, int id, int maxId)
 {
     while (id <= maxId)
     {
         int i = id >> SHIFT_SIZE;
         if (_array[i] == null)
         {
             if (bitset.Get(_fillValue))
                 return id;
             else
                 id = (i + 1) << SHIFT_SIZE; // jump to next segment
         }
         else
         {
             if (bitset.Get(_array[i][id & MASK]))
                 return id;
             else
                 id++;
         }
     }
     return DocIdSetIterator.NO_MORE_DOCS;
 }
        public bool Contains(int id, BitVector values)
        {
            // NOTE: Added Get() extension method call because 
            // the default .NET behavior throws an exception if the
            // index is out of bounds, rather than returning null.
            int[] page = _list.Get(id >> PAGEID_SHIFT);
            if (page == null) return false;

            int val = page[id & SLOTID_MASK];
            if (val >= 0)
            {
                return (values.Get(val));
            }
            else if (val != MISSING)
            {
                int idx = -(val >> VALIDX_SHIFT);// signed shift, remember this is a negative number
                int end = idx + (val & COUNT_MASK);
                while (idx < end)
                {
                    if (values.Get(page[idx++])) return true;
                }
            }
            return false;
        }
        public int FindValues(BitVector values, int id, int maxID, bool withMissing)
        {
            // NOTE: Added Get() extension method call because 
            // the default .NET behavior throws an exception if the
            // index is out of bounds, rather than returning null.
            int[] page = _list.Get(id >> PAGEID_SHIFT);
            if (page == null) page = MISSING_PAGE;

            while (true)
            {
                int val = page[id & SLOTID_MASK];
                if (val >= 0)
                {
                    if (values.Get(val)) return id;
                }
                else if (val != MISSING)
                {
                    int idx = -(val >> VALIDX_SHIFT);// signed shift, remember this is a negative number
                    int end = idx + (val & COUNT_MASK);
                    while (idx < end)
                    {
                        if (values.Get(page[idx++])) return id;
                    }
                }
                else if (withMissing)
                {
                    if (values.Get(0)) return id;
                }
                if (id >= maxID) break;

                if ((++id & SLOTID_MASK) == 0)
                {
                    // NOTE: Added Get() extension method call because 
                    // the default .NET behavior throws an exception if the
                    // index is out of bounds, rather than returning null.
                    page = _list.Get(id >> PAGEID_SHIFT);
                    if (page == null) page = MISSING_PAGE;
                }
            }

            return DocIdSetIterator.NO_MORE_DOCS;
        }
Example #16
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));
			}
		}
        public void CountNoReturnWithFilter(int id, int[] count, BitVector filter)
        {
            // NOTE: Added Get() extension method call because 
            // the default .NET behavior throws an exception if the
            // index is out of bounds, rather than returning null.
            int[] page = _list.Get(id >> PAGEID_SHIFT);
            if (page == null)
            {
                count[0]++;
                return;
            }

            int val = page[id & SLOTID_MASK];
            if (val >= 0)
            {
                if (filter.Get(val))
                {
                    count[val]++;
                }
                return;
            }
            else if (val != MISSING)
            {
                int idx = -(val >> VALIDX_SHIFT); // signed shift, remember val is a negative number
                int cnt = (val & COUNT_MASK);
                int end = idx + cnt;
                while (idx < end)
                {
                    int value = page[idx++];
                    if (filter.Get(value))
                    {
                        count[value]++;
                    }
                }
                return;
            }
            count[0]++;
            return;
        }