예제 #1
0
        public void TestStats()
        {
            var bitmap = new RoaringBitmap();

            bitmap.AddMany(1, 2, 3, 4, 6, 7);
            bitmap.AddMany(999991, 999992, 999993, 999994, 999996, 999997);
            var stats = bitmap.GetStatistics();

            Assert.Equal(stats.Cardinality, bitmap.Cardinality);
            Assert.Equal(stats.ContainerCount, 2U);
            Assert.Equal(stats.ArrayContainerCount, 2U);
            Assert.Equal(stats.RunContainerCount, 0U);
            Assert.Equal(stats.BitsetContainerCount, 0U);
        }
예제 #2
0
        internal BitVectorRoaringBitmap(IEnumerable <int> activeBitIndices, int count)
        {
            var activeBitIndicesArray = activeBitIndices.Select(i => (uint)i).ToArray();

            _roaringBitmap = new RoaringBitmap();
            _roaringBitmap.AddMany(activeBitIndicesArray, 0U, (uint)activeBitIndicesArray.Length);
            _roaringBitmap.Optimize();

            Count = count;
        }
예제 #3
0
        public void TestSerialization()
        {
            using (var rb1 = new RoaringBitmap())
            {
                rb1.AddMany(1, 2, 3, 4, 5, 100, 1000);
                rb1.Optimize();

                var s1 = rb1.Serialize(SerializationFormat.Normal);
                var s2 = rb1.Serialize(SerializationFormat.Portable);

                using (var rb2 = RoaringBitmap.Deserialize(s1, SerializationFormat.Normal))
                    using (var rb3 = RoaringBitmap.Deserialize(s2, SerializationFormat.Portable))
                    {
                        Assert.True(rb1.Equals(rb2));
                        Assert.True(rb1.Equals(rb3));
                    }
            }
        }
예제 #4
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));
                            }
                        }
                    }
        }