/// <summary> /// Initializes a new instance of the <see cref="EnumerableCache<T>.EnumeratorCache"/> class. /// </summary> /// <param name="parent">The parent cached enumerable whose GetEnumerator method is calling this constructor.</param> internal EnumeratorCache(EnumerableCache <T> parent) { if (parent == null) { throw new ArgumentNullException("parent"); } this.parent = parent; }
/// <summary> /// Split an enumerable into N equal enumerables (to prevent issues with "multiple enumeration of IEnumerable"). After being split, /// the original enumerable should not be used anywhere else, otherwise the tee enumerables may lose data. /// /// This method is thread-safe. You can use the <see cref="Tee" /> method in a single-thread scenario. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="source">Source to split.</param> /// <param name="subCount">Number of sub enumerables to create.</param> /// <remarks> /// Values consumed by the sub enumerables are cached in memory until ALL sub enumerables have consumed that value, /// which may consume a significant amount of storage if one enumerable is evaluated many times more than the others. /// </remarks> public static IEnumerable <T>[] ConcurrentTee <T>(this IEnumerable <T> source, int subCount) { EnumerableCache <T> cache = new EnumerableCache <T>(source.GetEnumerator()); IEnumerable <T>[] arr = new IEnumerable <T> [subCount]; for (int i = 0; i < subCount; i++) { arr[i] = ConcurrentSubEnumerable(cache.Register()); } return(arr); }
/// <summary> /// Initializes a new instance of the EnumeratorCache class. /// </summary> /// <param name="parent">The parent cached enumerable whose GetEnumerator method is calling this constructor.</param> internal EnumeratorCache(EnumerableCache <T> parent) { Requires.NotNull(parent, "parent"); this.parent = parent; }
/// <summary> /// Initializes a new instance of the <see cref="EnumerableCache<T>.EnumeratorCache" /> class. /// </summary> /// <param name="parent">The parent cached enumerable whose GetEnumerator method is calling this constructor.</param> internal EnumeratorCache(EnumerableCache <T> parent) { _parent = parent; }
/// <summary> /// Initializes a new instance of the <see cref="EnumeratorCache"/> class. /// </summary> /// <param name="parent">The parent cached enumerable whose GetEnumerator method is calling this constructor.</param> internal EnumeratorCache(EnumerableCache <T> parent) { Contract.Requires <ArgumentNullException>(parent != null); this.parent = parent; }
public EnumerableToken(EnumerableCache <T> cache) { Cache = cache; }
public EnumeratorCache(EnumerableCache <T> parent) { this.parent = parent; }