Ejemplo n.º 1
0
        /**
         * Compute the alpha decay factor such that the weight of an entry with age 'targetAgeInSeconds' is targetWeight'
         */
        public static double ComputeAlpha(double targetWeight, long targetAgeInSeconds)
        {
            ParameterCheck.Check(targetAgeInSeconds > 0, "targetAgeInSeconds must be > 0");
            ParameterCheck.Check(targetWeight > 0 && targetWeight < 1, "targetWeight must be in range (0, 1)");

            return(-Math.Log(targetWeight) / targetAgeInSeconds);
        }
Ejemplo n.º 2
0
        public void Merge(DecayCounter decayCounter)
        {
            if (decayCounter == null)
            {
                throw new ArgumentNullException("decayCounter");
            }

            ParameterCheck.Check(decayCounter.Alpha == this.Alpha, $"Expected decayCounter to have alpha {this.Alpha}, but was {decayCounter.Alpha}.");

            lock (SyncRoot)
            {
                // if the landmark this counter is behind the other counter
                if (this.LandmarkInSeconds < decayCounter.LandmarkInSeconds)
                {
                    // rescale this counter to the other counter, and add
                    this.RescaleToNewLandmark(decayCounter.LandmarkInSeconds);
                    this.Count += decayCounter.Count;
                }
                else
                {
                    // rescale the other counter and add
                    double OtherRescaledCount = decayCounter.Count / this.Weight(this.LandmarkInSeconds, decayCounter.LandmarkInSeconds);
                    this.Count += OtherRescaledCount;
                }
            }
        }
Ejemplo n.º 3
0
        public long ToBytes()
        {
            double Bytes = this.GetValue(DataSizeUnit.BYTE);

            ParameterCheck.Check(Bytes <= Int64.MaxValue, "Size in bytes is too large to be represented in bytes as a long.");

            return((long)Bytes);
        }
Ejemplo n.º 4
0
        public static Slice Allocate(int capacity)
        {
            if (capacity == 0)
            {
                return(EMPTY_SLICE);
            }

            ParameterCheck.Check(capacity <= MAX_ARRAY_SIZE, $"Cannot allocate slice largert than {MAX_ARRAY_SIZE} bytes.");

            return(new Slice(new byte[capacity]));
        }