// using System.Collections.Generic; // // namespace FishNet.Utility // { // public class SubsetIterator // { // /// // /// Current iterated index. // /// // private int _currentIndex = 0; // // /// // /// Iterates through a specified number of items from the list, // /// starting where the last call left off. // /// // /// The collection to iterate. // /// How many items to process in this call. // /// An enumerator yielding the subset of items. // public IEnumerator GetNextSet(List source, int iterations) // { // if (source == null || iterations == 0) // yield break; // // int listCount = source.Count; // if (listCount == 0) // yield break; // // /* If positive then the iterations from the currentIndex // * would exceed the list count. When true remove the over // * count from iterations, and iterate from the beginning using // * the over count value. // * // * Doing this removes the need to check for out of bounds per // * iteration, which scales very well with more iterations. */ // int overCountIterations = _currentIndex + iterations - listCount; // if (overCountIterations > 0) // iterations -= overCountIterations; // // for (int i = 0; i < iterations; i++) // { // T item = source[_currentIndex]; // _currentIndex++; // // yield return item; // } // // /* If iterations prior had exceeded the source // * count then reset the currentIndex and iterate the // * remainder from the start of the source. */ // if (overCountIterations > 0) // { // iterations = overCountIterations; // _currentIndex = 0; // // for (int i = 0; i < iterations; i++) // { // T item = source[_currentIndex]; // _currentIndex++; // // yield return item; // } // } // } // // /// // /// Manually resets the iterator to the beginning of the list. // /// // public void Reset() // { // _currentIndex = 0; // } // } // }