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
- DataBoundControlHelper.cs
- ThaiBuddhistCalendar.cs
- dataobject.cs
- MasterPageBuildProvider.cs
- TextLine.cs
- ListItemCollection.cs
- DataSourceGroupCollection.cs
- ReadOnlyDictionary.cs
- TreeNodeBindingDepthConverter.cs
- DecimalAnimation.cs
- StateDesigner.cs
- SQLSingle.cs
- XmlDesigner.cs
- MethodSet.cs
- WebSysDescriptionAttribute.cs
- SAPICategories.cs
- HtmlElement.cs
- GeneralTransform2DTo3D.cs
- TreeSet.cs
- _SSPIWrapper.cs
- DataTemplateKey.cs
- RpcCryptoContext.cs
- StylusPointPropertyInfoDefaults.cs
- BufferAllocator.cs
- WeakReferenceKey.cs
- XPathChildIterator.cs
- TripleDES.cs
- XmlTextReader.cs
- SqlDependency.cs
- Region.cs
- XmlAttributeCache.cs
- UTF7Encoding.cs
- CommandLibraryHelper.cs
- EncoderParameters.cs
- HandleCollector.cs
- XmlIncludeAttribute.cs
- AssemblyAttributes.cs
- Util.cs
- EntityDesignerBuildProvider.cs
- WebPartHeaderCloseVerb.cs
- DataControlFieldHeaderCell.cs
- OracleDataAdapter.cs
- XmlTextEncoder.cs
- Utils.cs
- TimeEnumHelper.cs
- RegistrationServices.cs
- CodeConditionStatement.cs
- DeferrableContent.cs
- BitSet.cs
- InkPresenterAutomationPeer.cs
- ObjectDataSourceEventArgs.cs
- BasicCellRelation.cs
- FilterQueryOptionExpression.cs
- Reference.cs
- DetailsViewPagerRow.cs
- LowerCaseStringConverter.cs
- BooleanToVisibilityConverter.cs
- QueryResultOp.cs
- RelativeSource.cs
- BitmapMetadata.cs
- AssemblyBuilder.cs
- XmlAnyAttributeAttribute.cs
- CellTreeNodeVisitors.cs
- Vector.cs
- CornerRadiusConverter.cs
- StreamInfo.cs
- XmlEntity.cs
- CurrentTimeZone.cs
- ObjectDataSourceChooseMethodsPanel.cs
- NativeActivityTransactionContext.cs
- EvidenceTypeDescriptor.cs
- CharAnimationBase.cs
- ProviderSettings.cs
- TypefaceMetricsCache.cs
- XamlTreeBuilder.cs
- DataGridItemCollection.cs
- XmlBuffer.cs
- ViewGenerator.cs
- PropertyGridDesigner.cs
- Errors.cs
- ResourcePart.cs
- MessageLoggingFilterTraceRecord.cs
- TypeConverter.cs
- SafeRightsManagementSessionHandle.cs
- ServiceTimeoutsElement.cs
- EntityDataSourceEntityTypeFilterConverter.cs
- entityreference_tresulttype.cs
- Authorization.cs
- RSAPKCS1SignatureFormatter.cs
- ManualResetEvent.cs
- ObservableCollection.cs
- Size3D.cs
- SoapObjectWriter.cs
- EntityDataSourceWrapperCollection.cs
- RelatedImageListAttribute.cs
- PnrpPeerResolverBindingElement.cs
- FloatMinMaxAggregationOperator.cs
- ErrorRuntimeConfig.cs
- ResourceManager.cs
- XPathNavigatorKeyComparer.cs