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
- FilteredXmlReader.cs
- InheritedPropertyChangedEventArgs.cs
- ProfileInfo.cs
- ReflectionUtil.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- Reference.cs
- LongValidator.cs
- VectorCollection.cs
- DbModificationClause.cs
- EntityExpressionVisitor.cs
- DataGridViewBindingCompleteEventArgs.cs
- MSAAWinEventWrap.cs
- TemplateBamlRecordReader.cs
- CharEntityEncoderFallback.cs
- FocusManager.cs
- CodeDirectoryCompiler.cs
- DateTimeFormatInfo.cs
- GeneralTransform.cs
- FixedPageStructure.cs
- TextTreeRootNode.cs
- UTF8Encoding.cs
- WeakEventManager.cs
- DiscoveryClientChannelFactory.cs
- PrintControllerWithStatusDialog.cs
- ServiceModelTimeSpanValidator.cs
- RequestQueue.cs
- HttpResponse.cs
- Axis.cs
- TextDecorationCollectionConverter.cs
- _CookieModule.cs
- Literal.cs
- CaseInsensitiveComparer.cs
- StyleHelper.cs
- RotateTransform3D.cs
- XPathQueryGenerator.cs
- OracleLob.cs
- ListSortDescription.cs
- AsyncPostBackErrorEventArgs.cs
- BooleanConverter.cs
- _NegoState.cs
- DSGeneratorProblem.cs
- AsymmetricKeyExchangeDeformatter.cs
- IndependentAnimationStorage.cs
- WorkflowMessageEventHandler.cs
- StandardBindingReliableSessionElement.cs
- ReadOnlyAttribute.cs
- IsolatedStorageFileStream.cs
- InternalRelationshipCollection.cs
- ListViewPagedDataSource.cs
- ReadOnlyPropertyMetadata.cs
- Rect3DConverter.cs
- DataGridViewRowsRemovedEventArgs.cs
- IUnknownConstantAttribute.cs
- XmlDataCollection.cs
- RightNameExpirationInfoPair.cs
- SMSvcHost.cs
- ApplicationInfo.cs
- SelectingProviderEventArgs.cs
- SiteMapNode.cs
- OLEDB_Enum.cs
- MemberAssignment.cs
- RemoteWebConfigurationHost.cs
- MenuItemCollection.cs
- TrustManager.cs
- RegexGroup.cs
- PrtTicket_Editor.cs
- ZipIOExtraFieldElement.cs
- __Error.cs
- DbReferenceCollection.cs
- XmlSchemaCollection.cs
- ResourceLoader.cs
- ExpressionBuilder.cs
- ClientConfigPaths.cs
- _LocalDataStore.cs
- StorageModelBuildProvider.cs
- EdmError.cs
- OneOfConst.cs
- HuffCodec.cs
- ProviderCollection.cs
- GenericIdentity.cs
- ResourcesChangeInfo.cs
- ZipArchive.cs
- RepeaterItem.cs
- WeakReference.cs
- GrammarBuilderBase.cs
- HitTestResult.cs
- OleDbParameter.cs
- IPeerNeighbor.cs
- JavascriptCallbackResponseProperty.cs
- TextParentUndoUnit.cs
- InternalConfigConfigurationFactory.cs
- DataGridViewTopRowAccessibleObject.cs
- ApplicationGesture.cs
- Message.cs
- SelectionItemProviderWrapper.cs
- ButtonBaseAdapter.cs
- Parser.cs
- messageonlyhwndwrapper.cs
- BehaviorEditorPart.cs
- SizeConverter.cs