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, QueryResults queryResults)
{
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()
{
ParallelQuery query = 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 IEnumerator GetEnumerator()
{
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
- NameScopePropertyAttribute.cs
- UIntPtr.cs
- ReadOnlyAttribute.cs
- X509Chain.cs
- Matrix3DConverter.cs
- ScrollPattern.cs
- WebServiceResponse.cs
- SystemBrushes.cs
- AttachInfo.cs
- JournalEntry.cs
- SqlXml.cs
- RemotingService.cs
- LinkLabel.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- SpecialFolderEnumConverter.cs
- WindowsListViewGroupSubsetLink.cs
- TemplateXamlParser.cs
- IsolatedStorageException.cs
- CodeSnippetCompileUnit.cs
- URIFormatException.cs
- sortedlist.cs
- RepeatButton.cs
- DbInsertCommandTree.cs
- SafeFindHandle.cs
- NativeMethods.cs
- IDictionary.cs
- ThicknessKeyFrameCollection.cs
- EntityClassGenerator.cs
- SerializerDescriptor.cs
- HttpInputStream.cs
- TempFiles.cs
- EdmToObjectNamespaceMap.cs
- EntityClientCacheEntry.cs
- SystemNetworkInterface.cs
- VariantWrapper.cs
- ReadOnlyHierarchicalDataSourceView.cs
- MemoryFailPoint.cs
- NativeWindow.cs
- Guid.cs
- Query.cs
- FreezableDefaultValueFactory.cs
- XmlWellformedWriter.cs
- ProtocolViolationException.cs
- GridToolTip.cs
- LostFocusEventManager.cs
- LoggedException.cs
- MILUtilities.cs
- PtsHelper.cs
- UserControl.cs
- SerializationEventsCache.cs
- XmlSchemaElement.cs
- MemberAccessException.cs
- AssociationSetMetadata.cs
- PathSegmentCollection.cs
- WebPart.cs
- ModelMemberCollection.cs
- _Events.cs
- ColorAnimationBase.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- HelpProvider.cs
- ThumbAutomationPeer.cs
- DefaultBindingPropertyAttribute.cs
- TypeBuilder.cs
- ConfigurationSectionGroup.cs
- FastEncoderWindow.cs
- AsyncOperation.cs
- Binding.cs
- EntityTemplateUserControl.cs
- EnumType.cs
- SizeAnimationBase.cs
- PreProcessor.cs
- BamlReader.cs
- BooleanConverter.cs
- AliasedExpr.cs
- EventDescriptor.cs
- DbExpressionRules.cs
- DeobfuscatingStream.cs
- Point3DAnimationUsingKeyFrames.cs
- PageThemeBuildProvider.cs
- AssemblyAssociatedContentFileAttribute.cs
- ParseNumbers.cs
- SQLInt16.cs
- BitmapFrameDecode.cs
- Int32RectValueSerializer.cs
- GridViewDeletedEventArgs.cs
- TypeContext.cs
- TargetException.cs
- CodeFieldReferenceExpression.cs
- _IPv6Address.cs
- HttpHandlersSection.cs
- HwndProxyElementProvider.cs
- StorageComplexTypeMapping.cs
- QueryComponents.cs
- __ConsoleStream.cs
- SelectedCellsCollection.cs
- ThreadInterruptedException.cs
- ResolveNameEventArgs.cs
- MetadataCache.cs
- MimeParameter.cs
- CookieParameter.cs