Flip() public method

Flips a range of bits
public Flip ( int startIndex, int endIndex ) : void
startIndex int lower index
endIndex int one-past the last bit to flip
return void
Esempio n. 1
0
        /// <summary>
        /// Note: The neededBounds Iterable must be unsigned (easier understanding what's happening) </summary>
        private void AssertIntRangeSplit(int lower, int upper, int precisionStep, bool useBitSet, IEnumerable <int> expectedBounds, IEnumerable <int> expectedShifts)
        {
            FixedBitSet       bits         = useBitSet ? new FixedBitSet(upper - lower + 1) : null;
            IEnumerator <int> neededBounds = (expectedBounds is null) ? null : expectedBounds.GetEnumerator();
            IEnumerator <int> neededShifts = (expectedShifts is null) ? null : expectedShifts.GetEnumerator();

            NumericUtils.SplitInt32Range(new IntRangeBuilderAnonymousClass(lower, upper, useBitSet, bits, neededBounds, neededShifts), precisionStep, lower, upper);

            if (useBitSet)
            {
                // after flipping all bits in the range, the cardinality should be zero
                bits.Flip(0, upper - lower + 1);
                Assert.AreEqual(0, bits.Cardinality, "The sub-range concenated should match the whole range");
            }
        }
Esempio n. 2
0
 private FixedBitSet InitialResult(AtomicReaderContext context, int logic, int[] index)
 {
     AtomicReader reader = context.AtomicReader;
     FixedBitSet result = new FixedBitSet(reader.MaxDoc);
     if (logic == AND)
     {
         result.Or(GetDISI(chain[index[0]], context));
         ++index[0];
     }
     else if (logic == ANDNOT)
     {
         result.Or(GetDISI(chain[index[0]], context));
         result.Flip(0, reader.MaxDoc); // NOTE: may set bits for deleted docs.
         ++index[0];
     }
     return result;
 }
            public DocumentFilteredAtomicIndexReader(AtomicReaderContext context, Filter preserveFilter, bool negateFilter)
                    : base(context.AtomicReader)
            {
                int maxDoc = @in.MaxDoc;
                FixedBitSet bits = new FixedBitSet(maxDoc);
                // ignore livedocs here, as we filter them later:
                DocIdSet docs = preserveFilter.GetDocIdSet(context, null);
                if (docs != null)
                {
                    DocIdSetIterator it = docs.GetIterator();
                    if (it != null)
                    {
                        bits.Or(it);
                    }
                }
                if (negateFilter)
                {
                    bits.Flip(0, maxDoc);
                }

                if (@in.HasDeletions)
                {
                    Bits oldLiveDocs = @in.LiveDocs;
                    Debug.Assert(oldLiveDocs != null);
                    DocIdSetIterator it = bits.GetIterator();
                    for (int i = it.NextDoc(); i < maxDoc; i = it.NextDoc())
                    {
                        if (!oldLiveDocs.Get(i))
                        {
                            // we can safely modify the current bit, as the iterator already stepped over it:
                            bits.Clear(i);
                        }
                    }
                }

                this.liveDocs = bits;
                this.numDocs_Renamed = bits.Cardinality();
            }