Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / QueryOperators / UnaryQueryOperator.cs / 1305376 / UnaryQueryOperator.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
// UnaryQueryOperator.cs
//
// [....]
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
using System.Collections.Generic;
using System.Diagnostics.Contracts;
namespace System.Linq.Parallel
{
///
/// The base class from which all binary query operators derive, that is, those that
/// have two child operators. This introduces some convenience methods for those
/// classes, as well as any state common to all subclasses.
///
///
///
internal abstract class UnaryQueryOperator : QueryOperator
{
// The single child operator for the current node.
private readonly QueryOperator m_child;
// The state of the order index of the output of this operator.
private OrdinalIndexState m_indexState = OrdinalIndexState.Shuffled;
//----------------------------------------------------------------------------------------
// Constructors
//
internal UnaryQueryOperator(IEnumerable child)
: this(QueryOperator.AsQueryOperator(child))
{
}
internal UnaryQueryOperator(IEnumerable child, bool outputOrdered)
: this(QueryOperator.AsQueryOperator(child), outputOrdered)
{
}
private UnaryQueryOperator(QueryOperator child)
: this(child, child.OutputOrdered, child.SpecifiedQuerySettings)
{
}
internal UnaryQueryOperator(QueryOperator child, bool outputOrdered)
: this(child, outputOrdered, child.SpecifiedQuerySettings)
{
}
private UnaryQueryOperator(QueryOperator child, bool outputOrdered, QuerySettings settings)
: base(outputOrdered, settings)
{
m_child = child;
}
internal QueryOperator Child
{
get { return m_child; }
}
internal override sealed OrdinalIndexState OrdinalIndexState
{
get { return m_indexState; }
}
protected void SetOrdinalIndexState(OrdinalIndexState indexState)
{
m_indexState = indexState;
}
//---------------------------------------------------------------------------------------
// This method wraps each enumerator in inputStream with an enumerator performing this
// operator's transformation. However, instead of returning the transformed partitioned
// stream, we pass it to a recipient object by calling recipient.Give(..). That
// way, we can "return" a partitioned stream that potentially uses a different order key
// from the order key of the input stream.
//
internal abstract void WrapPartitionedStream(
PartitionedStream inputStream, IPartitionedStreamRecipient recipient,
bool preferStriping, QuerySettings settings);
//---------------------------------------------------------------------------------------
// Implementation of QueryResults for an unary operator. The results will not be indexible
// unless a derived class provides that functionality.
//
internal class UnaryQueryOperatorResults : QueryResults
{
protected QueryResults m_childQueryResults; // Results of the child query
private UnaryQueryOperator m_op; // Operator that generated these results
private QuerySettings m_settings; // Settings collected from the query
private bool m_preferStriping; // If the results are indexible, should we use striping when partitioning them
internal UnaryQueryOperatorResults(QueryResults childQueryResults, UnaryQueryOperator op, QuerySettings settings, bool preferStriping)
{
m_childQueryResults = childQueryResults;
m_op = op;
m_settings = settings;
m_preferStriping = preferStriping;
}
internal override void GivePartitionedStream(IPartitionedStreamRecipient recipient)
{
Contract.Assert(IsIndexible == (m_op.OrdinalIndexState == OrdinalIndexState.Indexible));
if (m_settings.ExecutionMode.Value == ParallelExecutionMode.Default && m_op.LimitsParallelism)
{
// We need to run the query sequentially, up to and including this operator
IEnumerable opSequential = m_op.AsSequentialQuery(m_settings.CancellationState.ExternalCancellationToken);
PartitionedStream result = ExchangeUtilities.PartitionDataSource(
opSequential, m_settings.DegreeOfParallelism.Value, m_preferStriping);
recipient.Receive(result);
}
else if (IsIndexible)
{
// The output of this operator is indexible. Pass the partitioned output into the IPartitionedStreamRecipient.
PartitionedStream result = ExchangeUtilities.PartitionDataSource(this, m_settings.DegreeOfParallelism.Value, m_preferStriping);
recipient.Receive(result);
}
else
{
// The common case: get partitions from the child and wrap each partition.
m_childQueryResults.GivePartitionedStream(new ChildResultsRecipient(recipient, m_op, m_preferStriping, m_settings));
}
}
//---------------------------------------------------------------------------------------
// ChildResultsRecipient is a recipient of a partitioned stream. It receives a partitioned
// stream from the child operator, wraps the enumerators with the transformation for this
// operator, and passes the partitioned stream along to the next recipient (the parent
// operator).
//
private class ChildResultsRecipient : IPartitionedStreamRecipient
{
IPartitionedStreamRecipient m_outputRecipient;
UnaryQueryOperator m_op;
bool m_preferStriping;
QuerySettings m_settings;
internal ChildResultsRecipient(
IPartitionedStreamRecipient outputRecipient, UnaryQueryOperator op, bool preferStriping, QuerySettings settings)
{
m_outputRecipient = outputRecipient;
m_op = op;
m_preferStriping = preferStriping;
m_settings = settings;
}
public void Receive(PartitionedStream inputStream)
{
// Call WrapPartitionedStream on our operator, which will wrap the input
// partitioned stream, and pass the result along to m_outputRecipient.
m_op.WrapPartitionedStream(inputStream, m_outputRecipient, m_preferStriping, m_settings);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
// UnaryQueryOperator.cs
//
// [....]
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
using System.Collections.Generic;
using System.Diagnostics.Contracts;
namespace System.Linq.Parallel
{
///
/// The base class from which all binary query operators derive, that is, those that
/// have two child operators. This introduces some convenience methods for those
/// classes, as well as any state common to all subclasses.
///
///
///
internal abstract class UnaryQueryOperator : QueryOperator
{
// The single child operator for the current node.
private readonly QueryOperator m_child;
// The state of the order index of the output of this operator.
private OrdinalIndexState m_indexState = OrdinalIndexState.Shuffled;
//----------------------------------------------------------------------------------------
// Constructors
//
internal UnaryQueryOperator(IEnumerable child)
: this(QueryOperator.AsQueryOperator(child))
{
}
internal UnaryQueryOperator(IEnumerable child, bool outputOrdered)
: this(QueryOperator.AsQueryOperator(child), outputOrdered)
{
}
private UnaryQueryOperator(QueryOperator child)
: this(child, child.OutputOrdered, child.SpecifiedQuerySettings)
{
}
internal UnaryQueryOperator(QueryOperator child, bool outputOrdered)
: this(child, outputOrdered, child.SpecifiedQuerySettings)
{
}
private UnaryQueryOperator(QueryOperator child, bool outputOrdered, QuerySettings settings)
: base(outputOrdered, settings)
{
m_child = child;
}
internal QueryOperator Child
{
get { return m_child; }
}
internal override sealed OrdinalIndexState OrdinalIndexState
{
get { return m_indexState; }
}
protected void SetOrdinalIndexState(OrdinalIndexState indexState)
{
m_indexState = indexState;
}
//---------------------------------------------------------------------------------------
// This method wraps each enumerator in inputStream with an enumerator performing this
// operator's transformation. However, instead of returning the transformed partitioned
// stream, we pass it to a recipient object by calling recipient.Give(..). That
// way, we can "return" a partitioned stream that potentially uses a different order key
// from the order key of the input stream.
//
internal abstract void WrapPartitionedStream(
PartitionedStream inputStream, IPartitionedStreamRecipient recipient,
bool preferStriping, QuerySettings settings);
//---------------------------------------------------------------------------------------
// Implementation of QueryResults for an unary operator. The results will not be indexible
// unless a derived class provides that functionality.
//
internal class UnaryQueryOperatorResults : QueryResults
{
protected QueryResults m_childQueryResults; // Results of the child query
private UnaryQueryOperator m_op; // Operator that generated these results
private QuerySettings m_settings; // Settings collected from the query
private bool m_preferStriping; // If the results are indexible, should we use striping when partitioning them
internal UnaryQueryOperatorResults(QueryResults childQueryResults, UnaryQueryOperator op, QuerySettings settings, bool preferStriping)
{
m_childQueryResults = childQueryResults;
m_op = op;
m_settings = settings;
m_preferStriping = preferStriping;
}
internal override void GivePartitionedStream(IPartitionedStreamRecipient recipient)
{
Contract.Assert(IsIndexible == (m_op.OrdinalIndexState == OrdinalIndexState.Indexible));
if (m_settings.ExecutionMode.Value == ParallelExecutionMode.Default && m_op.LimitsParallelism)
{
// We need to run the query sequentially, up to and including this operator
IEnumerable opSequential = m_op.AsSequentialQuery(m_settings.CancellationState.ExternalCancellationToken);
PartitionedStream result = ExchangeUtilities.PartitionDataSource(
opSequential, m_settings.DegreeOfParallelism.Value, m_preferStriping);
recipient.Receive(result);
}
else if (IsIndexible)
{
// The output of this operator is indexible. Pass the partitioned output into the IPartitionedStreamRecipient.
PartitionedStream result = ExchangeUtilities.PartitionDataSource(this, m_settings.DegreeOfParallelism.Value, m_preferStriping);
recipient.Receive(result);
}
else
{
// The common case: get partitions from the child and wrap each partition.
m_childQueryResults.GivePartitionedStream(new ChildResultsRecipient(recipient, m_op, m_preferStriping, m_settings));
}
}
//---------------------------------------------------------------------------------------
// ChildResultsRecipient is a recipient of a partitioned stream. It receives a partitioned
// stream from the child operator, wraps the enumerators with the transformation for this
// operator, and passes the partitioned stream along to the next recipient (the parent
// operator).
//
private class ChildResultsRecipient : IPartitionedStreamRecipient
{
IPartitionedStreamRecipient m_outputRecipient;
UnaryQueryOperator m_op;
bool m_preferStriping;
QuerySettings m_settings;
internal ChildResultsRecipient(
IPartitionedStreamRecipient outputRecipient, UnaryQueryOperator op, bool preferStriping, QuerySettings settings)
{
m_outputRecipient = outputRecipient;
m_op = op;
m_preferStriping = preferStriping;
m_settings = settings;
}
public void Receive(PartitionedStream inputStream)
{
// Call WrapPartitionedStream on our operator, which will wrap the input
// partitioned stream, and pass the result along to m_outputRecipient.
m_op.WrapPartitionedStream(inputStream, m_outputRecipient, m_preferStriping, m_settings);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WeakReferenceKey.cs
- DefaultTraceListener.cs
- StrokeNodeEnumerator.cs
- WrappingXamlSchemaContext.cs
- LinkClickEvent.cs
- IntSecurity.cs
- TableHeaderCell.cs
- LayoutEvent.cs
- TabControl.cs
- DependencyPropertyChangedEventArgs.cs
- Menu.cs
- DeclarationUpdate.cs
- SizeF.cs
- WebDescriptionAttribute.cs
- CheckBoxStandardAdapter.cs
- CssStyleCollection.cs
- UdpChannelFactory.cs
- DataGridViewRowStateChangedEventArgs.cs
- HashHelpers.cs
- TabControlAutomationPeer.cs
- Int16KeyFrameCollection.cs
- UmAlQuraCalendar.cs
- AssociatedControlConverter.cs
- ModuleBuilder.cs
- RowParagraph.cs
- ProxyManager.cs
- TransformCollection.cs
- ActivityDesignerLayoutSerializers.cs
- Trace.cs
- SQLDouble.cs
- UnsafeNativeMethods.cs
- OptimalBreakSession.cs
- MetadataItem_Static.cs
- HebrewCalendar.cs
- ObjectManager.cs
- _NetworkingPerfCounters.cs
- AccessDataSource.cs
- PolyBezierSegmentFigureLogic.cs
- ControlParameter.cs
- SocketElement.cs
- DbConnectionHelper.cs
- AttachmentCollection.cs
- OperatingSystem.cs
- ToolStripLocationCancelEventArgs.cs
- TransportContext.cs
- BindingMemberInfo.cs
- ConfigurationElementProperty.cs
- RSAOAEPKeyExchangeDeformatter.cs
- TypeSemantics.cs
- DateTimeFormat.cs
- Helper.cs
- LongCountAggregationOperator.cs
- ResourceProviderFactory.cs
- UnknownBitmapEncoder.cs
- SchemaElement.cs
- XmlDocumentSerializer.cs
- Effect.cs
- SqlEnums.cs
- MenuItemAutomationPeer.cs
- unitconverter.cs
- ElementHost.cs
- XamlTreeBuilderBamlRecordWriter.cs
- CommentEmitter.cs
- AudienceUriMode.cs
- FrugalList.cs
- EncryptedReference.cs
- RadioButtonStandardAdapter.cs
- MembershipUser.cs
- InvokePattern.cs
- WebBrowserBase.cs
- StandardCommands.cs
- InheritablePropertyChangeInfo.cs
- PlatformNotSupportedException.cs
- DockPanel.cs
- Grant.cs
- StrongNameMembershipCondition.cs
- Attributes.cs
- DefaultValueAttribute.cs
- TagPrefixAttribute.cs
- UserPersonalizationStateInfo.cs
- MultiTouchSystemGestureLogic.cs
- Util.cs
- KeyGestureValueSerializer.cs
- PassportIdentity.cs
- ViewStateModeByIdAttribute.cs
- SqlProviderManifest.cs
- TypeNameConverter.cs
- DataGridViewRowEventArgs.cs
- AuthenticationConfig.cs
- SchemaMapping.cs
- OAVariantLib.cs
- CollectionCodeDomSerializer.cs
- GeneralTransform2DTo3DTo2D.cs
- TableItemStyle.cs
- UpdateTranslator.cs
- UIPermission.cs
- SemanticBasicElement.cs
- InputProviderSite.cs
- ExpressionNode.cs
- InputEventArgs.cs