Exemple #1
0
        private void UpdateAssert(
            CountMinSketchState state,
            string value,
            string expected)
        {
            state.Add(value.GetUTF8Bytes(), 1);
            var topkValues = state.TopKValues;
            IList <Pair <long, object> > topkList = new List <Pair <long, object> >();

            foreach (var topkValue in topkValues)
            {
                var frequency = state.Frequency(topkValue.Array);
                var text      = Encoding.UTF8.GetString(topkValue.Array);
                topkList.Add(new Pair <long, object>(frequency, text));
            }

            AssertList(expected, topkList);
        }
Exemple #2
0
        public CountMinSketchTopK[] GetFromBytes()
        {
            ICollection<ByteBuffer> bytes = state.TopKValues;
            if (bytes.IsEmpty()) {
                return new CountMinSketchTopK[0];
            }

            CountMinSketchTopK[] arr = new CountMinSketchTopK[bytes.Count];
            int index = 0;
            foreach (ByteBuffer buf in bytes) {
                long frequency = state.Frequency(buf.Array);
                fromBytes.Bytes = buf.Array;
                object value = agent.FromBytes(fromBytes);
                //if (frequency == null) {
                //    continue;
                //}

                arr[index++] = new CountMinSketchTopK(frequency, value);
            }

            return arr;
        }