BitsetsNET.Tests.SetGenerator.GetContiguousArrayWithExceptions C# (CSharp) Метод

GetContiguousArrayWithExceptions() публичный статический Метод

Knocks out a few selected values from a contiguous array to allow meaningful difference testing.This would ordinarily be done by just using GetContiguousArray and flipping the bits off with Set() or Flip(), but those are not currently Implemented in RLE.
public static GetContiguousArrayWithExceptions ( int start, int end, int exceptions ) : int[]
start int
end int
exceptions int
Результат int[]
        public static int[] GetContiguousArrayWithExceptions(int start, int end, int[] exceptions)
        {
            int irrelevantExceptions = 0;
            foreach (int exception in exceptions)
            {
                if (exception > end || exception < start)
                {
                    // We're not going to come across these exceptions in
                    // set generation.
                    irrelevantExceptions++;
                }
            }

            int relevantExceptions = exceptions.Length - irrelevantExceptions;
            int[] set = new int[end - start - relevantExceptions];
            int skipped = 0;
            for (int i = start; i < end; i++)
            {
                if(exceptions.Contains(i))
                {
                    skipped++;
                }
                else
                {
                    set[i - start - skipped] = i;
                }
            }

            return set;
        }

Usage Example

Пример #1
0
        public virtual void DifferenceWithTest()
        {
            // Test arrayContainer-based sets
            int[]         set1     = { 1, 2, 3, 7 };
            RoaringBitset testSet1 = RoaringBitset.Create(set1);

            int[]         set2     = { 1, 4, 7 };
            RoaringBitset testSet2 = RoaringBitset.Create(set2);

            testSet1.DifferenceWith(testSet2);

            Assert.AreEqual(false, testSet1.Get(1));
            Assert.AreEqual(true, testSet1.Get(3));

            // Test bitsetContainer-based sets
            int[]         set3     = SetGenerator.GetContiguousArray(0, 5000);
            RoaringBitset testSet3 = RoaringBitset.Create(set3);

            int[]         setExceptions = { 4 };
            int[]         set4          = SetGenerator.GetContiguousArrayWithExceptions(0, 5000, setExceptions);
            RoaringBitset testSet4      = RoaringBitset.Create(set4);

            // Reduce contiguous array to single value (4) via DifferenceWith
            testSet3.DifferenceWith(testSet4);

            Assert.AreEqual(false, testSet3.Get(2));
            Assert.AreEqual(true, testSet3.Get(4));

            //
            // Reduce testSet2 to 4 as well
            testSet2.DifferenceWith(testSet4);
            Assert.AreEqual(false, testSet2.Get(1));
            Assert.AreEqual(true, testSet2.Get(4));

            // Remove contents of set1 from set4
            testSet4.DifferenceWith(testSet1);
            Assert.AreEqual(false, testSet4.Get(2));
            Assert.AreEqual(true, testSet4.Get(6));
        }
All Usage Examples Of BitsetsNET.Tests.SetGenerator::GetContiguousArrayWithExceptions