public override SpanFilterResult BitSpans(IndexReader reader) { OpenBitSet bits = new OpenBitSet(reader.MaxDoc); Lucene.Net.Search.Spans.Spans spans = internalQuery.GetSpans(reader); IList<SpanFilterResult.PositionInfo> tmp = new List<SpanFilterResult.PositionInfo>(20); int currentDoc = - 1; SpanFilterResult.PositionInfo currentInfo = null; while (spans.Next()) { int doc = spans.Doc(); bits.Set(doc); if (currentDoc != doc) { currentInfo = new SpanFilterResult.PositionInfo(doc); tmp.Add(currentInfo); currentDoc = doc; } currentInfo.AddPosition(spans.Start(), spans.End()); } return new SpanFilterResult(bits, tmp); }
/// <summary>this = this XOR other </summary> public virtual void Xor(OpenBitSet other) { int newLen = System.Math.Max(wlen, other.wlen); EnsureCapacityWords(newLen); long[] thisArr = this.internalbits; long[] otherArr = other.internalbits; int pos = System.Math.Min(wlen, other.wlen); while (--pos >= 0) { thisArr[pos] ^= otherArr[pos]; } if (this.wlen < newLen) { Array.Copy(otherArr, this.wlen, thisArr, this.wlen, newLen - this.wlen); } this.wlen = newLen; }
/// <summary>Remove all elements set in other. this = this AND_NOT other </summary> public virtual void Remove(OpenBitSet other) { int idx = System.Math.Min(wlen, other.wlen); long[] thisArr = this.internalbits; long[] otherArr = other.internalbits; while (--idx >= 0) { thisArr[idx] &= ~ otherArr[idx]; } }
/// <summary>this = this AND other </summary> public virtual void Intersect(OpenBitSet other) { int newLen = System.Math.Min(this.wlen, other.wlen); long[] thisArr = this.internalbits; long[] otherArr = other.internalbits; // testing against zero can be more efficient int pos = newLen; while (--pos >= 0) { thisArr[pos] &= otherArr[pos]; } if (this.wlen > newLen) { // fill zeros from the new shorter length to the old length for (int i = newLen; i < this.wlen; i++) internalbits[i] = 0L; } this.wlen = newLen; }
public virtual System.Object Clone() { try { OpenBitSet obs = new OpenBitSet((long[]) internalbits.Clone(), wlen); //obs.bits = new long[obs.bits.Length]; //obs.bits.CopyTo(obs.bits, 0); // hopefully an array clone is as fast(er) than arraycopy return obs; } catch (System.Exception e) { throw new System.SystemException(e.Message, e); } }
/// <summary>Returns the popcount or cardinality of the exclusive-or of the two sets. /// Neither set is modified. /// </summary> public static long XorCount(OpenBitSet a, OpenBitSet b) { long tot = BitUtil.Pop_xor(a.internalbits, b.internalbits, 0, System.Math.Min(a.wlen, b.wlen)); if (a.wlen < b.wlen) { tot += BitUtil.Pop_array(b.internalbits, a.wlen, b.wlen - a.wlen); } else if (a.wlen > b.wlen) { tot += BitUtil.Pop_array(a.internalbits, b.wlen, a.wlen - b.wlen); } return tot; }
/// <summary>Returns the popcount or cardinality of the intersection of the two sets. /// Neither set is modified. /// </summary> public static long IntersectionCount(OpenBitSet a, OpenBitSet b) { return(BitUtil.Pop_intersect(a.internalbits, b.internalbits, 0, System.Math.Min(a.wlen, b.wlen))); }
//* see <see cref="andNot" /> */ public virtual void AndNot(OpenBitSet other) { Remove(other); }
public FieldCacheTermsFilterDocIdSet(FieldCacheTermsFilter enclosingInstance, StringIndex fcsi) { InitBlock(enclosingInstance); this.fcsi = fcsi; openBitSet = new OpenBitSet(this.fcsi.lookup.Length); foreach (string t in Enclosing_Instance.terms) { int termNumber = this.fcsi.BinarySearchLookup(t); if (termNumber > 0) { openBitSet.FastSet(termNumber); } } }
public OpenBitSetIterator(OpenBitSet obs):this(obs.Bits, obs.NumWords) { }
//* see <see cref="andNot" /> */ public virtual void AndNot(OpenBitSet other) { Remove(other); }
//* see <see cref="union" /> */ public virtual void Or(OpenBitSet other) { Union(other); }
// some BitSet compatability methods //* see <see cref="intersect" /> */ public virtual void And(OpenBitSet other) { Intersect(other); }
// some BitSet compatability methods //* see <see cref="intersect" /> */ public virtual void And(OpenBitSet other) { Intersect(other); }
/// <summary>Returns the popcount or cardinality of the intersection of the two sets. /// Neither set is modified. /// </summary> public static long IntersectionCount(OpenBitSet a, OpenBitSet b) { return BitUtil.Pop_intersect(a.internalbits, b.internalbits, 0, System.Math.Min(a.wlen, b.wlen)); }
//* see <see cref="union" /> */ public virtual void Or(OpenBitSet other) { Union(other); }
/// <summary>Returns the popcount or cardinality of "a and not b" /// or "intersection(a, not(b))". /// Neither set is modified. /// </summary> public static long AndNotCount(OpenBitSet a, OpenBitSet b) { long tot = BitUtil.Pop_andnot(a.internalbits, b.internalbits, 0, System.Math.Min(a.wlen, b.wlen)); if (a.wlen > b.wlen) { tot += BitUtil.Pop_array(a.internalbits, b.wlen, a.wlen - b.wlen); } return tot; }
/// <summary>returns true if the sets have any elements in common </summary> public virtual bool Intersects(OpenBitSet other) { int pos = System.Math.Min(this.wlen, other.wlen); long[] thisArr = this.internalbits; long[] otherArr = other.internalbits; while (--pos >= 0) { if ((thisArr[pos] & otherArr[pos]) != 0) return true; } return false; }
/// <summary> Create a SortedVIntList from an OpenBitSet.</summary> /// <param name="bits"> A bit set representing a set of integers. /// </param> public SortedVIntList(OpenBitSet bits) { SortedVIntListBuilder builder = new SortedVIntListBuilder(this); int nextInt = bits.NextSetBit(0); while (nextInt != - 1) { builder.AddInt(nextInt); nextInt = bits.NextSetBit(nextInt + 1); } builder.Done(); }