/// <summary> /// Iterates over all maximum intervals from the /// collection that are lower than or equal to epsilon. /// </summary> /// <param name="sortedNumbers">Sorted collection whose /// modes are to be calculated.</param> /// <param name="epsilon">Maximum size of the intervals.</param> /// <returns></returns> internal static IEnumerable <Interval> Intervals( IEnumerable <double> sortedNumbers, double epsilon) { SlidingWindow window = new SlidingWindow(sortedNumbers); window.MoveStart(); window.MoveEnd(); // No element contained? if (window.EndReached) { yield break; } Interval lastInterval = window.Interval; // While the end is not reached ... while (!window.EndReached) { // Move upper end as long as possible while (!window.EndReached && window.Width <= epsilon) { // Save the last interval anyway lastInterval = window.Interval; window.MoveEnd(); } // Return the last interval smaller than or equal to epsilon yield return(lastInterval); // Move lower bounds until we reach epsilon again while (!window.EndReached && window.Width > epsilon) { window.MoveStart(); } } }
/// <summary> /// Iterates over all maximum intervals from the /// collection that are lower than or equal to epsilon. /// </summary> /// <param name="sortedNumbers">Sorted collection whose /// modes are to be calculated.</param> /// <param name="epsilon">Maximum size of the intervals.</param> /// <returns></returns> internal static IEnumerable<Interval> Intervals( IEnumerable<double> sortedNumbers,double epsilon) { SlidingWindow window = new SlidingWindow(sortedNumbers); window.MoveStart(); window.MoveEnd(); // No element contained? if (window.EndReached) yield break; Interval lastInterval = window.Interval; // While the end is not reached ... while (!window.EndReached) { // Move upper end as long as possible while (!window.EndReached && window.Width <= epsilon) { // Save the last interval anyway lastInterval = window.Interval; window.MoveEnd(); } // Return the last interval smaller than or equal to epsilon yield return lastInterval; // Move lower bounds until we reach epsilon again while (!window.EndReached && window.Width > epsilon) { window.MoveStart(); } } }