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
28 using System
.Threading
;
29 using System
.Collections
;
30 using System
.Collections
.Generic
;
31 using System
.Collections
.Concurrent
;
37 public class ParallelQuery
: IEnumerable
39 ParallelExecutionMode execMode
= ParallelExecutionMode
.Default
;
40 ParallelMergeOptions mergeOptions
= ParallelMergeOptions
.Default
;
42 internal ParallelQuery ()
47 internal ParallelMergeOptions MergeOptions
{
56 internal ParallelExecutionMode ExecMode
{
65 IEnumerator IEnumerable
.GetEnumerator ()
67 return GetEnumeratorTrick ();
70 // Trick to get the correct IEnumerator from ParallelQuery<TSource>
71 internal virtual IEnumerator
GetEnumeratorTrick ()
76 internal virtual ParallelQuery
<object> TypedQuery
{
83 public class ParallelQuery
<TSource
> : ParallelQuery
, IEnumerable
<TSource
>, IEnumerable
85 QueryBaseNode
<TSource
> node
;
87 internal ParallelQuery (QueryBaseNode
<TSource
> node
)
92 internal QueryBaseNode
<TSource
> Node
{
98 public virtual IEnumerator
<TSource
> GetEnumerator ()
100 return GetEnumeratorInternal ();
103 IEnumerator IEnumerable
.GetEnumerator ()
105 return (IEnumerator
)GetEnumeratorInternal ();
108 IEnumerator
<TSource
> GetEnumeratorInternal ()
110 return new ParallelQueryEnumerator
<TSource
> (node
);
113 internal override IEnumerator
GetEnumeratorTrick ()
115 return (IEnumerator
)GetEnumeratorInternal ();
118 internal override ParallelQuery
<object> TypedQuery
{
120 return new ParallelQuery
<object> (new QueryCastNode
<TSource
> (node
));