Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Merging / ArrayMergeHelper.cs / 1305376 / ArrayMergeHelper.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // ArrayMergeHelper.cs // //[....] // // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Parallel; using System.Diagnostics; using System.Threading.Tasks; namespace System.Linq.Parallel { ////// A special merge helper for indexible queries. Given an indexible query, we know how many elements /// we'll have in the result set, so we can allocate the array ahead of time. Then, as each result element /// is produced, we can directly insert it into the appropriate position in the output array, paying /// no extra cost for ordering. /// ///internal class ArrayMergeHelper : IMergeHelper { private QueryResults m_queryResults; // Indexible query results private TInputOutput[] m_outputArray; // The output array. private QuerySettings m_settings; // Settings for the query. /// /// Instantiates the array merge helper. /// /// The query settings /// The query results public ArrayMergeHelper(QuerySettings settings, QueryResultsqueryResults) { m_settings = settings; m_queryResults = queryResults; int count = m_queryResults.Count; m_outputArray = new TInputOutput[count]; } /// /// A method used as a delegate passed into the ForAll operator /// private void ToArrayElement(int index) { m_outputArray[index] = m_queryResults[index]; } ////// Schedules execution of the merge itself. /// public void Execute() { ParallelQueryquery = ParallelEnumerable.Range(0, m_queryResults.Count); query = new QueryExecutionOption (QueryOperator .AsQueryOperator(query), m_settings); query.ForAll(ToArrayElement); } /// /// Gets the enumerator over the results. /// /// We never expect this method to be called. ArrayMergeHelper is intended to be used when we want /// to consume the results using GetResultsAsArray(). /// public IEnumeratorGetEnumerator() { Debug.Assert(false, "ArrayMergeHelper<>.GetEnumerator() is not intended to be used. Call GetResultsAsArray() instead."); return ((IEnumerable )GetResultsAsArray()).GetEnumerator(); } /// /// Returns the merged results as an array. /// ///public TInputOutput[] GetResultsAsArray() { Debug.Assert(m_outputArray != null); return m_outputArray; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // ArrayMergeHelper.cs // // [....] // // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Parallel; using System.Diagnostics; using System.Threading.Tasks; namespace System.Linq.Parallel { ////// A special merge helper for indexible queries. Given an indexible query, we know how many elements /// we'll have in the result set, so we can allocate the array ahead of time. Then, as each result element /// is produced, we can directly insert it into the appropriate position in the output array, paying /// no extra cost for ordering. /// ///internal class ArrayMergeHelper : IMergeHelper { private QueryResults m_queryResults; // Indexible query results private TInputOutput[] m_outputArray; // The output array. private QuerySettings m_settings; // Settings for the query. /// /// Instantiates the array merge helper. /// /// The query settings /// The query results public ArrayMergeHelper(QuerySettings settings, QueryResultsqueryResults) { m_settings = settings; m_queryResults = queryResults; int count = m_queryResults.Count; m_outputArray = new TInputOutput[count]; } /// /// A method used as a delegate passed into the ForAll operator /// private void ToArrayElement(int index) { m_outputArray[index] = m_queryResults[index]; } ////// Schedules execution of the merge itself. /// public void Execute() { ParallelQueryquery = ParallelEnumerable.Range(0, m_queryResults.Count); query = new QueryExecutionOption (QueryOperator .AsQueryOperator(query), m_settings); query.ForAll(ToArrayElement); } /// /// Gets the enumerator over the results. /// /// We never expect this method to be called. ArrayMergeHelper is intended to be used when we want /// to consume the results using GetResultsAsArray(). /// public IEnumeratorGetEnumerator() { Debug.Assert(false, "ArrayMergeHelper<>.GetEnumerator() is not intended to be used. Call GetResultsAsArray() instead."); return ((IEnumerable )GetResultsAsArray()).GetEnumerator(); } /// /// Returns the merged results as an array. /// ///public TInputOutput[] GetResultsAsArray() { Debug.Assert(m_outputArray != null); return m_outputArray; } } } // 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
- TimeZoneInfo.cs
- UriParserTemplates.cs
- TimeoutHelper.cs
- RevocationPoint.cs
- InternalConfigEventArgs.cs
- ApplicationCommands.cs
- UmAlQuraCalendar.cs
- StringSorter.cs
- XamlRtfConverter.cs
- EventProviderTraceListener.cs
- XmlSchemaValidationException.cs
- PipelineModuleStepContainer.cs
- BooleanAnimationBase.cs
- ObjectSelectorEditor.cs
- StringValidator.cs
- NavigationWindow.cs
- ThicknessAnimationBase.cs
- XXXOnTypeBuilderInstantiation.cs
- LinqDataView.cs
- PolyLineSegmentFigureLogic.cs
- DoubleStorage.cs
- WebPartsPersonalizationAuthorization.cs
- DataTableReader.cs
- HtmlHead.cs
- DesignerTransaction.cs
- DataGridViewRowPostPaintEventArgs.cs
- Int32CollectionValueSerializer.cs
- CodeFieldReferenceExpression.cs
- NameTable.cs
- ServiceTimeoutsBehavior.cs
- Latin1Encoding.cs
- externdll.cs
- DataGridViewControlCollection.cs
- BamlBinaryWriter.cs
- XmlElement.cs
- BooleanAnimationBase.cs
- SkipStoryboardToFill.cs
- Convert.cs
- PersistChildrenAttribute.cs
- StorageSetMapping.cs
- ProtocolElement.cs
- EncryptedKey.cs
- DivideByZeroException.cs
- OleDbCommandBuilder.cs
- MatrixIndependentAnimationStorage.cs
- DetailsView.cs
- FaultPropagationQuery.cs
- SocketInformation.cs
- KeyboardDevice.cs
- OutOfMemoryException.cs
- DataBindingCollection.cs
- ControlEvent.cs
- Timer.cs
- HtmlInputSubmit.cs
- RSAPKCS1KeyExchangeFormatter.cs
- ArrangedElementCollection.cs
- ArrayList.cs
- Simplifier.cs
- HashAlgorithm.cs
- RectAnimationClockResource.cs
- FormViewCommandEventArgs.cs
- UrlMappingCollection.cs
- ApplicationSecurityInfo.cs
- Imaging.cs
- HtmlTableCellCollection.cs
- MsdtcWrapper.cs
- TreeIterators.cs
- LogicalTreeHelper.cs
- Maps.cs
- SqlFunctionAttribute.cs
- DataControlFieldCollection.cs
- UpdatePanelControlTrigger.cs
- IteratorFilter.cs
- QualifiedCellIdBoolean.cs
- BuildResultCache.cs
- TimeSpanMinutesConverter.cs
- XmlEventCache.cs
- Utils.cs
- PageFunction.cs
- ToolStripRenderEventArgs.cs
- ErrorHandler.cs
- ResourceReader.cs
- EasingQuaternionKeyFrame.cs
- SelectionWordBreaker.cs
- PreviewPageInfo.cs
- PolicyManager.cs
- ISAPIWorkerRequest.cs
- XmlSchemaSet.cs
- DataServiceStreamProviderWrapper.cs
- BitStream.cs
- FormViewActionList.cs
- ActivityExecutorDelegateInfo.cs
- RenderData.cs
- DataGridViewComboBoxEditingControl.cs
- Emitter.cs
- ServiceBuildProvider.cs
- GridViewRow.cs
- CalendarSelectionChangedEventArgs.cs
- ModifiableIteratorCollection.cs
- RegexRunner.cs