Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Merging / OrderPreservingMergeHelper.cs / 1305376 / OrderPreservingMergeHelper.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // OrderPreservingMergeHelper.cs // //[....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Threading.Tasks; using System.Diagnostics.Contracts; namespace System.Linq.Parallel { ////// The order preserving merge helper guarantees the output stream is in a specific order. This is done /// by comparing keys from a set of already-sorted input partitions, and coalescing output data using /// incremental key comparisons. /// ////// internal class OrderPreservingMergeHelper : IMergeHelper { private QueryTaskGroupState m_taskGroupState; // State shared among tasks. private PartitionedStream m_partitions; // Source partitions. private Shared m_results; // The array where results are stored. private TaskScheduler m_taskScheduler; // The task manager to execute the query. //------------------------------------------------------------------------------------ // Instantiates a new merge helper. // // Arguments: // partitions - the source partitions from which to consume data. // ignoreOutput - whether we're enumerating "for effect" or for output. // internal OrderPreservingMergeHelper(PartitionedStream partitions, TaskScheduler taskScheduler, CancellationState cancellationState, int queryId) { Contract.Assert(partitions != null); TraceHelpers.TraceInfo("KeyOrderPreservingMergeHelper::.ctor(..): creating an order preserving merge helper"); m_taskGroupState = new QueryTaskGroupState(cancellationState, queryId); m_partitions = partitions; m_results = new Shared (null); m_taskScheduler = taskScheduler; } //----------------------------------------------------------------------------------- // Schedules execution of the merge itself. // // Arguments: // ordinalIndexState - the state of the ordinal index of the merged partitions // void IMergeHelper .Execute() { OrderPreservingSpoolingTask .Spool(m_taskGroupState, m_partitions, m_results, m_taskScheduler); } //----------------------------------------------------------------------------------- // Gets the enumerator from which to enumerate output results. // IEnumerator IMergeHelper .GetEnumerator() { Contract.Assert(m_results.Value != null); return ((IEnumerable )m_results.Value).GetEnumerator(); } //----------------------------------------------------------------------------------- // Returns the results as an array. // public TInputOutput[] GetResultsAsArray() { return m_results.Value; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // OrderPreservingMergeHelper.cs // // [....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Threading.Tasks; using System.Diagnostics.Contracts; namespace System.Linq.Parallel { ////// The order preserving merge helper guarantees the output stream is in a specific order. This is done /// by comparing keys from a set of already-sorted input partitions, and coalescing output data using /// incremental key comparisons. /// ////// internal class OrderPreservingMergeHelper : IMergeHelper { private QueryTaskGroupState m_taskGroupState; // State shared among tasks. private PartitionedStream m_partitions; // Source partitions. private Shared m_results; // The array where results are stored. private TaskScheduler m_taskScheduler; // The task manager to execute the query. //------------------------------------------------------------------------------------ // Instantiates a new merge helper. // // Arguments: // partitions - the source partitions from which to consume data. // ignoreOutput - whether we're enumerating "for effect" or for output. // internal OrderPreservingMergeHelper(PartitionedStream partitions, TaskScheduler taskScheduler, CancellationState cancellationState, int queryId) { Contract.Assert(partitions != null); TraceHelpers.TraceInfo("KeyOrderPreservingMergeHelper::.ctor(..): creating an order preserving merge helper"); m_taskGroupState = new QueryTaskGroupState(cancellationState, queryId); m_partitions = partitions; m_results = new Shared (null); m_taskScheduler = taskScheduler; } //----------------------------------------------------------------------------------- // Schedules execution of the merge itself. // // Arguments: // ordinalIndexState - the state of the ordinal index of the merged partitions // void IMergeHelper .Execute() { OrderPreservingSpoolingTask .Spool(m_taskGroupState, m_partitions, m_results, m_taskScheduler); } //----------------------------------------------------------------------------------- // Gets the enumerator from which to enumerate output results. // IEnumerator IMergeHelper .GetEnumerator() { Contract.Assert(m_results.Value != null); return ((IEnumerable )m_results.Value).GetEnumerator(); } //----------------------------------------------------------------------------------- // Returns the results as an array. // public TInputOutput[] GetResultsAsArray() { return m_results.Value; } } } // 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
- ManagedWndProcTracker.cs
- PeerNearMe.cs
- OciHandle.cs
- ImportContext.cs
- XPathQilFactory.cs
- ReferentialConstraint.cs
- ApplicationSecurityManager.cs
- Scheduler.cs
- DataGridViewRowPrePaintEventArgs.cs
- TextRenderingModeValidation.cs
- Crypto.cs
- listitem.cs
- ToolBarButtonDesigner.cs
- XmlDataSource.cs
- OleDbDataReader.cs
- ExpressionBindings.cs
- WebRequestModuleElementCollection.cs
- ScrollPatternIdentifiers.cs
- MulticastDelegate.cs
- CollectionContainer.cs
- invalidudtexception.cs
- ConfigXmlText.cs
- RequestBringIntoViewEventArgs.cs
- UdpReplyToBehavior.cs
- OleTxTransaction.cs
- SyndicationContent.cs
- NavigationService.cs
- TextTreeDeleteContentUndoUnit.cs
- PipeException.cs
- DiscoveryDocumentReference.cs
- DesignOnlyAttribute.cs
- ProtocolsConfigurationEntry.cs
- WebPartTransformerCollection.cs
- ObjectAnimationBase.cs
- SelectionPattern.cs
- HtmlTernaryTree.cs
- Panel.cs
- EntitySqlQueryBuilder.cs
- RequestCacheEntry.cs
- TextBoxLine.cs
- loginstatus.cs
- DataSourceView.cs
- ping.cs
- ParserOptions.cs
- ControllableStoryboardAction.cs
- BufferBuilder.cs
- XmlSchemaCompilationSettings.cs
- StartFileNameEditor.cs
- RSAPKCS1SignatureFormatter.cs
- Variant.cs
- Deflater.cs
- RemotingException.cs
- ImageSource.cs
- TreeViewImageKeyConverter.cs
- EncryptedPackage.cs
- JsonServiceDocumentSerializer.cs
- ObjectDataSourceDisposingEventArgs.cs
- WeakReferenceEnumerator.cs
- TextRangeBase.cs
- XsltSettings.cs
- PageFunction.cs
- DataPagerFieldCollection.cs
- AsyncWaitHandle.cs
- PerformanceCounterLib.cs
- ImageListStreamer.cs
- AQNBuilder.cs
- SqlDataSourceSelectingEventArgs.cs
- HostAdapter.cs
- HttpSocketManager.cs
- entityreference_tresulttype.cs
- MatchingStyle.cs
- PageThemeCodeDomTreeGenerator.cs
- InternalSafeNativeMethods.cs
- WriteableBitmap.cs
- SafeCryptHandles.cs
- StoreItemCollection.Loader.cs
- DataSourceHelper.cs
- SystemTcpConnection.cs
- BaseAddressElement.cs
- DbParameterCollection.cs
- FullTrustAssembly.cs
- OleDbParameter.cs
- SortFieldComparer.cs
- ClientTarget.cs
- RightsManagementResourceHelper.cs
- XmlConvert.cs
- IndexedEnumerable.cs
- XmlSchemaAny.cs
- EventMappingSettingsCollection.cs
- CheckBoxBaseAdapter.cs
- TypeHelpers.cs
- SizeAnimation.cs
- RowUpdatingEventArgs.cs
- BoundsDrawingContextWalker.cs
- FormsAuthenticationUserCollection.cs
- Int64.cs
- DesignerActionTextItem.cs
- ReadOnlyPropertyMetadata.cs
- _ListenerAsyncResult.cs
- RbTree.cs