예제 #1
0
        public void MergeSelf()
        {
            int[]  cardinalities = { 0, 1, 10, 100, 1000, 10000, 100000 };
            uint[] ps            = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
            uint[] sps           = { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 };

            foreach (int cardinality in cardinalities)
            {
                for (int j = 0; j < ps.Length; j++)
                {
                    foreach (var sp in sps)
                    {
                        if (sp < ps[j])
                        {
                            continue;
                        }
                        var hll = new HyperLogLogPlus(ps[j], sp);
                        for (int l = 0; l < cardinality; l++)
                        {
                            hll.OfferHashed(Hash64(Rnd.Next()));
                        }

                        var deserialized = HyperLogLogPlus.FromBytes(hll.ToBytes());
                        Console.WriteLine(ps[j] + "-" + sp + ": " + cardinality + " -> " + hll.Cardinality());
                        Assert.That(deserialized.Cardinality(), Is.EqualTo(hll.Cardinality()));
                        var merged = hll.Merge(deserialized);
                        Assert.That(merged.Cardinality(), Is.EqualTo(hll.Cardinality()));
                    }
                }
            }
        }
예제 #2
0
        public void SparseSpace()
        {
            var hllp = new HyperLogLogPlus(14, 14);

            for (int i = 0; i < 10000; ++i)
            {
                hllp.OfferHashed(Hash64(i));
            }
            Console.WriteLine("Size: {0}", hllp.ToBytes().Length);
        }
예제 #3
0
        public void Serialization_Sparse()
        {
            var hll = new HyperLogLogPlus(14, 25);

            hll.OfferHashed(Hash64("a"));
            hll.OfferHashed(Hash64("b"));
            hll.OfferHashed(Hash64("c"));
            hll.OfferHashed(Hash64("d"));
            hll.OfferHashed(Hash64("e"));

            var hll2 = HyperLogLogPlus.FromBytes(hll.ToBytes());

            Assert.That(hll2.Cardinality(), Is.EqualTo(hll.Cardinality()));
        }
예제 #4
0
        public void Serialization_Normal()
        {
            var hll = new HyperLogLogPlus(5, 25);

            for (var i = 0; i < 100000; ++i)
            {
                hll.OfferHashed(Hash64(i));
            }
            Console.WriteLine(hll.Cardinality());

            var hll2 = HyperLogLogPlus.FromBytes(hll.ToBytes());

            Assert.That(hll2.Cardinality(), Is.EqualTo(hll.Cardinality()));
        }
예제 #5
0
        public void MergeSelf_ForceNormal()
        {
            int[] cardinalities = { 0, 1, 10, 100, 1000, 10000, 100000, 1000000 };
            foreach (var cardinality in cardinalities)
            {
                for (uint j = 4; j < 24; ++j)
                {
                    Console.WriteLine("p=" + j);
                    var hll = new HyperLogLogPlus(j, 0);
                    for (var l = 0; l < cardinality; l++)
                    {
                        hll.OfferHashed(Hash64(Rnd.Next()));
                    }

                    Console.WriteLine("hllcardinality={0} cardinality={1}", hll.Cardinality(), cardinality);

                    var deserialized = HyperLogLogPlus.FromBytes(hll.ToBytes());
                    Assert.That(deserialized.Cardinality(), Is.EqualTo(hll.Cardinality()));
                    var merged = hll.Merge(deserialized);
                    Console.WriteLine(merged.Cardinality() + " : " + hll.Cardinality());
                    Assert.That(merged.Cardinality(), Is.EqualTo(hll.Cardinality()));
                }
            }
        }