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
- CustomAttributeBuilder.cs
- PropertyEntry.cs
- SymDocumentType.cs
- HttpPostLocalhostServerProtocol.cs
- TransactionTable.cs
- TreeWalker.cs
- TextEditorDragDrop.cs
- AutoCompleteStringCollection.cs
- GorillaCodec.cs
- mediaeventshelper.cs
- ColumnResizeAdorner.cs
- WizardStepBase.cs
- UTF32Encoding.cs
- NamedObject.cs
- CharStorage.cs
- ObjectStateManagerMetadata.cs
- PropertyGridCommands.cs
- TimeIntervalCollection.cs
- HotSpotCollection.cs
- DataGridViewHitTestInfo.cs
- MiniMapControl.xaml.cs
- Span.cs
- SByteConverter.cs
- HttpModulesSection.cs
- RC2.cs
- PhysicalAddress.cs
- UnsafeNativeMethods.cs
- SecUtil.cs
- BinaryQueryOperator.cs
- SafeBitVector32.cs
- EpmContentDeSerializerBase.cs
- TextMetrics.cs
- NegotiateStream.cs
- RegisteredHiddenField.cs
- Repeater.cs
- ColorTranslator.cs
- EventProviderBase.cs
- DBDataPermissionAttribute.cs
- EmptyEnumerator.cs
- OracleDataReader.cs
- _SecureChannel.cs
- GlyphInfoList.cs
- CodeBinaryOperatorExpression.cs
- ContentElementAutomationPeer.cs
- TriggerCollection.cs
- DependencyPropertyDescriptor.cs
- ProfilePropertyMetadata.cs
- SqlWriter.cs
- _UriTypeConverter.cs
- AuthenticationConfig.cs
- FlowDocumentReader.cs
- DbCommandTree.cs
- GrammarBuilder.cs
- HostedTransportConfigurationBase.cs
- ComponentEditorPage.cs
- ResourceReferenceKeyNotFoundException.cs
- FrameworkElementFactory.cs
- SemanticAnalyzer.cs
- DirectoryInfo.cs
- IfJoinedCondition.cs
- XPathNode.cs
- SupportingTokenBindingElement.cs
- _NegoState.cs
- NetStream.cs
- TemplateContent.cs
- ServicePerformanceCounters.cs
- BreakSafeBase.cs
- UInt16.cs
- Atom10FormatterFactory.cs
- VarRefManager.cs
- PrintPreviewGraphics.cs
- LinqDataSourceHelper.cs
- TabControl.cs
- OrderToken.cs
- ChildChangedEventArgs.cs
- Themes.cs
- StringValueSerializer.cs
- PathFigureCollectionConverter.cs
- DesignerAttributeInfo.cs
- PropertyValueChangedEvent.cs
- JsonSerializer.cs
- DataObjectMethodAttribute.cs
- FigureParaClient.cs
- SrgsRule.cs
- ListControl.cs
- FontNameEditor.cs
- ConfigXmlComment.cs
- WriteFileContext.cs
- ValueSerializer.cs
- CodeSubDirectoriesCollection.cs
- ErrorWebPart.cs
- HttpConfigurationSystem.cs
- _ConnectStream.cs
- HtmlEncodedRawTextWriter.cs
- HttpListenerPrefixCollection.cs
- AssociativeAggregationOperator.cs
- PropertyEntry.cs
- Italic.cs
- DataGridViewCellEventArgs.cs
- DrawingVisualDrawingContext.cs