Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListViewTableRow.cs
- LayoutSettings.cs
- TableCell.cs
- WorkflowDebuggerSteppingAttribute.cs
- FrameworkTemplate.cs
- KeyTimeConverter.cs
- ObjectToIdCache.cs
- Rfc2898DeriveBytes.cs
- MouseWheelEventArgs.cs
- Compiler.cs
- QueryOutputWriterV1.cs
- PerformanceCounterPermissionEntryCollection.cs
- CngUIPolicy.cs
- XmlReflectionImporter.cs
- CapabilitiesSection.cs
- ImageMap.cs
- Button.cs
- ActiveXHost.cs
- LinqDataSourceInsertEventArgs.cs
- ModuleConfigurationInfo.cs
- RoleManagerModule.cs
- QilFunction.cs
- ServiceDeploymentInfo.cs
- RightNameExpirationInfoPair.cs
- EventlogProvider.cs
- TableRow.cs
- Typography.cs
- TemplatePartAttribute.cs
- SystemParameters.cs
- ExtendedPropertyDescriptor.cs
- DriveNotFoundException.cs
- LockCookie.cs
- ModuleBuilder.cs
- RoleGroup.cs
- RootBrowserWindowProxy.cs
- FillErrorEventArgs.cs
- EncoderExceptionFallback.cs
- DataListItemEventArgs.cs
- EmptyControlCollection.cs
- DataTableNewRowEvent.cs
- EventLogPermission.cs
- MutexSecurity.cs
- ContourSegment.cs
- MasterPageParser.cs
- StringUtil.cs
- DataTablePropertyDescriptor.cs
- InputBuffer.cs
- GradientBrush.cs
- ClientFormsAuthenticationMembershipProvider.cs
- WebPartEditorApplyVerb.cs
- ResourcePermissionBaseEntry.cs
- AsyncStreamReader.cs
- LateBoundBitmapDecoder.cs
- EntityReference.cs
- CategoryAttribute.cs
- SimpleType.cs
- IntMinMaxAggregationOperator.cs
- BinaryReader.cs
- ContainerFilterService.cs
- TreeView.cs
- Axis.cs
- QueryTask.cs
- FaultContext.cs
- DataStorage.cs
- ResXResourceSet.cs
- Version.cs
- ProvideValueServiceProvider.cs
- SqlRetyper.cs
- BinaryObjectReader.cs
- XmlCollation.cs
- FileDocument.cs
- ParallelTimeline.cs
- Floater.cs
- GridErrorDlg.cs
- WebPartMinimizeVerb.cs
- Int64AnimationUsingKeyFrames.cs
- FormViewRow.cs
- SafeFileHandle.cs
- SecurityCookieModeValidator.cs
- COM2ExtendedBrowsingHandler.cs
- XmlSchemaIdentityConstraint.cs
- WindowsIPAddress.cs
- ClonableStack.cs
- PolicyException.cs
- ColorDialog.cs
- InternalMappingException.cs
- CodeVariableDeclarationStatement.cs
- Queue.cs
- SpellCheck.cs
- MetadataHelper.cs
- PromptEventArgs.cs
- CodeTypeMemberCollection.cs
- BaseContextMenu.cs
- ButtonField.cs
- XPathNodeInfoAtom.cs
- CategoryState.cs
- Pts.cs
- followingquery.cs
- _LocalDataStoreMgr.cs
- ResourceWriter.cs