Esempio n. 1
0
		public System.Object Clone()
		{
			byte[] copyBits = new byte[bits.Length];
			Array.Copy(bits, 0, copyBits, 0, bits.Length);
            BitVector clone = new BitVector(copyBits, size);
            clone.count = count;
            return clone;
		}
Esempio n. 2
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;
 }
Esempio n. 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));
			}
		}
Esempio n. 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));
			}
		}
 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;
 }
Esempio n. 6
0
        private void  DoTestConstructOfSize(int n)
        {
            BitVector bv = new BitVector(n);

            Assert.AreEqual(n, bv.Size());
        }
Esempio n. 7
0
		private void  DoTestConstructOfSize(int n)
		{
			BitVector bv = new BitVector(n);
			Assert.AreEqual(n, bv.Size());
		}
Esempio n. 8
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;
		}
Esempio n. 9
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;
		}
Esempio n. 10
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");
			}
		}
Esempio n. 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));
			}
		}
Esempio n. 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;
 }
Esempio n. 14
0
 public abstract int FindValues(BitVector bitset, int id, int maxId);
Esempio n. 15
0
        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;
        }
Esempio n. 16
0
 public int FindValues(BitVector values, int id, int maxID)
 {
     return FindValues(values, id, maxID, false);
 }
Esempio n. 17
0
        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;
        }
Esempio n. 18
0
        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;
        }