Replies: 3 comments 1 reply
-
Consider using XxHash3, we might even use it as a default String.GetHashCode algorithm in future (#85206) |
Beta Was this translation helpful? Give feedback.
0 replies
-
I just found XxHash in System.IO.Hashing namespace. Is this the right thing to use? |
Beta Was this translation helpful? Give feedback.
0 replies
-
If you want the same hashes as are produced by System.String; I believe they get exposed via |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am writing a Specialized Dictionary class for string values where the lookup is done by a char sequence. This could be any string,
ReadOnlySpan<char>
,ReadOnlyMemory<char>
,ReadOnlySequence<char>
. The goal is to retrieve a string that is equivalent to the input without allocations or create it when it doesn't exist. I know that we have aReadOnlySpan<char>
overload ofstring.GetHashCode
but none forReadOnlySequence<char>
.To make it work with
ReadOnlySequence<char>
there are following possibilities I could think of so far:FirstSpan
property with theGetHashCode
overload or if it is made of multiple segments copy the data into a stack allocated buffer and pass this span intoGetHashCode
. This is almost optimal. Only in the case of multiple segments we need a seemingly unnecessary data copy.HashCode
struct to produce hashes in every case. In this case I am not sure if the resulting hashes would be as good as the ones produced instring.GetHashCode
with the Marvin algorithm. It would look something like this:So what I am looking for is a .NET built in way to produce
string.GetHashCode
equivalent hash fromReadOnlySequence<char>
without making a copy of the sequence when it is made of multiple segments.Beta Was this translation helpful? Give feedback.
All reactions