示例#1
0
        /// <summary>
        /// Add a new sample of a value at a given position.
        /// </summary>
        /// <param name = "sample">The value.</param>
        /// <param name = "at">The position of the value.</param>
        public void AddSample(TValue sample, TOver at)
        {
            if (_samples.Count > 0 && at.CompareTo(_samples.Last().Item2) < 0)
            {
                throw new ArgumentException("Samples are required to be added in order.", "at");
            }

            _samples.Add(sample, at);

            // Clean up samples older than the specified interval.
            // TODO: This LINQ query probably isn't optimized for lists. What's the performance impact?
            if (_samples.Count > 2)
            {
                var toRemove = _samples
                               .Reverse <Tuple <TValue, TOver> >()
                               .Skip(2)
                               .SkipWhile(s => Operator <TOver> .Subtract(at, s.Item2).CompareTo(Interval) <= 0)
                               .ToList();
                toRemove.ForEach(r => _samples.Remove(r));
            }
        }