Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DefaultMergeHelper.cs
Go to the documentation of this file.
1
using
System.Collections.Generic
;
2
using
System.Threading.Tasks
;
3
4
namespace
System.Linq.Parallel
;
5
6
internal
sealed
class
DefaultMergeHelper
<
TInputOutput
,
TIgnoreKey
> :
IMergeHelper
<TInputOutput>
7
{
8
private
readonly
QueryTaskGroupState
_taskGroupState
;
9
10
private
readonly
PartitionedStream<TInputOutput, TIgnoreKey>
_partitions
;
11
12
private
readonly
AsynchronousChannel<TInputOutput>
[]
_asyncChannels
;
13
14
private
readonly
SynchronousChannel<TInputOutput>
[]
_syncChannels
;
15
16
private
readonly
IEnumerator<TInputOutput>
_channelEnumerator
;
17
18
private
readonly
TaskScheduler
_taskScheduler
;
19
20
private
readonly
bool
_ignoreOutput
;
21
22
internal
DefaultMergeHelper
(
PartitionedStream<TInputOutput, TIgnoreKey>
partitions
,
bool
ignoreOutput
,
ParallelMergeOptions
options
,
TaskScheduler
taskScheduler
,
CancellationState
cancellationState
,
int
queryId
)
23
{
24
_taskGroupState
=
new
QueryTaskGroupState
(
cancellationState
,
queryId
);
25
_partitions
=
partitions
;
26
_taskScheduler
=
taskScheduler
;
27
_ignoreOutput
=
ignoreOutput
;
28
IntValueEvent
consumerEvent
=
new
IntValueEvent
();
29
if
(
ignoreOutput
)
30
{
31
return
;
32
}
33
if
(
options
!=
ParallelMergeOptions
.FullyBuffered)
34
{
35
if
(
partitions
.PartitionCount > 1)
36
{
37
_asyncChannels
=
MergeExecutor<TInputOutput>
.MakeAsynchronousChannels(
partitions
.PartitionCount,
options
,
consumerEvent
,
cancellationState
.MergedCancellationToken);
38
_channelEnumerator
=
new
AsynchronousChannelMergeEnumerator<TInputOutput>
(
_taskGroupState
,
_asyncChannels
,
consumerEvent
);
39
}
40
else
41
{
42
_channelEnumerator
=
ExceptionAggregator
.WrapQueryEnumerator(
partitions
[0],
_taskGroupState
.
CancellationState
).GetEnumerator();
43
}
44
}
45
else
46
{
47
_syncChannels
=
MergeExecutor<TInputOutput>
.MakeSynchronousChannels(
partitions
.PartitionCount);
48
_channelEnumerator
=
new
SynchronousChannelMergeEnumerator<TInputOutput>
(
_taskGroupState
,
_syncChannels
);
49
}
50
}
51
52
void
IMergeHelper<TInputOutput>
.Execute()
53
{
54
if
(
_asyncChannels
!=
null
)
55
{
56
SpoolingTask
.SpoolPipeline(
_taskGroupState
,
_partitions
,
_asyncChannels
,
_taskScheduler
);
57
}
58
else
if
(
_syncChannels
!=
null
)
59
{
60
SpoolingTask
.SpoolStopAndGo(
_taskGroupState
,
_partitions
,
_syncChannels
,
_taskScheduler
);
61
}
62
else
if
(
_ignoreOutput
)
63
{
64
SpoolingTask
.SpoolForAll(
_taskGroupState
,
_partitions
,
_taskScheduler
);
65
}
66
}
67
68
IEnumerator<TInputOutput>
IMergeHelper<TInputOutput>
.
GetEnumerator
()
69
{
70
return
_channelEnumerator
;
71
}
72
73
public
TInputOutput
[]
GetResultsAsArray
()
74
{
75
if
(
_syncChannels
!=
null
)
76
{
77
int
num = 0;
78
for
(
int
i = 0; i <
_syncChannels
.Length; i++)
79
{
80
num +=
_syncChannels
[i].
Count
;
81
}
82
TInputOutput
[]
array
=
new
TInputOutput
[num];
83
int
num2
= 0;
84
for
(
int
j
= 0;
j
<
_syncChannels
.Length;
j
++)
85
{
86
_syncChannels
[
j
].
CopyTo
(
array
,
num2
);
87
num2
+=
_syncChannels
[
j
].
Count
;
88
}
89
return
array
;
90
}
91
List<TInputOutput>
list
=
new
List<TInputOutput>
();
92
foreach
(
TInputOutput
item
in
(
IMergeHelper<TInputOutput>
)
this
)
93
{
94
list
.Add(
item
);
95
}
96
return
list
.ToArray();
97
}
98
}
System.Collections.Generic.Dictionary.GetEnumerator
Enumerator GetEnumerator()
Definition
Dictionary.cs:984
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Linq.Parallel.CancellationState
Definition
CancellationState.cs:6
System.Linq.Parallel.DefaultMergeHelper._partitions
readonly PartitionedStream< TInputOutput, TIgnoreKey > _partitions
Definition
DefaultMergeHelper.cs:10
System.Linq.Parallel.DefaultMergeHelper._syncChannels
readonly SynchronousChannel< TInputOutput >[] _syncChannels
Definition
DefaultMergeHelper.cs:14
System.Linq.Parallel.DefaultMergeHelper._channelEnumerator
readonly IEnumerator< TInputOutput > _channelEnumerator
Definition
DefaultMergeHelper.cs:16
System.Linq.Parallel.DefaultMergeHelper._ignoreOutput
readonly bool _ignoreOutput
Definition
DefaultMergeHelper.cs:20
System.Linq.Parallel.DefaultMergeHelper._taskGroupState
readonly QueryTaskGroupState _taskGroupState
Definition
DefaultMergeHelper.cs:8
System.Linq.Parallel.DefaultMergeHelper._taskScheduler
readonly TaskScheduler _taskScheduler
Definition
DefaultMergeHelper.cs:18
System.Linq.Parallel.DefaultMergeHelper.DefaultMergeHelper
DefaultMergeHelper(PartitionedStream< TInputOutput, TIgnoreKey > partitions, bool ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, CancellationState cancellationState, int queryId)
Definition
DefaultMergeHelper.cs:22
System.Linq.Parallel.DefaultMergeHelper._asyncChannels
readonly AsynchronousChannel< TInputOutput >[] _asyncChannels
Definition
DefaultMergeHelper.cs:12
System.Linq.Parallel.DefaultMergeHelper.GetResultsAsArray
TInputOutput[] GetResultsAsArray()
Definition
DefaultMergeHelper.cs:73
System.Linq.Parallel.DefaultMergeHelper
Definition
DefaultMergeHelper.cs:7
System.Linq.Parallel.ExceptionAggregator
Definition
ExceptionAggregator.cs:6
System.Linq.Parallel.IntValueEvent
Definition
IntValueEvent.cs:6
System.Linq.Parallel.QueryTaskGroupState.CancellationState
CancellationState CancellationState
Definition
QueryTaskGroupState.cs:18
System.Linq.Parallel.QueryTaskGroupState
Definition
QueryTaskGroupState.cs:7
System.Linq.Parallel.SpoolingTask
Definition
SpoolingTask.cs:6
System.Linq.Parallel.SynchronousChannel.CopyTo
void CopyTo(T[] array, int arrayIndex)
Definition
SynchronousChannel.cs:34
System.Linq.Parallel.SynchronousChannel.Count
int Count
Definition
SynchronousChannel.cs:9
System.Threading.Tasks.TaskScheduler
Definition
TaskScheduler.cs:10
System.Linq.Parallel.IMergeHelper
Definition
IMergeHelper.cs:6
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Linq.Parallel
Definition
AnyAllSearchOperator.cs:5
System.Linq.ParallelMergeOptions
ParallelMergeOptions
Definition
ParallelMergeOptions.cs:4
System.Threading.Tasks
Definition
TaskToApm.cs:3
System.ExceptionArgument.list
@ list
System.ExceptionArgument.item
@ item
System.ExceptionArgument.options
@ options
System.ExceptionArgument.array
@ array
source
System.Linq.Parallel
System.Linq.Parallel
DefaultMergeHelper.cs
Generated by
1.10.0