Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Misc / CompatibleIComparer.cs / 1 / CompatibleIComparer.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * This class is used to create hashcodes that are Everett Compatible. * * Copyright (c) 2004 Microsoft Corporation */ namespace System.Collections.Specialized { using Microsoft.Win32; using System.Collections; using System.Runtime.Serialization; using System.Globalization; internal class BackCompatibleStringComparer : IEqualityComparer { static internal IEqualityComparer Default = new BackCompatibleStringComparer(); internal BackCompatibleStringComparer() { } //This comes from VS# 434837 and is specifically written to get backcompat public static int GetHashCode(string obj) { unsafe { fixed (char* src = obj) { int hash = 5381; int c; char* szStr = src; while ((c = *szStr) != 0) { hash = ((hash << 5) + hash) ^ c; ++szStr; } return hash; } } } bool IEqualityComparer.Equals(Object a, Object b) { return Object.Equals(a, b); } public virtual int GetHashCode(Object o) { String obj = o as string; if (obj == null) { return o.GetHashCode(); } return BackCompatibleStringComparer.GetHashCode(obj); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * This class is used to create hashcodes that are Everett Compatible. * * Copyright (c) 2004 Microsoft Corporation */ namespace System.Collections.Specialized { using Microsoft.Win32; using System.Collections; using System.Runtime.Serialization; using System.Globalization; internal class BackCompatibleStringComparer : IEqualityComparer { static internal IEqualityComparer Default = new BackCompatibleStringComparer(); internal BackCompatibleStringComparer() { } //This comes from VS# 434837 and is specifically written to get backcompat public static int GetHashCode(string obj) { unsafe { fixed (char* src = obj) { int hash = 5381; int c; char* szStr = src; while ((c = *szStr) != 0) { hash = ((hash << 5) + hash) ^ c; ++szStr; } return hash; } } } bool IEqualityComparer.Equals(Object a, Object b) { return Object.Equals(a, b); } public virtual int GetHashCode(Object o) { String obj = o as string; if (obj == null) { return o.GetHashCode(); } return BackCompatibleStringComparer.GetHashCode(obj); } } } // 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
- CharacterMetricsDictionary.cs
- EastAsianLunisolarCalendar.cs
- CategoryNameCollection.cs
- SimpleHandlerFactory.cs
- URLEditor.cs
- TextParagraphCache.cs
- TextChangedEventArgs.cs
- URLIdentityPermission.cs
- Region.cs
- ClassicBorderDecorator.cs
- CodeTypeDelegate.cs
- SoapAttributeAttribute.cs
- HWStack.cs
- SourceFileBuildProvider.cs
- SqlMethodAttribute.cs
- ConnectionInterfaceCollection.cs
- SeekableMessageNavigator.cs
- PropertySegmentSerializationProvider.cs
- XPathQueryGenerator.cs
- StylusOverProperty.cs
- UncommonField.cs
- BypassElement.cs
- GcHandle.cs
- UseAttributeSetsAction.cs
- DirtyTextRange.cs
- DataSourceCollectionBase.cs
- Scripts.cs
- MemberCollection.cs
- FieldDescriptor.cs
- DynamicScriptObject.cs
- SimpleBitVector32.cs
- DataConnectionHelper.cs
- Base64Decoder.cs
- DetailsViewDeletedEventArgs.cs
- SRef.cs
- WindowsFormsSectionHandler.cs
- EventDescriptor.cs
- ETagAttribute.cs
- PeerReferralPolicy.cs
- DataBoundControl.cs
- HttpWebResponse.cs
- _ProxyChain.cs
- Bits.cs
- PropertyGridCommands.cs
- HttpConfigurationSystem.cs
- ToolboxCategoryItems.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- SQLUtility.cs
- Gdiplus.cs
- TokenBasedSetEnumerator.cs
- Int64AnimationBase.cs
- TransactionBridgeSection.cs
- ClientSession.cs
- DragAssistanceManager.cs
- FactoryMaker.cs
- HttpWebRequestElement.cs
- SendMailErrorEventArgs.cs
- ActivationArguments.cs
- RelationshipSet.cs
- MetadataPropertyvalue.cs
- WebPartVerbCollection.cs
- _ListenerAsyncResult.cs
- VisualCollection.cs
- MessageFilter.cs
- X509Certificate.cs
- BaseCollection.cs
- bidPrivateBase.cs
- latinshape.cs
- ExpandCollapsePattern.cs
- VarRefManager.cs
- UnaryExpression.cs
- SimpleApplicationHost.cs
- MsmqIntegrationMessageProperty.cs
- ScriptingProfileServiceSection.cs
- DataGridTextColumn.cs
- LayoutExceptionEventArgs.cs
- XmlEnumAttribute.cs
- ConfigurationErrorsException.cs
- PropertyMapper.cs
- TypeUtil.cs
- ResourceAssociationSetEnd.cs
- ValidationError.cs
- BindingValueChangedEventArgs.cs
- RegexGroupCollection.cs
- SlipBehavior.cs
- SelectionChangedEventArgs.cs
- EdmProperty.cs
- ToolStripManager.cs
- SetterBaseCollection.cs
- Cursors.cs
- XmlCodeExporter.cs
- TemplatePagerField.cs
- XmlnsPrefixAttribute.cs
- BStrWrapper.cs
- RemoteWebConfigurationHostServer.cs
- QilChoice.cs
- CopyOnWriteList.cs
- DesignerImageAdapter.cs
- OleDbDataReader.cs
- HashMembershipCondition.cs