Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Collections / Generic / HashSetEqualityComparer.cs / 1305376 / HashSetEqualityComparer.cs
using System; using System.Collections; using System.Collections.Generic; namespace System.Collections.Generic { ////// Equality comparer for hashsets of hashsets /// ///[Serializable()] internal class HashSetEqualityComparer : IEqualityComparer > { private IEqualityComparer m_comparer; public HashSetEqualityComparer() { m_comparer = EqualityComparer .Default; } public HashSetEqualityComparer(IEqualityComparer comparer) { if (comparer == null) { m_comparer = EqualityComparer .Default; } else { m_comparer = comparer; } } // using m_comparer to keep equals properties in tact; don't want to choose one of the comparers public bool Equals(HashSet x, HashSet y) { return HashSet .HashSetEquals(x, y, m_comparer); } public int GetHashCode(HashSet obj) { int hashCode = 0; if (obj != null) { foreach (T t in obj) { hashCode = hashCode ^ (m_comparer.GetHashCode(t) & 0x7FFFFFFF); } } // else returns hashcode of 0 for null hashsets return hashCode; } // Equals method for the comparer itself. public override bool Equals(Object obj){ HashSetEqualityComparer comparer = obj as HashSetEqualityComparer ; if (comparer == null) { return false; } return (this.m_comparer == comparer.m_comparer); } public override int GetHashCode() { return m_comparer.GetHashCode(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections; using System.Collections.Generic; namespace System.Collections.Generic { /// /// Equality comparer for hashsets of hashsets /// ///[Serializable()] internal class HashSetEqualityComparer : IEqualityComparer > { private IEqualityComparer m_comparer; public HashSetEqualityComparer() { m_comparer = EqualityComparer .Default; } public HashSetEqualityComparer(IEqualityComparer comparer) { if (comparer == null) { m_comparer = EqualityComparer .Default; } else { m_comparer = comparer; } } // using m_comparer to keep equals properties in tact; don't want to choose one of the comparers public bool Equals(HashSet x, HashSet y) { return HashSet .HashSetEquals(x, y, m_comparer); } public int GetHashCode(HashSet obj) { int hashCode = 0; if (obj != null) { foreach (T t in obj) { hashCode = hashCode ^ (m_comparer.GetHashCode(t) & 0x7FFFFFFF); } } // else returns hashcode of 0 for null hashsets return hashCode; } // Equals method for the comparer itself. public override bool Equals(Object obj){ HashSetEqualityComparer comparer = obj as HashSetEqualityComparer ; if (comparer == null) { return false; } return (this.m_comparer == comparer.m_comparer); } public override int GetHashCode() { return m_comparer.GetHashCode(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HelpKeywordAttribute.cs
- HttpModulesInstallComponent.cs
- TreeNodeEventArgs.cs
- CaseInsensitiveOrdinalStringComparer.cs
- OAVariantLib.cs
- PrimitiveType.cs
- SctClaimSerializer.cs
- StylusPlugin.cs
- SpecularMaterial.cs
- BasicHttpMessageSecurityElement.cs
- BooleanExpr.cs
- TaiwanLunisolarCalendar.cs
- TypedReference.cs
- SmiEventSink_DeferedProcessing.cs
- FieldAccessException.cs
- OleDbStruct.cs
- MessageFormatterConverter.cs
- X509Utils.cs
- XmlAnyAttributeAttribute.cs
- LinearGradientBrush.cs
- MachineKeySection.cs
- Single.cs
- SHA512.cs
- TemplatePartAttribute.cs
- UDPClient.cs
- RoleManagerSection.cs
- COM2IDispatchConverter.cs
- ZoneLinkButton.cs
- StateDesigner.cs
- XmlIncludeAttribute.cs
- ErrorWrapper.cs
- ObjectStateEntry.cs
- SoapAttributes.cs
- MdImport.cs
- GridLengthConverter.cs
- PcmConverter.cs
- WindowsIPAddress.cs
- LineProperties.cs
- BasicHttpSecurity.cs
- WebScriptEnablingElement.cs
- TextElementEnumerator.cs
- ListView.cs
- SecurityTokenAuthenticator.cs
- ExceptionHelpers.cs
- EventWaitHandleSecurity.cs
- InterleavedZipPartStream.cs
- BindingGraph.cs
- GridViewRowCollection.cs
- PhysicalAddress.cs
- EdmItemCollection.cs
- MultiByteCodec.cs
- AssertSection.cs
- Connection.cs
- DataGridViewElement.cs
- MessageDesigner.cs
- TextEditorSpelling.cs
- TreeNodeCollection.cs
- FontStretchConverter.cs
- RuleValidation.cs
- XmlNotation.cs
- DetailsViewUpdateEventArgs.cs
- DataMisalignedException.cs
- PeerNameResolver.cs
- CompilerResults.cs
- BrowserCapabilitiesFactory.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- DataTableTypeConverter.cs
- TextEditorLists.cs
- CompoundFileStreamReference.cs
- CopyOfAction.cs
- RC2.cs
- EntityParameterCollection.cs
- AddDataControlFieldDialog.cs
- XmlSchemaSet.cs
- X509Chain.cs
- ResourceExpressionBuilder.cs
- COAUTHINFO.cs
- ListBoxItemAutomationPeer.cs
- XmlWellformedWriterHelpers.cs
- GlyphShapingProperties.cs
- EntitySetDataBindingList.cs
- InplaceBitmapMetadataWriter.cs
- XamlSerializerUtil.cs
- SettingsBase.cs
- Int64Storage.cs
- SessionStateModule.cs
- DataTablePropertyDescriptor.cs
- WindowsListView.cs
- XmlSchemaSimpleContentExtension.cs
- WindowsImpersonationContext.cs
- SafeRightsManagementEnvironmentHandle.cs
- BitmapEffectDrawingContextState.cs
- XmlAutoDetectWriter.cs
- SqlDataSourceSelectingEventArgs.cs
- SourceFileInfo.cs
- QueryExpr.cs
- OneOfElement.cs
- CompilationUnit.cs
- RayMeshGeometry3DHitTestResult.cs
- UnionExpr.cs