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
- Scene3D.cs
- QuotedPairReader.cs
- ErrorRuntimeConfig.cs
- PermissionRequestEvidence.cs
- iisPickupDirectory.cs
- DateTimeOffset.cs
- JapaneseLunisolarCalendar.cs
- ThrowHelper.cs
- TextHidden.cs
- RegexInterpreter.cs
- DataGridViewAdvancedBorderStyle.cs
- HttpClientCertificate.cs
- ComponentChangedEvent.cs
- ProjectedSlot.cs
- PaginationProgressEventArgs.cs
- XmlSchemas.cs
- TextAnchor.cs
- FixedSOMPageElement.cs
- StateMachineSubscriptionManager.cs
- QueryOperator.cs
- Assign.cs
- DataServiceClientException.cs
- AddInPipelineAttributes.cs
- InstancePersistenceException.cs
- VariableElement.cs
- ListBoxAutomationPeer.cs
- TargetException.cs
- CalendarDesigner.cs
- HttpVersion.cs
- SafeFileMappingHandle.cs
- FunctionNode.cs
- DrawingContextFlattener.cs
- Stroke2.cs
- MatrixStack.cs
- CustomError.cs
- XmlSchemaCollection.cs
- ConnectionPointCookie.cs
- GenericPrincipal.cs
- ClassValidator.cs
- ZipArchive.cs
- CachedFontFamily.cs
- EmptyEnumerable.cs
- CultureTable.cs
- ReflectionTypeLoadException.cs
- SoapServerMessage.cs
- OleDbException.cs
- ControlAdapter.cs
- ServiceOperationListItemList.cs
- InputBinder.cs
- XmlSignatureManifest.cs
- EventRecordWrittenEventArgs.cs
- Int32Rect.cs
- SHA256Managed.cs
- XmlAttributeCollection.cs
- PageAsyncTaskManager.cs
- SecuritySessionSecurityTokenProvider.cs
- XsdDataContractExporter.cs
- DbConnectionOptions.cs
- CommandConverter.cs
- FrameworkContentElement.cs
- webeventbuffer.cs
- SingleKeyFrameCollection.cs
- CompModSwitches.cs
- AncillaryOps.cs
- RowToParametersTransformer.cs
- PrimitiveDataContract.cs
- DiscoveryClientRequestChannel.cs
- IgnoreSectionHandler.cs
- GroupDescription.cs
- DataGridPageChangedEventArgs.cs
- ConfigurationValue.cs
- FlowLayout.cs
- HotSpotCollection.cs
- PaginationProgressEventArgs.cs
- KnownBoxes.cs
- Path.cs
- SecurityKeyUsage.cs
- Operand.cs
- EventMappingSettingsCollection.cs
- ToolStripDropDownButton.cs
- HandoffBehavior.cs
- ModelProperty.cs
- CommonGetThemePartSize.cs
- CompilationUnit.cs
- ControlFilterExpression.cs
- Win32.cs
- WeakReferenceKey.cs
- BamlRecordHelper.cs
- MessageHeaderAttribute.cs
- LocalizeDesigner.cs
- AbstractExpressions.cs
- OleDbPermission.cs
- MissingFieldException.cs
- SocketPermission.cs
- Int32Converter.cs
- MenuAdapter.cs
- SectionInformation.cs
- PageAsyncTask.cs
- TerminateDesigner.cs
- CallbackValidator.cs