Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ObjectItemLoadingSessionData.cs
- RegistryKey.cs
- CodeDomSerializationProvider.cs
- DataGridViewCellParsingEventArgs.cs
- ConnectionStringSettingsCollection.cs
- BrowserTree.cs
- OAVariantLib.cs
- TreeViewImageKeyConverter.cs
- WindowsSysHeader.cs
- NameValuePair.cs
- PropertyGridEditorPart.cs
- WpfXamlMember.cs
- Unit.cs
- TextRange.cs
- PropertyCollection.cs
- SqlDataSourceEnumerator.cs
- Line.cs
- StyleCollection.cs
- SharedHttpTransportManager.cs
- DispatchChannelSink.cs
- TaiwanCalendar.cs
- SamlAuthenticationStatement.cs
- AutoCompleteStringCollection.cs
- StringTraceRecord.cs
- MarkupObject.cs
- BitmapEffectInputData.cs
- TransformDescriptor.cs
- DataGridItemCollection.cs
- Identity.cs
- _OverlappedAsyncResult.cs
- FindSimilarActivitiesVerb.cs
- ArgIterator.cs
- StrongNameMembershipCondition.cs
- PolyQuadraticBezierSegment.cs
- SafeEventLogReadHandle.cs
- NopReturnReader.cs
- BasicCellRelation.cs
- AppliedDeviceFiltersDialog.cs
- Win32KeyboardDevice.cs
- WebProxyScriptElement.cs
- LeaseManager.cs
- SchemaTableColumn.cs
- CodeStatementCollection.cs
- TransactionManager.cs
- NativeMethods.cs
- GenericParameterDataContract.cs
- unsafenativemethodstextservices.cs
- QueueAccessMode.cs
- RelatedCurrencyManager.cs
- NullableDoubleSumAggregationOperator.cs
- RecognizerStateChangedEventArgs.cs
- VersionedStreamOwner.cs
- TextMetrics.cs
- SchemaInfo.cs
- WindowsEditBox.cs
- Propagator.Evaluator.cs
- ProxyWebPartManager.cs
- FixedLineResult.cs
- Int32AnimationBase.cs
- StylusTouchDevice.cs
- AccessDataSource.cs
- FloaterBaseParaClient.cs
- AssemblyName.cs
- RecordsAffectedEventArgs.cs
- RedirectionProxy.cs
- EmptyEnumerator.cs
- ConfigurationStrings.cs
- WindowsTooltip.cs
- UnsafeNetInfoNativeMethods.cs
- Command.cs
- CompareValidator.cs
- InteropAutomationProvider.cs
- OleStrCAMarshaler.cs
- ByteArrayHelperWithString.cs
- SpecularMaterial.cs
- XmlQualifiedNameTest.cs
- ButtonPopupAdapter.cs
- MarkedHighlightComponent.cs
- AttachedPropertyInfo.cs
- UpdateTracker.cs
- SQlBooleanStorage.cs
- Vector3DKeyFrameCollection.cs
- DesignerSerializationOptionsAttribute.cs
- VirtualPath.cs
- PhysicalFontFamily.cs
- XsdValidatingReader.cs
- Label.cs
- MgmtResManager.cs
- RuntimeConfigurationRecord.cs
- XPathSingletonIterator.cs
- DPTypeDescriptorContext.cs
- PreProcessInputEventArgs.cs
- ScriptReference.cs
- XmlMembersMapping.cs
- WebPartConnectVerb.cs
- DocumentEventArgs.cs
- PersistenceContext.cs
- SettingsSection.cs
- RuntimeArgumentHandle.cs
- ExpandSegment.cs