5 // Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
7 // Copyright (c) 2010 Jérémie "Garuma" Laval
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 using System.Threading;
31 using System.Collections;
32 using System.Collections.Generic;
33 using System.Collections.Concurrent;
34 using System.Linq.Parallel;
35 using System.Linq.Parallel.QueryNodes;
39 public class ParallelQuery : IEnumerable
41 ParallelExecutionMode execMode = ParallelExecutionMode.Default;
42 ParallelMergeOptions mergeOptions = ParallelMergeOptions.Default;
44 internal ParallelQuery ()
49 internal ParallelMergeOptions MergeOptions {
58 internal ParallelExecutionMode ExecMode {
67 IEnumerator IEnumerable.GetEnumerator ()
69 return GetEnumeratorTrick ();
72 // Trick to get the correct IEnumerator from ParallelQuery<TSource>
73 internal virtual IEnumerator GetEnumeratorTrick ()
78 internal virtual ParallelQuery<object> TypedQuery {
85 public class ParallelQuery<TSource> : ParallelQuery, IEnumerable<TSource>, IEnumerable
87 QueryBaseNode<TSource> node;
89 internal ParallelQuery (QueryBaseNode<TSource> node)
94 internal QueryBaseNode<TSource> Node {
100 public virtual IEnumerator<TSource> GetEnumerator ()
102 return GetEnumeratorInternal ();
105 IEnumerator IEnumerable.GetEnumerator ()
107 return (IEnumerator)GetEnumeratorInternal ();
110 IEnumerator<TSource> GetEnumeratorInternal ()
112 return new ParallelQueryEnumerator<TSource> (node);
115 internal override IEnumerator GetEnumeratorTrick ()
117 return (IEnumerator)GetEnumeratorInternal ();
120 internal override ParallelQuery<object> TypedQuery {
122 return new ParallelQuery<object> (new QueryCastNode<TSource> (node));