Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / Microsoft / Scripting / Compiler / KeyedQueue.cs / 1305376 / KeyedQueue.cs
/* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Collections.Generic; using System.Linq.Expressions; #if SILVERLIGHT using System.Core; #endif namespace System.Linq.Expressions.Compiler { ////// A simple dictionary of queues, keyed off a particular type /// This is useful for storing free lists of variables /// internal sealed class KeyedQueue{ private readonly Dictionary > _data; internal KeyedQueue() { _data = new Dictionary >(); } internal void Enqueue(K key, V value) { Queue queue; if (!_data.TryGetValue(key, out queue)) { _data.Add(key, queue = new Queue ()); } queue.Enqueue(value); } internal V Dequeue(K key) { Queue queue; if (!_data.TryGetValue(key, out queue)) { throw Error.QueueEmpty(); } V result = queue.Dequeue(); if (queue.Count == 0) { _data.Remove(key); } return result; } internal bool TryDequeue(K key, out V value) { Queue queue; if (_data.TryGetValue(key, out queue) && queue.Count > 0) { value = queue.Dequeue(); if (queue.Count == 0) { _data.Remove(key); } return true; } value = default(V); return false; } internal V Peek(K key) { Queue queue; if (!_data.TryGetValue(key, out queue)) { throw Error.QueueEmpty(); } return queue.Peek(); } internal int GetCount(K key) { Queue queue; if (!_data.TryGetValue(key, out queue)) { return 0; } return queue.Count; } internal void Clear() { _data.Clear(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Collections.Generic; using System.Linq.Expressions; #if SILVERLIGHT using System.Core; #endif namespace System.Linq.Expressions.Compiler { /// /// A simple dictionary of queues, keyed off a particular type /// This is useful for storing free lists of variables /// internal sealed class KeyedQueue{ private readonly Dictionary > _data; internal KeyedQueue() { _data = new Dictionary >(); } internal void Enqueue(K key, V value) { Queue queue; if (!_data.TryGetValue(key, out queue)) { _data.Add(key, queue = new Queue ()); } queue.Enqueue(value); } internal V Dequeue(K key) { Queue queue; if (!_data.TryGetValue(key, out queue)) { throw Error.QueueEmpty(); } V result = queue.Dequeue(); if (queue.Count == 0) { _data.Remove(key); } return result; } internal bool TryDequeue(K key, out V value) { Queue queue; if (_data.TryGetValue(key, out queue) && queue.Count > 0) { value = queue.Dequeue(); if (queue.Count == 0) { _data.Remove(key); } return true; } value = default(V); return false; } internal V Peek(K key) { Queue queue; if (!_data.TryGetValue(key, out queue)) { throw Error.QueueEmpty(); } return queue.Peek(); } internal int GetCount(K key) { Queue queue; if (!_data.TryGetValue(key, out queue)) { return 0; } return queue.Count; } internal void Clear() { _data.Clear(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RubberbandSelector.cs
- FontFamily.cs
- ArraySubsetEnumerator.cs
- ExpressionConverter.cs
- MailAddressParser.cs
- RelationshipDetailsRow.cs
- Bezier.cs
- NamespaceList.cs
- NumericUpDownAccelerationCollection.cs
- DebugView.cs
- SecondaryIndexDefinition.cs
- AdornedElementPlaceholder.cs
- ParenthesizePropertyNameAttribute.cs
- ProgressBarHighlightConverter.cs
- CqlParser.cs
- Peer.cs
- MultipleViewPattern.cs
- ChannelSettingsElement.cs
- FixedSOMContainer.cs
- LinqDataSourceContextEventArgs.cs
- SizeIndependentAnimationStorage.cs
- XmlSchemaValidationException.cs
- ApplicationTrust.cs
- Point4D.cs
- Facet.cs
- ReceiveReply.cs
- MessagePropertyVariants.cs
- prefixendpointaddressmessagefiltertable.cs
- prefixendpointaddressmessagefilter.cs
- EventPrivateKey.cs
- WindowsFormsHelpers.cs
- DataGridCellItemAutomationPeer.cs
- BaseAsyncResult.cs
- KeyConstraint.cs
- mediaeventargs.cs
- WebPartHelpVerb.cs
- InputBindingCollection.cs
- tooltip.cs
- NetMsmqBindingCollectionElement.cs
- ColorMatrix.cs
- StringComparer.cs
- SafeMILHandleMemoryPressure.cs
- InvalidFilterCriteriaException.cs
- Run.cs
- EncryptedData.cs
- VisualStateChangedEventArgs.cs
- ContentElement.cs
- TransportSecurityBindingElement.cs
- DbParameterCollectionHelper.cs
- PathParser.cs
- ResourceIDHelper.cs
- XmlDataProvider.cs
- UnsafeNativeMethods.cs
- DiscoveryClientChannelBase.cs
- XmlSchemaAnnotation.cs
- OneOfConst.cs
- DisplayClaim.cs
- SqlConnectionManager.cs
- DayRenderEvent.cs
- QueryExecutionOption.cs
- HandlerElementCollection.cs
- PromptBuilder.cs
- ValidatorUtils.cs
- PrintPreviewGraphics.cs
- KnowledgeBase.cs
- GridViewSelectEventArgs.cs
- TcpAppDomainProtocolHandler.cs
- DeferredBinaryDeserializerExtension.cs
- DurableServiceAttribute.cs
- EntityProviderFactory.cs
- Transform3D.cs
- DbMetaDataFactory.cs
- FixedFlowMap.cs
- MoveSizeWinEventHandler.cs
- ObjectRef.cs
- DocumentAutomationPeer.cs
- BrushMappingModeValidation.cs
- DataServiceRequestOfT.cs
- FlowLayout.cs
- AutomationPropertyInfo.cs
- NoClickablePointException.cs
- EnumerableRowCollection.cs
- ParallelRangeManager.cs
- BezierSegment.cs
- GroupBox.cs
- Events.cs
- MailMessage.cs
- TabItemAutomationPeer.cs
- DoubleAnimationClockResource.cs
- WebReferenceCollection.cs
- CircleHotSpot.cs
- URL.cs
- TextTreeTextNode.cs
- IUnknownConstantAttribute.cs
- DocumentsTrace.cs
- InputLanguageManager.cs
- ContentElementAutomationPeer.cs
- RemotingAttributes.cs
- PropertyGroupDescription.cs
- Normalization.cs