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
- ButtonBase.cs
- PropertyEmitter.cs
- LinearQuaternionKeyFrame.cs
- ItemChangedEventArgs.cs
- ConfigurationStrings.cs
- FileCodeGroup.cs
- XmlArrayItemAttribute.cs
- InternalPermissions.cs
- ValidationErrorInfo.cs
- Variant.cs
- RankException.cs
- DataTemplateKey.cs
- DataGridViewComboBoxEditingControl.cs
- ADRoleFactory.cs
- BindingObserver.cs
- FunctionDetailsReader.cs
- RequiredFieldValidator.cs
- TextSpan.cs
- CompositeScriptReference.cs
- Helper.cs
- DataPointer.cs
- Preprocessor.cs
- EncoderFallback.cs
- RenamedEventArgs.cs
- GAC.cs
- GACMembershipCondition.cs
- OpacityConverter.cs
- QueryRewriter.cs
- Visual.cs
- SecureUICommand.cs
- DbConnectionClosed.cs
- RelOps.cs
- SiteMembershipCondition.cs
- DataGridViewCellValidatingEventArgs.cs
- StateMachineSubscription.cs
- DefaultTextStore.cs
- AuthorizationRuleCollection.cs
- _Events.cs
- IteratorFilter.cs
- KeyTimeConverter.cs
- SqlDataSourceFilteringEventArgs.cs
- VectorKeyFrameCollection.cs
- TraceHandler.cs
- UnmanagedHandle.cs
- GridViewDeleteEventArgs.cs
- ImageClickEventArgs.cs
- StringInfo.cs
- AlignmentYValidation.cs
- LoginView.cs
- ObjectDataSourceStatusEventArgs.cs
- Roles.cs
- GenericAuthenticationEventArgs.cs
- _ServiceNameStore.cs
- DefaultParameterValueAttribute.cs
- Policy.cs
- ControlIdConverter.cs
- WindowsImpersonationContext.cs
- RequiredFieldValidator.cs
- WmlFormAdapter.cs
- ObjectConverter.cs
- EventLogPermissionHolder.cs
- DataRowChangeEvent.cs
- BmpBitmapDecoder.cs
- RectangleHotSpot.cs
- SqlConnection.cs
- GuidelineCollection.cs
- ProcessStartInfo.cs
- RewritingSimplifier.cs
- WebZone.cs
- SapiInterop.cs
- ColorPalette.cs
- ChtmlCalendarAdapter.cs
- DataServiceResponse.cs
- ProfileSection.cs
- CompiledIdentityConstraint.cs
- ResourceReader.cs
- ProfileManager.cs
- DataSet.cs
- BlurEffect.cs
- Rect3D.cs
- FloatUtil.cs
- CompositeKey.cs
- TargetInvocationException.cs
- SimpleBitVector32.cs
- EntityContainerEmitter.cs
- ShapingEngine.cs
- TextDecorationLocationValidation.cs
- HandleCollector.cs
- ThreadStartException.cs
- DataComponentNameHandler.cs
- XmlDataDocument.cs
- PersistenceTypeAttribute.cs
- SpeechAudioFormatInfo.cs
- Thread.cs
- ServicesUtilities.cs
- TypeDescriptor.cs
- TargetParameterCountException.cs
- ObjectTag.cs
- ContentPosition.cs
- OciLobLocator.cs