Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / DuplicateDetector.cs / 1305376 / DuplicateDetector.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Runtime { using System.Collections.Generic; class DuplicateDetectorwhere T : class { LinkedList fifoList; Dictionary > items; int capacity; object thisLock; public DuplicateDetector(int capacity) { Fx.Assert(capacity >= 0, "The capacity parameter must be a positive value."); this.capacity = capacity; this.items = new Dictionary >(); this.fifoList = new LinkedList (); this.thisLock = new object(); } public bool AddIfNotDuplicate(T value) { Fx.Assert(value != null, "The value must be non null."); bool success = false; lock (this.thisLock) { if (!this.items.ContainsKey(value)) { Add(value); success = true; } } return success; } void Add(T value) { Fx.Assert(this.items.Count == this.fifoList.Count, "The items and fifoList must be synchronized."); if (this.items.Count == this.capacity) { LinkedListNode node = this.fifoList.Last; this.items.Remove(node.Value); this.fifoList.Remove(node); } this.items.Add(value, this.fifoList.AddFirst(value)); } public bool Remove(T value) { Fx.Assert(value != null, "The value must be non null."); bool success = false; LinkedListNode node; lock (this.thisLock) { if (this.items.TryGetValue(value, out node)) { this.items.Remove(value); this.fifoList.Remove(node); success = true; } } return success; } public void Clear() { lock (this.thisLock) { this.fifoList.Clear(); this.items.Clear(); } } } } // 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
- EventHandlersStore.cs
- IncrementalReadDecoders.cs
- WinInetCache.cs
- TripleDES.cs
- DataControlField.cs
- SchemeSettingElement.cs
- FrameworkElement.cs
- EntityCommandDefinition.cs
- ThicknessConverter.cs
- FixedDocument.cs
- MsmqBindingMonitor.cs
- RowUpdatingEventArgs.cs
- Camera.cs
- COM2Enum.cs
- ChtmlPageAdapter.cs
- DataGridCellItemAutomationPeer.cs
- DelimitedListTraceListener.cs
- NullableDoubleAverageAggregationOperator.cs
- CachedRequestParams.cs
- ImpersonationContext.cs
- AssemblyBuilderData.cs
- ThreadStateException.cs
- LinqExpressionNormalizer.cs
- Parameter.cs
- GridViewEditEventArgs.cs
- CheckBox.cs
- ConstructorBuilder.cs
- IdentitySection.cs
- FakeModelPropertyImpl.cs
- AttachmentService.cs
- PropertyRef.cs
- SimpleColumnProvider.cs
- SetStateDesigner.cs
- DataRelationPropertyDescriptor.cs
- UIElement3DAutomationPeer.cs
- COM2ExtendedTypeConverter.cs
- NGCSerializationManager.cs
- NullableDecimalAverageAggregationOperator.cs
- EncoderNLS.cs
- clipboard.cs
- BasicViewGenerator.cs
- Rect3D.cs
- SectionInformation.cs
- VariableQuery.cs
- ListViewEditEventArgs.cs
- XmlChildEnumerator.cs
- TargetFrameworkUtil.cs
- DbParameterCollectionHelper.cs
- Baml2006KeyRecord.cs
- VideoDrawing.cs
- InputLanguageEventArgs.cs
- Rule.cs
- ToolStripContentPanelRenderEventArgs.cs
- PageThemeCodeDomTreeGenerator.cs
- FtpCachePolicyElement.cs
- Win32Exception.cs
- TextElementEnumerator.cs
- RangeBase.cs
- XmlSchemaObject.cs
- InlineObject.cs
- XhtmlConformanceSection.cs
- ParseNumbers.cs
- Permission.cs
- DataGridViewCellCancelEventArgs.cs
- XmlAnyElementAttribute.cs
- ObjectSecurity.cs
- LoggedException.cs
- baseshape.cs
- TextTreeInsertUndoUnit.cs
- DescendantQuery.cs
- NotImplementedException.cs
- PrtTicket_Base.cs
- ScriptBehaviorDescriptor.cs
- ProfilePropertySettings.cs
- ScriptingJsonSerializationSection.cs
- FixedTextSelectionProcessor.cs
- DelayedRegex.cs
- CodeDomSerializationProvider.cs
- ToolStripPanelRenderEventArgs.cs
- WorkflowServiceAttributes.cs
- UnitySerializationHolder.cs
- TimeSpanConverter.cs
- WebBrowser.cs
- FormsAuthenticationCredentials.cs
- Helper.cs
- DataServiceQueryProvider.cs
- FixedSOMTextRun.cs
- InstanceHandleConflictException.cs
- PeerObject.cs
- StaticContext.cs
- GridView.cs
- MultilineStringConverter.cs
- FormatConvertedBitmap.cs
- XmlKeywords.cs
- ObjectDataSourceFilteringEventArgs.cs
- EUCJPEncoding.cs
- ConfigurationStrings.cs
- TrimSurroundingWhitespaceAttribute.cs
- ObjectDataSourceStatusEventArgs.cs
- RootBuilder.cs