Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MergeExecutor.cs
Go to the documentation of this file.
1
using
System.Collections
;
2
using
System.Collections.Generic
;
3
using
System.Threading
;
4
using
System.Threading.Tasks
;
5
6
namespace
System.Linq.Parallel
;
7
8
internal
sealed
class
MergeExecutor
<
TInputOutput
> :
IEnumerable
<TInputOutput>,
IEnumerable
9
{
10
private
IMergeHelper<TInputOutput>
_mergeHelper
;
11
12
private
MergeExecutor
()
13
{
14
}
15
16
internal
static
MergeExecutor<TInputOutput>
Execute<TKey>
(
PartitionedStream<TInputOutput, TKey>
partitions
,
bool
ignoreOutput
,
ParallelMergeOptions
options
,
TaskScheduler
taskScheduler
,
bool
isOrdered
,
CancellationState
cancellationState
,
int
queryId
)
17
{
18
MergeExecutor<TInputOutput>
mergeExecutor
=
new
MergeExecutor<TInputOutput>
();
19
if
(
isOrdered
&& !
ignoreOutput
)
20
{
21
if
(
options
!=
ParallelMergeOptions
.FullyBuffered && !
partitions
.OrdinalIndexState.IsWorseThan(
OrdinalIndexState
.Increasing))
22
{
23
bool
autoBuffered
=
options
==
ParallelMergeOptions
.AutoBuffered;
24
if
(
partitions
.PartitionCount > 1)
25
{
26
mergeExecutor._mergeHelper =
new
OrderPreservingPipeliningMergeHelper<TInputOutput, TKey>
(
partitions
,
taskScheduler
,
cancellationState
,
autoBuffered
,
queryId
,
partitions
.KeyComparer);
27
}
28
else
29
{
30
mergeExecutor._mergeHelper =
new
DefaultMergeHelper<TInputOutput, TKey>
(
partitions
,
ignoreOutput
:
false
,
options
,
taskScheduler
,
cancellationState
,
queryId
);
31
}
32
}
33
else
34
{
35
mergeExecutor._mergeHelper =
new
OrderPreservingMergeHelper<TInputOutput, TKey>
(
partitions
,
taskScheduler
,
cancellationState
,
queryId
);
36
}
37
}
38
else
39
{
40
mergeExecutor._mergeHelper =
new
DefaultMergeHelper<TInputOutput, TKey>
(
partitions
,
ignoreOutput
,
options
,
taskScheduler
,
cancellationState
,
queryId
);
41
}
42
mergeExecutor
.Execute();
43
return
mergeExecutor
;
44
}
45
46
private
void
Execute
()
47
{
48
_mergeHelper
.Execute();
49
}
50
51
IEnumerator
IEnumerable
.
GetEnumerator
()
52
{
53
return
GetEnumerator
();
54
}
55
56
public
IEnumerator<TInputOutput>
GetEnumerator
()
57
{
58
return
_mergeHelper
.GetEnumerator();
59
}
60
61
internal
TInputOutput
[]
GetResultsAsArray
()
62
{
63
return
_mergeHelper
.GetResultsAsArray();
64
}
65
66
internal
static
AsynchronousChannel<TInputOutput>
[]
MakeAsynchronousChannels
(
int
partitionCount
,
ParallelMergeOptions
options
,
IntValueEvent
consumerEvent
,
CancellationToken
cancellationToken
)
67
{
68
AsynchronousChannel<TInputOutput>
[]
array
=
new
AsynchronousChannel<TInputOutput>
[
partitionCount
];
69
int
chunkSize
= 0;
70
if
(
options
==
ParallelMergeOptions
.NotBuffered)
71
{
72
chunkSize
= 1;
73
}
74
for
(
int
i = 0; i <
array
.Length; i++)
75
{
76
array
[i] =
new
AsynchronousChannel<TInputOutput>
(i,
chunkSize
,
cancellationToken
,
consumerEvent
);
77
}
78
return
array
;
79
}
80
81
internal
static
SynchronousChannel<TInputOutput>
[]
MakeSynchronousChannels
(
int
partitionCount
)
82
{
83
SynchronousChannel<TInputOutput>
[]
array
=
new
SynchronousChannel<TInputOutput>
[
partitionCount
];
84
for
(
int
i = 0; i <
array
.Length; i++)
85
{
86
array
[i] =
new
SynchronousChannel<TInputOutput>
();
87
}
88
return
array
;
89
}
90
}
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Linq.Parallel.CancellationState
Definition
CancellationState.cs:6
System.Linq.Parallel.IntValueEvent
Definition
IntValueEvent.cs:6
System.Linq.Parallel.MergeExecutor.GetEnumerator
IEnumerator< TInputOutput > GetEnumerator()
Definition
MergeExecutor.cs:56
System.Linq.Parallel.MergeExecutor.MakeAsynchronousChannels
static AsynchronousChannel< TInputOutput >[] MakeAsynchronousChannels(int partitionCount, ParallelMergeOptions options, IntValueEvent consumerEvent, CancellationToken cancellationToken)
Definition
MergeExecutor.cs:66
System.Linq.Parallel.MergeExecutor.GetEnumerator
IEnumerator IEnumerable. GetEnumerator()
Definition
MergeExecutor.cs:51
System.Linq.Parallel.MergeExecutor.MakeSynchronousChannels
static SynchronousChannel< TInputOutput >[] MakeSynchronousChannels(int partitionCount)
Definition
MergeExecutor.cs:81
System.Linq.Parallel.MergeExecutor.Execute< TKey >
static MergeExecutor< TInputOutput > Execute< TKey >(PartitionedStream< TInputOutput, TKey > partitions, bool ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, bool isOrdered, CancellationState cancellationState, int queryId)
Definition
MergeExecutor.cs:16
System.Linq.Parallel.MergeExecutor.GetResultsAsArray
TInputOutput[] GetResultsAsArray()
Definition
MergeExecutor.cs:61
System.Linq.Parallel.MergeExecutor._mergeHelper
IMergeHelper< TInputOutput > _mergeHelper
Definition
MergeExecutor.cs:10
System.Linq.Parallel.MergeExecutor.MergeExecutor
MergeExecutor()
Definition
MergeExecutor.cs:12
System.Linq.Parallel.MergeExecutor.Execute
void Execute()
Definition
MergeExecutor.cs:46
System.Linq.Parallel.MergeExecutor
Definition
MergeExecutor.cs:9
System.Threading.Tasks.TaskScheduler
Definition
TaskScheduler.cs:10
System.Collections.Generic.IEnumerable.GetEnumerator
new IEnumerator< T > GetEnumerator()
System.Collections.Generic.IEnumerable
Definition
IEnumerable.cs:4
System.Collections.Generic.IEnumerator
Definition
IEnumerator.cs:4
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Collections
Definition
BlockingCollection.cs:8
System.Linq.Parallel.OrdinalIndexState
OrdinalIndexState
Definition
OrdinalIndexState.cs:4
System.Linq.Parallel
Definition
AnyAllSearchOperator.cs:5
System.Linq.ParallelMergeOptions
ParallelMergeOptions
Definition
ParallelMergeOptions.cs:4
System.Threading.Tasks
Definition
TaskToApm.cs:3
System.Threading
Definition
TaskToApm.cs:3
System.ExceptionArgument.cancellationToken
@ cancellationToken
System.ExceptionArgument.options
@ options
System.ExceptionArgument.array
@ array
System.Threading.CancellationToken
Definition
CancellationToken.cs:8
source
System.Linq.Parallel
System.Linq.Parallel
MergeExecutor.cs
Generated by
1.10.0