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
- SoapAttributeOverrides.cs
- ClockController.cs
- FontSizeConverter.cs
- ToolStripTextBox.cs
- ColorMatrix.cs
- ValidationErrorEventArgs.cs
- VSDExceptions.cs
- SessionIDManager.cs
- XmlFormatExtensionAttribute.cs
- SynchronizedInputHelper.cs
- ServiceChannelProxy.cs
- NotFiniteNumberException.cs
- XmlSchemaSimpleContent.cs
- KnownBoxes.cs
- LayoutEditorPart.cs
- MimePart.cs
- DataGridCellAutomationPeer.cs
- FormViewUpdatedEventArgs.cs
- AtlasWeb.Designer.cs
- ManagementEventArgs.cs
- TransactionTable.cs
- EventMappingSettings.cs
- DataObjectAttribute.cs
- Constraint.cs
- GlyphRunDrawing.cs
- WebPartsPersonalization.cs
- Point3D.cs
- ClientConfigPaths.cs
- UrlMappingsSection.cs
- Point3D.cs
- DBConcurrencyException.cs
- FileIOPermission.cs
- TypeElement.cs
- EventLogPermissionEntryCollection.cs
- ToolStripSeparatorRenderEventArgs.cs
- XmlAttributeCollection.cs
- DragCompletedEventArgs.cs
- PackageController.cs
- QuaternionRotation3D.cs
- EntityDataSourceReferenceGroup.cs
- ForEachAction.cs
- InputLanguageManager.cs
- OperationResponse.cs
- ToolStripItemCollection.cs
- DecoderNLS.cs
- GACMembershipCondition.cs
- InputEventArgs.cs
- Listbox.cs
- Rfc2898DeriveBytes.cs
- AssemblyFilter.cs
- SchemaConstraints.cs
- PolicyReader.cs
- LoginName.cs
- DataPagerFieldItem.cs
- DrawingImage.cs
- ConditionCollection.cs
- MappingModelBuildProvider.cs
- TextEndOfLine.cs
- ListSourceHelper.cs
- OdbcFactory.cs
- GridViewCellAutomationPeer.cs
- IncomingWebRequestContext.cs
- IdentityModelStringsVersion1.cs
- MetadataCollection.cs
- OrderPreservingPipeliningSpoolingTask.cs
- ToolboxItemAttribute.cs
- SR.cs
- StringReader.cs
- ClientEventManager.cs
- ColumnResizeAdorner.cs
- DependencyObjectType.cs
- DataBinding.cs
- ScriptReferenceEventArgs.cs
- AssertHelper.cs
- RepeatBehaviorConverter.cs
- DBCommand.cs
- ThreadStartException.cs
- PageAsyncTask.cs
- LabelInfo.cs
- SettingsProperty.cs
- UserControl.cs
- HttpProxyCredentialType.cs
- XmlParserContext.cs
- ManagedWndProcTracker.cs
- UnauthorizedAccessException.cs
- WindowsImpersonationContext.cs
- UnsafeNativeMethods.cs
- ContentHostHelper.cs
- XmlSchemaDocumentation.cs
- DefaultBindingPropertyAttribute.cs
- DbConnectionStringBuilder.cs
- ImageClickEventArgs.cs
- ResourceExpression.cs
- SmiSettersStream.cs
- TextParaClient.cs
- TextElementEnumerator.cs
- IndicCharClassifier.cs
- PrinterResolution.cs
- StringAnimationBase.cs
- TextTreeTextNode.cs