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
- Logging.cs
- ScriptBehaviorDescriptor.cs
- EncodingNLS.cs
- TCPListener.cs
- HttpDebugHandler.cs
- Empty.cs
- XmlSchemaNotation.cs
- TraceSwitch.cs
- XmlSchemaAppInfo.cs
- Binding.cs
- VisualStyleRenderer.cs
- DataSourceUtil.cs
- RoutedEventHandlerInfo.cs
- StaticExtensionConverter.cs
- Base64Stream.cs
- RenderDataDrawingContext.cs
- BackgroundWorker.cs
- WindowsGraphics.cs
- ValidateNames.cs
- SafeHandles.cs
- DataColumn.cs
- DataComponentGenerator.cs
- CqlParserHelpers.cs
- DesignerForm.cs
- GuidelineSet.cs
- ActivityDesignerAccessibleObject.cs
- ToolStripButton.cs
- ApplicationId.cs
- JapaneseCalendar.cs
- ResourceDictionary.cs
- RowCache.cs
- WebBrowserContainer.cs
- ContextProperty.cs
- AssemblyCache.cs
- ProtocolsSection.cs
- SqlTypeSystemProvider.cs
- SafeBitVector32.cs
- AppDomainManager.cs
- SessionStateItemCollection.cs
- AnnotationHighlightLayer.cs
- PriorityBindingExpression.cs
- HighContrastHelper.cs
- FtpWebResponse.cs
- HierarchicalDataSourceConverter.cs
- ControlValuePropertyAttribute.cs
- ExceptionValidationRule.cs
- CompilerGeneratedAttribute.cs
- WebPartEditorCancelVerb.cs
- SystemIcons.cs
- IdentifierService.cs
- XmlAttribute.cs
- XmlCharCheckingWriter.cs
- FixedTextContainer.cs
- DesignerVerb.cs
- CultureTableRecord.cs
- ResXFileRef.cs
- JoinQueryOperator.cs
- ColumnMap.cs
- Nullable.cs
- Overlapped.cs
- ConnectionStringsExpressionEditor.cs
- HyperLinkField.cs
- CodeMemberField.cs
- MergePropertyDescriptor.cs
- InkCanvasSelection.cs
- ItemCheckedEvent.cs
- ProfileProvider.cs
- UnconditionalPolicy.cs
- TimelineGroup.cs
- ThrowOnMultipleAssignment.cs
- Int64KeyFrameCollection.cs
- PackWebResponse.cs
- CLSCompliantAttribute.cs
- TimeZoneNotFoundException.cs
- ModelItemExtensions.cs
- ManipulationLogic.cs
- PeerNameRecordCollection.cs
- Module.cs
- RequestQueue.cs
- AppDomainUnloadedException.cs
- EditableTreeList.cs
- SimpleType.cs
- DbgCompiler.cs
- SingleSelectRootGridEntry.cs
- TypeConverterAttribute.cs
- SqlTrackingQuery.cs
- Subtract.cs
- webeventbuffer.cs
- WebServiceClientProxyGenerator.cs
- InvalidProgramException.cs
- SeekableReadStream.cs
- ProxyWebPart.cs
- PathSegmentCollection.cs
- Pkcs7Signer.cs
- OwnerDrawPropertyBag.cs
- TemplateBindingExtension.cs
- CheckBoxBaseAdapter.cs
- IfAction.cs
- OpacityConverter.cs
- ScriptControl.cs