cocowalla / wyhash-dotnet

Zero-allocation C# implementation of Wang Yi's wyhash hash algorithm and wyrand PRNG
Apache License 2.0
55 stars 3 forks source link

Added static helpers for span based arguments. #3

Closed azhmur closed 5 years ago

azhmur commented 5 years ago

I have added Span version of static helper methods with string support.

cocowalla commented 5 years ago

Thanks for the PR!

You know, it always annoys me when libraries don't provide Span-based APIs, forcing me to cast to a byte array, so I'm not sure why I didn't do this sooner :grin:

I'll try to take a closer look within the next few days and get this merged and packaged :thumbsup:

cocowalla commented 5 years ago

@azhmur hi, sorry it's taken me so long to get round to reviewing this!

.NET Core added Span-based overloads to HashAlgorithm a while back, and I was wondering what you thought about making some changes to implement the Span-based TryComputeHash, HashCore and TryHashFinal methods, then restructuring your static helpers if needed?

Some test coverage of the Span-based overloads would also be great if you get a chance, but I don't mind adding it if not 👍

azhmur commented 5 years ago

I made some improvements, but supporting both old and new HashAlgorithm features seems not very convinient. OOP works really bad in such cases. I have to change HashSize override to use of protected member, and other inherited members (like HashValue and State) also should be used. Like for example right now after WyHash64.HashCore called HashAlgorithm.Hash/HashValue are empty. I don't think it should be supported.

cocowalla commented 5 years ago

@azhmur thanks for this, I've merged it and published a new NuGet package!