Ejemplo n.º 1
0
        public override void Copy(DDSketchStore store_)
        {
            Contract.Requires(store_ is DDSketchUnboundedStore);
            var store = (DDSketchUnboundedStore)store_;

            _data = new Dictionary <int, int>(store._data);
        }
Ejemplo n.º 2
0
        public override void Merge(DDSketchStore store_)
        {
            Contract.Requires(store_ is DDSketchUnboundedStore);
            var store = (DDSketchUnboundedStore)store_;

            foreach (var kvp in store._data)
            {
                if (!_data.ContainsKey(kvp.Key))
                {
                    _data[kvp.Key] = kvp.Value;
                }
                else
                {
                    _data[kvp.Key] += kvp.Value;
                }
            }
        }
Ejemplo n.º 3
0
        public DDSketch(double alpha = 0.01, double minimumRepresentableValue = 1e-9, DDSketchStore?store = null)
        {
            Contract.Requires(0 < alpha && alpha < 1, "Alpha must be a probability");
            Contract.Requires(minimumRepresentableValue >= 0, "The minimum absolute value must be at least 0");

            Alpha = alpha;
            _minimumRepresentableValue = minimumRepresentableValue;

            Gamma = 1.0 + ((2.0 * Alpha) / (1.0 - Alpha));
            Contract.Assert(Gamma >= 1.0);

            // \gamma = 1 + \frac{2 \alpha}{1 - \alpha}, so this is exactly \ln \gamma
            _ln_gamma = Log1p((2.0 * Alpha) / (1.0 - Alpha));

            _minimumRepresentableOffset = -ObliviousIndex(_minimumRepresentableValue) + 1;
            Contract.Assert(_minimumRepresentableOffset > 0);

            _store = store ?? new DDSketchUnboundedStore();
        }