/** * 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); }
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; } } }
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); }
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])); }