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
- Queue.cs
- WindowsImpersonationContext.cs
- SwitchElementsCollection.cs
- cookieexception.cs
- HandledMouseEvent.cs
- ExpressionBuilderCollection.cs
- Renderer.cs
- UrlRoutingModule.cs
- ListViewDeletedEventArgs.cs
- ForwardPositionQuery.cs
- ListControl.cs
- ProxyWebPart.cs
- XmlSchemaAppInfo.cs
- HttpDigestClientElement.cs
- ClientSettingsSection.cs
- EntityCommand.cs
- QueryException.cs
- WindowsGraphics2.cs
- QueryInterceptorAttribute.cs
- CellQuery.cs
- SiteMapHierarchicalDataSourceView.cs
- FormsAuthenticationConfiguration.cs
- EncryptedPackage.cs
- DebugView.cs
- MetadataArtifactLoaderCompositeResource.cs
- IgnoreFileBuildProvider.cs
- FilterEventArgs.cs
- _KerberosClient.cs
- TypeBuilderInstantiation.cs
- CacheMemory.cs
- SecurityKeyUsage.cs
- GenericPrincipal.cs
- MethodImplAttribute.cs
- WebPartConnectionCollection.cs
- PersonalizationEntry.cs
- EtwTrackingBehavior.cs
- HttpCacheVary.cs
- ObjectSelectorEditor.cs
- ToolStripContextMenu.cs
- ResourceExpressionBuilder.cs
- translator.cs
- RangeValidator.cs
- ByteStorage.cs
- CopyCodeAction.cs
- MLangCodePageEncoding.cs
- HttpResponse.cs
- ZipIOLocalFileDataDescriptor.cs
- InstancePersistenceCommandException.cs
- mda.cs
- TextLineResult.cs
- BinaryConverter.cs
- Msec.cs
- CacheChildrenQuery.cs
- Knowncolors.cs
- CompilationRelaxations.cs
- XmlValidatingReaderImpl.cs
- InputLangChangeRequestEvent.cs
- RefreshEventArgs.cs
- ListQueryResults.cs
- Cursor.cs
- RangeBase.cs
- Lease.cs
- DiscoveryEndpointValidator.cs
- RuntimeArgumentHandle.cs
- PerformanceCounterNameAttribute.cs
- MarkupExtensionSerializer.cs
- MatrixValueSerializer.cs
- ISAPIWorkerRequest.cs
- TextTreeObjectNode.cs
- GroupAggregateExpr.cs
- OrderingInfo.cs
- GlobalizationSection.cs
- DataGridState.cs
- WarningException.cs
- AddInAdapter.cs
- FileDialogCustomPlace.cs
- PersistencePipeline.cs
- GeneralTransform2DTo3D.cs
- ConnectionPoint.cs
- ListViewSelectEventArgs.cs
- SettingsPropertyCollection.cs
- SimpleWebHandlerParser.cs
- KerberosRequestorSecurityTokenAuthenticator.cs
- DataControlFieldCell.cs
- SignatureHelper.cs
- Tokenizer.cs
- StatusStrip.cs
- StringResourceManager.cs
- LockCookie.cs
- AsymmetricSignatureFormatter.cs
- SQLDecimal.cs
- ChangeTracker.cs
- HttpServerVarsCollection.cs
- EventLogPropertySelector.cs
- ScriptControlDescriptor.cs
- StubHelpers.cs
- XsltInput.cs
- TreeView.cs
- ZoneMembershipCondition.cs
- MsmqChannelListenerBase.cs