One popular open source library that provides faster hashing for strings than GetHashCode()
is CityHash. CityHash is a fast non-cryptographic hash function that produces well-distributed 64-bit hashes for strings.
You can use the CityHash.Net
NuGet package to add CityHash to your C# project. Here's an example of how to use it:
main.cs128 chars5 lines
In this example, we first import the Google.CityHash
namespace. We then define an example string and call the CityHash64
method to get the 64-bit hash code for the string.
Note that CityHash is not a drop-in replacement for GetHashCode()
. It is designed to provide faster hash codes for strings specifically and may not work as well for other types of objects.
gistlibby LogSnag