コード例 #1
0
        public void OperateGetUnion()
        {
            int                    index_bits           = 14;
            long                   expected_union_count = 0;
            List <IList>           vals = new List <IList>();
            IList <Value.HLLValue> hlls = new List <Value.HLLValue>();

            for (int i = 0; i < keys.Length; i++)
            {
                List <Value> sub_vals = new List <Value>();

                for (int j = 0; j < n_entries / 3; j++)
                {
                    sub_vals.Add(new Value.StringValue("key" + i + " " + j));
                }

                Record record = AssertSuccess("init other keys", keys[i], Operation.Delete(), HLLOperation.Add(HLLPolicy.Default, binName, sub_vals, index_bits), Operation.Get(binName));

                IList result_list = record.GetList(binName);
                hlls.Add((Value.HLLValue)result_list[1]);
                expected_union_count += sub_vals.Count;
                vals.Add(sub_vals);
            }

            // Keep record around win binName is removed.
            AssertSuccess("other bin", key,
                          Operation.Delete(),
                          HLLOperation.Init(HLLPolicy.Default, binName + "other", index_bits),
                          HLLOperation.Add(HLLPolicy.Default, binName, vals[0], index_bits)
                          );

            Record r           = AssertSuccess("union and unionCount", key, HLLOperation.GetUnion(binName, hlls), HLLOperation.GetUnionCount(binName, hlls));
            IList  rlist       = r.GetList(binName);
            long   union_count = (long)rlist[1];

            AssertHLLCount("verify union count", index_bits, union_count, expected_union_count);

            Value.HLLValue union_hll = (Value.HLLValue)rlist[0];

            r     = AssertSuccess("", key, Operation.Put(new Bin(binName, union_hll)), HLLOperation.GetCount(binName));
            rlist = r.GetList(binName);
            long union_count_2 = (long)rlist[1];

            Assert.AreEqual(union_count, union_count_2, "unions equal");
        }