Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SortQueryOperator.cs
Go to the documentation of this file.
1
using
System.Collections
;
2
using
System.Collections.Generic
;
3
using
System.Threading
;
4
5
namespace
System.Linq.Parallel
;
6
7
internal
sealed
class
SortQueryOperator
<
TInputOutput
,
TSortKey
> :
UnaryQueryOperator
<TInputOutput, TInputOutput>,
IOrderedEnumerable
<TInputOutput>,
IEnumerable
<TInputOutput>,
IEnumerable
8
{
9
private
readonly
Func<TInputOutput, TSortKey>
_keySelector
;
10
11
private
readonly
IComparer<TSortKey>
_comparer
;
12
13
internal
override
bool
LimitsParallelism
=>
false
;
14
15
internal
SortQueryOperator
(
IEnumerable<TInputOutput>
source
,
Func<TInputOutput, TSortKey>
keySelector
,
IComparer<TSortKey>
comparer
,
bool
descending
)
16
:
base
(
source
,
outputOrdered
:
true
)
17
{
18
_keySelector
=
keySelector
;
19
if
(
comparer
==
null
)
20
{
21
_comparer
=
Util
.GetDefaultComparer<
TSortKey
>();
22
}
23
else
24
{
25
_comparer
=
comparer
;
26
}
27
if
(
descending
)
28
{
29
_comparer
=
new
ReverseComparer<TSortKey>
(
_comparer
);
30
}
31
SetOrdinalIndexState
(
OrdinalIndexState
.Shuffled);
32
}
33
34
IOrderedEnumerable<TInputOutput>
IOrderedEnumerable<TInputOutput>
.CreateOrderedEnumerable<
TKey2
>(
Func<TInputOutput, TKey2>
key2Selector
,
IComparer<TKey2>
key2Comparer
,
bool
descending
)
35
{
36
key2Comparer
=
key2Comparer
??
Util
.GetDefaultComparer<
TKey2
>();
37
if
(
descending
)
38
{
39
key2Comparer
=
new
ReverseComparer<TKey2>
(
key2Comparer
);
40
}
41
IComparer<Pair<TSortKey, TKey2>
>
comparer
=
new
PairComparer<TSortKey, TKey2>
(
_comparer
,
key2Comparer
);
42
Func<TInputOutput, Pair<TSortKey, TKey2>
>
keySelector
= (
TInputOutput
elem
) =>
new
Pair<TSortKey, TKey2>
(
_keySelector
(
elem
),
key2Selector
(
elem
));
43
return
new
SortQueryOperator<TInputOutput, Pair<TSortKey, TKey2>
>(
base
.Child,
keySelector
,
comparer
,
descending
:
false
);
44
}
45
46
internal
override
QueryResults<TInputOutput>
Open
(
QuerySettings
settings,
bool
preferStriping
)
47
{
48
QueryResults<TInputOutput>
childQueryResults
=
base
.Child.Open(settings,
preferStriping
:
false
);
49
return
new
SortQueryOperatorResults<TInputOutput, TSortKey>
(
childQueryResults
,
this
, settings);
50
}
51
52
internal
override
void
WrapPartitionedStream<TKey>
(
PartitionedStream<TInputOutput, TKey>
inputStream,
IPartitionedStreamRecipient<TInputOutput>
recipient
,
bool
preferStriping
,
QuerySettings
settings)
53
{
54
PartitionedStream<TInputOutput, TSortKey>
partitionedStream
=
new
PartitionedStream<TInputOutput, TSortKey>
(inputStream.PartitionCount,
_comparer
,
OrdinalIndexState
);
55
for
(
int
i = 0; i <
partitionedStream
.PartitionCount; i++)
56
{
57
partitionedStream
[i] =
new
SortQueryOperatorEnumerator<TInputOutput, TKey, TSortKey>
(inputStream[i],
_keySelector
);
58
}
59
recipient
.Receive(
partitionedStream
);
60
}
61
62
internal
override
IEnumerable<TInputOutput>
AsSequentialQuery
(
CancellationToken
token)
63
{
64
IEnumerable<TInputOutput>
source
=
CancellableEnumerable
.Wrap(
base
.Child.AsSequentialQuery(token), token);
65
return
source
.OrderBy(
_keySelector
,
_comparer
);
66
}
67
}
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Linq.Parallel.CancellableEnumerable
Definition
CancellableEnumerable.cs:7
System.Linq.Parallel.SortQueryOperator.SortQueryOperator
SortQueryOperator(IEnumerable< TInputOutput > source, Func< TInputOutput, TSortKey > keySelector, IComparer< TSortKey > comparer, bool descending)
Definition
SortQueryOperator.cs:15
System.Linq.Parallel.SortQueryOperator._comparer
readonly IComparer< TSortKey > _comparer
Definition
SortQueryOperator.cs:11
System.Linq.Parallel.SortQueryOperator._keySelector
readonly Func< TInputOutput, TSortKey > _keySelector
Definition
SortQueryOperator.cs:9
System.Linq.Parallel.SortQueryOperator.LimitsParallelism
override bool LimitsParallelism
Definition
SortQueryOperator.cs:13
System.Linq.Parallel.SortQueryOperator.Open
override QueryResults< TInputOutput > Open(QuerySettings settings, bool preferStriping)
Definition
SortQueryOperator.cs:46
System.Linq.Parallel.SortQueryOperator.WrapPartitionedStream< TKey >
override void WrapPartitionedStream< TKey >(PartitionedStream< TInputOutput, TKey > inputStream, IPartitionedStreamRecipient< TInputOutput > recipient, bool preferStriping, QuerySettings settings)
Definition
SortQueryOperator.cs:52
System.Linq.Parallel.SortQueryOperator.AsSequentialQuery
override IEnumerable< TInputOutput > AsSequentialQuery(CancellationToken token)
Definition
SortQueryOperator.cs:62
System.Linq.Parallel.SortQueryOperator
Definition
SortQueryOperator.cs:8
System.Linq.Parallel.UnaryQueryOperator< TInputOutput, TInputOutput >::SetOrdinalIndexState
void SetOrdinalIndexState(OrdinalIndexState indexState)
Definition
UnaryQueryOperator.cs:103
System.Linq.Parallel.UnaryQueryOperator
Definition
UnaryQueryOperator.cs:6
System.Linq.Parallel.Util
Definition
Util.cs:6
System.Collections.Generic.IEnumerable
Definition
IEnumerable.cs:4
System.Linq.IOrderedEnumerable
Definition
IOrderedEnumerable.cs:7
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.ExceptionArgument.source
@ source
System.Linq.ExceptionArgument.keySelector
@ keySelector
System.Threading
Definition
TaskToApm.cs:3
System.ExceptionArgument.comparer
@ comparer
System.Linq.Parallel.QuerySettings
Definition
QuerySettings.cs:7
System.Threading.CancellationToken
Definition
CancellationToken.cs:8
source
System.Linq.Parallel
System.Linq.Parallel
SortQueryOperator.cs
Generated by
1.10.0