Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Utils / ListChunk.cs / 1305376 / ListChunk.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // ListChunk.cs // //[....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Diagnostics.Contracts; namespace System.Linq.Parallel { ////// A linked list of array chunks. Allows direct access to its arrays. /// ///The elements held within. internal class ListChunk: IEnumerable { internal TInputOutput[] m_chunk; private int m_chunkCount; private ListChunk m_nextChunk; private ListChunk m_tailChunk; /// /// Allocates a new root chunk of a particular size. /// internal ListChunk(int size) { Contract.Assert(size > 0); m_chunk = new TInputOutput[size]; m_chunkCount = 0; m_tailChunk = this; } ////// Adds an element to this chunk. Only ever called on the root. /// /// The new element. internal void Add(TInputOutput e) { ListChunktail = m_tailChunk; if (tail.m_chunkCount == tail.m_chunk.Length) { m_tailChunk = new ListChunk (tail.m_chunkCount * 2); tail = (tail.m_nextChunk = m_tailChunk); } tail.m_chunk[tail.m_chunkCount++] = e; } /// /// The next chunk in the linked chain. /// internal ListChunkNext { get { return m_nextChunk; } } /// /// The number of elements contained within this particular chunk. /// internal int Count { get { return m_chunkCount; } } ////// Fetches an enumerator to walk the elements in all chunks rooted from this one. /// public IEnumeratorGetEnumerator() { ListChunk curr = this; while (curr != null) { for (int i = 0; i < curr.m_chunkCount; i++) { yield return curr.m_chunk[i]; } Contract.Assert(curr.m_chunkCount == curr.m_chunk.Length || curr.m_nextChunk == null); curr = curr.m_nextChunk; } } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return ((IEnumerable )this).GetEnumerator(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // ListChunk.cs // // [....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Diagnostics.Contracts; namespace System.Linq.Parallel { ////// A linked list of array chunks. Allows direct access to its arrays. /// ///The elements held within. internal class ListChunk: IEnumerable { internal TInputOutput[] m_chunk; private int m_chunkCount; private ListChunk m_nextChunk; private ListChunk m_tailChunk; /// /// Allocates a new root chunk of a particular size. /// internal ListChunk(int size) { Contract.Assert(size > 0); m_chunk = new TInputOutput[size]; m_chunkCount = 0; m_tailChunk = this; } ////// Adds an element to this chunk. Only ever called on the root. /// /// The new element. internal void Add(TInputOutput e) { ListChunktail = m_tailChunk; if (tail.m_chunkCount == tail.m_chunk.Length) { m_tailChunk = new ListChunk (tail.m_chunkCount * 2); tail = (tail.m_nextChunk = m_tailChunk); } tail.m_chunk[tail.m_chunkCount++] = e; } /// /// The next chunk in the linked chain. /// internal ListChunkNext { get { return m_nextChunk; } } /// /// The number of elements contained within this particular chunk. /// internal int Count { get { return m_chunkCount; } } ////// Fetches an enumerator to walk the elements in all chunks rooted from this one. /// public IEnumeratorGetEnumerator() { ListChunk curr = this; while (curr != null) { for (int i = 0; i < curr.m_chunkCount; i++) { yield return curr.m_chunk[i]; } Contract.Assert(curr.m_chunkCount == curr.m_chunk.Length || curr.m_nextChunk == null); curr = curr.m_nextChunk; } } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return ((IEnumerable )this).GetEnumerator(); } } } // 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
- HttpChannelBindingToken.cs
- SByte.cs
- basenumberconverter.cs
- ExpressionBuilder.cs
- basevalidator.cs
- AttachedPropertyMethodSelector.cs
- NonVisualControlAttribute.cs
- SqlColumnizer.cs
- ExpressionPrefixAttribute.cs
- Hex.cs
- DataSourceCache.cs
- PrimaryKeyTypeConverter.cs
- Pair.cs
- IndicCharClassifier.cs
- DataGridrowEditEndingEventArgs.cs
- UserControl.cs
- CompositionDesigner.cs
- GridViewDeletedEventArgs.cs
- SimpleHandlerBuildProvider.cs
- PropertyGeneratedEventArgs.cs
- InstanceHandleConflictException.cs
- RegistryPermission.cs
- WinFormsUtils.cs
- WebConfigurationManager.cs
- UserPrincipalNameElement.cs
- Logging.cs
- DbConvert.cs
- CharAnimationUsingKeyFrames.cs
- Int32AnimationUsingKeyFrames.cs
- Html32TextWriter.cs
- HashCodeCombiner.cs
- ResolveCriteria.cs
- Track.cs
- RightsManagementPermission.cs
- StateMachine.cs
- DrawingContextWalker.cs
- ProcessStartInfo.cs
- StructuralObject.cs
- Point3D.cs
- LogSwitch.cs
- SharedPerformanceCounter.cs
- MetadataArtifactLoaderResource.cs
- MobileListItem.cs
- RichTextBoxAutomationPeer.cs
- ChangeConflicts.cs
- UrlRoutingHandler.cs
- ControlBindingsCollection.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- CheckBox.cs
- SqlConnectionString.cs
- ApplicationFileParser.cs
- TextBoxRenderer.cs
- RadioButton.cs
- SourceSwitch.cs
- ColumnResult.cs
- RegisteredDisposeScript.cs
- OutputCache.cs
- cookie.cs
- cookiecontainer.cs
- TdsParserHelperClasses.cs
- PathParser.cs
- UpWmlMobileTextWriter.cs
- PreProcessInputEventArgs.cs
- FrameworkElementAutomationPeer.cs
- SelectionHighlightInfo.cs
- Itemizer.cs
- WindowsGraphicsCacheManager.cs
- MetafileHeader.cs
- TextRangeEditTables.cs
- HwndSourceParameters.cs
- WebEventTraceProvider.cs
- UniqueEventHelper.cs
- _HeaderInfo.cs
- ScrollItemPattern.cs
- Renderer.cs
- BinaryObjectInfo.cs
- InputLanguageManager.cs
- ResourceDefaultValueAttribute.cs
- TextBoxRenderer.cs
- ObjectDataSourceMethodEventArgs.cs
- LinqDataSourceUpdateEventArgs.cs
- InputProcessorProfiles.cs
- TextCharacters.cs
- FrameSecurityDescriptor.cs
- KnownBoxes.cs
- TCEAdapterGenerator.cs
- SmtpNtlmAuthenticationModule.cs
- CFStream.cs
- DetailsViewInsertedEventArgs.cs
- XmlCompatibilityReader.cs
- NativeActivityContext.cs
- BufferedStream.cs
- CompiledQueryCacheEntry.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- DataServiceHost.cs
- ProfileSection.cs
- CustomValidator.cs
- IntSecurity.cs
- GridViewSelectEventArgs.cs
- IProducerConsumerCollection.cs