Пример #1
0
                /// <summary>
                /// Initializes a new instance of the <see cref="EnumerableCache&lt;T&gt;.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;
                }
Пример #2
0
        /// <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);
        }
Пример #3
0
                /// <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;
                }
Пример #4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EnumerableCache&lt;T&gt;.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;
 }
Пример #5
0
                /// <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;
                }
Пример #6
0
 public EnumerableToken(EnumerableCache <T> cache)
 {
     Cache = cache;
 }
 public EnumeratorCache(EnumerableCache <T> parent)
 {
     this.parent = parent;
 }