Exemple #1
0
        public void TestCardinality()
        {
            uint[] values = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };

            using (var result = RoaringBitmap.FromValues(values))
                Assert.Equal(7U, result.Cardinality);
        }
Exemple #2
0
        public void TestEnumerator()
        {
            uint[] values = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };

            using (var result = RoaringBitmap.FromValues(values))
                Assert.True(Enumerable.SequenceEqual(result, values));
        }
Exemple #3
0
        public void TestRemove()
        {
            uint[] initialValues = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };
            uint[] removeValues  = new uint[] { 2, 3 };
            uint[] finalValues   = initialValues.Except(removeValues).ToArray();
            uint   max           = initialValues.Max() + 1;

            using (var rb = RoaringBitmap.FromValues(initialValues))
            {
                rb.RemoveMany(removeValues);
                rb.Optimize();

                Assert.Equal(rb.Cardinality, (uint)finalValues.Length);

                for (uint i = 0; i < max; i++)
                {
                    if (finalValues.Contains(i))
                    {
                        Assert.True(rb.Contains(i));
                    }
                    else
                    {
                        Assert.False(rb.Contains(i));
                    }
                }
            }
        }
Exemple #4
0
        public void TestMax()
        {
            uint[] values = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };

            using (var result = RoaringBitmap.FromValues(values))
                Assert.Equal(1000U, result.Max);
        }
Exemple #5
0
        public void TestIXor()
        {
            uint[] values1 = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };
            uint[] values2 = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };
            uint[] values3 = new uint[] { 3, 4, 5, 7, 100, 1020 };

            using (var result = RoaringBitmap.FromValues(values1))
                using (var source1 = RoaringBitmap.FromValues(values2))
                    using (var source2 = RoaringBitmap.FromValues(values3))
                    {
                        result.IXor(source1);
                        result.IXor(source2);
                        Assert.Equal(result.Cardinality, XorCount(values1, values2, values3));
                    }
        }
Exemple #6
0
        public void TestXor()
        {
            uint[] values1 = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };
            uint[] values2 = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };
            uint[] values3 = new uint[] { 3, 4, 5, 7, 100, 1020 };

            using (var source1 = RoaringBitmap.FromValues(values1))
                using (var source2 = RoaringBitmap.FromValues(values2))
                    using (var source3 = RoaringBitmap.FromValues(values3))
                        using (var result1 = source1.Xor(source2))
                            using (var result2 = source2.Xor(source3))
                                using (var result3 = result1.Xor(source3))
                                {
                                    Assert.Equal(result1.Cardinality, XorCount(values1, values2));
                                    Assert.Equal(result2.Cardinality, XorCount(values2, values3));
                                    Assert.Equal(result3.Cardinality, XorCount(values1, values2, values3));
                                }
        }
Exemple #7
0
        public void TestAdd()
        {
            uint[] values = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };
            uint   max    = values.Max() + 1;

            using (var rb1 = new RoaringBitmap())
                using (var rb2 = new RoaringBitmap())
                    using (var rb3 = RoaringBitmap.FromValues(values))
                    {
                        for (int i = 0; i < values.Length; i++)
                        {
                            rb1.Add(values[i]);
                        }
                        rb1.Optimize();

                        rb2.AddMany(values);
                        rb2.Optimize();

                        rb3.Optimize();

                        Assert.Equal(rb1.Cardinality, (uint)values.Length);
                        Assert.Equal(rb2.Cardinality, (uint)values.Length);
                        Assert.Equal(rb3.Cardinality, (uint)values.Length);

                        for (uint i = 0; i < max; i++)
                        {
                            if (values.Contains(i))
                            {
                                Assert.True(rb1.Contains(i));
                                Assert.True(rb2.Contains(i));
                                Assert.True(rb3.Contains(i));
                            }
                            else
                            {
                                Assert.False(rb1.Contains(i));
                                Assert.False(rb2.Contains(i));
                                Assert.False(rb3.Contains(i));
                            }
                        }
                    }
        }
Exemple #8
0
        public void TestNot()
        {
            uint[] values = new uint[] { 1, 2, 3, 4, 5, 100, 1000 };
            uint   max    = values.Max() + 1;

            using (var source = RoaringBitmap.FromValues(values))
                using (var result = source.Not(0, max))
                {
                    for (uint i = 0; i < max; i++)
                    {
                        if (values.Contains(i))
                        {
                            Assert.False(result.Contains(i));
                        }
                        else
                        {
                            Assert.True(result.Contains(i));
                        }
                    }
                }
        }