Ejemplo n.º 1
0
        public void Update(long value, string userValue = null)
        {
            long c = this.count.Increment();

            if (c <= this.values.Length)
            {
                values[(int)c - 1] = new UserValueWrapper(value, userValue);
            }
            else
            {
                long r = NextLong(c);
                if (r < values.Length)
                {
                    values[(int)r] = new UserValueWrapper(value, userValue);
                }
            }
        }
Ejemplo n.º 2
0
        public Snapshot GetSnapshot(bool resetReservoir = false)
        {
            var size = this.Size;

            if (size == 0)
            {
                return(new UniformSnapshot(0, Enumerable.Empty <long>()));
            }

            UserValueWrapper[] values = new UserValueWrapper[size];
            Array.Copy(this.values, values, size);

            if (resetReservoir)
            {
                count.SetValue(0L);
            }

            Array.Sort(values, UserValueWrapper.Comparer);
            var minValue = values[0].UserValue;
            var maxValue = values[size - 1].UserValue;

            return(new UniformSnapshot(this.count.Value, values.Select(v => v.Value), valuesAreSorted: true, minUserValue: minValue, maxUserValue: maxValue));
        }