Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use string.GetHashCode in ROM #191

Closed
Shane32 opened this issue Jan 14, 2022 · 6 comments · Fixed by #203
Closed

Use string.GetHashCode in ROM #191

Shane32 opened this issue Jan 14, 2022 · 6 comments · Fixed by #203
Milestone

Comments

@Shane32
Copy link
Member Author

Shane32 commented Jan 17, 2022

MemoryExtensions.Equals just calls SequenceEqual, so no need to use that.

@Shane32
Copy link
Member Author

Shane32 commented Jan 17, 2022

However, the GetHashCode method looks to be extremely optimized and a good hash. See this "Marvin" class which is used by the method:

https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Marvin.cs

@sungam3r sungam3r added this to the 8.0 milestone Jan 17, 2022
@Shane32 Shane32 changed the title Use MemoryExtensions.Equals and string.GetHashCode in ROM Use string.GetHashCode in ROM Jan 20, 2022
@sungam3r
Copy link
Member

As I said it does not work. See MemoryTests.GetHashCode_Issue . Both net5/net6 tests failed. Such implementation of hash is simply not suitable for our purposes.
"abcabc".AsMemory().Slice(0, 3).GetHashCode() should be equal to "abcabc".AsMemory().Slice(3, 3).GetHashCode() Otherwise, all dictionaries with ROM keys in GraphQL.NET are stopped working correctly.

@sungam3r
Copy link
Member

See #203

@Shane32
Copy link
Member Author

Shane32 commented Jan 22, 2022

As I said it does not work. See MemoryTests.GetHashCode_Issue . Both net5/net6 tests failed. Such implementation of hash is simply not suitable for our purposes. "abcabc".AsMemory().Slice(0, 3).GetHashCode() should be equal to "abcabc".AsMemory().Slice(3, 3).GetHashCode() Otherwise, all dictionaries with ROM keys in GraphQL.NET are stopped working correctly.

I understand. The suggestion here is to use string.GetHashCode, not ReadOnlyMemory.GetHashCode. It is only available on .NET 6.

string.GetHashCode("abcabc".AsMemory().Slice(0, 3).Span) equals string.GetHashCode("abcabc".AsMemory().Slice(3, 3).Span)

@sungam3r
Copy link
Member

🤦 done

@sungam3r sungam3r linked a pull request Jan 22, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants