Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Partitioning / PartitionedStream.cs / 1305376 / PartitionedStream.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // PartitionedStream.cs // //[....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Diagnostics.Contracts; namespace System.Linq.Parallel { ////// A partitioned stream just partitions some data source using an extensible /// partitioning algorithm and exposes a set of N enumerators that are consumed by /// their ordinal index [0..N). It is used to build up a set of streaming computations. /// At instantiation time, the actual data source to be partitioned is supplied; and /// then the caller will layer on top additional enumerators to represent phases in the /// computation. Eventually, a merge can then schedule enumeration of all of the /// individual partitions in parallel by obtaining references to the individual /// partition streams. /// /// This type has a set of subclasses which implement different partitioning algorithms, /// allowing us to easily plug in different partitioning techniques as needed. The type /// supports wrapping IEnumerables and IEnumerators alike, with some preference for the /// former as many partitioning algorithms are more intelligent for certain data types. /// ////// internal class PartitionedStream { protected QueryOperatorEnumerator [] m_partitions; // Partitions exposed by this object. private readonly IComparer m_keyComparer; // Comparer for order keys. private readonly OrdinalIndexState m_indexState; // State of the order keys. internal PartitionedStream(int partitionCount, IComparer keyComparer, OrdinalIndexState indexState) { Contract.Assert(partitionCount > 0); m_partitions = new QueryOperatorEnumerator [partitionCount]; m_keyComparer = keyComparer; m_indexState = indexState; } //---------------------------------------------------------------------------------------- // Retrieves or sets a partition for the given index. // // Assumptions: // The index falls within the legal range of the enumerator, i.e. 0 <= value < count. // internal QueryOperatorEnumerator this[int index] { get { Contract.Assert(m_partitions != null); Contract.Assert(0 <= index && index < m_partitions.Length, "index out of bounds"); return m_partitions[index]; } set { Contract.Assert(m_partitions != null); Contract.Assert(value != null); Contract.Assert(0 <= index && index < m_partitions.Length, "index out of bounds"); m_partitions[index] = value; } } //--------------------------------------------------------------------------------------- // Retrives the number of partitions. // public int PartitionCount { get { Contract.Assert(m_partitions != null); return m_partitions.Length; } } //--------------------------------------------------------------------------------------- // The comparer for the order keys. // internal IComparer KeyComparer { get { return m_keyComparer; } } //--------------------------------------------------------------------------------------- // State of the order keys. // internal OrdinalIndexState OrdinalIndexState { get { return m_indexState; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // PartitionedStream.cs // // [....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Diagnostics.Contracts; namespace System.Linq.Parallel { ////// A partitioned stream just partitions some data source using an extensible /// partitioning algorithm and exposes a set of N enumerators that are consumed by /// their ordinal index [0..N). It is used to build up a set of streaming computations. /// At instantiation time, the actual data source to be partitioned is supplied; and /// then the caller will layer on top additional enumerators to represent phases in the /// computation. Eventually, a merge can then schedule enumeration of all of the /// individual partitions in parallel by obtaining references to the individual /// partition streams. /// /// This type has a set of subclasses which implement different partitioning algorithms, /// allowing us to easily plug in different partitioning techniques as needed. The type /// supports wrapping IEnumerables and IEnumerators alike, with some preference for the /// former as many partitioning algorithms are more intelligent for certain data types. /// ////// internal class PartitionedStream { protected QueryOperatorEnumerator [] m_partitions; // Partitions exposed by this object. private readonly IComparer m_keyComparer; // Comparer for order keys. private readonly OrdinalIndexState m_indexState; // State of the order keys. internal PartitionedStream(int partitionCount, IComparer keyComparer, OrdinalIndexState indexState) { Contract.Assert(partitionCount > 0); m_partitions = new QueryOperatorEnumerator [partitionCount]; m_keyComparer = keyComparer; m_indexState = indexState; } //---------------------------------------------------------------------------------------- // Retrieves or sets a partition for the given index. // // Assumptions: // The index falls within the legal range of the enumerator, i.e. 0 <= value < count. // internal QueryOperatorEnumerator this[int index] { get { Contract.Assert(m_partitions != null); Contract.Assert(0 <= index && index < m_partitions.Length, "index out of bounds"); return m_partitions[index]; } set { Contract.Assert(m_partitions != null); Contract.Assert(value != null); Contract.Assert(0 <= index && index < m_partitions.Length, "index out of bounds"); m_partitions[index] = value; } } //--------------------------------------------------------------------------------------- // Retrives the number of partitions. // public int PartitionCount { get { Contract.Assert(m_partitions != null); return m_partitions.Length; } } //--------------------------------------------------------------------------------------- // The comparer for the order keys. // internal IComparer KeyComparer { get { return m_keyComparer; } } //--------------------------------------------------------------------------------------- // State of the order keys. // internal OrdinalIndexState OrdinalIndexState { get { return m_indexState; } } } } // 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
- GreenMethods.cs
- MarkedHighlightComponent.cs
- WinHttpWebProxyFinder.cs
- FixedSOMTableCell.cs
- TypeSystem.cs
- ContextDataSourceContextData.cs
- Translator.cs
- DivideByZeroException.cs
- SuppressMessageAttribute.cs
- CodeNamespace.cs
- DataList.cs
- EncoderParameters.cs
- Material.cs
- PerformanceCounterScope.cs
- MtomMessageEncoder.cs
- StyleCollection.cs
- DispatcherHookEventArgs.cs
- ParenthesizePropertyNameAttribute.cs
- LogReservationCollection.cs
- PropertyTabAttribute.cs
- HttpsHostedTransportConfiguration.cs
- QueryableDataSourceView.cs
- InfocardChannelParameter.cs
- X509ChainPolicy.cs
- ObjectQueryState.cs
- Int64KeyFrameCollection.cs
- QilCloneVisitor.cs
- BlockUIContainer.cs
- CachedBitmap.cs
- RayHitTestParameters.cs
- XmlJsonWriter.cs
- PropertyGridView.cs
- ManipulationStartingEventArgs.cs
- Panel.cs
- XamlGridLengthSerializer.cs
- SelectionListDesigner.cs
- ConditionalBranch.cs
- ArrayConverter.cs
- SqlSelectClauseBuilder.cs
- ObjectViewEntityCollectionData.cs
- GrammarBuilder.cs
- ValidateNames.cs
- TemplateControlBuildProvider.cs
- WrappedDispatcherException.cs
- FloaterBaseParaClient.cs
- altserialization.cs
- Error.cs
- EncryptedPackage.cs
- IndependentAnimationStorage.cs
- SchemaContext.cs
- ScriptingProfileServiceSection.cs
- SqlMethodCallConverter.cs
- ControlBuilderAttribute.cs
- HTTPRemotingHandler.cs
- WebPartConnectionsEventArgs.cs
- InternalControlCollection.cs
- TableRow.cs
- ConditionalAttribute.cs
- NativeRecognizer.cs
- WebReferencesBuildProvider.cs
- WebPartHeaderCloseVerb.cs
- Inflater.cs
- CultureInfoConverter.cs
- WindowHelperService.cs
- InputBindingCollection.cs
- TriggerBase.cs
- SecurityUtils.cs
- ProxySimple.cs
- MouseActionValueSerializer.cs
- BitmapEffectDrawingContextWalker.cs
- WebPartEventArgs.cs
- DynamicUpdateCommand.cs
- _Connection.cs
- DependencyPropertyHelper.cs
- CallTemplateAction.cs
- ContextStaticAttribute.cs
- GenericWebPart.cs
- SqlDataSource.cs
- BinaryObjectWriter.cs
- ObsoleteAttribute.cs
- ClientCredentialsElement.cs
- BaseProcessor.cs
- ConcurrencyMode.cs
- WsatConfiguration.cs
- NamespaceListProperty.cs
- Match.cs
- OdbcUtils.cs
- EntityDataSourceWrapperCollection.cs
- DataServiceQueryOfT.cs
- EntityDataSourceDataSelection.cs
- AccessKeyManager.cs
- ScaleTransform.cs
- SqlEnums.cs
- FileUpload.cs
- BuildDependencySet.cs
- OLEDB_Util.cs
- Panel.cs
- CodeAttributeArgumentCollection.cs
- SystemResourceHost.cs
- QueryCacheManager.cs