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
- COM2EnumConverter.cs
- OdbcRowUpdatingEvent.cs
- VirtualizedContainerService.cs
- NativeWindow.cs
- SafeNativeMethods.cs
- FactoryGenerator.cs
- RecognitionResult.cs
- ServiceProviders.cs
- HttpSessionStateWrapper.cs
- ComNativeDescriptor.cs
- OdbcStatementHandle.cs
- JournalEntry.cs
- TypeDelegator.cs
- CodeRemoveEventStatement.cs
- DatagridviewDisplayedBandsData.cs
- HtmlControl.cs
- OutOfProcStateClientManager.cs
- UriSection.cs
- IndexingContentUnit.cs
- SymLanguageVendor.cs
- _TransmitFileOverlappedAsyncResult.cs
- XmlDataSourceView.cs
- TabControlAutomationPeer.cs
- ValidationHelper.cs
- ContextMenuStrip.cs
- HttpRuntimeSection.cs
- CombinedGeometry.cs
- AppDomainShutdownMonitor.cs
- Helpers.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- SchemaMapping.cs
- Line.cs
- FixUpCollection.cs
- XmlSchemaSequence.cs
- COM2Properties.cs
- ClientSideQueueItem.cs
- LinearKeyFrames.cs
- Button.cs
- GC.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- SqlDataAdapter.cs
- SystemTcpStatistics.cs
- AdapterUtil.cs
- PartitionedStreamMerger.cs
- ConfigXmlReader.cs
- DictionaryEntry.cs
- ElementUtil.cs
- SamlSubject.cs
- TraceUtils.cs
- PagedControl.cs
- LoadedOrUnloadedOperation.cs
- InternalRelationshipCollection.cs
- LicFileLicenseProvider.cs
- FrameworkContextData.cs
- WindowsListBox.cs
- GiveFeedbackEvent.cs
- AlternateView.cs
- MessageVersion.cs
- FormattedText.cs
- UpdatePanelTrigger.cs
- GAC.cs
- DetailsViewPageEventArgs.cs
- SqlDataSourceQueryConverter.cs
- StateFinalizationDesigner.cs
- Rect3DValueSerializer.cs
- OracleConnection.cs
- SynchronousSendBindingElement.cs
- SqlError.cs
- Point.cs
- NumericUpDownAcceleration.cs
- OleDbRowUpdatedEvent.cs
- ClientSettingsStore.cs
- MetabaseSettingsIis7.cs
- BufferBuilder.cs
- RC2CryptoServiceProvider.cs
- AttachmentCollection.cs
- CacheChildrenQuery.cs
- ChtmlPageAdapter.cs
- CodeGenerator.cs
- RegionIterator.cs
- RightsManagementInformation.cs
- FillBehavior.cs
- XmlWellformedWriter.cs
- COM2TypeInfoProcessor.cs
- GridItemPatternIdentifiers.cs
- SerializationException.cs
- ForwardPositionQuery.cs
- MatrixAnimationUsingPath.cs
- DataGridTablesFactory.cs
- CatalogZoneBase.cs
- FontUnitConverter.cs
- ObjectConverter.cs
- Pkcs7Signer.cs
- MenuBase.cs
- XPathNodeHelper.cs
- RoleServiceManager.cs
- SelfIssuedAuthRSACryptoProvider.cs
- ExtensionWindowHeader.cs
- EmbeddedObject.cs
- Annotation.cs