示例#1
0
 public CountMinSketchAggState(CountMinSketchState state, CountMinSketchAgent agent)
 {
     _state     = state;
     _agent     = agent;
     _add       = new CountMinSketchAgentContextAdd(state);
     _estimate  = new CountMinSketchAgentContextEstimate(state);
     _fromBytes = new CountMinSketchAgentContextFromBytes(state);
 }
        private void UpdateAssert(CountMinSketchState state, string value, string expected)
        {
            var bytes = Encoding.UTF8.GetBytes(value);

            state.Add(bytes, 1);
            var topkValues = state.TopKValues;
            var topkList   = new List <Pair <long, object> >();

            foreach (var topkValue in topkValues)
            {
                var array     = topkValue.Data;
                var frequency = state.Frequency(array);
                var text      = Encoding.UTF8.GetString(array);
                topkList.Add(new Pair <long, object>(frequency, text));
            }
            AssertList(expected, topkList);
        }
        public void TestFlow()
        {
            // top-k for 3
            var spec  = new CountMinSketchSpec(TestCountMinSketchStateHashes.GetDefaultSpec(), 3, new CountMinSketchAgentStringUTF16());
            var state = CountMinSketchState.MakeState(spec);

            UpdateAssert(state, "a", "a=1");
            UpdateAssert(state, "b", "a=1,b=1");
            UpdateAssert(state, "a", "a=2,b=1");
            UpdateAssert(state, "c", "a=2,b=1,c=1");
            UpdateAssert(state, "d", "a=2,b=1,c=1");
            UpdateAssert(state, "c", "a=2,b=1,c=2");
            UpdateAssert(state, "a", "a=3,b=1,c=2");
            UpdateAssert(state, "d", "a=3,d=2,c=2");
            UpdateAssert(state, "e", "a=3,d=2,c=2");
            UpdateAssert(state, "e", "a=3,d=2,c=2");
            UpdateAssert(state, "e", "a=3,e=3,c=2");
            UpdateAssert(state, "d", "a=3,e=3,d=3");
            UpdateAssert(state, "c", "a=3,e=3,d=3");
            UpdateAssert(state, "c", "a=3,e=3,c=4");
        }