Beispiel #1
0
        public void TestFlow()
        {
            // top-k for 3
            var spec = new CountMinSketchSpec();

            spec.HashesSpec = TestCountMinSketchStateHashes.DefaultSpec;
            spec.TopkSpec   = 3;
            spec.Agent      = 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");
        }
Beispiel #2
0
 public CountMinSketchAggState(
     CountMinSketchState state,
     CountMinSketchAgent agent)
 {
     this.state = state;
     this.agent = agent;
     add = new CountMinSketchAgentContextAdd(state);
     estimate = new CountMinSketchAgentContextEstimate(state);
     fromBytes = new CountMinSketchAgentContextFromBytes(state);
 }
Beispiel #3
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);
        }
Beispiel #4
0
 public CountMinSketchAggState MakeAggState()
 {
     return new CountMinSketchAggState(CountMinSketchState.MakeState(this), Agent);
 }